Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
binpack_decoder.h
1#ifndef SOURCEMETA_BLAZE_BINPACK_DECODER_H_
2#define SOURCEMETA_BLAZE_BINPACK_DECODER_H_
3
4#ifndef SOURCEMETA_BLAZE_BINPACK_EXPORT
5#include <sourcemeta/blaze/binpack_export.h>
6#endif
7
8#include <sourcemeta/blaze/binpack_encoding.h>
9
10#include <sourcemeta/core/io.h>
11#include <sourcemeta/core/json.h>
12
13#include <istream> // std::basic_istream
14
15namespace sourcemeta::blaze {
16
18class SOURCEMETA_BLAZE_BINPACK_EXPORT BinPackDecoder
19 : private sourcemeta::core::BinaryReader {
20public:
21 using Stream = std::basic_istream<sourcemeta::core::JSON::Char,
22 sourcemeta::core::JSON::CharTraits>;
23 BinPackDecoder(Stream &input);
24 auto read(const BinPackEncoding &encoding) -> sourcemeta::core::JSON;
25
26// The methods that implement individual encodings as considered private
27#ifndef DOXYGEN
28// The encoding names are the ones the JSON BinPack specification defines, so
29// they keep their casing rather than following the C++ naming convention
30// NOLINTBEGIN(readability-identifier-naming)
31#define DECLARE_ENCODING(name) \
32 auto name(const name &) -> sourcemeta::core::JSON;
33
34 // Integer
35 DECLARE_ENCODING(BOUNDED_MULTIPLE_8BITS_ENUM_FIXED)
36 DECLARE_ENCODING(FLOOR_MULTIPLE_ENUM_VARINT)
37 DECLARE_ENCODING(ROOF_MULTIPLE_MIRROR_ENUM_VARINT)
38 DECLARE_ENCODING(ARBITRARY_MULTIPLE_ZIGZAG_VARINT)
39
40 // Number
41 DECLARE_ENCODING(DOUBLE_VARINT_TUPLE)
42 DECLARE_ENCODING(NUMBER_VARINT_TUPLE)
43
44 // Any
45 DECLARE_ENCODING(BYTE_CHOICE_INDEX)
46 DECLARE_ENCODING(LARGE_CHOICE_INDEX)
47 DECLARE_ENCODING(TOP_LEVEL_BYTE_CHOICE_INDEX)
48 DECLARE_ENCODING(CONST_NONE)
49 DECLARE_ENCODING(ANY_PACKED_TYPE_TAG_BYTE_PREFIX)
50
51 // String
52 DECLARE_ENCODING(UTF8_STRING_NO_LENGTH)
56 DECLARE_ENCODING(RFC3339_DATE_INTEGER_TRIPLET)
58 // TODO: Implement STRING_BROTLI encoding
59 // TODO: Implement STRING_DICTIONARY_COMPRESSOR encoding
60 // TODO: Implement STRING_UNBOUNDED_SCOPED_PREFIX_LENGTH encoding
61 // TODO: Implement URL_PROTOCOL_HOST_REST encoding
62
63 // Array
64 DECLARE_ENCODING(FIXED_TYPED_ARRAY)
65 DECLARE_ENCODING(BOUNDED_8BITS_TYPED_ARRAY)
66 DECLARE_ENCODING(FLOOR_TYPED_ARRAY)
67 DECLARE_ENCODING(ROOF_TYPED_ARRAY)
68
69 // Object
70 DECLARE_ENCODING(FIXED_TYPED_ARBITRARY_OBJECT)
71 DECLARE_ENCODING(VARINT_TYPED_ARBITRARY_OBJECT)
72
73#undef DECLARE_ENCODING
74// NOLINTEND(readability-identifier-naming)
75#endif
76};
77
78} // namespace sourcemeta::blaze
79
80#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 > BinPackEncoding
Definition binpack_encoding.h:49
The encoding consists of an index to the enumeration choices encoded as an 8-bit fixed-length unsigne...
Definition binpack_encoding.h:365
The constant input value is not encoded.
Definition binpack_encoding.h:460
The encoding consists of an index to the enumeration choices encoded as a Base-128 64-bit Little Endi...
Definition binpack_encoding.h:399
If the input value corresponds to the index 0 to the enumeration choices, the encoding stores no data...
Definition binpack_encoding.h:438
The encoding consists of the length of the array minus minimum encoded as an 8-bit fixed-length unsig...
Definition binpack_encoding.h:912
The encoding consists of the elements of the fixed array encoded in order. The encoding of the elemen...
Definition binpack_encoding.h:863
The encoding consists of the length of the array minus minimum encoded as a Base-128 64-bit Little En...
Definition binpack_encoding.h:960
The encoding consists of maximum minus the length of the array encoded as a Base-128 64-bit Little En...
Definition binpack_encoding.h:1005
The encoding consists of the the integer value divided by the multiplier encoded as a ZigZag-encoded ...
Definition binpack_encoding.h:218
The encoding consists of the integer value divided by the multiplier, minus the ceil of minimum divid...
Definition binpack_encoding.h:104
The encoding consists of the integer value divided by the multiplier, minus the ceil of minimum divid...
Definition binpack_encoding.h:145
The encoding consists of the floor of maximum divided by the multiplier, minus the integer value divi...
Definition binpack_encoding.h:183
The encoding consists of a sequence of two integers: The signed integer that results from concatenati...
Definition binpack_encoding.h:268
The encoding consists of a sequence of two integers. The first is the signed coefficient of the numbe...
Definition binpack_encoding.h:319
The encoding consists of each pair encoded as the key followed by the value according to key_encoding...
Definition binpack_encoding.h:1062
The encoding consists of the number of key-value pairs in the input object as a Base-128 64-bit Littl...
Definition binpack_encoding.h:1108
The encoding consists of the byte-length of the string minus minimum plus 1 as an 8-bit fixed-length ...
Definition binpack_encoding.h:732
The encoding consists of the byte-length of the string minus minimum plus 1 as a Base-128 64-bit Litt...
Definition binpack_encoding.h:618
The encoding consists of the byte-length of the string plus 1 as a Base-128 64-bit Little Endian vari...
Definition binpack_encoding.h:820
The encoding consists of an implementation of RFC3339 date expressions as the sequence of 3 integers:...
Definition binpack_encoding.h:775
The encoding consists of maximum minus the byte-length of the string plus 1 as a Base-128 64-bit Litt...
Definition binpack_encoding.h:672
The encoding consist in the UTF-8 encoding of the input string.
Definition binpack_encoding.h:564