TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ from_ubjson() [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_ubjson ( InputType &&  i,
const bool  strict = true,
const bool  allow_exceptions = true 
)
inlinestatic

create a JSON value from an input in UBJSON format

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

The library maps UBJSON types to JSON value types as follows:

UBJSON type JSON value type marker
no-op no value, next value is read N
null null Z
false false F
true true T
float32 number_float d
float64 number_float D
uint8 number_unsigned U
int8 number_integer i
int16 number_integer I
int32 number_integer l
int64 number_integer L
high-precision number number_integer, number_unsigned, or number_float - depends on number string 'H'
string string S
char string C
array array (optimized values are supported) [
object object (optimized values are supported) {
Note
The mapping is complete in the sense that any UBJSON value can be converted to a JSON value.
Parameters
[in]ian input in UBJSON 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.110if the given input ends prematurely or the end of file was not reached when strict was set to true
parse_error.112if a parse error occurs
parse_error.113if a string could not be parsed successfully

@complexity Linear in the size of the input i.

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

See also
http://ubjson.org
see to_ubjson(const basic_json&, const bool, const bool) 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_bson(InputType&&, const bool, const bool) for the related BSON format
Since
version 3.1.0; added allow_exceptions parameter since 3.2.0

Definition at line 25711 of file json.hpp.

25714 {
25715 basic_json result;
25716 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25717 auto ia = detail::input_adapter(std::forward<InputType>(i));
25718 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25719 return res ? result : basic_json(value_t::discarded);
25720 }
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