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

Fix protobuf semidynamic encoding/decoding #260

Merged
merged 6 commits into from
May 27, 2022

Conversation

petoalbert
Copy link
Contributor

Encoding of semidynamic values should conform to the protobuf encoding protocol. Each encoded object should be preceded by a length-limited tag.

With the current setup, the semidynamic encoder just concatenates the encoded schema act bytes and the encoded value bytes. This causes issues in the following scenario:

Encode a top-level enum, whose case wraps a semidynamic schema. When decoding, the enum decoder will read the length-delimited tag for the encoded ast which doesn't include the total length (its missing the encoded value). This is because top-level values don't encode any tag, but the top-level enum decoder will still find a length-limited tag and skip the rest of the message. This is needed by zit-flow's Remote values, more details in this issue: zio/zio-flow#144

My fix is that semidynamic should encode a tuple, so the attached length-delimited tag will include the correct message length.

@petoalbert petoalbert requested a review from a team as a code owner May 26, 2022 16:41
case Schema.Enum4(c1, c2, c3, c4, _) => enumDecoder(c1, c2, c3, c4)
case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this reordering :)

Copy link
Contributor

@vigoo vigoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, just a single comment

vigoo
vigoo previously approved these changes May 27, 2022
Copy link
Contributor

@vigoo vigoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open another pull request against the zio 2 branch too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants