-
Notifications
You must be signed in to change notification settings - Fork 162
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
Conversation
case Schema.Enum4(c1, c2, c3, c4, _) => enumDecoder(c1, c2, c3, c4) | ||
case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo this reordering :)
There was a problem hiding this 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
There was a problem hiding this 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?
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.