All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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)
 

Static Public Member Functions

template<typename C = CharType, enable_if_t< std::is_signed< C >::value and std::is_signed< char >::value > * = nullptr>
static constexpr CharType to_char_type (std::uint8_t x) noexcept
 
template<typename C = CharType, enable_if_t< std::is_signed< C >::value and std::is_unsigned< char >::value > * = nullptr>
static CharType to_char_type (std::uint8_t x) noexcept
 
template<typename C = CharType, enable_if_t< std::is_unsigned< C >::value > * = nullptr>
static constexpr CharType to_char_type (std::uint8_t x) noexcept
 
template<typename InputCharType , typename C = CharType, enable_if_t< std::is_signed< C >::value andstd::is_signed< char >::value andstd::is_same< char, typename std::remove_cv< InputCharType >::type >::value > * = nullptr>
static constexpr CharType to_char_type (InputCharType x) noexcept
 

Private Types

using string_t = typename BasicJsonType::string_t
 

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. More...
 
void write_bson_boolean (const string_t &name, const bool value)
 Writes a BSON element with key name and boolean value value. More...
 
void write_bson_double (const string_t &name, const double value)
 Writes a BSON element with key name and double value value. More...
 
void write_bson_string (const string_t &name, const string_t &value)
 Writes a BSON element with key name and string value value. More...
 
void write_bson_null (const string_t &name)
 Writes a BSON element with key name and null value. More...
 
void write_bson_integer (const string_t &name, const std::int64_t value)
 Writes a BSON element with key name and integer value. More...
 
void write_bson_unsigned (const string_t &name, const std::uint64_t value)
 Writes a BSON element with key name and unsigned value. More...
 
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. More...
 
void write_bson_array (const string_t &name, const typename BasicJsonType::array_t &value)
 Writes a BSON element with key name and array value. More...
 
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)
 
template<typename NumberType , typename std::enable_if< std::is_floating_point< NumberType >::value, int >::type = 0>
void write_number_with_ubjson_prefix (const NumberType n, const bool add_prefix)
 
template<typename NumberType , typename std::enable_if< std::is_unsigned< NumberType >::value, int >::type = 0>
void write_number_with_ubjson_prefix (const NumberType n, const bool add_prefix)
 
template<typename NumberType , typename std::enable_if< std::is_signed< NumberType >::value andnot std::is_floating_point< NumberType >::value, int >::type = 0>
void write_number_with_ubjson_prefix (const NumberType n, const bool add_prefix)
 
CharType ubjson_prefix (const BasicJsonType &j) const noexcept
 determine the type prefix of container values More...
 
template<typename NumberType , bool OutputIsLittleEndian = false>
void write_number (const NumberType n)
 

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_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...
 
static constexpr CharType get_cbor_float_prefix (float)
 
static constexpr CharType get_cbor_float_prefix (double)
 
static constexpr CharType get_msgpack_float_prefix (float)
 
static constexpr CharType get_msgpack_float_prefix (double)
 
static constexpr CharType get_ubjson_float_prefix (float)
 
static constexpr CharType get_ubjson_float_prefix (double)
 

Private Attributes

const bool is_little_endian = binary_reader<BasicJsonType>::little_endianess()
 whether we can assume little endianess More...
 
output_adapter_t< CharType > oa = nullptr
 the output More...
 

Detailed Description

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

serialization to CBOR and MessagePack values

Definition at line 11318 of file json.hpp.

Member Typedef Documentation

template<typename BasicJsonType , typename CharType >
using nlohmann::detail::binary_writer< BasicJsonType, CharType >::string_t = typename BasicJsonType::string_t
private

Definition at line 11320 of file json.hpp.

Constructor & Destructor Documentation

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]adapteroutput adapter to write to

Definition at line 11328 of file json.hpp.

11328  : oa(adapter)
11329  {
11330  assert(oa);
11331  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624

Member Function Documentation

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

Definition at line 12154 of file json.hpp.

12155  {
12156  std::size_t array_index = 0ul;
12157 
12158  const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), 0ul, [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
12159  {
12160  return result + calc_bson_element_size(std::to_string(array_index++), el);
12161  });
12162 
12163  return sizeof(std::int32_t) + embedded_document_size + 1ul;
12164  }
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
std::string to_string(WindowPattern const &pattern)
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.
Definition: json.hpp:12189
temporary value
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.

Definition at line 12189 of file json.hpp.

12191  {
12192  const auto header_size = calc_bson_entry_header_size(name);
12193  switch (j.type())
12194  {
12195  case value_t::object:
12196  return header_size + calc_bson_object_size(*j.m_value.object);
12197 
12198  case value_t::array:
12199  return header_size + calc_bson_array_size(*j.m_value.array);
12200 
12201  case value_t::boolean:
12202  return header_size + 1ul;
12203 
12204  case value_t::number_float:
12205  return header_size + 8ul;
12206 
12208  return header_size + calc_bson_integer_size(j.m_value.number_integer);
12209 
12211  return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
12212 
12213  case value_t::string:
12214  return header_size + calc_bson_string_size(*j.m_value.string);
12215 
12216  case value_t::null:
12217  return header_size + 0ul;
12218 
12219  // LCOV_EXCL_START
12220  default:
12221  assert(false);
12222  return 0ul;
12223  // LCOV_EXCL_STOP
12224  }
12225  }
static std::size_t calc_bson_string_size(const string_t &value)
Definition: json.hpp:12054
array (ordered collection of values)
number value (signed integer)
static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
Definition: json.hpp:12112
object (unordered set of name/value pairs)
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t &value)
Definition: json.hpp:12154
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.
Definition: json.hpp:12277
static std::size_t calc_bson_entry_header_size(const string_t &name)
Definition: json.hpp:12007
static std::size_t calc_bson_integer_size(const std::int64_t value)
Definition: json.hpp:12084
number value (unsigned integer)
then echo fcl name
number value (floating-point)
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).

