]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/doc/mkdocs/docs/api/basic_json/to_cbor.md
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / nlohmann-json / doc / mkdocs / docs / api / basic_json / to_cbor.md
1 # <small>nlohmann::basic_json::</small>to_cbor
2
3 ```cpp
4 // (1)
5 static std::vector<std::uint8_t> to_cbor(const basic_json& j);
6
7 // (2)
8 static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o);
9 static void to_cbor(const basic_json& j, detail::output_adapter<char> o);
10 ```
11
12 Serializes a given JSON value `j` to a byte vector using the CBOR (Concise Binary Object Representation) serialization
13 format. CBOR is a binary serialization format which aims to be more compact than JSON itself, yet more efficient to
14 parse.
15
16 1. Returns a byte vector containing the CBOR serialization.
17 2. Writes the CBOR serialization to an output adapter.
18
19 The exact mapping and its limitations is described on a [dedicated page](../../features/binary_formats/cbor.md).
20
21 ## Parameters
22
23 `j` (in)
24 : JSON value to serialize
25
26 `o` (in)
27 : output adapter to write serialization to
28
29 ## Return value
30
31 1. CBOR serialization as byte vector
32 2. /
33
34 ## Exception safety
35
36 Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
37
38 ## Complexity
39
40 Linear in the size of the JSON value `j`.
41
42 ## Examples
43
44 ??? example
45
46 The example shows the serialization of a JSON value to a byte vector in CBOR format.
47
48 ```cpp
49 --8<-- "examples/to_cbor.cpp"
50 ```
51
52 Output:
53
54 ```json
55 --8<-- "examples/to_cbor.output"
56 ```
57
58 ## Version history
59
60 - Added in version 2.0.9.
61 - Compact representation of floating-point numbers added in version 3.8.0.