This commit is contained in:
nlohmann
2026-09-27 21:37:45 +00:00
parent 0cd46537bb
commit be6bcd470b
322 changed files with 1586 additions and 534 deletions

File diff suppressed because one or more lines are too long

View File

@@ -174,6 +174,40 @@ Note that subtype (42) is **not** serialized and that BJData has **no binary typ
}
```
### BON8
[BON8](https://json.nlohmann.me/features/binary_formats/bon8/index.md) neither supports binary values nor subtypes. The library serializes binary values as an array of integers.
Example
Code:
```
// create a binary value of subtype 42 (will be ignored in BON8)
json j;
j["binary"] = json::binary({0xCA, 0xFE, 0xBA, 0xBE}, 42);
// convert to BON8
auto v = json::to_bon8(j);
```
`v` is a `std::vector<std::uint8_t>` with the following 16 elements:
```
0x87 // object with 1 member
0x62 0x69 0x6E 0x61 0x72 0x79 // "binary"
0x84 // array with 4 elements
0xC3 0x22 0xC3 0x56 0xC3 0x12 0xC3 0x16 // content (each byte as a 2-byte integer)
```
Note that the subtype is lost, and deserializing `v` would yield the following value:
```
{
"binary": [202, 254, 186, 190]
}
```
### BSON
[BSON](https://json.nlohmann.me/features/binary_formats/bson/index.md) supports binary values and subtypes. If a subtype is given, it is used and added as an unsigned 8-bit integer. If no subtype is given, the generic binary subtype 0x00 is used.