Definition at line 12007 of file json.hpp.

12008  {
12009  const auto it = name.find(static_cast<typename string_t::value_type>(0));
12010  if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
12011  {
12013  "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")"));
12014  }
12015 
12016  return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
12017  }
#define JSON_THROW(exception)
Definition: json.hpp:1754
std::string to_string(WindowPattern const &pattern)
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
then echo fcl name
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
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

Definition at line 12084 of file json.hpp.

12085  {
12086  return (std::numeric_limits<std::int32_t>::min)() <= value and value <= (std::numeric_limits<std::int32_t>::max)()
12087  ? sizeof(std::int32_t)
12088  : sizeof(std::int64_t);
12089  }
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
temporary value
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]jJSON value to serialize
Precondition
j.type() == value_t::object

Definition at line 12277 of file json.hpp.

12278  {
12279  std::size_t document_size = std::accumulate(value.begin(), value.end(), 0ul,
12280  [](size_t result, const typename BasicJsonType::object_t::value_type & el)
12281  {
12282  return result += calc_bson_element_size(el.first, el.second);
12283  });
12284 
12285  return sizeof(std::int32_t) + document_size + 1ul;
12286  }
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.
Definition: json.hpp:12189
temporary value
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

Definition at line 12054 of file json.hpp.

12055  {
12056  return sizeof(std::int32_t) + value.size() + 1ul;
12057  }
temporary value
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)
inlinestaticprivatenoexcept
Returns
The size of the BSON-encoded unsigned integer in j

Definition at line 12112 of file json.hpp.

12113  {
12114  return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
12115  ? sizeof(std::int32_t)
12116  : sizeof(std::int64_t);
12117  }
temporary value
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_cbor_float_prefix ( float  )
inlinestaticprivate

Definition at line 12308 of file json.hpp.

12309  {
12310  return to_char_type(0xFA); // Single-Precision Float
12311  }
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_cbor_float_prefix ( double  )
inlinestaticprivate

Definition at line 12313 of file json.hpp.

12314  {
12315  return to_char_type(0xFB); // Double-Precision Float
12316  }
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_msgpack_float_prefix ( float  )
inlinestaticprivate

Definition at line 12322 of file json.hpp.

12323  {
12324  return to_char_type(0xCA); // float 32
12325  }
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_msgpack_float_prefix ( double  )
inlinestaticprivate

Definition at line 12327 of file json.hpp.

12328  {
12329  return to_char_type(0xCB); // float 64
12330  }
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_ubjson_float_prefix ( float  )
inlinestaticprivate

Definition at line 12536 of file json.hpp.

12537  {
12538  return 'd'; // float 32
12539  }
template<typename BasicJsonType , typename CharType >
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::get_ubjson_float_prefix ( double  )
inlinestaticprivate

Definition at line 12541 of file json.hpp.

12542  {
12543  return 'D'; // float 64
12544  }
template<typename BasicJsonType , typename CharType >
template<typename C = CharType, enable_if_t< std::is_signed< C >::value and std::is_signed< char >::value > * = nullptr>
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::to_char_type ( std::uint8_t  x)
inlinestaticnoexcept

Definition at line 12585 of file json.hpp.

12586  {
12587  return *reinterpret_cast<char*>(&x);
12588  }
process_name opflash particleana ie x
template<typename BasicJsonType , typename CharType >
template<typename C = CharType, enable_if_t< std::is_signed< C >::value and std::is_unsigned< char >::value > * = nullptr>
static CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::to_char_type ( std::uint8_t  x)
inlinestaticnoexcept

Definition at line 12592 of file json.hpp.

12593  {
12594  static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
12595  static_assert(std::is_pod<CharType>::value, "CharType must be POD");
12596  CharType result;
12597  std::memcpy(&result, &x, sizeof(x));
12598  return result;
12599  }
process_name opflash particleana ie x
temporary value
template<typename BasicJsonType , typename CharType >
template<typename C = CharType, enable_if_t< std::is_unsigned< C >::value > * = nullptr>
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::to_char_type ( std::uint8_t  x)
inlinestaticnoexcept

Definition at line 12603 of file json.hpp.

12604  {
12605  return x;
12606  }
process_name opflash particleana ie x
template<typename BasicJsonType , typename CharType >
template<typename InputCharType , typename C = CharType, enable_if_t< std::is_signed< C >::value andstd::is_signed< char >::value andstd::is_same< char, typename std::remove_cv< InputCharType >::type >::value > * = nullptr>
static constexpr CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::to_char_type ( InputCharType  x)
inlinestaticnoexcept

Definition at line 12614 of file json.hpp.

12615  {
12616  return x;
12617  }
process_name opflash particleana ie x
template<typename BasicJsonType , typename CharType >
CharType nlohmann::detail::binary_writer< BasicJsonType, CharType >::ubjson_prefix ( const BasicJsonType &  j) const
inlineprivatenoexcept

determine the type prefix of container values

Note
This function does not need to be 100% accurate when it comes to integer limits. In case a number exceeds the limits of int64_t, this will be detected by a later call to function write_number_with_ubjson_prefix. Therefore, we return 'L' for any value that does not fit the previous limits.

Definition at line 12465 of file json.hpp.

