Skip to content

Commit

Permalink
Remove global parse_length_delimited* functions
Browse files Browse the repository at this point in the history
These functions are not very useful and are a source of confusion
for users.

Issue #328
  • Loading branch information
stepancheg committed Sep 2, 2018
1 parent 75fac07 commit 91c0875
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
4 changes: 3 additions & 1 deletion protobuf-test-common/src/serialize_deserialize_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use protobuf::*;

pub fn test_serialize_deserialize_length_delimited<M : Message + PartialEq>(msg: &M) {
let serialized_bytes = msg.write_length_delimited_to_bytes().unwrap();
let parsed = parse_length_delimited_from_bytes::<M>(&serialized_bytes).unwrap();
let mut is = CodedInputStream::from_bytes(&serialized_bytes);
let parsed = is.read_message().unwrap();
is.check_eof().unwrap();
assert_eq!(*msg, parsed);
}

Expand Down
4 changes: 3 additions & 1 deletion protobuf-test/src/common/v2/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ fn test_parse_length_delimited_from_network_smoke() {
});

let mut tcp_stream = net::TcpStream::connect(addr).expect("connect");
let test1: Test1 = parse_length_delimited_from_reader(&mut tcp_stream).expect("parse...");
let mut is = CodedInputStream::new(&mut tcp_stream);
let test1: Test1 = is.read_message().expect("read_message");
assert_eq!(10, test1.get_a());
is.check_eof().expect("check_eof");
}
25 changes: 0 additions & 25 deletions protobuf/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,3 @@ pub fn parse_from_carllerche_bytes<M : Message>(
// Call trait explicitly to avoid accidental construction from `&[u8]`
WithCodedInputStream::with_coded_input_stream(bytes, |is| parse_from::<M>(is))
}

/// Parse length-delimited message from stream.
///
/// Read varint length first, and read messages of that length then.
pub fn parse_length_delimited_from<M : Message>(
is: &mut CodedInputStream,
) -> ProtobufResult<M> {
is.read_message::<M>()
}

/// Parse length-delimited message from `Read`.
pub fn parse_length_delimited_from_reader<M : Message>(
r: &mut Read,
) -> ProtobufResult<M> {
// TODO: wrong: we may read length first, and then read exact number of bytes needed
r.with_coded_input_stream(|is| is.read_message::<M>())
}

/// Parse length-delimited message from bytes.
// TODO: currently it's not possible to know how many bytes read from slice.
pub fn parse_length_delimited_from_bytes<M : Message>(
bytes: &[u8],
) -> ProtobufResult<M> {
bytes.with_coded_input_stream(|is| is.read_message::<M>())
}
3 changes: 0 additions & 3 deletions protobuf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ pub use core::parse_from_bytes;
pub use core::parse_from_reader;
#[cfg(feature = "bytes")]
pub use core::parse_from_carllerche_bytes;
pub use core::parse_length_delimited_from;
pub use core::parse_length_delimited_from_reader;
pub use core::parse_length_delimited_from_bytes;
pub use enums::ProtobufEnum;
pub use oneof::Oneof;
pub use stream::CodedInputStream;
Expand Down

0 comments on commit 91c0875

Please sign in to comment.