]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/doc/mkdocs/docs/api/basic_json/to_ubjson.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_ubjson.md
1 # <small>nlohmann::basic_json::</small>to_ubjson
2
3 ```cpp
4 // (1)
5 static std::vector<std::uint8_t> to_ubjson(const basic_json& j,
6 const bool use_size = false,
7 const bool use_type = false);
8
9 // (2)
10 static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
11 const bool use_size = false, const bool use_type = false);
12 static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
13 const bool use_size = false, const bool use_type = false);
14 ```
15
16 Serializes a given JSON value `j` to a byte vector using the UBJSON (Universal Binary JSON) serialization format. UBJSON
17 aims to be more compact than JSON itself, yet more efficient to parse.
18
19 1. Returns a byte vector containing the UBJSON serialization.
20 2. Writes the UBJSON serialization to an output adapter.
21
22 The exact mapping and its limitations is described on a [dedicated page](../../features/binary_formats/ubjson.md).
23
24 ## Parameters
25
26 `j` (in)
27 : JSON value to serialize
28
29 `o` (in)
30 : output adapter to write serialization to
31
32 `use_size` (in)
33 : whether to add size annotations to container types; optional, `#!cpp false` by default.
34
35 `use_type` (in)
36 : whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
37 `#!cpp false` by default.
38
39 ## Return value
40
41 1. UBJSON serialization as byte vector
42 2. /
43
44 ## Exception safety
45
46 Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
47
48 ## Complexity
49
50 Linear in the size of the JSON value `j`.
51
52 ## Examples
53
54 ??? example
55
56 The example shows the serialization of a JSON value to a byte vector in UBJSON format.
57
58 ```cpp
59 --8<-- "examples/to_ubjson.cpp"
60 ```
61
62 Output:
63
64 ```json
65 --8<-- "examples/to_ubjson.output"
66 ```
67
68 ## Version history
69
70 - Added in version 3.1.0.