MySQL 9.1.0
Source Code Documentation
|
Classes | |
class | Value |
Class used for reading JSON values that are stored in the binary format. More... | |
Enumerations | |
enum | enum_serialization_result { OK , VALUE_TOO_BIG , JSON_KEY_TOO_BIG , FAILURE } |
Status codes for JSON serialization. More... | |
Functions | |
static enum_serialization_result | serialize_json_value (const Json_dom *dom, size_t type_pos, size_t depth, bool small_parent, const JsonSerializationErrorHandler &error_handler, String *dest) |
Serialize a JSON value at the end of the destination string. More... | |
bool | serialize (const Json_dom *dom, const JsonSerializationErrorHandler &error_handler, String *dest) |
Serialize the JSON document represented by dom to binary format in the destination string, replacing any content already in the destination string. More... | |
static bool | reserve (String *buffer, size_t bytes_needed) |
Reserve space for the given amount of extra bytes at the end of a String buffer. More... | |
bool | append_int16 (String *dest, int16_t value) |
Encode a 16-bit int at the end of the destination string. More... | |
static bool | append_int32 (String *dest, int32 value) |
Encode a 32-bit int at the end of the destination string. More... | |
static bool | append_int64 (String *dest, int64 value) |
Encode a 64-bit int at the end of the destination string. More... | |
bool | append_offset_or_size (String *dest, size_t offset_or_size, bool large) |
Append an offset or a size to a String. More... | |
static void | insert_offset_or_size (String *dest, size_t pos, size_t offset_or_size, bool large) |
Insert an offset or a size at the specified position in a String. More... | |
void | write_offset_or_size (char *dest, size_t offset_or_size, bool large) |
Write an offset or a size to a char array. More... | |
static bool | check_document_size (size_t size) |
Check if the size of a document exceeds the maximum JSON binary size (4 GB, aka UINT_MAX32). More... | |
static bool | append_variable_length (String *dest, size_t length) |
Append a length to a String. More... | |
static bool | read_variable_length (const char *data, size_t data_length, uint32 *length, uint8 *num) |
Read a variable length written by append_variable_length(). More... | |
static bool | is_too_big_for_json (size_t offset_or_size, bool large) |
Check if the specified offset or size is too big to store in the binary JSON format. More... | |
static enum_serialization_result | append_key_entries (const Json_object *object, String *dest, size_t offset, bool large) |
Append all the key entries of a JSON object to a destination string. More... | |
bool | inlined_type (uint8_t type, bool large) |
Will a value of the specified type be inlined? More... | |
uint8_t | offset_size (bool large) |
Get the size of an offset value. More... | |
uint8_t | key_entry_size (bool large) |
Get the size of a key entry. More... | |
uint8_t | value_entry_size (bool large) |
Get the size of a value entry. More... | |
bool | attempt_inline_value (const Json_dom *value, String *dest, size_t pos, bool large) |
Attempt to inline a value in its value entry at the beginning of an object or an array. More... | |
static enum_serialization_result | serialize_json_array (const Json_array *array, bool large, size_t depth, const JsonSerializationErrorHandler &error_handler, String *dest) |
Serialize a JSON array at the end of the destination string. More... | |
static enum_serialization_result | serialize_json_object (const Json_object *object, bool large, size_t depth, const JsonSerializationErrorHandler &error_handler, String *dest) |
Serialize a JSON object at the end of the destination string. More... | |
static enum_serialization_result | serialize_opaque (const Json_opaque *opaque, size_t type_pos, String *dest) |
Serialize a JSON opaque value at the end of the destination string. More... | |
static enum_serialization_result | serialize_decimal (const Json_decimal *jd, size_t type_pos, String *dest) |
Serialize a DECIMAL value at the end of the destination string. More... | |
static enum_serialization_result | serialize_datetime (const Json_datetime *jdt, size_t type_pos, String *dest) |
Serialize a DATETIME value at the end of the destination string. More... | |
static Value | err () |
Create a Value object that represents an error condition. More... | |
static Value | parse_scalar (uint8 type, const char *data, size_t len) |
Parse a JSON scalar value. More... | |
uint32_t | read_offset_or_size (const char *data, bool large) |
Read an offset or size field from a buffer. More... | |
static Value | parse_array_or_object (Value::enum_type t, const char *data, size_t len, bool large) |
Parse a JSON array or object. More... | |
static Value | parse_value (uint8 type, const char *data, size_t len) |
Parse a JSON value within a larger JSON document. More... | |
Value | parse_binary (const char *data, size_t len) |
Parse a JSON binary document. More... | |
bool | space_needed (const Json_wrapper *value, bool large, size_t *needed) |
How much space is needed for a JSON value when it is stored in the binary format. More... | |
template<typename Func > | |
bool | for_each_node (const Value &value, const Func &func) |
Apply a function to every value in a JSON document. More... | |
Variables | |
constexpr char | JSONB_TYPE_SMALL_OBJECT = 0x0 |
constexpr char | JSONB_TYPE_LARGE_OBJECT = 0x1 |
constexpr char | JSONB_TYPE_SMALL_ARRAY = 0x2 |
constexpr char | JSONB_TYPE_LARGE_ARRAY = 0x3 |
constexpr char | JSONB_TYPE_LITERAL = 0x4 |
constexpr char | JSONB_TYPE_INT16 = 0x5 |
constexpr char | JSONB_TYPE_UINT16 = 0x6 |
constexpr char | JSONB_TYPE_INT32 = 0x7 |
constexpr char | JSONB_TYPE_UINT32 = 0x8 |
constexpr char | JSONB_TYPE_INT64 = 0x9 |
constexpr char | JSONB_TYPE_UINT64 = 0xA |
constexpr char | JSONB_TYPE_DOUBLE = 0xB |
constexpr char | JSONB_TYPE_STRING = 0xC |
constexpr char | JSONB_TYPE_OPAQUE = 0xF |
constexpr char | JSONB_NULL_LITERAL = 0x0 |
constexpr char | JSONB_TRUE_LITERAL = 0x1 |
constexpr char | JSONB_FALSE_LITERAL = 0x2 |
Status codes for JSON serialization.
bool json_binary::append_int16 | ( | String * | dest, |
int16_t | value | ||
) |
Encode a 16-bit int at the end of the destination string.
Encode a 32-bit int at the end of the destination string.
Encode a 64-bit int at the end of the destination string.
|
static |
Append all the key entries of a JSON object to a destination string.
The key entries are just a series of offset/length pairs that point to where the actual key names are stored.
[in] | object | the JSON object |
[out] | dest | the destination string |
[in] | offset | the offset of the first key |
[in] | large | if true, the large storage format will be used |
bool json_binary::append_offset_or_size | ( | String * | dest, |
size_t | offset_or_size, | ||
bool | large | ||
) |
Append an offset or a size to a String.
dest | the destination String |
offset_or_size | the offset or size to append |
large | if true, use the large storage format (4 bytes); otherwise, use the small storage format (2 bytes) |
|
static |
Append a length to a String.
The number of bytes used to store the length uses a variable number of bytes depending on how large the length is. If the highest bit in a byte is 1, then the length is continued on the next byte. The least significant bits are stored in the first byte.
dest | the destination String |
length | the length to write |
bool json_binary::attempt_inline_value | ( | const Json_dom * | value, |
String * | dest, | ||
size_t | pos, | ||
bool | large | ||
) |
Attempt to inline a value in its value entry at the beginning of an object or an array.
This function assumes that the destination string has already allocated enough space to hold the inlined value.
[in] | value | the JSON value |
[out] | dest | the destination string |
[in] | pos | the offset where the value should be inlined |
[in] | large | true if the large storage format is used |
|
static |
Check if the size of a document exceeds the maximum JSON binary size (4 GB, aka UINT_MAX32).
Raise an error if it is too big.
size | the size of the document |
|
static |
Create a Value object that represents an error condition.
bool json_binary::for_each_node | ( | const Value & | value, |
const Func & | func | ||
) |
Apply a function to every value in a JSON document.
That is, apply the function to the root node of the JSON document, to all its children, grandchildren and so on.
value | the root of the JSON document |
func | the function to apply |
true | if the processing was stopped |
false | if the processing was completed |
Func | a functor type that takes a json_binary::Value parameter and returns a bool which is true if the processing should stop or false if the processing should continue with the next node |
bool json_binary::inlined_type | ( | uint8_t | type, |
bool | large | ||
) |
Will a value of the specified type be inlined?
type | the type to check |
large | true if the large storage format is used |
|
static |
Insert an offset or a size at the specified position in a String.
It is assumed that the String has already allocated enough space to hold the value.
dest | the destination String |
pos | the position in the String |
offset_or_size | the offset or size to append |
large | if true, use the large storage format (4 bytes); otherwise, use the small storage format (2 bytes) |
|
static |
Check if the specified offset or size is too big to store in the binary JSON format.
If the small storage format is used, the caller is expected to retry serialization in the large storage format, so no error is generated if the offset or size is too big. If the large storage format is used, an error will be generated if the offset or size is too big.
offset_or_size | the offset or size to check |
large | if true, we are using the large storage format for JSON arrays and objects, which allows offsets and sizes that fit in a uint32; otherwise, we are using the small storage format, which allow offsets and sizes that fit in a uint16. |
uint8_t json_binary::key_entry_size | ( | bool | large | ) |
Get the size of a key entry.
large | true if the large storage format is used |
uint8_t json_binary::offset_size | ( | bool | large | ) |
Get the size of an offset value.
large | true if the large storage format is used |
|
static |
Parse a JSON array or object.
t | type (either ARRAY or OBJECT) |
data | pointer to the start of the array or object |
len | the maximum number of bytes to read from data |
large | if true, the array or object is stored using the large storage format; otherwise, it is stored using the small storage format |
EXPORT_JSON_FUNCTION Value json_binary::parse_binary | ( | const char * | data, |
size_t | len | ||
) |
Parse a JSON binary document.
[in] | data | a pointer to the binary data |
[in] | len | the size of the binary document in bytes |
Parse a JSON scalar value.
type | the binary type of the scalar |
data | pointer to the start of the binary representation of the scalar |
len | the maximum number of bytes to read from data |
Parse a JSON value within a larger JSON document.
type | the binary type of the value to parse |
data | pointer to the start of the binary representation of the value |
len | the maximum number of bytes to read from data |
uint32_t json_binary::read_offset_or_size | ( | const char * | data, |
bool | large | ||
) |
Read an offset or size field from a buffer.
The offset could be either a two byte unsigned integer or a four byte unsigned integer.
data | the buffer to read from |
large | tells if the large or small storage format is used; true means read four bytes, false means read two bytes |
|
static |
Read a variable length written by append_variable_length().
[in] | data | the buffer to read from |
[in] | data_length | the maximum number of bytes to read from data |
[out] | length | the length that was read |
[out] | num | the number of bytes needed to represent the length |
|
static |
Reserve space for the given amount of extra bytes at the end of a String buffer.
If the String needs to allocate more memory, it will grow by at least 50%, to avoid frequent reallocations.
bool json_binary::serialize | ( | const Json_dom * | dom, |
const JsonSerializationErrorHandler & | error_handler, | ||
String * | dest | ||
) |
Serialize the JSON document represented by dom to binary format in the destination string, replacing any content already in the destination string.
[in] | dom | the input DOM tree |
error_handler | a handler that is invoked if an error occurs | |
[in,out] | dest | the destination string |
false | on success |
true | if an error occurred |
|
static |
Serialize a DATETIME value at the end of the destination string.
[in] | jdt | the DATETIME value |
[in] | type_pos | where to write the type specifier |
[out] | dest | the destination string |
|
static |
Serialize a DECIMAL value at the end of the destination string.
[in] | jd | the DECIMAL value |
[in] | type_pos | where to write the type specifier |
[out] | dest | the destination string |
|
static |
Serialize a JSON array at the end of the destination string.
array | the JSON array to serialize |
large | if true, the large storage format will be used |
depth | the current nesting level |
error_handler | a handler that is invoked if an error occurs |
dest | the destination string |
|
static |
Serialize a JSON object at the end of the destination string.
object | the JSON object to serialize |
large | if true, the large storage format will be used |
depth | the current nesting level |
error_handler | a handler that is invoked if an error occurs |
dest | the destination string |
|
static |
Serialize a JSON value at the end of the destination string.
Also go back and update the type specifier for the value to specify the correct type. For top-level documents, the type specifier is located in the byte right in front of the value. For documents that are nested within other documents, the type specifier is located in the value entry portion at the beginning of the parent document.
dom | the JSON value to serialize |
type_pos | the position of the type specifier to update |
dest | the destination string |
depth | the current nesting level |
small_parent | tells if dom is contained in an array or object which is stored in the small storage format |
error_handler | a handler that is invoked if an error occurs |
|
static |
Serialize a JSON opaque value at the end of the destination string.
[in] | opaque | the JSON opaque value |
[in] | type_pos | where to write the type specifier |
[out] | dest | the destination string |
bool json_binary::space_needed | ( | const Json_wrapper * | value, |
bool | large, | ||
size_t * | needed | ||
) |
How much space is needed for a JSON value when it is stored in the binary format.
[in] | value | the JSON value to add to a document |
[in] | large | true if the large storage format is used |
[out] | needed | gets set to the amount of bytes needed to store the value |
false | if successful |
true | if an error occurred while calculating the needed space |
uint8_t json_binary::value_entry_size | ( | bool | large | ) |
Get the size of a value entry.
large | true if the large storage format is used |
void json_binary::write_offset_or_size | ( | char * | dest, |
size_t | offset_or_size, | ||
bool | large | ||
) |
Write an offset or a size to a char array.
The char array is assumed to be large enough to hold an offset or size value.
dest | the array to write to |
offset_or_size | the offset or size to write |
large | if true, use the large storage format |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |