ts-proto and prost inconsistencies when serializing empty numeric arrays
#898
Unanswered
haardikk21
asked this question in
Q&A
Replies: 1 comment 3 replies
-
|
If there are inconsistency one is likely wrong. If you have some sort of reproduction that would be helpful. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
I find myself in a situation trying to translate a TypeScript codebase to Rust, while maintaining compatibility and not breaking things.
On the TypeScript side of things,
ts-protohas been used to generate bindings - and on the Rust side I've been usingprostandtonic- which have been amazing so far btw thank you!Recently, I realized that one specific field in one of our messages has inconsistencies in it's serialization format between the two implementations. Specifically, numeric arrays are treated differently when encoding to bytes.
In
ts-proto, given a numeric array field on a message, if the array is empty - it's bytes serialization includes two zero bytesIn
prost, given an empty numeric array, the field is skipped entirely and not part of the serialization at allUnfortunately I cannot change the message structure.
What I'd like to ideally do is have a way to override the
encode_rawfunction generated throughprost_buildfor that message type - but that message is further present as a property in other messages and isn't a top-level object by itself.Being new to Rust I also recently learnt it's not possible to override methods in trait implementations - and ideally I don't want to fork prost and maintain that myself
Now, I'm seeking help from the community here who have more experience with both Rust and
prostthan I do - here's the options I find myself with right now, but please suggest more if you have any:ts-protofor embeddings inside Rust and call it using the JS Sandboxprostand maintain a slightly modified version which includes empty numeric arrays in the bytes serialization in the same way asts-protodoesWhat would you suggest?
Beta Was this translation helpful? Give feedback.
All reactions