Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
binpack_encoder.h
1#ifndef SOURCEMETA_BLAZE_BINPACK_ENCODER_H_
2#define SOURCEMETA_BLAZE_BINPACK_ENCODER_H_
3
4#ifndef SOURCEMETA_BLAZE_BINPACK_EXPORT
5#include <sourcemeta/blaze/binpack_export.h>
6#endif
7
8#include <sourcemeta/blaze/binpack_encoder_cache.h>
9#include <sourcemeta/blaze/binpack_encoding.h>
10
11#include <sourcemeta/core/io.h>
12#include <sourcemeta/core/json.h>
13
14#include <ostream> // std::basic_ostream
15
16namespace sourcemeta::blaze {
17
19class SOURCEMETA_BLAZE_BINPACK_EXPORT BinPackEncoder
20 : private sourcemeta::core::BinaryWriter {
21public:
22 using Stream = std::basic_ostream<sourcemeta::core::JSON::Char,
23 sourcemeta::core::JSON::CharTraits>;
24 BinPackEncoder(Stream &output);
25 auto write(const sourcemeta::core::JSON &document,
26 const BinPackEncoding &encoding) -> void;
27
28// The methods that implement individual encodings as considered private
29#ifndef DOXYGEN
30// The encoding names are the ones the JSON BinPack specification defines, so
31// they keep their casing rather than following the C++ naming convention
32// NOLINTBEGIN(readability-identifier-naming)
33#define DECLARE_ENCODING(name) \
34 auto name(const sourcemeta::core::JSON &document, const name &) -> void;
35
36 // Integer
37 DECLARE_ENCODING(BOUNDED_MULTIPLE_8BITS_ENUM_FIXED)
38 DECLARE_ENCODING(FLOOR_MULTIPLE_ENUM_VARINT)
39 DECLARE_ENCODING(ROOF_MULTIPLE_MIRROR_ENUM_VARINT)
40 DECLARE_ENCODING(ARBITRARY_MULTIPLE_ZIGZAG_VARINT)
41
42 // Number
43 DECLARE_ENCODING(DOUBLE_VARINT_TUPLE)
44 DECLARE_ENCODING(NUMBER_VARINT_TUPLE)
45
46 // Any
47 DECLARE_ENCODING(BYTE_CHOICE_INDEX)
48 DECLARE_ENCODING(LARGE_CHOICE_INDEX)
49 DECLARE_ENCODING(TOP_LEVEL_BYTE_CHOICE_INDEX)
50 DECLARE_ENCODING(CONST_NONE)
51 DECLARE_ENCODING(ANY_PACKED_TYPE_TAG_BYTE_PREFIX)
52
53 // String
54 DECLARE_ENCODING(UTF8_STRING_NO_LENGTH)
58 DECLARE_ENCODING(RFC3339_DATE_INTEGER_TRIPLET)
60 // TODO: Implement STRING_BROTLI encoding
61 // TODO: Implement STRING_DICTIONARY_COMPRESSOR encoding
62 // TODO: Implement STRING_UNBOUNDED_SCOPED_PREFIX_LENGTH encoding
63 // TODO: Implement URL_PROTOCOL_HOST_REST encoding
64
65 // Array
66 DECLARE_ENCODING(FIXED_TYPED_ARRAY)
67 DECLARE_ENCODING(BOUNDED_8BITS_TYPED_ARRAY)
68 DECLARE_ENCODING(FLOOR_TYPED_ARRAY)
69 DECLARE_ENCODING(ROOF_TYPED_ARRAY)
70
71 // Object
72 DECLARE_ENCODING(FIXED_TYPED_ARBITRARY_OBJECT)
73 DECLARE_ENCODING(VARINT_TYPED_ARBITRARY_OBJECT)
74
75#undef DECLARE_ENCODING
76// NOLINTEND(readability-identifier-naming)
77#endif
78
79private:
80 BinPackCache cache_;
81};
82
83} // namespace sourcemeta::blaze
84
85#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