-
Couldn't load subscription status.
- Fork 11
less allocate and memcpy in serialization #6
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
base: v2.8
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,12 +56,7 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { | |
| /// Results in error if message is not fully initialized. | ||
| fn write_to(&self, os: &mut CodedOutputStream) -> ProtobufResult<()> { | ||
| self.check_initialized()?; | ||
|
|
||
| // cache sizes | ||
| self.compute_size(); | ||
| // TODO: reserve additional | ||
| self.write_to_with_cached_sizes(os)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -71,9 +66,6 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { | |
| let size = self.compute_size(); | ||
| os.write_raw_varint32(size)?; | ||
| self.write_to_with_cached_sizes(os)?; | ||
|
|
||
| // TODO: assert we've written same number of bytes as computed | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -103,13 +95,26 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { | |
| } | ||
| } | ||
|
|
||
| /// Write the message to the writer. | ||
| /// Write the message to the writer; an internal buffer is used. | ||
| fn write_to_writer(&self, w: &mut Write) -> ProtobufResult<()> { | ||
| w.with_coded_output_stream(|os| self.write_to(os)) | ||
| } | ||
|
|
||
| /// Write the message to the writer. | ||
| fn write_to_writer_without_buffer(&self, w: &mut Write) -> ProtobufResult<()> { | ||
| // TODO: add a unbuffer version. | ||
| w.with_coded_output_stream(|os| { | ||
| os.use_internal_buffer = false; | ||
| self.write_to(os) | ||
| }) | ||
| } | ||
|
|
||
| /// Write the message to bytes vec. | ||
| fn write_to_vec(&self, v: &mut Vec<u8>) -> ProtobufResult<()> { | ||
| let size = self.compute_size() as usize; | ||
| if v.capacity() - v.len() < size { | ||
| v.reserve(size - v.len()); | ||
|
||
| } | ||
| v.with_coded_output_stream(|os| self.write_to(os)) | ||
| } | ||
|
|
||
|
|
||
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.
I think this is necessary?
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.
No indeed. the cached internal size is not used later.