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.
sourcemeta::jsonbinpack::BOUNDED_8BIT_PREFIX_UTF8_STRING_SHARED Struct Reference

The encoding consists of the byte-length of the string minus minimum plus 1 as an 8-bit fixed-length unsigned integer followed by the UTF-8 encoding of the input value. More...

#include <runtime_plan.h>

Public Attributes

const std::uint64_t minimum
 The inclusive minimum string UTF-8 byte-length.
 
const std::uint64_t maximum
 The inclusive maximum string UTF-8 byte-length.
 

Detailed Description

The encoding consists of the byte-length of the string minus minimum plus 1 as an 8-bit fixed-length unsigned integer followed by the UTF-8 encoding of the input value.

Optionally, if the input string has already been encoded to the buffer using UTF-8, the encoding may consist of the byte constant 0x00 followed by the byte-length of the string minus minimum plus 1 as an 8-bit fixed-length unsigned integer, followed by the current offset minus the offset to the start of the UTF-8 string value in the buffer encoded as a Base-128 64-bit Little Endian variable-length unsigned integer.

The byte-length of the string is encoded even if maximum equals minimum in order to disambiguate between shared and non-shared fixed strings.

Options

Option Type Description
minimum uint The inclusive minimum string UTF-8 byte-length
maximum uint The inclusive maximum string UTF-8 byte-length

Conditions

Condition Description
len(value) >= minimum The input string byte-length is equal to or greater than the minimum
len(value) <= maximum The input string byte-length is equal to or less than the maximum
maximum - minimum < 2 ** 8 - 1 The range minus 1 must be representable in 8 bits

Examples

Given the input string foo with a minimum 3 and a maximum 5 where the string has not been previously encoded, the encoding results in:

+------+------+------+------+
| 0x01 | 0x66 | 0x6f | 0x6f |
+------+------+------+------+
f o o

Given the encoding of foo with a minimum of 0 and a maximum of 6 followed by the encoding of foo with a minimum of 3 and a maximum of 100, the encoding may result in:

0 1 2 3 4 5 6
^ ^ ^ ^ ^ ^ ^
+------+------+------+------+------+------+------+
| 0x04 | 0x66 | 0x6f | 0x6f | 0x00 | 0x01 | 0x05 |
+------+------+------+------+------+------+------+
f o o 6 - 1