# Renderd7-nightly: nlohmann::detail::binary_writer< BasicJsonType, CharType > Class Template Reference

nlohmann::detail::binary_writer< BasicJsonType, CharType > Class Template Reference

serialization to CBOR and MessagePack values More...

`#include <json.hpp>`

## Public Member Functions

| binary_writer (output_adapter_t< CharType > adapter)
| create a binary writer More...
void | write_bson (const BasicJsonType &j)
void | write_cbor (const BasicJsonType &j)
void | write_msgpack (const BasicJsonType &j)
void | write_ubjson (const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true)

## Private Member Functions

void | write_bson_entry_header (const string_t &name, const std::uint8_t element_type)
| Writes the given element_type and name to the output adapter.
void | write_bson_boolean (const string_t &name, const bool value)
| Writes a BSON element with key name and boolean value value.
void | write_bson_double (const string_t &name, const double value)
| Writes a BSON element with key name and double value value.
void | write_bson_string (const string_t &name, const string_t &value)
| Writes a BSON element with key name and string value value.
void | write_bson_null (const string_t &name)
| Writes a BSON element with key name and null value.
void | write_bson_integer (const string_t &name, const std::int64_t value)
| Writes a BSON element with key name and integer value.
void | write_bson_unsigned (const string_t &name, const std::uint64_t value)
| Writes a BSON element with key name and unsigned value.
void | write_bson_object_entry (const string_t &name, const typename BasicJsonType::object_t &value)
| Writes a BSON element with key name and object value.
void | write_bson_array (const string_t &name, const typename BasicJsonType::array_t &value)
| Writes a BSON element with key name and array value.
void | write_bson_binary (const string_t &name, const binary_t &value)
| Writes a BSON element with key name and binary value value.
void | write_bson_element (const string_t &name, const BasicJsonType &j)
| Serializes the JSON value j to BSON and associates it with the key name. More...
void | write_bson_object (const typename BasicJsonType::object_t &value)
CharType | ubjson_prefix (const BasicJsonType &j) const noexcept
| determine the type prefix of container values

## Static Private Member Functions

static std::size_t | calc_bson_entry_header_size (const string_t &name)
static std::size_t | calc_bson_string_size (const string_t &value)
static std::size_t | calc_bson_integer_size (const std::int64_t value)
static constexpr std::size_t | calc_bson_unsigned_size (const std::uint64_t value) noexcept
static std::size_t | calc_bson_array_size (const typename BasicJsonType::array_t &value)
static std::size_t | calc_bson_binary_size (const typename BasicJsonType::binary_t &value)
static std::size_t | calc_bson_element_size (const string_t &name, const BasicJsonType &j)
| Calculates the size necessary to serialize the JSON value j with its name. More...
static std::size_t | calc_bson_object_size (const typename BasicJsonType::object_t &value)
| Calculates the size of the BSON serialization of the given JSON-object j. More...

## Private Attributes

const bool | is_little_endian = little_endianess()
| whether we can assume little endianess
output_adapter_t< CharType > | oa = nullptr
| the output

## Detailed Description

### template<typename BasicJsonType, typename CharType>
class nlohmann::detail::binary_writer< BasicJsonType, CharType >

serialization to CBOR and MessagePack values

## Constructor & Destructor Documentation

## binary_writer()

template<typename BasicJsonType , typename CharType >

nlohmann::detail::binary_writer< BasicJsonType, CharType >::binary_writer | ( | output_adapter_t< CharType > | adapter | ) |

inlineexplicit

create a binary writer

Parameters

  [in] | adapter | output adapter to write to

## Member Function Documentation

## write_bson()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson | ( | const BasicJsonType & | j | ) |

inline

Parameters

  [in] | j | JSON value to serialize

Precondition
  j.type() == value_t::object

## write_cbor()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_cbor | ( | const BasicJsonType & | j | ) |

inline

Parameters

  [in] | j | JSON value to serialize

## write_msgpack()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_msgpack | ( | const BasicJsonType & | j | ) |

inline

Parameters

  [in] | j | JSON value to serialize

## write_ubjson()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_ubjson | ( | const BasicJsonType & | j,
|  | const bool | use_count,
|  | const bool | use_type,
|  | const bool | add_prefix = `true`
| ) |  |

inline

Parameters

  [in] | j | JSON value to serialize
  [in] | use_count | whether to use '#' prefixes (optimized format)
  [in] | use_type | whether to use '$' prefixes (optimized format)
  [in] | add_prefix | whether prefixes need to be used for this value

## calc_bson_entry_header_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_entry_header_size | ( | const string_t & | name | ) |

inlinestaticprivate

Returns
  The size of a BSON document entry header, including the id marker and the entry name size (and its null-terminator).

## calc_bson_string_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_string_size | ( | const string_t & | value | ) |

inlinestaticprivate

Returns
  The size of the BSON-encoded string in value

## calc_bson_integer_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_integer_size | ( | const std::int64_t | value | ) |

inlinestaticprivate

Returns
  The size of the BSON-encoded integer value

## calc_bson_unsigned_size()

template<typename BasicJsonType , typename CharType >

static constexpr std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_unsigned_size | ( | const std::uint64_t | value | ) |

inlinestaticconstexprprivatenoexcept

Returns
  The size of the BSON-encoded unsigned integer in j

## calc_bson_array_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_array_size | ( | const typename BasicJsonType::array_t & | value | ) |

inlinestaticprivate

Returns
  The size of the BSON-encoded array value

## calc_bson_binary_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_binary_size | ( | const typename BasicJsonType::binary_t & | value | ) |

inlinestaticprivate

Returns
  The size of the BSON-encoded binary array value

## calc_bson_element_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_element_size | ( | const string_t & | name,
|  | const BasicJsonType & | j
| ) |  |

inlinestaticprivate

Calculates the size necessary to serialize the JSON value j with its name.

Returns
  The calculated size for the BSON document entry for j with the given name.

## write_bson_element()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_element | ( | const string_t & | name,
|  | const BasicJsonType & | j
| ) |  |

inlineprivate

Serializes the JSON value j to BSON and associates it with the key name.

Parameters

  name | The name to associate with the JSON entity j within the current BSON document

Returns
  The size of the BSON entry

## calc_bson_object_size()

template<typename BasicJsonType , typename CharType >

static std::size_t nlohmann::detail::binary_writer< BasicJsonType, CharType >::calc_bson_object_size | ( | const typename BasicJsonType::object_t & | value | ) |

inlinestaticprivate

Calculates the size of the BSON serialization of the given JSON-object j.

Parameters

  [in] | j | JSON value to serialize

Precondition
  j.type() == value_t::object

## write_bson_object()

template<typename BasicJsonType , typename CharType >

void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_object | ( | const typename BasicJsonType::object_t & | value | ) |

inlineprivate

Parameters

  [in] | j | JSON value to serialize

Precondition
  j.type() == value_t::object