12466  {
12467  switch (j.type())
12468  {
12469  case value_t::null:
12470  return 'Z';
12471 
12472  case value_t::boolean:
12473  return j.m_value.boolean ? 'T' : 'F';
12474 
12476  {
12477  if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
12478  {
12479  return 'i';
12480  }
12481  if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
12482  {
12483  return 'U';
12484  }
12485  if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
12486  {
12487  return 'I';
12488  }
12489  if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
12490  {
12491  return 'l';
12492  }
12493  // no check and assume int64_t (see note above)
12494  return 'L';
12495  }
12496 
12498  {
12499  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
12500  {
12501  return 'i';
12502  }
12503  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)()))
12504  {
12505  return 'U';
12506  }
12507  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
12508  {
12509  return 'I';
12510  }
12511  if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
12512  {
12513  return 'l';
12514  }
12515  // no check and assume int64_t (see note above)
12516  return 'L';
12517  }
12518 
12519  case value_t::number_float:
12520  return get_ubjson_float_prefix(j.m_value.number_float);
12521 
12522  case value_t::string:
12523  return 'S';
12524 
12525  case value_t::array:
12526  return '[';
12527 
12528  case value_t::object:
12529  return '{';
12530 
12531  default: // discarded values
12532  return 'N';
12533  }
12534  }
static constexpr CharType get_ubjson_float_prefix(float)
Definition: json.hpp:12536
array (ordered collection of values)
number value (signed integer)
object (unordered set of name/value pairs)
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
number value (unsigned integer)
number value (floating-point)
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson ( const BasicJsonType &  j)
inline
Parameters
[in]jJSON value to serialize
Precondition
j.type() == value_t::object

Definition at line 11337 of file json.hpp.

11338  {
11339  switch (j.type())
11340  {
11341  case value_t::object:
11342  {
11343  write_bson_object(*j.m_value.object);
11344  break;
11345  }
11346 
11347  default:
11348  {
11349  JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
11350  }
11351  }
11352  }
void write_bson_object(const typename BasicJsonType::object_t &value)
Definition: json.hpp:12292
#define JSON_THROW(exception)
Definition: json.hpp:1754
object (unordered set of name/value pairs)
static type_error create(int id_, const std::string &what_arg)
Definition: json.hpp:2078
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_array ( const string_t name,
const typename BasicJsonType::array_t &  value 
)
inlineprivate

Writes a BSON element with key name and array value.

Definition at line 12169 of file json.hpp.

12171  {
12172  write_bson_entry_header(name, 0x04); // array
12173  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_array_size(value)));
12174 
12175  std::size_t array_index = 0ul;
12176 
12177  for (const auto& el : value)
12178  {
12179  write_bson_element(std::to_string(array_index++), el);
12180  }
12181 
12182  oa->write_character(to_char_type(0x00));
12183  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
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.
Definition: json.hpp:12022
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t &value)
Definition: json.hpp:12154
std::string to_string(WindowPattern const &pattern)
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
then echo fcl name
temporary 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.
Definition: json.hpp:12234
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_boolean ( const string_t name,
const bool  value 
)
inlineprivate

Writes a BSON element with key name and boolean value value.

Definition at line 12034 of file json.hpp.

