Streamline parsing of fixed length strings and blobs

This commit is contained in:
TennesseeTrash 2025-09-19 02:06:37 +02:00
parent 257be2e57a
commit bec16e493f
3 changed files with 90 additions and 117 deletions

View file

@ -59,10 +59,10 @@ SomeStruct Decode1(std::span<std::uint8_t> buffer)
CBOR::Map object = dec.Map();
while (!object.Done()) {
CBOR::KeyValue kv = object.Next();
std::string_view key = kv.Key().String().Get();
std::string_view key = kv.Key().String();
CBOR::Item value = kv.Value();
if (key == "name") {
result.name = value.String().Get();
result.name = value.String();
}
else if (key == "speed") {
result.speed = value.Double();
@ -82,7 +82,7 @@ SomeStruct Decode1(std::span<std::uint8_t> buffer)
else if (key == "tools") {
CBOR::Array tools = value.Array();
while(!tools.Done()) {
result.tools.push_back(std::string(tools.Next().String().Get()));
result.tools.push_back(std::string(tools.Next().String()));
}
}
}
@ -98,10 +98,10 @@ SomeStruct Decode2(std::span<std::uint8_t> buffer)
CBOR::Map object = dec.Map();
while (!object.Done()) {
CBOR::KeyValue kv = object.Next();
std::string_view key = kv.Key().String().Get();
std::string_view key = kv.Key().String();
CBOR::Item value = kv.Value();
if (key == "name") {
result.name = value.String().Get();
result.name = value.String();
}
else if (key == "speed") {
result.speed = value.Double();
@ -122,8 +122,7 @@ SomeStruct Decode2(std::span<std::uint8_t> buffer)
CBOR::Array tools = value.Array();
while(!tools.Done()) {
result.tools.push_back("");
CBOR::String tool = tools.Next().String();
tool.AllowIndefinite();
CBOR::String tool = tools.Next().IndefiniteString();
while (!tool.Done()) {
result.tools.back().append(tool.Next());
}