TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ from_bson() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType >
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::from_bson ( InputType &&  i,
const bool  strict = true,
const bool  allow_exceptions = true 
)
inlinestatic

Create a JSON value from an input in BSON format.

Deserializes a given input i to a JSON value using the BSON (Binary JSON) serialization format.

The library maps BSON record types to JSON value types as follows:

BSON type BSON marker byte JSON value type
double 0x01 number_float
string 0x02 string
document 0x03 object
array 0x04 array
binary 0x05 binary
undefined 0x06 still unsupported
ObjectId 0x07 still unsupported
boolean 0x08 boolean
UTC Date-Time 0x09 still unsupported
null 0x0A null
Regular Expr. 0x0B still unsupported
DB Pointer 0x0C still unsupported
JavaScript Code 0x0D still unsupported
Symbol 0x0E still unsupported
JavaScript Code 0x0F still unsupported
int32 0x10 number_integer
Timestamp 0x11 still unsupported
128-bit decimal float 0x13 still unsupported
Max Key 0x7F still unsupported
Min Key 0xFF still unsupported
Warning
The mapping is incomplete. The unsupported mappings are indicated in the table above.
Parameters
[in]ian input in BSON format convertible to an input adapter
[in]strictwhether to expect the input to be consumed until EOF (true by default)
[in]allow_exceptionswhether to throw exceptions in case of a parse error (optional, true by default)
Returns
deserialized JSON value; in case of a parse error and allow_exceptions set to false, the return value will be value_t::discarded.
Exceptions
parse_error.114if an unsupported BSON record type is encountered

@complexity Linear in the size of the input i.

@liveexample{The example shows the deserialization of a byte vector in BSON format to a JSON value.,from_bson}

See also
http://bsonspec.org/spec.html
see to_bson(const basic_json&) for the analogous serialization
see from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the related CBOR format
see from_msgpack(InputType&&, const bool, const bool) for the related MessagePack format
see from_ubjson(InputType&&, const bool, const bool) for the related UBJSON format

Definition at line 25825 of file json.hpp.

25828 {
25829 basic_json result;
25830 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25831 auto ia = detail::input_adapter(std::forward<InputType>(i));
25832 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25833 return res ? result : basic_json(value_t::discarded);
25834 }
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:19164
@ discarded
discarded by the parser callback function