Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
Loading...
Searching...
No Matches
binpack_encoding.h
1#ifndef SOURCEMETA_BLAZE_BINPACK_ENCODING_H_
2#define SOURCEMETA_BLAZE_BINPACK_ENCODING_H_
3
4#include <sourcemeta/core/json.h>
5#include <sourcemeta/core/numeric.h>
6
7#include <cstdint> // std::int64_t, std::uint64_t
8#include <memory> // std::shared_ptr
9#include <variant> // std::variant
10#include <vector> // std::vector
11
12namespace sourcemeta::blaze {
13
14// Forward declarations for the sole purpose of being bale to define circular
15// structures
16#ifndef DOXYGEN
17// The encoding names are the ones the JSON BinPack specification
18// defines, so they keep their casing rather than following the C++
19// naming convention
20// NOLINTBEGIN(readability-identifier-naming)
30struct CONST_NONE;
41struct ROOF_TYPED_ARRAY;
44// NOLINTEND(readability-identifier-naming)
45#endif
46
49using BinPackEncoding = std::variant<
61
62// The encoding names are the ones the JSON BinPack specification
63// defines, so they keep their casing rather than following the C++
64// naming convention
65// NOLINTBEGIN(readability-identifier-naming)
66
70
71// clang-format off
103// clang-format on
106 std::int64_t minimum;
108 std::int64_t maximum;
110 std::uint64_t multiplier;
111};
112
113// clang-format off
144// clang-format on
147 std::int64_t minimum;
149 std::uint64_t multiplier;
150};
151
152// clang-format off
182// clang-format on
185 std::int64_t maximum;
187 std::uint64_t multiplier;
188};
189
190// clang-format off
217// clang-format on
222
224
228
229// clang-format off
267// clang-format on
269
270// clang-format off
318// clang-format on
320
322
326
327// clang-format off
364// clang-format on
367 std::vector<sourcemeta::core::JSON> choices;
368};
369
370// clang-format off
398// clang-format on
401 std::vector<sourcemeta::core::JSON> choices;
402};
403
404// clang-format off
437// clang-format on
440 std::vector<sourcemeta::core::JSON> choices;
441};
442
443// clang-format off
459// clang-format on
462 sourcemeta::core::JSON value;
463};
464
465// TODO: Write brief description
467#ifndef DOXYGEN
468namespace any_packed_type_tag_byte_prefix {
469constexpr auto TYPE_SIZE = 3;
470constexpr std::uint8_t TYPE_SHARED_STRING = 0b00000000;
471constexpr std::uint8_t TYPE_STRING = 0b00000001;
472constexpr std::uint8_t TYPE_LONG_STRING = 0b00000010;
473constexpr std::uint8_t TYPE_OBJECT = 0b00000011;
474constexpr std::uint8_t TYPE_ARRAY = 0b00000100;
475constexpr std::uint8_t TYPE_POSITIVE_INTEGER_BYTE = 0b00000101;
476constexpr std::uint8_t TYPE_NEGATIVE_INTEGER_BYTE = 0b00000110;
477constexpr std::uint8_t TYPE_OTHER = 0b00000111;
478static_assert(TYPE_SHARED_STRING <= sourcemeta::core::uint_max<TYPE_SIZE>);
479static_assert(TYPE_STRING <= sourcemeta::core::uint_max<TYPE_SIZE>);
480static_assert(TYPE_LONG_STRING <= sourcemeta::core::uint_max<TYPE_SIZE>);
481static_assert(TYPE_OBJECT <= sourcemeta::core::uint_max<TYPE_SIZE>);
482static_assert(TYPE_ARRAY <= sourcemeta::core::uint_max<TYPE_SIZE>);
483static_assert(TYPE_POSITIVE_INTEGER_BYTE <=
484 sourcemeta::core::uint_max<TYPE_SIZE>);
485static_assert(TYPE_NEGATIVE_INTEGER_BYTE <=
486 sourcemeta::core::uint_max<TYPE_SIZE>);
487static_assert(TYPE_OTHER <= sourcemeta::core::uint_max<TYPE_SIZE>);
488
489constexpr auto SUBTYPE_SIZE = 5;
490constexpr std::uint8_t SUBTYPE_FALSE = 0b00000000;
491constexpr std::uint8_t SUBTYPE_TRUE = 0b00000001;
492constexpr std::uint8_t SUBTYPE_NULL = 0b00000010;
493constexpr std::uint8_t SUBTYPE_POSITIVE_INTEGER = 0b00000011;
494constexpr std::uint8_t SUBTYPE_NEGATIVE_INTEGER = 0b00000100;
495constexpr std::uint8_t SUBTYPE_NUMBER = 0b00000101;
496constexpr std::uint8_t SUBTYPE_POSITIVE_REAL_INTEGER_BYTE = 0b00000110;
497constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_7 = 0b00000111;
498constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_8 = 0b00001000;
499constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_9 = 0b00001001;
500constexpr std::uint8_t SUBTYPE_LONG_STRING_BASE_EXPONENT_10 = 0b00001010;
501constexpr std::uint8_t SUBTYPE_DECIMAL = 0b00001011;
502
503static_assert(SUBTYPE_FALSE <= sourcemeta::core::uint_max<SUBTYPE_SIZE>);
504static_assert(SUBTYPE_TRUE <= sourcemeta::core::uint_max<SUBTYPE_SIZE>);
505static_assert(SUBTYPE_NULL <= sourcemeta::core::uint_max<SUBTYPE_SIZE>);
506static_assert(SUBTYPE_POSITIVE_INTEGER <=
507 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
508static_assert(SUBTYPE_NEGATIVE_INTEGER <=
509 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
510static_assert(SUBTYPE_NUMBER <= sourcemeta::core::uint_max<SUBTYPE_SIZE>);
511static_assert(SUBTYPE_POSITIVE_REAL_INTEGER_BYTE <=
512 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
513static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_7 <=
514 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
515static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_8 <=
516 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
517static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_9 <=
518 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
519static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_10 <=
520 sourcemeta::core::uint_max<SUBTYPE_SIZE>);
521static_assert(SUBTYPE_DECIMAL <= sourcemeta::core::uint_max<SUBTYPE_SIZE>);
522
523// Note that the binary values actually match the declared exponents
524static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_7 == 7);
525static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_8 == 8);
526static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_9 == 9);
527static_assert(SUBTYPE_LONG_STRING_BASE_EXPONENT_10 == 10);
528} // namespace any_packed_type_tag_byte_prefix
529#endif
530
532
536
537// clang-format off
563// clang-format on
566 std::uint64_t size;
567};
568
569// clang-format off
617// clang-format on
622
623// clang-format off
671// clang-format on
676
677// clang-format off
731// clang-format on
734 std::uint64_t minimum;
736 std::uint64_t maximum;
737};
738
739// clang-format off
774// clang-format on
776
777// clang-format off
819// clang-format on
821
823
827
828// clang-format off
862// clang-format on
865 std::uint64_t size;
867 std::shared_ptr<BinPackEncoding> encoding;
869 std::vector<BinPackEncoding> prefix_encodings;
870};
871
872// clang-format off
911// clang-format on
914 std::uint64_t minimum;
916 std::uint64_t maximum;
918 std::shared_ptr<BinPackEncoding> encoding;
920 std::vector<BinPackEncoding> prefix_encodings;
921};
922
923// clang-format off
959// clang-format on
962 std::uint64_t minimum;
964 std::shared_ptr<BinPackEncoding> encoding;
966 std::vector<BinPackEncoding> prefix_encodings;
967};
968
969// clang-format off
1004// clang-format on
1007 std::uint64_t maximum;
1009 std::shared_ptr<BinPackEncoding> encoding;
1011 std::vector<BinPackEncoding> prefix_encodings;
1012};
1013
1015
1019
1020// clang-format off
1061// clang-format on
1064 std::uint64_t size;
1066 std::shared_ptr<BinPackEncoding> key_encoding;
1068 std::shared_ptr<BinPackEncoding> encoding;
1069};
1070
1071// clang-format off
1107// clang-format on
1110 std::shared_ptr<BinPackEncoding> key_encoding;
1112 std::shared_ptr<BinPackEncoding> encoding;
1113};
1114
1116
1117// NOLINTEND(readability-identifier-naming)
1118
1119} // namespace sourcemeta::blaze
1120
1121#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
std::vector< sourcemeta::core::JSON > choices
The set of choice values.
Definition binpack_encoding.h:367
std::vector< sourcemeta::core::JSON > choices
The set of choice values.
Definition binpack_encoding.h:401
sourcemeta::core::JSON value
The constant value.
Definition binpack_encoding.h:462
std::vector< sourcemeta::core::JSON > choices
The set of choice values.
Definition binpack_encoding.h:440
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
std::vector< BinPackEncoding > prefix_encodings
Positional encodings.
Definition binpack_encoding.h:920
std::shared_ptr< BinPackEncoding > encoding
Element encoding.
Definition binpack_encoding.h:1009
std::uint64_t maximum
The maximum length of the array.
Definition binpack_encoding.h:1007
std::shared_ptr< BinPackEncoding > encoding
Element encoding.
Definition binpack_encoding.h:964
std::shared_ptr< BinPackEncoding > encoding
Element encoding.
Definition binpack_encoding.h:867
std::uint64_t minimum
The minimum length of the array.
Definition binpack_encoding.h:914
std::vector< BinPackEncoding > prefix_encodings
Positional encodings.
Definition binpack_encoding.h:1011
std::vector< BinPackEncoding > prefix_encodings
Positional encodings.
Definition binpack_encoding.h:869
std::uint64_t minimum
The minimum length of the array.
Definition binpack_encoding.h:962
std::uint64_t maximum
The maximum length of the array.
Definition binpack_encoding.h:916
std::vector< BinPackEncoding > prefix_encodings
Positional encodings.
Definition binpack_encoding.h:966
std::uint64_t size
The array length.
Definition binpack_encoding.h:865
std::shared_ptr< BinPackEncoding > encoding
Element encoding.
Definition binpack_encoding.h:918
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
std::int64_t maximum
The inclusive maximum value.
Definition binpack_encoding.h:185
std::uint64_t multiplier
The multiplier value.
Definition binpack_encoding.h:149
std::uint64_t multiplier
The multiplier value.
Definition binpack_encoding.h:187
std::uint64_t multiplier
The multiplier value.
Definition binpack_encoding.h:110
std::uint64_t multiplier
The multiplier value.
Definition binpack_encoding.h:220
std::int64_t minimum
The inclusive minimum value.
Definition binpack_encoding.h:147
std::int64_t maximum
The inclusive maximum value.
Definition binpack_encoding.h:108
std::int64_t minimum
The inclusive minimum value.
Definition binpack_encoding.h:106
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
std::uint64_t size
The object size.
Definition binpack_encoding.h:1064
std::shared_ptr< BinPackEncoding > key_encoding
Key encoding.
Definition binpack_encoding.h:1110
std::shared_ptr< BinPackEncoding > key_encoding
Key encoding.
Definition binpack_encoding.h:1066
std::shared_ptr< BinPackEncoding > encoding
Value encoding.
Definition binpack_encoding.h:1068
std::shared_ptr< BinPackEncoding > encoding
Value encoding.
Definition binpack_encoding.h:1112
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
std::uint64_t maximum
The inclusive maximum string UTF-8 byte-length.
Definition binpack_encoding.h:736
std::uint64_t maximum
The inclusive maximum string UTF-8 byte-length.
Definition binpack_encoding.h:674
std::uint64_t minimum
The inclusive minimum string UTF-8 byte-length.
Definition binpack_encoding.h:620
std::uint64_t size
The string UTF-8 byte-length.
Definition binpack_encoding.h:566
std::uint64_t minimum
The inclusive minimum string UTF-8 byte-length.
Definition binpack_encoding.h:734
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