Concept: json::binary / blob
- Dominant language
- C++
- Stars
- 479
- Forks
- 110
- Avg merge
- 10d 3h
- Merged PRs (30d)
- 5
Description
Json could have a binary/blob type that can story raw memory and must/should have a conversion operator to a data type that can be represented as json. If optional that would be a string.
# Motivation:
## 1. json::value as freeform data
In a statically typed language it is often useful to still have free form data for certain things, e.g. for dumping diagnostic information or data in addition to what's typed. `json::value` does an excellent job at this, and I have used it in exactly this way.
Adding in a binary type will make this more efficient and "more correct" in that we don't need to stringify data that is by nature binary. As an example, consider the following enum:
```cpp
enum this_idea
{
great = 1,
greater,
the_greatest
};
```
This enum could be stored as a single byte, yet obviously serialized into a string for json.
## 2. other serialization format
Some issues, such as #822 and #510 have address the possibility of adding other formats, such as MsgPack & CBOR respectively. Both of those formats know of a binary type. Since they are made to lower in data, the above enum would most likely be serialized as it's binary value in cbor and msgpack.
# Rough design idea
The rough design idea is to provide a `json::binary` type that is either similar to `json::string` without the `.c_str()` or holds the raw memory as a `void*, size_t` pair.
At construction it should get assigned a tag and an optional conversion function. The tag indicates bulit-in conversions, such as are provided by [cbor](https://www.rfc-editor.org/rfc/rfc8949.html#name-tagging-of-items).
The conversion function shall be without context and thus a raw function pointer.
With other serializers boost::json can become the basis of advanced RPC libraries to compete with the big ones, such as gRPC.
Contributor guide
Assessment
This issue has not been assessed yet.