12036  {
12038  oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
12039  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
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.
Definition: json.hpp:12022
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
then echo fcl name
temporary value
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_double ( const string_t name,
const double  value 
)
inlineprivate

Writes a BSON element with key name and double value value.

Definition at line 12044 of file json.hpp.

12046  {
12048  write_number<double, true>(value);
12049  }
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.
Definition: json.hpp:12022
then echo fcl name
temporary value
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
nameThe name to associate with the JSON entity j within the current BSON document
Returns
The size of the BSON entry

Definition at line 12234 of file json.hpp.

12236  {
12237  switch (j.type())
12238  {
12239  case value_t::object:
12240  return write_bson_object_entry(name, *j.m_value.object);
12241 
12242  case value_t::array:
12243  return write_bson_array(name, *j.m_value.array);
12244 
12245  case value_t::boolean:
12246  return write_bson_boolean(name, j.m_value.boolean);
12247 
12248  case value_t::number_float:
12249  return write_bson_double(name, j.m_value.number_float);
12250 
12252  return write_bson_integer(name, j.m_value.number_integer);
12253 
12255  return write_bson_unsigned(name, j.m_value.number_unsigned);
12256 
12257  case value_t::string:
12258  return write_bson_string(name, *j.m_value.string);
12259 
12260  case value_t::null:
12261  return write_bson_null(name);
12262 
12263  // LCOV_EXCL_START
12264  default:
12265  assert(false);
12266  return;
12267  // LCOV_EXCL_STOP
12268  }
12269  }
array (ordered collection of values)
void write_bson_double(const string_t &name, const double value)
Writes a BSON element with key name and double value value.
Definition: json.hpp:12044
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.
Definition: json.hpp:12144
number value (signed integer)
void write_bson_string(const string_t &name, const string_t &value)
Writes a BSON element with key name and string value value.
Definition: json.hpp:12062
void write_bson_null(const string_t &name)
Writes a BSON element with key name and null value.
Definition: json.hpp:12076
object (unordered set of name/value pairs)
void write_bson_array(const string_t &name, const typename BasicJsonType::array_t &value)
Writes a BSON element with key name and array value.
Definition: json.hpp:12169
void write_bson_integer(const string_t &name, const std::int64_t value)
Writes a BSON element with key name and integer value.
Definition: json.hpp:12094
void write_bson_boolean(const string_t &name, const bool value)
Writes a BSON element with key name and boolean value value.
Definition: json.hpp:12034
number value (unsigned integer)
then echo fcl name
void write_bson_unsigned(const string_t &name, const std::uint64_t value)
Writes a BSON element with key name and unsigned value.
Definition: json.hpp:12122
number value (floating-point)
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_entry_header ( const string_t name,
const std::uint8_t  element_type 
)
inlineprivate

Writes the given element_type and name to the output adapter.

Definition at line 12022 of file json.hpp.

12024  {
12025  oa->write_character(to_char_type(element_type)); // boolean
12026  oa->write_characters(
12027  reinterpret_cast<const CharType*>(name.c_str()),
12028  name.size() + 1u);
12029  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
then echo fcl name
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_integer ( const string_t name,
const std::int64_t  value 
)
inlineprivate

Writes a BSON element with key name and integer value.

Definition at line 12094 of file json.hpp.

12096  {
12097  if ((std::numeric_limits<std::int32_t>::min)() <= value and value <= (std::numeric_limits<std::int32_t>::max)())
12098  {
12099  write_bson_entry_header(name, 0x10); // int32
12100  write_number<std::int32_t, true>(static_cast<std::int32_t>(value));
12101  }
12102  else
12103  {
12104  write_bson_entry_header(name, 0x12); // int64
12105  write_number<std::int64_t, true>(static_cast<std::int64_t>(value));
12106  }
12107  }
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.
Definition: json.hpp:12022
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
then echo fcl name
temporary value
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_null ( const string_t name)
inlineprivate

Writes a BSON element with key name and null value.

Definition at line 12076 of file json.hpp.

12077  {
12079  }
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.
Definition: json.hpp:12022
then echo fcl name
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_object ( const typename BasicJsonType::object_t &  value)
inlineprivate
Parameters
[in]jJSON value to serialize
Precondition
j.type() == value_t::object

Definition at line 12292 of file json.hpp.

12293  {
12294  write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_object_size(value)));
12295 
12296  for (const auto& el : value)
12297  {
12298  write_bson_element(el.first, el.second);
12299  }
12300 
12301  oa->write_character(to_char_type(0x00));
12302  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
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.
Definition: json.hpp:12277
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
temporary 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.
Definition: json.hpp:12234
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_object_entry ( const string_t name,
const typename BasicJsonType::object_t &  value 
)
inlineprivate

Writes a BSON element with key name and object value.

Definition at line 12144 of file json.hpp.

12146  {
12147  write_bson_entry_header(name, 0x03); // object
12149  }
void write_bson_object(const typename BasicJsonType::object_t &value)
Definition: json.hpp:12292
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.
Definition: json.hpp:12022
then echo fcl name
temporary value
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_string ( const string_t name,
const string_t value 
)
inlineprivate

Writes a BSON element with key name and string value value.

Definition at line 12062 of file json.hpp.

12064  {
12066 
12067  write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size() + 1ul));
12068  oa->write_characters(
12069  reinterpret_cast<const CharType*>(value.c_str()),
12070  value.size() + 1);
12071  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
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.
Definition: json.hpp:12022
then echo fcl name
temporary value
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson_unsigned ( const string_t name,
const std::uint64_t  value 
)
inlineprivate

Writes a BSON element with key name and unsigned value.

Definition at line 12122 of file json.hpp.

12124  {
12125  if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
12126  {
12127  write_bson_entry_header(name, 0x10 /* int32 */);
12128  write_number<std::int32_t, true>(static_cast<std::int32_t>(value));
12129  }
12130  else if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
12131  {
12132  write_bson_entry_header(name, 0x12 /* int64 */);
12133  write_number<std::int64_t, true>(static_cast<std::int64_t>(value));
12134  }
12135  else
12136  {
12137  JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(value) + " cannot be represented by BSON as it does not fit int64"));
12138  }
12139  }
#define JSON_THROW(exception)
Definition: json.hpp:1754
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.
Definition: json.hpp:12022
std::string to_string(WindowPattern const &pattern)
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
then echo fcl name
temporary value
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_cbor ( const BasicJsonType &  j)
inline
Parameters
[in]jJSON value to serialize

Definition at line 11357 of file json.hpp.

