MySQL  8.0.27
Source Code Documentation
json_binary.cc File Reference
#include "sql/json_binary.h"
#include <string.h>
#include <algorithm>
#include <cassert>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "m_ctype.h"
#include "my_byteorder.h"
#include "my_sys.h"
#include "mysqld_error.h"
#include "sql/check_stack.h"
#include "sql/field.h"
#include "sql/json_dom.h"
#include "sql/json_syntax_check.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql_string.h"
#include "template_utils.h"

Namespaces

 anonymous_namespace{json_binary.cc}
 
 json_binary
 

Enumerations

enum  json_binary::enum_serialization_result { json_binary::OK , json_binary::VALUE_TOO_BIG , json_binary::FAILURE }
 Status codes for JSON serialization. More...
 

Functions

static enum_serialization_result json_binary::serialize_json_value (const THD *thd, const Json_dom *dom, size_t type_pos, String *dest, size_t depth, bool small_parent)
 Serialize a JSON value at the end of the destination string. More...
 
static 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. More...
 
static uint8 json_binary::offset_size (bool large)
 Get the size of an offset value. More...
 
bool json_binary::serialize (const THD *thd, const Json_dom *dom, 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 json_binary::reserve (String *buffer, size_t bytes_needed)
 Reserve space for the given amount of extra bytes at the end of a String buffer. More...
 
static bool json_binary::append_int16 (String *dest, int16 value)
 Encode a 16-bit int at the end of the destination string. More...
 
static bool json_binary::append_int32 (String *dest, int32 value)
 Encode a 32-bit int at the end of the destination string. More...
 
static bool json_binary::append_int64 (String *dest, int64 value)
 Encode a 64-bit int at the end of the destination string. More...
 
static 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. More...
 
static void json_binary::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...
 
static bool json_binary::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 json_binary::append_variable_length (String *dest, size_t length)
 Append a length to a String. More...
 
static bool json_binary::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 json_binary::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 json_binary::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...
 
static bool json_binary::inlined_type (uint8 type, bool large)
 Will a value of the specified type be inlined? More...
 
static uint8 json_binary::key_entry_size (bool large)
 Get the size of a key entry. More...
 
static uint8 json_binary::value_entry_size (bool large)
 Get the size of a value entry. More...
 
static 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. More...
 
static enum_serialization_result json_binary::serialize_json_array (const THD *thd, const Json_array *array, String *dest, bool large, size_t depth)
 Serialize a JSON array at the end of the destination string. More...
 
static enum_serialization_result json_binary::serialize_json_object (const THD *thd, const Json_object *object, String *dest, bool large, size_t depth)
 Serialize a JSON object at the end of the destination string. More...
 
static enum_serialization_result json_binary::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 json_binary::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 json_binary::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 json_binary::err ()
 Create a Value object that represents an error condition. More...
 
static Value json_binary::parse_scalar (uint8 type, const char *data, size_t len)
 Parse a JSON scalar value. More...
 
static uint32 json_binary::read_offset_or_size (const char *data, bool large)
 Read an offset or size field from a buffer. More...
 
static Value json_binary::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 json_binary::parse_value (uint8 type, const char *data, size_t len)
 Parse a JSON value within a larger JSON document. More...
 
Value json_binary::parse_binary (const char *data, size_t len)
 Parse a JSON binary document. More...
 
bool json_binary::space_needed (const THD *thd, 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...
 

Variables

constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_SMALL_OBJECT = 0x0
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_LARGE_OBJECT = 0x1
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_SMALL_ARRAY = 0x2
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_LARGE_ARRAY = 0x3
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_LITERAL = 0x4
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_INT16 = 0x5
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_UINT16 = 0x6
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_INT32 = 0x7
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_UINT32 = 0x8
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_INT64 = 0x9
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_UINT64 = 0xA
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_DOUBLE = 0xB
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_STRING = 0xC
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TYPE_OPAQUE = 0xF
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_NULL_LITERAL = 0x0
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_TRUE_LITERAL = 0x1
 
constexpr char anonymous_namespace{json_binary.cc}::JSONB_FALSE_LITERAL = 0x2
 
constexpr uint8 anonymous_namespace{json_binary.cc}::SMALL_OFFSET_SIZE = 2
 
constexpr uint8 anonymous_namespace{json_binary.cc}::LARGE_OFFSET_SIZE = 4
 
constexpr uint8 anonymous_namespace{json_binary.cc}::KEY_ENTRY_SIZE_SMALL = 2 + SMALL_OFFSET_SIZE
 
constexpr uint8 anonymous_namespace{json_binary.cc}::KEY_ENTRY_SIZE_LARGE = 2 + LARGE_OFFSET_SIZE
 
constexpr uint8 anonymous_namespace{json_binary.cc}::VALUE_ENTRY_SIZE_SMALL = 1 + SMALL_OFFSET_SIZE
 
constexpr uint8 anonymous_namespace{json_binary.cc}::VALUE_ENTRY_SIZE_LARGE = 1 + LARGE_OFFSET_SIZE