✨ implemented indefinite-length CBOR types (#387)
This commit is contained in:
parent
6b84c4155c
commit
d99c230f51
3 changed files with 86 additions and 0 deletions
35
src/json.hpp
35
src/json.hpp
|
@ -7043,6 +7043,18 @@ class basic_json
|
|||
idx += len + 8; // skip 8 size bytes + content bytes
|
||||
return std::string(reinterpret_cast<const char*>(v.data()) + offset, len);
|
||||
}
|
||||
else if (v[current_idx] == 0x7f) // UTF-8 string (indefinite length)
|
||||
{
|
||||
std::string result;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
string_t s = from_cbor_internal(v, idx);
|
||||
result += s;
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] >= 0x80 and v[current_idx] <= 0x97) // array
|
||||
{
|
||||
basic_json result = value_t::array;
|
||||
|
@ -7097,6 +7109,17 @@ class basic_json
|
|||
}
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0x9f) // array (indefinite length)
|
||||
{
|
||||
basic_json result = value_t::array;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
result.push_back(from_cbor_internal(v, idx));
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] >= 0xa0 and v[current_idx] <= 0xb7) // map
|
||||
{
|
||||
basic_json result = value_t::object;
|
||||
|
@ -7156,6 +7179,18 @@ class basic_json
|
|||
}
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0xbf) // map (indefinite length)
|
||||
{
|
||||
basic_json result = value_t::object;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
std::string key = from_cbor_internal(v, idx);
|
||||
result[key] = from_cbor_internal(v, idx);
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0xf4) // false
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -7043,6 +7043,18 @@ class basic_json
|
|||
idx += len + 8; // skip 8 size bytes + content bytes
|
||||
return std::string(reinterpret_cast<const char*>(v.data()) + offset, len);
|
||||
}
|
||||
else if (v[current_idx] == 0x7f) // UTF-8 string (indefinite length)
|
||||
{
|
||||
std::string result;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
string_t s = from_cbor_internal(v, idx);
|
||||
result += s;
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] >= 0x80 and v[current_idx] <= 0x97) // array
|
||||
{
|
||||
basic_json result = value_t::array;
|
||||
|
@ -7097,6 +7109,17 @@ class basic_json
|
|||
}
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0x9f) // array (indefinite length)
|
||||
{
|
||||
basic_json result = value_t::array;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
result.push_back(from_cbor_internal(v, idx));
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] >= 0xa0 and v[current_idx] <= 0xb7) // map
|
||||
{
|
||||
basic_json result = value_t::object;
|
||||
|
@ -7156,6 +7179,18 @@ class basic_json
|
|||
}
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0xbf) // map (indefinite length)
|
||||
{
|
||||
basic_json result = value_t::object;
|
||||
while (v[idx] != 0xff)
|
||||
{
|
||||
std::string key = from_cbor_internal(v, idx);
|
||||
result[key] = from_cbor_internal(v, idx);
|
||||
}
|
||||
// skip break byte (0xFF)
|
||||
idx += 1;
|
||||
return result;
|
||||
}
|
||||
else if (v[current_idx] == 0xf4) // false
|
||||
{
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue