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
-
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-proto
has been used to generate bindings - and on the Rust side I've been usingprost
andtonic
- 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_raw
function generated throughprost_build
for 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
prost
than I do - here's the options I find myself with right now, but please suggest more if you have any:ts-proto
for embeddings inside Rust and call it using the JS Sandboxprost
and maintain a slightly modified version which includes empty numeric arrays in the bytes serialization in the same way asts-proto
doesWhat would you suggest?
Beta Was this translation helpful? Give feedback.
All reactions