11358  {
11359  switch (j.type())
11360  {
11361  case value_t::null:
11362  {
11363  oa->write_character(to_char_type(0xF6));
11364  break;
11365  }
11366 
11367  case value_t::boolean:
11368  {
11369  oa->write_character(j.m_value.boolean
11370  ? to_char_type(0xF5)
11371  : to_char_type(0xF4));
11372  break;
11373  }
11374 
11376  {
11377  if (j.m_value.number_integer >= 0)
11378  {
11379  // CBOR does not differentiate between positive signed
11380  // integers and unsigned integers. Therefore, we used the
11381  // code from the value_t::number_unsigned case here.
11382  if (j.m_value.number_integer <= 0x17)
11383  {
11384  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11385  }
11386  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
11387  {
11388  oa->write_character(to_char_type(0x18));
11389  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11390  }
11391  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
11392  {
11393  oa->write_character(to_char_type(0x19));
11394  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
11395  }
11396  else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
11397  {
11398  oa->write_character(to_char_type(0x1A));
11399  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
11400  }
11401  else
11402  {
11403  oa->write_character(to_char_type(0x1B));
11404  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
11405  }
11406  }
11407  else
11408  {
11409  // The conversions below encode the sign in the first
11410  // byte, and the value is converted to a positive number.
11411  const auto positive_number = -1 - j.m_value.number_integer;
11412  if (j.m_value.number_integer >= -24)
11413  {
11414  write_number(static_cast<std::uint8_t>(0x20 + positive_number));
11415  }
11416  else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
11417  {
11418  oa->write_character(to_char_type(0x38));
11419  write_number(static_cast<std::uint8_t>(positive_number));
11420  }
11421  else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
11422  {
11423  oa->write_character(to_char_type(0x39));
11424  write_number(static_cast<std::uint16_t>(positive_number));
11425  }
11426  else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
11427  {
11428  oa->write_character(to_char_type(0x3A));
11429  write_number(static_cast<std::uint32_t>(positive_number));
11430  }
11431  else
11432  {
11433  oa->write_character(to_char_type(0x3B));
11434  write_number(static_cast<std::uint64_t>(positive_number));
11435  }
11436  }
11437  break;
11438  }
11439 
11441  {
11442  if (j.m_value.number_unsigned <= 0x17)
11443  {
11444  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
11445  }
11446  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11447  {
11448  oa->write_character(to_char_type(0x18));
11449  write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
11450  }
11451  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11452  {
11453  oa->write_character(to_char_type(0x19));
11454  write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
11455  }
11456  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11457  {
11458  oa->write_character(to_char_type(0x1A));
11459  write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
11460  }
11461  else
11462  {
11463  oa->write_character(to_char_type(0x1B));
11464  write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
11465  }
11466  break;
11467  }
11468 
11469  case value_t::number_float:
11470  {
11471  oa->write_character(get_cbor_float_prefix(j.m_value.number_float));
11472  write_number(j.m_value.number_float);
11473  break;
11474  }
11475 
11476  case value_t::string:
11477  {
11478  // step 1: write control byte and the string length
11479  const auto N = j.m_value.string->size();
11480  if (N <= 0x17)
11481  {
11482  write_number(static_cast<std::uint8_t>(0x60 + N));
11483  }
11484  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11485  {
11486  oa->write_character(to_char_type(0x78));
11487  write_number(static_cast<std::uint8_t>(N));
11488  }
11489  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11490  {
11491  oa->write_character(to_char_type(0x79));
11492  write_number(static_cast<std::uint16_t>(N));
11493  }
11494  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11495  {
11496  oa->write_character(to_char_type(0x7A));
11497  write_number(static_cast<std::uint32_t>(N));
11498  }
11499  // LCOV_EXCL_START
11500  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11501  {
11502  oa->write_character(to_char_type(0x7B));
11503  write_number(static_cast<std::uint64_t>(N));
11504  }
11505  // LCOV_EXCL_STOP
11506 
11507  // step 2: write the string
11508  oa->write_characters(
11509  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
11510  j.m_value.string->size());
11511  break;
11512  }
11513 
11514  case value_t::array:
11515  {
11516  // step 1: write control byte and the array size
11517  const auto N = j.m_value.array->size();
11518  if (N <= 0x17)
11519  {
11520  write_number(static_cast<std::uint8_t>(0x80 + N));
11521  }
11522  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11523  {
11524  oa->write_character(to_char_type(0x98));
11525  write_number(static_cast<std::uint8_t>(N));
11526  }
11527  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11528  {
11529  oa->write_character(to_char_type(0x99));
11530  write_number(static_cast<std::uint16_t>(N));
11531  }
11532  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11533  {
11534  oa->write_character(to_char_type(0x9A));
11535  write_number(static_cast<std::uint32_t>(N));
11536  }
11537  // LCOV_EXCL_START
11538  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11539  {
11540  oa->write_character(to_char_type(0x9B));
11541  write_number(static_cast<std::uint64_t>(N));
11542  }
11543  // LCOV_EXCL_STOP
11544 
11545  // step 2: write each element
11546  for (const auto& el : *j.m_value.array)
11547  {
11548  write_cbor(el);
11549  }
11550  break;
11551  }
11552 
11553  case value_t::object:
11554  {
11555  // step 1: write control byte and the object size
11556  const auto N = j.m_value.object->size();
11557  if (N <= 0x17)
11558  {
11559  write_number(static_cast<std::uint8_t>(0xA0 + N));
11560  }
11561  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11562  {
11563  oa->write_character(to_char_type(0xB8));
11564  write_number(static_cast<std::uint8_t>(N));
11565  }
11566  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11567  {
11568  oa->write_character(to_char_type(0xB9));
11569  write_number(static_cast<std::uint16_t>(N));
11570  }
11571  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11572  {
11573  oa->write_character(to_char_type(0xBA));
11574  write_number(static_cast<std::uint32_t>(N));
11575  }
11576  // LCOV_EXCL_START
11577  else if (N <= (std::numeric_limits<std::uint64_t>::max)())
11578  {
11579  oa->write_character(to_char_type(0xBB));
11580  write_number(static_cast<std::uint64_t>(N));
11581  }
11582  // LCOV_EXCL_STOP
11583 
11584  // step 2: write each element
11585  for (const auto& el : *j.m_value.object)
11586  {
11587  write_cbor(el.first);
11588  write_cbor(el.second);
11589  }
11590  break;
11591  }
11592 
11593  default:
11594  break;
11595  }
11596  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
static constexpr CharType get_cbor_float_prefix(float)
Definition: json.hpp:12308
array (ordered collection of values)
number value (signed integer)
object (unordered set of name/value pairs)
void write_number(const NumberType n)
Definition: json.hpp:12562
process_name largeant stream1 can override from command line with o or output physics producers generator N
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
number value (unsigned integer)
number value (floating-point)
void write_cbor(const BasicJsonType &j)
Definition: json.hpp:11357
template<typename BasicJsonType , typename CharType >
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_msgpack ( const BasicJsonType &  j)
inline
Parameters
[in]jJSON value to serialize

Definition at line 11601 of file json.hpp.

11602  {
11603  switch (j.type())
11604  {
11605  case value_t::null: // nil
11606  {
11607  oa->write_character(to_char_type(0xC0));
11608  break;
11609  }
11610 
11611  case value_t::boolean: // true and false
11612  {
11613  oa->write_character(j.m_value.boolean
11614  ? to_char_type(0xC3)
11615  : to_char_type(0xC2));
11616  break;
11617  }
11618 
11620  {
11621  if (j.m_value.number_integer >= 0)
11622  {
11623  // MessagePack does not differentiate between positive
11624  // signed integers and unsigned integers. Therefore, we used
11625  // the code from the value_t::number_unsigned case here.
11626  if (j.m_value.number_unsigned < 128)
11627  {
11628  // positive fixnum
11629  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11630  }
11631  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11632  {
11633  // uint 8
11634  oa->write_character(to_char_type(0xCC));
11635  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11636  }
11637  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11638  {
11639  // uint 16
11640  oa->write_character(to_char_type(0xCD));
11641  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
11642  }
11643  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11644  {
11645  // uint 32
11646  oa->write_character(to_char_type(0xCE));
11647  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
11648  }
11649  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
11650  {
11651  // uint 64
11652  oa->write_character(to_char_type(0xCF));
11653  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
11654  }
11655  }
11656  else
11657  {
11658  if (j.m_value.number_integer >= -32)
11659  {
11660  // negative fixnum
11661  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
11662  }
11663  else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() and
11664  j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
11665  {
11666  // int 8
11667  oa->write_character(to_char_type(0xD0));
11668  write_number(static_cast<std::int8_t>(j.m_value.number_integer));
11669  }
11670  else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() and
11671  j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
11672  {
11673  // int 16
11674  oa->write_character(to_char_type(0xD1));
11675  write_number(static_cast<std::int16_t>(j.m_value.number_integer));
11676  }
11677  else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() and
11678  j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
11679  {
11680  // int 32
11681  oa->write_character(to_char_type(0xD2));
11682  write_number(static_cast<std::int32_t>(j.m_value.number_integer));
11683  }
11684  else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() and
11685  j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
11686  {
11687  // int 64
11688  oa->write_character(to_char_type(0xD3));
11689  write_number(static_cast<std::int64_t>(j.m_value.number_integer));
11690  }
11691  }
11692  break;
11693  }
11694 
11696  {
11697  if (j.m_value.number_unsigned < 128)
11698  {
11699  // positive fixnum
11700  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11701  }
11702  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
11703  {
11704  // uint 8
11705  oa->write_character(to_char_type(0xCC));
11706  write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
11707  }
11708  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
11709  {
11710  // uint 16
11711  oa->write_character(to_char_type(0xCD));
11712  write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
11713  }
11714  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
11715  {
11716  // uint 32
11717  oa->write_character(to_char_type(0xCE));
11718  write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
11719  }
11720  else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
11721  {
11722  // uint 64
11723  oa->write_character(to_char_type(0xCF));
11724  write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
11725  }
11726  break;
11727  }
11728 
11729  case value_t::number_float:
11730  {
11731  oa->write_character(get_msgpack_float_prefix(j.m_value.number_float));
11732  write_number(j.m_value.number_float);
11733  break;
11734  }
11735 
11736  case value_t::string:
11737  {
11738  // step 1: write control byte and the string length
11739  const auto N = j.m_value.string->size();
11740  if (N <= 31)
11741  {
11742  // fixstr
11743  write_number(static_cast<std::uint8_t>(0xA0 | N));
11744  }
11745  else if (N <= (std::numeric_limits<std::uint8_t>::max)())
11746  {
11747  // str 8
11748  oa->write_character(to_char_type(0xD9));
11749  write_number(static_cast<std::uint8_t>(N));
11750  }
11751  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11752  {
11753  // str 16
11754  oa->write_character(to_char_type(0xDA));
11755  write_number(static_cast<std::uint16_t>(N));
11756  }
11757  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11758  {
11759  // str 32
11760  oa->write_character(to_char_type(0xDB));
11761  write_number(static_cast<std::uint32_t>(N));
11762  }
11763 
11764  // step 2: write the string
11765  oa->write_characters(
11766  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
11767  j.m_value.string->size());
11768  break;
11769  }
11770 
11771  case value_t::array:
11772  {
11773  // step 1: write control byte and the array size
11774  const auto N = j.m_value.array->size();
11775  if (N <= 15)
11776  {
11777  // fixarray
11778  write_number(static_cast<std::uint8_t>(0x90 | N));
11779  }
11780  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11781  {
11782  // array 16
11783  oa->write_character(to_char_type(0xDC));
11784  write_number(static_cast<std::uint16_t>(N));
11785  }
11786  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11787  {
11788  // array 32
11789  oa->write_character(to_char_type(0xDD));
11790  write_number(static_cast<std::uint32_t>(N));
11791  }
11792 
11793  // step 2: write each element
11794  for (const auto& el : *j.m_value.array)
11795  {
11796  write_msgpack(el);
11797  }
11798  break;
11799  }
11800 
11801  case value_t::object:
11802  {
11803  // step 1: write control byte and the object size
11804  const auto N = j.m_value.object->size();
11805  if (N <= 15)
11806  {
11807  // fixmap
11808  write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF)));
11809  }
11810  else if (N <= (std::numeric_limits<std::uint16_t>::max)())
11811  {
11812  // map 16
11813  oa->write_character(to_char_type(0xDE));
11814  write_number(static_cast<std::uint16_t>(N));
11815  }
11816  else if (N <= (std::numeric_limits<std::uint32_t>::max)())
11817  {
11818  // map 32
11819  oa->write_character(to_char_type(0xDF));
11820  write_number(static_cast<std::uint32_t>(N));
11821  }
11822 
11823  // step 2: write each element
11824  for (const auto& el : *j.m_value.object)
11825  {
11826  write_msgpack(el.first);
11827  write_msgpack(el.second);
11828  }
11829  break;
11830  }
11831 
11832  default:
11833  break;
11834  }
11835  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
array (ordered collection of values)
number value (signed integer)
void write_msgpack(const BasicJsonType &j)
Definition: json.hpp:11601
object (unordered set of name/value pairs)
void write_number(const NumberType n)
Definition: json.hpp:12562
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
static constexpr CharType get_msgpack_float_prefix(float)
Definition: json.hpp:12322
process_name largeant stream1 can override from command line with o or output physics producers generator N
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
number value (unsigned integer)
number value (floating-point)
template<typename BasicJsonType , typename CharType >
template<typename NumberType , bool OutputIsLittleEndian = false>
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_number ( const NumberType  n)
inlineprivate

