TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ 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)
inlineprivate

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]resultcreated string
Returns
whether string creation completed

Definition at line 9298 of file json.hpp.

9299 {
9300 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
9301 {
9302 return false;
9303 }
9304
9305 switch (current)
9306 {
9307 // UTF-8 string (0x00..0x17 bytes follow)
9308 case 0x60:
9309 case 0x61:
9310 case 0x62:
9311 case 0x63:
9312 case 0x64:
9313 case 0x65:
9314 case 0x66:
9315 case 0x67:
9316 case 0x68:
9317 case 0x69:
9318 case 0x6A:
9319 case 0x6B:
9320 case 0x6C:
9321 case 0x6D:
9322 case 0x6E:
9323 case 0x6F:
9324 case 0x70:
9325 case 0x71:
9326 case 0x72:
9327 case 0x73:
9328 case 0x74:
9329 case 0x75:
9330 case 0x76:
9331 case 0x77:
9332 {
9333 return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
9334 }
9335
9336 case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
9337 {
9338 std::uint8_t len{};
9339 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9340 }
9341
9342 case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
9343 {
9344 std::uint16_t len{};
9345 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9346 }
9347
9348 case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
9349 {
9350 std::uint32_t len{};
9351 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9352 }
9353
9354 case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
9355 {
9356 std::uint64_t len{};
9357 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9358 }
9359
9360 case 0x7F: // UTF-8 string (indefinite length)
9361 {
9362 while (get() != 0xFF)
9363 {
9364 string_t chunk;
9365
9366 if (!get_cbor_string(chunk))
9367 {
9368 return false;
9369 }
9370
9371 result.append(chunk);
9372 }
9373
9374 return true;
9375 }
9376
9377 default:
9378 {
9379 auto last_token = get_token_string();
9380 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), BasicJsonType()));
9381 }
9382 }
9383 }
bool get_string(const input_format_t format, const NumberType len, string_t &result)
create a string by reading characters from the input
Definition: json.hpp:10849
bool get_cbor_string(string_t &result)
reads a CBOR string
Definition: json.hpp:9298
bool unexpect_eof(const input_format_t format, const char *context) const
Definition: json.hpp:10914
std::string get_token_string() const
Definition: json.hpp:10928
std::string exception_message(const input_format_t format, const std::string &detail, const std::string &context) const
Definition: json.hpp:10941
std::size_t chars_read
the number of characters read
Definition: json.hpp:10981
char_int_type current
the current character
Definition: json.hpp:10978
json_sax_t * sax
the SAX parser
Definition: json.hpp:10987
char_int_type get()
get next character from the input
Definition: json.hpp:10769
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: json.hpp:2800