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

Serialize/Deserialize slices without length prefix with break-change #245

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions quick-protobuf/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ impl BytesReader {
pub fn read_message<'a, M>(&mut self, bytes: &'a [u8]) -> Result<M>
where
M: MessageRead<'a>,
{
self.read_len_varint(bytes, M::from_reader)
{
let len = bytes.len();
self.read_len(bytes, M::from_reader, len)
}

/// Reads a nested message
Expand Down
4 changes: 1 addition & 3 deletions quick-protobuf/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ impl<W: WriterBackend> Writer<W> {
/// Writes a message which implements `MessageWrite`
#[cfg_attr(std, inline)]
pub fn write_message<M: MessageWrite>(&mut self, m: &M) -> Result<()> {
let len = m.get_size();
self.write_varint(len as u64)?;
m.write_message(self)
}

Expand Down Expand Up @@ -331,7 +329,7 @@ pub fn serialize_into_vec<M: MessageWrite>(message: &M) -> Result<Vec<u8>> {
/// Serialize a `MessageWrite` into a byte slice
pub fn serialize_into_slice<M: MessageWrite>(message: &M, out: &mut [u8]) -> Result<()> {
let len = message.get_size();
if out.len() < crate::sizeofs::sizeof_len(len) {
if out.len() < len {
return Err(Error::OutputBufferTooSmall);
}
{
Expand Down