JSON BinPack 0.0.1
A space-efficient open-source binary JSON serialization format based on JSON Schema with both schema-driven and schema-less support.
Loading...
Searching...
No Matches
runtime_decoder.h
1#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_
2#define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_
3
4#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT
5#include <sourcemeta/jsonbinpack/runtime_export.h>
6#endif
7
8#include <sourcemeta/jsonbinpack/runtime_encoding.h>
9#include <sourcemeta/jsonbinpack/runtime_input_stream.h>
10
11#include <sourcemeta/core/json.h>
12
13namespace sourcemeta::jsonbinpack {
14
16class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT Decoder : private InputStream {
17public:
18 Decoder(Stream &input);
19 auto read(const Encoding &encoding) -> sourcemeta::core::JSON;
20
21// The methods that implement individual encodings as considered private
22#ifndef DOXYGEN
23// The encoding names are the ones the JSON BinPack specification defines, so
24// they keep their casing rather than following the C++ naming convention
25// NOLINTBEGIN(readability-identifier-naming)
26#define DECLARE_ENCODING(name) \
27 auto name(const name &) -> sourcemeta::core::JSON;
28
29 // Integer
30 DECLARE_ENCODING(BOUNDED_MULTIPLE_8BITS_ENUM_FIXED)
31 DECLARE_ENCODING(FLOOR_MULTIPLE_ENUM_VARINT)
32 DECLARE_ENCODING(ROOF_MULTIPLE_MIRROR_ENUM_VARINT)
33 DECLARE_ENCODING(ARBITRARY_MULTIPLE_ZIGZAG_VARINT)
34
35 // Number
36 DECLARE_ENCODING(DOUBLE_VARINT_TUPLE)
37 DECLARE_ENCODING(NUMBER_VARINT_TUPLE)
38
39 // Any
40 DECLARE_ENCODING(BYTE_CHOICE_INDEX)
41 DECLARE_ENCODING(LARGE_CHOICE_INDEX)
42 DECLARE_ENCODING(TOP_LEVEL_BYTE_CHOICE_INDEX)
43 DECLARE_ENCODING(CONST_NONE)
44 DECLARE_ENCODING(ANY_PACKED_TYPE_TAG_BYTE_PREFIX)
45
46 // String
47 DECLARE_ENCODING(UTF8_STRING_NO_LENGTH)
51 DECLARE_ENCODING(RFC3339_DATE_INTEGER_TRIPLET)
53 // TODO: Implement STRING_BROTLI encoding
54 // TODO: Implement STRING_DICTIONARY_COMPRESSOR encoding
55 // TODO: Implement STRING_UNBOUNDED_SCOPED_PREFIX_LENGTH encoding
56 // TODO: Implement URL_PROTOCOL_HOST_REST encoding
57
58 // Array
59 DECLARE_ENCODING(FIXED_TYPED_ARRAY)
60 DECLARE_ENCODING(BOUNDED_8BITS_TYPED_ARRAY)
61 DECLARE_ENCODING(FLOOR_TYPED_ARRAY)
62 DECLARE_ENCODING(ROOF_TYPED_ARRAY)
63
64 // Object
65 DECLARE_ENCODING(FIXED_TYPED_ARBITRARY_OBJECT)
66 DECLARE_ENCODING(VARINT_TYPED_ARBITRARY_OBJECT)
67
68#undef DECLARE_ENCODING
69// NOLINTEND(readability-identifier-naming)
70#endif
71};
72
73} // namespace sourcemeta::jsonbinpack
74
75#endif
std::variant< BOUNDED_MULTIPLE_8BITS_ENUM_FIXED, FLOOR_MULTIPLE_ENUM_VARINT, ROOF_MULTIPLE_MIRROR_ENUM_VARINT, ARBITRARY_MULTIPLE_ZIGZAG_VARINT, DOUBLE_VARINT_TUPLE, BYTE_CHOICE_INDEX, LARGE_CHOICE_INDEX, TOP_LEVEL_BYTE_CHOICE_INDEX, CONST_NONE, ANY_PACKED_TYPE_TAG_BYTE_PREFIX, UTF8_STRING_NO_LENGTH, FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED, ROOF_VARINT_PREFIX_UTF8_STRING_SHARED, BOUNDED_8BIT_PREFIX_UTF8_STRING_SHARED, RFC3339_DATE_INTEGER_TRIPLET, PREFIX_VARINT_LENGTH_STRING_SHARED, FIXED_TYPED_ARRAY, BOUNDED_8BITS_TYPED_ARRAY, FLOOR_TYPED_ARRAY, ROOF_TYPED_ARRAY, FIXED_TYPED_ARBITRARY_OBJECT, VARINT_TYPED_ARBITRARY_OBJECT, NUMBER_VARINT_TUPLE > Encoding
Definition runtime_encoding.h:49
The encoding consists of the the integer value divided by the multiplier encoded as a ZigZag-encoded ...
Definition runtime_encoding.h:218
The encoding consists of the byte-length of the string minus minimum plus 1 as an 8-bit fixed-length ...
Definition runtime_encoding.h:732
The encoding consists of the length of the array minus minimum encoded as an 8-bit fixed-length unsig...
Definition runtime_encoding.h:912
The encoding consists of the integer value divided by the multiplier, minus the ceil of minimum divid...
Definition runtime_encoding.h:104
The encoding consists of an index to the enumeration choices encoded as an 8-bit fixed-length unsigne...
Definition runtime_encoding.h:365
The constant input value is not encoded.
Definition runtime_encoding.h:460
The encoding consists of a sequence of two integers: The signed integer that results from concatenati...
Definition runtime_encoding.h:268
The encoding consists of each pair encoded as the key followed by the value according to key_encoding...
Definition runtime_encoding.h:1062
The encoding consists of the elements of the fixed array encoded in order. The encoding of the elemen...
Definition runtime_encoding.h:863
The encoding consists of the integer value divided by the multiplier, minus the ceil of minimum divid...
Definition runtime_encoding.h:145
The encoding consists of the length of the array minus minimum encoded as a Base-128 64-bit Little En...
Definition runtime_encoding.h:960
The encoding consists of the byte-length of the string minus minimum plus 1 as a Base-128 64-bit Litt...
Definition runtime_encoding.h:618
The encoding consists of an index to the enumeration choices encoded as a Base-128 64-bit Little Endi...
Definition runtime_encoding.h:399
The encoding consists of a sequence of two integers. The first is the signed coefficient of the numbe...
Definition runtime_encoding.h:319
The encoding consists of the byte-length of the string plus 1 as a Base-128 64-bit Little Endian vari...
Definition runtime_encoding.h:820
The encoding consists of an implementation of RFC3339 date expressions as the sequence of 3 integers:...
Definition runtime_encoding.h:775
The encoding consists of the floor of maximum divided by the multiplier, minus the integer value divi...
Definition runtime_encoding.h:183
The encoding consists of maximum minus the length of the array encoded as a Base-128 64-bit Little En...
Definition runtime_encoding.h:1005
The encoding consists of maximum minus the byte-length of the string plus 1 as a Base-128 64-bit Litt...
Definition runtime_encoding.h:672
If the input value corresponds to the index 0 to the enumeration choices, the encoding stores no data...
Definition runtime_encoding.h:438
The encoding consist in the UTF-8 encoding of the input string.
Definition runtime_encoding.h:564
The encoding consists of the number of key-value pairs in the input object as a Base-128 64-bit Littl...
Definition runtime_encoding.h:1108