Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] DynamicParser may not emit OmittedField for compile-time schema #1120

Closed
ara-ayvazyan opened this issue Sep 9, 2021 · 0 comments · Fixed by #1121
Closed

[c++] DynamicParser may not emit OmittedField for compile-time schema #1120

ara-ayvazyan opened this issue Sep 9, 2021 · 0 comments · Fixed by #1121
Labels

Comments

@ara-ayvazyan
Copy link
Contributor

ara-ayvazyan commented Sep 9, 2021

Under some conditions, bond::DynamicParser may not emit OmittedField for a compile-time schema. For the most transforms that is implemented as a no-op. However, bond::Merge relies on that in order to take data from a struct.

/*
    struct ABC
    {
        0: int8 a;
        1: int8 b;
        2: int8 c;
    };
    struct B view_of ABC
    {
        b;
    };
*/
bond::CompactBinaryReader<bond::InputBuffer> abc_payload{ {} };
{
    ABC abc;
    abc.a = 'a';
    // Leave ABC::b with default value, such that it will be skipped in the payload.
    abc.c = 'c';

    bond::OutputBuffer output;
    bond::CompactBinaryWriter<bond::OutputBuffer> writer{ output };
    bond::Serialize(abc, writer);
    abc_payload = { output.GetBuffer() };
}
bond::CompactBinaryReader<bond::InputBuffer> abc_merged_b_payload{ {} };
{
    B b;
    b.b = 'b';

    bond::OutputBuffer output;
    bond::CompactBinaryWriter<bond::OutputBuffer> writer{ output };
    bond::Merge(b, abc_payload, writer);
    abc_merged_b_payload = { output.GetBuffer() };
}
ABC abc;
bond::Deserialize(abc_merged_b_payload, abc);
assert(abc.a == 'a');
assert(abc.b == 'b');   // Fails, since OmittedField is not called for B::b
assert(abc.c == 'c');
B b;
bond::Deserialize(abc_merged_b_payload, b);
assert(b.b == 'b');     // Fails, since OmittedField is not called for B::b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant