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

Is trait.Message.html#method.encode the preferred way to encode a message? #461

Closed
Jasperav opened this issue Apr 14, 2021 · 2 comments
Closed

Comments

@Jasperav
Copy link

Jasperav commented Apr 14, 2021

Is https://docs.rs/prost/0.7.0/prost/trait.Message.html#method.encode the general way to encode messages? It takes a buffer. A quick look in:

both use the encoded_len of the message for the capacity of the buffer. https://hockeybuggy.com/blog/post/2020/01/experimenting-with-protobufs-generated-types-in-rust uses just a value of 200 'to be sure'. That looks a little bit odd to me.

My question is: what should be the value of the buffer? Isn't it always the encoded_len of the same message? If so, why is the buffer parameter needed?

@rubdos
Copy link
Contributor

rubdos commented Apr 16, 2021

The reason that you can specify it, is because you may be encoding this into part of an existing buffer. That said, through #378 you would have the most common case of prost doing the allocation for you, for a single message.

@LucioFranco
Copy link
Member

Seems like #378 should fix this.

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

No branches or pull requests

3 participants