Skip to content

Efficient partial reads of optional fields near the start of a large message #2406

@Allybag

Description

@Allybag

So, I have a use case where I want to extract two strings from large JSON messages, where one will always be present, and the other is only present about 1% of the time. I think basically what I would want is something like

struct partial_struct
{
   std::string always{};
   std::optional<std::string> maybe{};
};
partial_struct obj{};
std::string s = R"({"always":"present","rest":"All sorts of other information and fields I don't care about...})";
glz::read<glz::opts{.partial_read = true}>(obj, std::string_view{s}.substr(0, N));

Where N is a number which I know will be < the min size of S and > the final index of the values of both always and maybe. The issue is that of course the first N chars of S are very unlikely to be valid JSON as it might end in the middle of some element or whatever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions