Renderd7-nightly v0.7.0

Public Member Functions | Private Member Functions | Private Attributes | List of all members
nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX > Class Template Reference

deserialization of CBOR, MessagePack, and UBJSON values More...

`#include <json.hpp>`

## Public Member Functions
| binary_reader (InputAdapterType &&adapter)
| create a binary reader More...
bool | sax_parse (const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)

## Private Member Functions
bool | parse_bson_internal ()
| Reads in a BSON-object and passes it to the SAX-parser. More...
bool | get_bson_cstr (string_t &result)
| Parses a C-style string from the BSON input. More...
template<typename NumberType >
bool | get_bson_string (const NumberType len, string_t &result)
| Parses a zero-terminated string of length len from the BSON input. More...
template<typename NumberType >
bool | get_bson_binary (const NumberType len, binary_t &result)
| Parses a byte array input of length len from the BSON input. More...
bool | parse_bson_element_internal (const char_int_type element_type, const std::size_t element_type_parse_position)
| Read a BSON document element of the given element_type. More...
bool | parse_bson_element_list (const bool is_array)
| Read a BSON element list (as specified in the BSON-spec) More...
bool | parse_bson_array ()
| Reads an array from the BSON input and passes it to the SAX-parser. More...
bool | parse_cbor_internal (const bool get_char, const cbor_tag_handler_t tag_handler)
bool | get_cbor_string (string_t &result)
| reads a CBOR string More...
bool | get_cbor_binary (binary_t &result)
| reads a CBOR byte array More...
bool | get_cbor_array (const std::size_t len, const cbor_tag_handler_t tag_handler)
bool | get_cbor_object (const std::size_t len, const cbor_tag_handler_t tag_handler)
bool | parse_msgpack_internal ()
bool | get_msgpack_string (string_t &result)
| reads a MessagePack string More...
bool | get_msgpack_binary (binary_t &result)
| reads a MessagePack byte array More...
bool | get_msgpack_array (const std::size_t len)
bool | get_msgpack_object (const std::size_t len)
bool | parse_ubjson_internal (const bool get_char=true)
bool | get_ubjson_string (string_t &result, const bool get_char=true)
| reads a UBJSON string More...
bool | get_ubjson_size_value (std::size_t &result)
bool | get_ubjson_size_type (std::pair< std::size_t, char_int_type > &result)
| determine the type and size for a container More...
bool | get_ubjson_value (const char_int_type prefix)
bool | get_ubjson_array ()
bool | get_ubjson_object ()
char_int_type | get ()
| get next character from the input More...
char_int_type | get_ignore_noop ()
template<typename NumberType >
bool | get_string (const input_format_t format, const NumberType len, string_t &result)
| create a string by reading characters from the input More...
template<typename NumberType >
bool | get_binary (const input_format_t format, const NumberType len, binary_t &result)
| create a byte array by reading bytes from the input More...
bool | unexpect_eof (const input_format_t format, const char *context) const
std::string | get_token_string () const
std::string | exception_message (const input_format_t format, const std::string &detail, const std::string &context) const

## Private Attributes
InputAdapterType | ia
| input adapter
char_int_type | current = std::char_traits<char_type>::eof()
| the current character
std::size_t | chars_read = 0
| the number of characters read
const bool | is_little_endian = little_endianess()
| whether we can assume little endianess
json_sax_t * | sax = nullptr
| the SAX parser

## Detailed Description

### template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>
class nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >

deserialization of CBOR, MessagePack, and UBJSON values

## Constructor & Destructor Documentation

## ◆ binary_reader()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::binary_reader | ( | InputAdapterType && | adapter | ) |
| inline explicit

create a binary reader

Parameters

  [in] | adapter | input adapter to read from

## Member Function Documentation

## ◆ sax_parse()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse | ( | const input_format_t | format,
|  | json_sax_t * | sax_,
|  | const bool | strict = `true`,
|  | const cbor_tag_handler_t | tag_handler = `cbor_tag_handler_t::error`
| ) |  |
| inline

Parameters

  [in] | format | the binary format to parse
  [in] | sax_ | a SAX event processor
  [in] | strict | whether to expect the input to be consumed completed
  [in] | tag_handler | how to treat CBOR tags

Returns

## ◆ parse_bson_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_bson_internal | ( |  | ) |
| inline private

Reads in a BSON-object and passes it to the SAX-parser.

Returns
  whether a valid BSON-value was passed to the SAX parser

## ◆ get_bson_cstr()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_bson_cstr | ( | string_t & | result | ) |
| inline private

Parses a C-style string from the BSON input.

Parameters

  [in,out] | result | A reference to the string variable where the read string is to be stored.

