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
Encode to Vec<u8> #378
Encode to Vec<u8> #378
Conversation
Rebased on master, subtle nod nod to the owners ;-) |
I guess this fixes https://github.com/danburkert/prost/issues/461, what do you think @rubdos? Adding this change as an example in the readme.md will help newcomers to this library :) |
I agree that it'd fix #461 if it's added to the README. I'd have hoped to have some feedback from the maintainers though by now :/ |
@danburkert please review |
This is a relatively simple QoL patch; would any of the people that have commit rights please take a look? |
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.
sorry for the delay on this!
Adds
Message::encode_to_vec(&self) -> Vec<u8>
andMessage::encode_length_delimited_to_vec() -> Vec<u8>
onstd
-enabled configurations.This is one line shorter than writing
and replaces it by
The main reason I do that is because it's confused me (and others) before when writing PROST code in combination with symmetric crypto code (where
encrypt(&self, &mut [u8])
overwrites allocated bytes, instead of extending the buffer like PROST).It also omits the extra capacity checking of
encode
(sinceVec
is pre-allocated because this patch usesVec::with_capacity()
).Fixes #154 in spirit, if you agree that
Into<Vec<u8>> for Message
is a slightly worse idea (i.e.,.into
doesn't specify whether to have length encoding or not, so it might yield slightly more unreadable code).EDIT: CI failure seems to be due to use of a new
rustc
feature? I don't think it's this patch.