MySQL 8.3.0
Source Code Documentation
json_binary.cc File Reference
#include "sql-common/json_binary.h"
#include <string.h>
#include <algorithm>
#include <cassert>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <sys/types.h>
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "mysql/strings/m_ctype.h"
#include "sql-common/json_dom.h"
#include "sql-common/json_error_handler.h"
#include "sql-common/json_syntax_check.h"
#include "sql/sql_const.h"
#include "sql_string.h"
#include "template_utils.h"
#include "my_sys.h"
#include "mysqld_error.h"
#include "sql/check_stack.h"
#include "sql/current_thd.h"
#include "sql/field.h"
#include "sql/table.h"

Namespaces

namespace  anonymous_namespace{json_binary.cc}
 
namespace  json_binary
 

Enumerations

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

Functions

static enum_serialization_result json_binary::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 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. 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...
 
bool json_binary::append_int16 (String *dest, int16_t 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...
 
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...
 
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 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...
 
bool json_binary::inlined_type (uint8_t type, bool large)
 Will a value of the specified type be inlined? More...
 
uint8_t json_binary::offset_size (bool large)
 Get the size of an offset value. More...
 
uint8_t json_binary::key_entry_size (bool large)
 Get the size of a key entry. More...
 
uint8_t json_binary::value_entry_size (bool large)
 Get the size of a value entry. More...
 
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 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 json_binary::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 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...
 
uint32_t 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 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