Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oatpp/oatpp-bob
Object-Mapper for binary serialization/deserialization
https://github.com/oatpp/oatpp-bob
binary-json bob oatpp object-mapper
Last synced: about 2 months ago
JSON representation
Object-Mapper for binary serialization/deserialization
- Host: GitHub
- URL: https://github.com/oatpp/oatpp-bob
- Owner: oatpp
- License: apache-2.0
- Created: 2023-01-18T23:49:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-30T11:09:24.000Z (7 months ago)
- Last Synced: 2024-10-29T22:48:56.314Z (2 months ago)
- Topics: binary-json, bob, oatpp, object-mapper
- Language: C++
- Homepage: https://oatpp.io/
- Size: 45.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oatpp-bob [![Build Status](https://dev.azure.com/lganzzzo/lganzzzo/_apis/build/status/oatpp.oatpp-bob?branchName=main)](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=33&branchName=main)
*(oatpp-BinaryOBject - BOB)*
Object-Mapper for binary serialization/deserialization.## BOB Format
BOB is basically a regular JSON in which values are written in binary format.
It supports JSON data types only - [`object`, `array`, `string`, `number`(ints and floats), `true`, `false`, `null`].
Thus, JSON and oatpp-BOB are 100% interchangeable.### Format Structure
BOB uses big-endian format (network byte order) to store binary values.
| type | description | format |
|-----------|--------------------------------------------|---------------------------|
| `int1` | 1 - byte signed integer | `'1'<1-byte value>` |
| `int2` | 2 - byte signed integer | `'2'<2-byte value>` |
| `int4` | 4 - byte signed integer | `'4'<4-byte value>` |
| `int8` | 8 - byte signed integer | `'8'<8-byte value>` |
| `uint1` | 1 - byte unsigned integer | `'b'<1-byte value>` |
| `uint2` | 2 - byte unsigned integer | `'i'<2-byte value>` |
| `uint4` | 4 - byte unsigned integer | `'I'<4-byte value>` |
| `uint8` | 8 - byte unsigned integer | `'L'<8-byte value>` |
| `float4` | 4 - byte float | `'f'<4-byte value>` |
| `float8` | 8 - byte float | `'d'<8-byte value>` |
| `true` | boolean true | `'+'` |
| `false` | boolean false | `'-'` |
| `null` | null value | `'0'` |
| `string1` | string with max length of `2^8 - 1` chars | `'s'<1-byte size>` |
| `string2` | string with max length of `2^16 - 1` chars | `'S'<2-byte size>` |
| `string4` | string with max length of `2^32 - 1` chars | `'$'<4-byte size>` |
| `object` | sequence of key-value pairs | `'{'')'` |
| `array` | sequence of values | `'['')'` |- **Note**: `` pairs in object are stored without any delimiters.
Each key is encoded as a null-terminated string.
- **Note**: `` in array are stored without any delimiters. Each value begins with the type-designating byte (char).Example - JSONs and their equivalent BOBs
```
json = '{"key":"value"}'; // size: 15 bytes
bob = "{key\0s\7value)"; // size: 13 bytes
``````
json = '{"key1":"value1","key2":5}'; // size: 26 bytes
bob = "{key1\0s\6value1key2\0b\5)"; // size: 22 bytes
```Examples in C++
```cpp
oatpp::String bob("{key\0s\5value)", 13); // <- You have to provide length explicitly because of the '\0' char in the middle of string
auto obj = bobMapper.readFromString(bob);
auto json = jsonMapper.writeToString(obj);
OATPP_LOGD(TAG, "json='%s'", json->c_str()) // <- json='{"key":"value"}'
``````cpp
oatpp::String bob("{key1\0s\6value1key2\0b\5)", 22); // <- You have to provide length explicitly because of the '\0' char in the middle of string
auto obj = bobMapper.readFromString(bob);
auto json = jsonMapper.writeToString(obj);
OATPP_LOGD(TAG, "json='%s'", json->c_str()) // <- json='{"key1":"value1","key2":5}'
```