MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / write_bjdata_ndarray

Method write_bjdata_ndarray

Source/external/json.hpp:16533–16640  ·  view source on GitHub ↗

! @return false if the object is successfully converted to a bjdata ndarray, true if the type or size is invalid */

Source from the content-addressed store, hash-verified

16531 @return false if the object is successfully converted to a bjdata ndarray, true if the type or size is invalid
16532 */
16533 bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
16534 {
16535 std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'},
16536 {"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'}
16537 };
16538
16539 string_t key = "_ArrayType_";
16540 auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
16541 if (it == bjdtype.end())
16542 {
16543 return true;
16544 }
16545 CharType dtype = it->second;
16546
16547 key = "_ArraySize_";
16548 std::size_t len = (value.at(key).empty() ? 0 : 1);
16549 for (const auto& el : value.at(key))
16550 {
16551 len *= static_cast<std::size_t>(el.m_value.number_unsigned);
16552 }
16553
16554 key = "_ArrayData_";
16555 if (value.at(key).size() != len)
16556 {
16557 return true;
16558 }
16559
16560 oa->write_character('[');
16561 oa->write_character('$');
16562 oa->write_character(dtype);
16563 oa->write_character('#');
16564
16565 key = "_ArraySize_";
16566 write_ubjson(value.at(key), use_count, use_type, true, true);
16567
16568 key = "_ArrayData_";
16569 if (dtype == 'U' || dtype == 'C')
16570 {
16571 for (const auto& el : value.at(key))
16572 {
16573 write_number(static_cast<std::uint8_t>(el.m_value.number_unsigned), true);
16574 }
16575 }
16576 else if (dtype == 'i')
16577 {
16578 for (const auto& el : value.at(key))
16579 {
16580 write_number(static_cast<std::int8_t>(el.m_value.number_integer), true);
16581 }
16582 }
16583 else if (dtype == 'u')
16584 {
16585 for (const auto& el : value.at(key))
16586 {
16587 write_number(static_cast<std::uint16_t>(el.m_value.number_unsigned), true);
16588 }
16589 }
16590 else if (dtype == 'I')

Callers

nothing calls this directly

Calls 4

endMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80
write_characterMethod · 0.45

Tested by

no test coverage detected