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_encoder.h
1#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_
2#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_
3
4#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT
5#include <sourcemeta/jsonbinpack/runtime_export.h>
6#endif
7
8#include <sourcemeta/jsonbinpack/runtime_encoder_cache.h>
9#include <sourcemeta/jsonbinpack/runtime_encoding.h>
10#include <sourcemeta/jsonbinpack/runtime_output_stream.h>
11
12#include <sourcemeta/core/json.h>
13
14namespace sourcemeta::jsonbinpack {
15
17class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT Encoder : private OutputStream {
18public:
19 Encoder(Stream &output);
20 auto write(const sourcemeta::core::JSON &document, const Encoding &encoding)
21 -> void;
22
23// The methods that implement individual encodings as considered private
24#ifndef DOXYGEN
25// The encoding names are the ones the JSON BinPack specification defines, so
26// they keep their casing rather than following the C++ naming convention
27// NOLINTBEGIN(readability-identifier-naming)
28#define DECLARE_ENCODING(name) \
29 auto name(const sourcemeta::core::JSON &document, const name &) -> void;
30
31 // Integer
32 DECLARE_ENCODING(BOUNDED_MULTIPLE_8BITS_ENUM_FIXED)
33 DECLARE_ENCODING(FLOOR_MULTIPLE_ENUM_VARINT)
34 DECLARE_ENCODING(ROOF_MULTIPLE_MIRROR_ENUM_VARINT)
35 DECLARE_ENCODING(ARBITRARY_MULTIPLE_ZIGZAG_VARINT)
36
37 // Number
38 DECLARE_ENCODING(DOUBLE_VARINT_TUPLE)
39 DECLARE_ENCODING(NUMBER_VARINT_TUPLE)
40
41 // Any
42 DECLARE_ENCODING(BYTE_CHOICE_INDEX)
43 DECLARE_ENCODING(LARGE_CHOICE_INDEX)
44 DECLARE_ENCODING(TOP_LEVEL_BYTE_CHOICE_INDEX)
45 DECLARE_ENCODING(CONST_NONE)
46 DECLARE_ENCODING(ANY_PACKED_TYPE_TAG_BYTE_PREFIX)
47
48 // String
49 DECLARE_ENCODING(UTF8_STRING_NO_LENGTH)
53 DECLARE_ENCODING(RFC3339_DATE_INTEGER_TRIPLET)
55 // TODO: Implement STRING_BROTLI encoding
56 // TODO: Implement STRING_DICTIONARY_COMPRESSOR encoding
57 // TODO: Implement STRING_UNBOUNDED_SCOPED_PREFIX_LENGTH encoding
58 // TODO: Implement URL_PROTOCOL_HOST_REST encoding
59
60 // Array
61 DECLARE_ENCODING(FIXED_TYPED_ARRAY)
62 DECLARE_ENCODING(BOUNDED_8BITS_TYPED_ARRAY)
63 DECLARE_ENCODING(FLOOR_TYPED_ARRAY)
64 DECLARE_ENCODING(ROOF_TYPED_ARRAY)
65
66 // Object
67 DECLARE_ENCODING(FIXED_TYPED_ARBITRARY_OBJECT)
68 DECLARE_ENCODING(VARINT_TYPED_ARBITRARY_OBJECT)
69
70#undef DECLARE_ENCODING
71// NOLINTEND(readability-identifier-naming)
72#endif
73
74private:
75 Cache cache_;
76};
77
78} // namespace sourcemeta::jsonbinpack
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 > 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