Definition at line 12562 of file json.hpp.

12563  {
12564  // step 1: write number to array of length NumberType
12565  std::array<CharType, sizeof(NumberType)> vec;
12566  std::memcpy(vec.data(), &n, sizeof(NumberType));
12567 
12568  // step 2: write array to output (with possible reordering)
12569  if (is_little_endian != OutputIsLittleEndian)
12570  {
12571  // reverse byte order prior to conversion if necessary
12572  std::reverse(vec.begin(), vec.end());
12573  }
12574 
12575  oa->write_characters(vec.data(), sizeof(NumberType));
12576  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
const bool is_little_endian
whether we can assume little endianess
Definition: json.hpp:12621
template<typename BasicJsonType , typename CharType >
template<typename NumberType , typename std::enable_if< std::is_floating_point< NumberType >::value, int >::type = 0>
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_number_with_ubjson_prefix ( const NumberType  n,
const bool  add_prefix 
)
inlineprivate

Definition at line 12339 of file json.hpp.

12341  {
12342  if (add_prefix)
12343  {
12344  oa->write_character(get_ubjson_float_prefix(n));
12345  }
12346  write_number(n);
12347  }
static constexpr CharType get_ubjson_float_prefix(float)
Definition: json.hpp:12536
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
void write_number(const NumberType n)
Definition: json.hpp:12562
template<typename BasicJsonType , typename CharType >
template<typename NumberType , typename std::enable_if< std::is_unsigned< NumberType >::value, int >::type = 0>
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_number_with_ubjson_prefix ( const NumberType  n,
const bool  add_prefix 
)
inlineprivate

Definition at line 12352 of file json.hpp.

12354  {
12355  if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
12356  {
12357  if (add_prefix)
12358  {
12359  oa->write_character(to_char_type('i')); // int8
12360  }
12361  write_number(static_cast<std::uint8_t>(n));
12362  }
12363  else if (n <= (std::numeric_limits<std::uint8_t>::max)())
12364  {
12365  if (add_prefix)
12366  {
12367  oa->write_character(to_char_type('U')); // uint8
12368  }
12369  write_number(static_cast<std::uint8_t>(n));
12370  }
12371  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
12372  {
12373  if (add_prefix)
12374  {
12375  oa->write_character(to_char_type('I')); // int16
12376  }
12377  write_number(static_cast<std::int16_t>(n));
12378  }
12379  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
12380  {
12381  if (add_prefix)
12382  {
12383  oa->write_character(to_char_type('l')); // int32
12384  }
12385  write_number(static_cast<std::int32_t>(n));
12386  }
12387  else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
12388  {
12389  if (add_prefix)
12390  {
12391  oa->write_character(to_char_type('L')); // int64
12392  }
12393  write_number(static_cast<std::int64_t>(n));
12394  }
12395  else
12396  {
12397  JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(n) + " cannot be represented by UBJSON as it does not fit int64"));
12398  }
12399  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
#define JSON_THROW(exception)
Definition: json.hpp:1754
void write_number(const NumberType n)
Definition: json.hpp:12562
std::string to_string(WindowPattern const &pattern)
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
template<typename BasicJsonType , typename CharType >
template<typename NumberType , typename std::enable_if< std::is_signed< NumberType >::value andnot std::is_floating_point< NumberType >::value, int >::type = 0>
void nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_number_with_ubjson_prefix ( const NumberType  n,
const bool  add_prefix 
)
inlineprivate