Returns
  `true` if the \x00-byte indicating the end of the string was encountered before the EOF; false` indicates an unexpected EOF.

## ◆ get_bson_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>
template<typename NumberType >

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_bson_string | ( | const NumberType | len,
|  | string_t & | result
| ) |  |
| inline private

Parses a zero-terminated string of length len from the BSON input.

Parameters

  [in] | len | The length (including the zero-byte at the end) of the string to be read.
  [in,out] | result | A reference to the string variable where the read string is to be stored.

Template Parameters

  NumberType | The type of the length len

Precondition
  len >= 1

Returns
  `true` if the string was successfully parsed

## ◆ get_bson_binary()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>
template<typename NumberType >

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_bson_binary | ( | const NumberType | len,
|  | binary_t & | result
| ) |  |
| inline private

Parses a byte array input of length len from the BSON input.

Parameters

  [in] | len | The length of the byte array to be read.
  [in,out] | result | A reference to the binary variable where the read array is to be stored.

Template Parameters

  NumberType | The type of the length len

Precondition
  len >= 0

Returns
  `true` if the byte array was successfully parsed

## ◆ parse_bson_element_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_bson_element_internal | ( | const char_int_type | element_type,
|  | const std::size_t | element_type_parse_position
| ) |  |
| inline private

Read a BSON document element of the given element_type.

Parameters

  [in] | element_type | The BSON element type, c.f. http://bsonspec.org/spec.html
  [in] | element_type_parse_position | The position in the input stream, where the `element_type` was read.

Warning
  Not all BSON element types are supported yet. An unsupported element_type will give rise to a parse_error.114: Unsupported BSON record type 0x...

Returns
  whether a valid BSON-object/array was passed to the SAX parser

## ◆ parse_bson_element_list()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_bson_element_list | ( | const bool | is_array | ) |
| inline private

Read a BSON element list (as specified in the BSON-spec)

The same binary layout is used for objects and arrays, hence it must be indicated with the argument is_array which one is expected (true --> array, false --> object).

Parameters

  [in] | is_array | Determines if the element list being read is to be treated as an object (is_array == false), or as an array (is_array == true).

Returns
  whether a valid BSON-object/array was passed to the SAX parser

## ◆ parse_bson_array()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_bson_array | ( |  | ) |
| inline private

Reads an array from the BSON input and passes it to the SAX-parser.

Returns
  whether a valid BSON-array was passed to the SAX parser

## ◆ parse_cbor_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_cbor_internal | ( | const bool | get_char,
|  | const cbor_tag_handler_t | tag_handler
| ) |  |
| inline private

Parameters

  [in] | get_char | whether a new character should be retrieved from the input (true) or whether the last read character should be considered instead (false)
  [in] | tag_handler | how CBOR tags should be treated

Returns
  whether a valid CBOR value was passed to the SAX parser

## ◆ get_cbor_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_cbor_string | ( | string_t & | result | ) |
| inline private

reads a CBOR string

This function first reads starting bytes to determine the expected string length and then copies this number of bytes into a string. Additionally, CBOR's strings with indefinite lengths are supported.

Parameters

  [out] | result | created string

Returns
  whether string creation completed

## ◆ get_cbor_binary()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_cbor_binary | ( | binary_t & | result | ) |
| inline private

reads a CBOR byte array

This function first reads starting bytes to determine the expected byte array length and then copies this number of bytes into the byte array. Additionally, CBOR's byte arrays with indefinite lengths are supported.

Parameters

  [out] | result | created byte array

Returns
  whether byte array creation completed

## ◆ get_cbor_array()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_cbor_array | ( | const std::size_t | len,
|  | const cbor_tag_handler_t | tag_handler
| ) |  |
| inline private

Parameters

  [in] | len | the length of the array or std::size_t(-1) for an array of indefinite size
  [in] | tag_handler | how CBOR tags should be treated

Returns
  whether array creation completed

## ◆ get_cbor_object()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_cbor_object | ( | const std::size_t | len,
|  | const cbor_tag_handler_t | tag_handler
| ) |  |
| inline private

Parameters

  [in] | len | the length of the object or std::size_t(-1) for an object of indefinite size
  [in] | tag_handler | how CBOR tags should be treated

Returns
  whether object creation completed

## ◆ parse_msgpack_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_msgpack_internal | ( |  | ) |
| inline private

Returns
  whether a valid MessagePack value was passed to the SAX parser

## ◆ get_msgpack_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_msgpack_string | ( | string_t & | result | ) |
| inline private

reads a MessagePack string

This function first reads starting bytes to determine the expected string length and then copies this number of bytes into a string.

Parameters

  [out] | result | created string

Returns
  whether string creation completed

## ◆ get_msgpack_binary()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_msgpack_binary | ( | binary_t & | result | ) |
| inline private

reads a MessagePack byte array

This function first reads starting bytes to determine the expected byte array length and then copies this number of bytes into a byte array.

Parameters

  [out] | result | created byte array

Returns
  whether byte array creation completed

## ◆ get_msgpack_array()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_msgpack_array | ( | const std::size_t | len | ) |
| inline private

Parameters

  [in] | len | the length of the array

Returns
  whether array creation completed

## ◆ get_msgpack_object()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_msgpack_object | ( | const std::size_t | len | ) |
| inline private

Parameters

  [in] | len | the length of the object

Returns
  whether object creation completed

## ◆ parse_ubjson_internal()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::parse_ubjson_internal | ( | const bool | get_char = `true` | ) |
| inline private

Parameters

  [in] | get_char | whether a new character should be retrieved from the input (true, default) or whether the last read character should be considered instead

Returns
  whether a valid UBJSON value was passed to the SAX parser

## ◆ get_ubjson_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_string | ( | string_t & | result,
|  | const bool | get_char = `true`
| ) |  |
| inline private

reads a UBJSON string

This function is either called after reading the 'S' byte explicitly indicating a string, or in case of an object key where the 'S' byte can be left out.

Parameters

  [out] | result | created string
  [in] | get_char | whether a new character should be retrieved from the input (true, default) or whether the last read character should be considered instead

Returns
  whether string creation completed

## ◆ get_ubjson_size_value()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_size_value | ( | std::size_t & | result | ) |
| inline private

Parameters

  [out] | result | determined size

Returns
  whether size determination completed

## ◆ get_ubjson_size_type()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_size_type | ( | std::pair< std::size_t, char_int_type > & | result | ) |
| inline private

determine the type and size for a container

In the optimized UBJSON format, a type and a size can be provided to allow for a more compact representation.

Parameters

  [out] | result | pair of the size and the type

Returns
  whether pair creation completed

## ◆ get_ubjson_value()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_value | ( | const char_int_type | prefix | ) |
| inline private

Parameters

  prefix | the previously read or set type prefix

Returns
  whether value creation completed

## ◆ get_ubjson_array()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_array | ( |  | ) |
| inline private

Returns
  whether array creation completed

## ◆ get_ubjson_object()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ubjson_object | ( |  | ) |
| inline private

Returns
  whether object creation completed

## ◆ get()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

char_int_type nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get | ( |  | ) |
| inline private

get next character from the input

This function provides the interface to the used input adapter. It does not throw in case the input reached EOF, but returns a -'ve valued `std::char_traits<char_type>::eof()` in that case.

Returns
  character read from the input

## ◆ get_ignore_noop()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

char_int_type nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_ignore_noop | ( |  | ) |
| inline private

Returns
  character read from the input after ignoring all 'N' entries

## ◆ get_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>
template<typename NumberType >

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_string | ( | const input_format_t | format,
|  | const NumberType | len,
|  | string_t & | result
| ) |  |
| inline private

create a string by reading characters from the input

Template Parameters

  NumberType | the type of the number

Parameters

  [in] | format | the current format (for diagnostics)
  [in] | len | number of characters to read
  [out] | result | string created by reading len bytes

Returns
  whether string creation completed

Note
  We can not reserve len bytes for the result, because len may be too large. Usually, unexpect_eof() detects the end of the input before we run out of string memory.

## ◆ get_binary()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>
template<typename NumberType >

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_binary | ( | const input_format_t | format,
|  | const NumberType | len,
|  | binary_t & | result
| ) |  |
| inline private

create a byte array by reading bytes from the input

Template Parameters

  NumberType | the type of the number

Parameters

  [in] | format | the current format (for diagnostics)
  [in] | len | number of bytes to read
  [out] | result | byte array created by reading len bytes

Returns
  whether byte array creation completed

Note
  We can not reserve len bytes for the result, because len may be too large. Usually, unexpect_eof() detects the end of the input before we run out of memory.

## ◆ unexpect_eof()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

bool nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::unexpect_eof | ( | const input_format_t | format,
|  | const char * | context
| ) |  | const
| inline private

Parameters

  [in] | format | the current format (for diagnostics)
  [in] | context | further context information (for diagnostics)

Returns
  whether the last read character is not EOF

## ◆ get_token_string()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

std::string nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::get_token_string | ( |  | ) | const
| inline private

Returns
  a string representation of the last read byte

## ◆ exception_message()

template<typename BasicJsonType , typename InputAdapterType , typename SAX = json_sax_dom_parser<BasicJsonType>>

std::string nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::exception_message | ( | const input_format_t | format,
|  | const std::string & | detail,
|  | const std::string & | context
| ) |  | const
| inline private

Parameters

  [in] | format | the current format
  [in] | detail | a detailed error message
  [in] | context | further context information

Returns
  a message string to use in the parse_error exceptions