• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::binary_t
2
3```cpp
4using binary_t = byte_container_with_subtype<BinaryType>;
5```
6
7This type is a type designed to carry binary data that appears in various serialized formats, such as CBOR's Major Type
82, MessagePack's bin, and BSON's generic binary subtype. This type is NOT a part of standard JSON and exists solely for
9compatibility with these binary types. As such, it is simply defined as an ordered sequence of zero or more byte values.
10
11Additionally, as an implementation detail, the subtype of the binary data is carried around as a `std::uint8_t`, which
12is compatible with both of the binary data formats that use binary subtyping, (though the specific numbering is
13incompatible with each other, and it is up to the user to translate between them).
14
15[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
16> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers
17> (major type 0).
18
19[MessagePack's documentation on the bin type
20family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
21> Bin format family stores an byte array in 2, 3, or 5 bytes of extra bytes in addition to the size of the byte array.
22
23[BSON's specifications](http://bsonspec.org/spec.html) describe several binary types; however, this type is intended to
24represent the generic binary type which has the description:
25> Generic binary subtype - This is the most commonly used binary subtype and should be the 'default' for drivers and
26> tools.
27
28None of these impose any limitations on the internal representation other than the basic unit of storage be some type of
29array whose parts are decomposable into bytes.
30
31The default representation of this binary format is a `#!cpp std::vector<std::uint8_t>`, which is a very common way to
32represent a byte array in modern C++.
33
34## Template parameters
35
36`BinaryType`
37:   container type to store arrays
38
39## Notes
40
41#### Default type
42
43The default values for `BinaryType` is `#!cpp std::vector<std::uint8_t>`.
44
45#### Storage
46
47Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the
48type `#!cpp binary_t*` must be dereferenced.
49
50#### Notes on subtypes
51
52- CBOR
53    - Binary values are represented as byte strings. Subtypes are written as tags.
54
55- MessagePack
56    - If a subtype is given and the binary array contains exactly 1, 2, 4, 8, or 16 elements, the fixext family (fixext1,
57      fixext2, fixext4, fixext8) is used. For other sizes, the ext family (ext8, ext16, ext32) is used. The subtype is
58      then added as singed 8-bit integer.
59    - If no subtype is given, the bin family (bin8, bin16, bin32) is used.
60
61- BSON
62    - If a subtype is given, it is used and added as unsigned 8-bit integer.
63    - If no subtype is given, the generic binary subtype 0x00 is used.
64
65## Version history
66
67- Added in version 3.8.0. Changed type of subtype to `std::uint64_t` in version 3.10.0.
68