|
2 | 2 |
|
3 | 3 | The [BJData format](https://neurojson.org) was derived from and improved upon |
4 | 4 | [Universal Binary JSON(UBJSON)](https://ubjson.org) specification (Draft 12). Specifically, it introduces an optimized |
5 | | -array container for efficient storage of N-dimensional packed arrays (**ND-arrays**); it also adds 4 new type markers - |
6 | | -`[u] - uint16`, `[m] - uint32`, `[M] - uint64` and `[h] - float16` - to unambiguously map common binary numeric types; |
7 | | -furthermore, it uses little-endian (LE) to store all numerics instead of big-endian (BE) as in UBJSON to avoid |
8 | | -unnecessary conversions on commonly available platforms. |
| 5 | +array container for efficient storage of N-dimensional packed arrays (**ND-arrays**); it also adds 5 new type markers - |
| 6 | +`[u] - uint16`, `[m] - uint32`, `[M] - uint64`, `[h] - float16` and `[B] - byte` - to unambiguously map common binary |
| 7 | +numeric types; furthermore, it uses little-endian (LE) to store all numerics instead of big-endian (BE) as in UBJSON to |
| 8 | +avoid unnecessary conversions on commonly available platforms. |
9 | 9 |
|
10 | 10 | Compared to other binary JSON-like formats such as MessagePack and CBOR, both BJData and UBJSON demonstrate a rare |
11 | 11 | combination of being both binary and **quasi-human-readable**. This is because all semantic elements in BJData and |
@@ -49,6 +49,7 @@ The library uses the following mapping from JSON values types to BJData types ac |
49 | 49 | | string | *with shortest length indicator* | string | `S` | |
50 | 50 | | array | *see notes on optimized format/ND-array* | array | `[` | |
51 | 51 | | object | *see notes on optimized format* | map | `{` | |
| 52 | +| binary | *see notes on binary values* | array | `[$B` | |
52 | 53 |
|
53 | 54 | !!! success "Complete mapping" |
54 | 55 |
|
@@ -128,15 +129,24 @@ The library uses the following mapping from JSON values types to BJData types ac |
128 | 129 |
|
129 | 130 | Due to diminished space saving, hampered readability, and increased security risks, in BJData, the allowed data |
130 | 131 | types following the `$` marker in an optimized array and object container are restricted to |
131 | | - **non-zero-fixed-length** data types. Therefore, the valid optimized type markers can only be one of `UiuImlMLhdDC`. |
132 | | - This also means other variable (`[{SH`) or zero-length types (`TFN`) can not be used in an optimized array or object |
133 | | - in BJData. |
| 132 | + **non-zero-fixed-length** data types. Therefore, the valid optimized type markers can only be one of |
| 133 | + `UiuImlMLhdDCB`. This also means other variable (`[{SH`) or zero-length types (`TFN`) can not be used in an |
| 134 | + optimized array or object in BJData. |
134 | 135 |
|
135 | 136 | !!! info "Binary values" |
136 | 137 |
|
137 | | - If the JSON data contains the binary type, the value stored is a list of integers, as suggested by the BJData |
138 | | - documentation. In particular, this means that the serialization and the deserialization of JSON containing binary |
139 | | - values into BJData and back will result in a different JSON object. |
| 138 | + BJData provides a dedicated `B` marker (defined in the [BJData specification (Draft 3)][BJDataBinArr]) that is used |
| 139 | + in optimized arrays to designate binary data. This means that, unlike UBJSON, binary data can be both serialized and |
| 140 | + deserialized. |
| 141 | + |
| 142 | + To preserve compatibility with BJData Draft 2, the Draft 3 optimized binary array must be explicitly enabled using |
| 143 | + the `version` parameter of [`to_bjdata`](../../api/basic_json/to_bjdata.md). |
| 144 | + |
| 145 | + In Draft2 mode (default), if the JSON data contains the binary type, the value stored as a list of integers, as |
| 146 | + suggested by the BJData documentation. In particular, this means that the serialization and the deserialization of |
| 147 | + JSON containing binary values into BJData and back will result in a different JSON object. |
| 148 | + |
| 149 | + [BJDataBinArr]: https://github.com/NeuroJSON/bjdata/blob/master/Binary_JData_Specification.md#optimized-binary-array) |
140 | 150 |
|
141 | 151 | ??? example |
142 | 152 |
|
@@ -171,11 +181,13 @@ The library maps BJData types to JSON value types as follows: |
171 | 181 | | int32 | number_integer | `l` | |
172 | 182 | | uint64 | number_unsigned | `M` | |
173 | 183 | | int64 | number_integer | `L` | |
| 184 | +| byte | number_unsigned | `B` | |
174 | 185 | | string | string | `S` | |
175 | 186 | | char | string | `C` | |
176 | 187 | | array | array (optimized values are supported) | `[` | |
177 | 188 | | ND-array | object (in JData annotated array format)|`[$.#[.`| |
178 | 189 | | object | object (optimized values are supported) | `{` | |
| 190 | +| binary | binary (strongly-typed byte array) | `[$B` | |
179 | 191 |
|
180 | 192 | !!! success "Complete mapping" |
181 | 193 |
|
|
0 commit comments