• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::binary
2
3```cpp
4// (1)
5static basic_json binary(const typename binary_t::container_type& init);
6static basic_json binary(typename binary_t::container_type&& init);
7
8// (2)
9static basic_json binary(const typename binary_t::container_type& init,
10                         std::uint8_t subtype);
11static basic_json binary(typename binary_t::container_type&& init,
12                         std::uint8_t subtype);
13```
14
151. Creates a JSON binary array value from a given binary container.
162. Creates a JSON binary array value from a given binary container with subtype.
17
18Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to
19create a value for serialization to those formats.
20
21## Parameters
22
23`init` (in)
24:   container containing bytes to use as binary type
25
26`subtype` (in)
27:   subtype to use in CBOR, MessagePack, and BSON
28
29## Return value
30
31JSON binary array value
32
33## Exception safety
34
35Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
36
37## Complexity
38
39Linear in the size of `init`; constant for `typename binary_t::container_type&& init` versions.
40
41## Notes
42
43Note, this function exists because of the difficulty in correctly specifying the correct template overload in the
44standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a `std::vector`. Because
45JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization
46of a binary array type, for backwards compatibility and so it does not happen on accident.
47
48## Version history
49
50- Added in version 3.8.0.
51