Definition at line 12405 of file json.hpp.

12407  {
12408  if ((std::numeric_limits<std::int8_t>::min)() <= n and n <= (std::numeric_limits<std::int8_t>::max)())
12409  {
12410  if (add_prefix)
12411  {
12412  oa->write_character(to_char_type('i')); // int8
12413  }
12414  write_number(static_cast<std::int8_t>(n));
12415  }
12416  else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n and n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
12417  {
12418  if (add_prefix)
12419  {
12420  oa->write_character(to_char_type('U')); // uint8
12421  }
12422  write_number(static_cast<std::uint8_t>(n));
12423  }
12424  else if ((std::numeric_limits<std::int16_t>::min)() <= n and n <= (std::numeric_limits<std::int16_t>::max)())
12425  {
12426  if (add_prefix)
12427  {
12428  oa->write_character(to_char_type('I')); // int16
12429  }
12430  write_number(static_cast<std::int16_t>(n));
12431  }
12432  else if ((std::numeric_limits<std::int32_t>::min)() <= n and n <= (std::numeric_limits<std::int32_t>::max)())
12433  {
12434  if (add_prefix)
12435  {
12436  oa->write_character(to_char_type('l')); // int32
12437  }
12438  write_number(static_cast<std::int32_t>(n));
12439  }
12440  else if ((std::numeric_limits<std::int64_t>::min)() <= n and n <= (std::numeric_limits<std::int64_t>::max)())
12441  {
12442  if (add_prefix)
12443  {
12444  oa->write_character(to_char_type('L')); // int64
12445  }
12446  write_number(static_cast<std::int64_t>(n));
12447  }
12448  // LCOV_EXCL_START
12449  else
12450  {
12451  JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(n) + " cannot be represented by UBJSON as it does not fit int64"));
12452  }
12453  // LCOV_EXCL_STOP
12454  }
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
#define JSON_THROW(exception)
Definition: json.hpp:1754
void write_number(const NumberType n)
Definition: json.hpp:12562
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::string to_string(WindowPattern const &pattern)
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
static out_of_range create(int id_, const std::string &what_arg)
Definition: json.hpp:2125
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]jJSON value to serialize
[in]use_countwhether to use '#' prefixes (optimized format)
[in]use_typewhether to use '$' prefixes (optimized format)
[in]add_prefixwhether prefixes need to be used for this value

