MCPcopy Create free account
hub / github.com/aixed/WeChat-Hook / get_ubjson_array

Method get_ubjson_array

include/json.hpp:11474–11577  ·  view source on GitHub ↗

! @return whether array creation completed */

Source from the content-addressed store, hash-verified

11472 @return whether array creation completed
11473 */
11474 bool get_ubjson_array()
11475 {
11476 std::pair<std::size_t, char_int_type> size_and_type;
11477 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11478 {
11479 return false;
11480 }
11481
11482 // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata):
11483 // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]}
11484
11485 if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0)
11486 {
11487 std::map<char_int_type, string_t> bjdtype = {{'U', "uint8"}, {'i', "int8"}, {'u', "uint16"}, {'I', "int16"},
11488 {'m', "uint32"}, {'l', "int32"}, {'M', "uint64"}, {'L', "int64"}, {'d', "single"}, {'D', "double"}, {'C', "char"}
11489 };
11490
11491 size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker
11492
11493 string_t key = "_ArrayType_";
11494 if (JSON_HEDLEY_UNLIKELY(bjdtype.count(size_and_type.second) == 0))
11495 {
11496 auto last_token = get_token_string();
11497 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11498 exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr));
11499 }
11500
11501 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(bjdtype[size_and_type.second]) ))
11502 {
11503 return false;
11504 }
11505
11506 if (size_and_type.second == 'C')
11507 {
11508 size_and_type.second = 'U';
11509 }
11510
11511 key = "_ArrayData_";
11512 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
11513 {
11514 return false;
11515 }
11516
11517 for (std::size_t i = 0; i < size_and_type.first; ++i)
11518 {
11519 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11520 {
11521 return false;
11522 }
11523 }
11524
11525 return (sax->end_array() && sax->end_object());
11526 }
11527
11528 if (size_and_type.first != string_t::npos)
11529 {
11530 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
11531 {

Callers

nothing calls this directly

Calls 9

countMethod · 0.80
get_token_stringFunction · 0.70
createFunction · 0.70
parse_errorMethod · 0.45
keyMethod · 0.45
stringMethod · 0.45
start_arrayMethod · 0.45
end_arrayMethod · 0.45
end_objectMethod · 0.45

Tested by

no test coverage detected