Definition at line 11843 of file json.hpp.

11845  {
11846  switch (j.type())
11847  {
11848  case value_t::null:
11849  {
11850  if (add_prefix)
11851  {
11852  oa->write_character(to_char_type('Z'));
11853  }
11854  break;
11855  }
11856 
11857  case value_t::boolean:
11858  {
11859  if (add_prefix)
11860  {
11861  oa->write_character(j.m_value.boolean
11862  ? to_char_type('T')
11863  : to_char_type('F'));
11864  }
11865  break;
11866  }
11867 
11869  {
11870  write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
11871  break;
11872  }
11873 
11875  {
11876  write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
11877  break;
11878  }
11879 
11880  case value_t::number_float:
11881  {
11882  write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
11883  break;
11884  }
11885 
11886  case value_t::string:
11887  {
11888  if (add_prefix)
11889  {
11890  oa->write_character(to_char_type('S'));
11891  }
11892  write_number_with_ubjson_prefix(j.m_value.string->size(), true);
11893  oa->write_characters(
11894  reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
11895  j.m_value.string->size());
11896  break;
11897  }
11898 
11899  case value_t::array:
11900  {
11901  if (add_prefix)
11902  {
11903  oa->write_character(to_char_type('['));
11904  }
11905 
11906  bool prefix_required = true;
11907  if (use_type and not j.m_value.array->empty())
11908  {
11909  assert(use_count);
11910  const CharType first_prefix = ubjson_prefix(j.front());
11911  const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
11912  [this, first_prefix](const BasicJsonType & v)
11913  {
11914  return ubjson_prefix(v) == first_prefix;
11915  });
11916 
11917  if (same_prefix)
11918  {
11919  prefix_required = false;
11920  oa->write_character(to_char_type('$'));
11921  oa->write_character(first_prefix);
11922  }
11923  }
11924 
11925  if (use_count)
11926  {
11927  oa->write_character(to_char_type('#'));
11928  write_number_with_ubjson_prefix(j.m_value.array->size(), true);
11929  }
11930 
11931  for (const auto& el : *j.m_value.array)
11932  {
11933  write_ubjson(el, use_count, use_type, prefix_required);
11934  }
11935 
11936  if (not use_count)
11937  {
11938  oa->write_character(to_char_type(']'));
11939  }
11940 
11941  break;
11942  }
11943 
11944  case value_t::object:
11945  {
11946  if (add_prefix)
11947  {
11948  oa->write_character(to_char_type('{'));
11949  }
11950 
11951  bool prefix_required = true;
11952  if (use_type and not j.m_value.object->empty())
11953  {
11954  assert(use_count);
11955  const CharType first_prefix = ubjson_prefix(j.front());
11956  const bool same_prefix = std::all_of(j.begin(), j.end(),
11957  [this, first_prefix](const BasicJsonType & v)
11958  {
11959  return ubjson_prefix(v) == first_prefix;
11960  });
11961 
11962  if (same_prefix)
11963  {
11964  prefix_required = false;
11965  oa->write_character(to_char_type('$'));
11966  oa->write_character(first_prefix);
11967  }
11968  }
11969 
11970  if (use_count)
11971  {
11972  oa->write_character(to_char_type('#'));
11973  write_number_with_ubjson_prefix(j.m_value.object->size(), true);
11974  }
11975 
11976  for (const auto& el : *j.m_value.object)
11977  {
11978  write_number_with_ubjson_prefix(el.first.size(), true);
11979  oa->write_characters(
11980  reinterpret_cast<const CharType*>(el.first.c_str()),
11981  el.first.size());
11982  write_ubjson(el.second, use_count, use_type, prefix_required);
11983  }
11984 
11985  if (not use_count)
11986  {
11987  oa->write_character(to_char_type('}'));
11988  }
11989 
11990  break;
11991  }
11992 
11993  default:
11994  break;
11995  }
11996  }
void write_number_with_ubjson_prefix(const NumberType n, const bool add_prefix)
Definition: json.hpp:12339
output_adapter_t< CharType > oa
the output
Definition: json.hpp:12624
array (ordered collection of values)
number value (signed integer)
object (unordered set of name/value pairs)
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true)
Definition: json.hpp:11843
number value (unsigned integer)
CharType ubjson_prefix(const BasicJsonType &j) const noexcept
determine the type prefix of container values
Definition: json.hpp:12465
number value (floating-point)

Member Data Documentation

template<typename BasicJsonType , typename CharType >
const bool nlohmann::detail::binary_writer< BasicJsonType, CharType >::is_little_endian = binary_reader<BasicJsonType>::little_endianess()
private

whether we can assume little endianess

Definition at line 12621 of file json.hpp.

template<typename BasicJsonType , typename CharType >
output_adapter_t<CharType> nlohmann::detail::binary_writer< BasicJsonType, CharType >::oa = nullptr
private

the output

Definition at line 12624 of file json.hpp.


The documentation for this class was generated from the following file: