Skip to content

Commit 910a778

Browse files
committed
Add example for decode_length_delimiter.
1 parent df814bb commit 910a778

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

prost/src/encoding/length_delimiter.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ pub fn length_delimiter_len(length: usize) -> usize {
4242
/// input is required to decode the full delimiter.
4343
/// * If the supplied buffer contains 10 bytes or more, then the buffer contains an invalid
4444
/// delimiter, and typically the buffer should be considered corrupt.
45+
///
46+
/// # Examples
47+
///
48+
/// ```
49+
/// use prost::bytes::Bytes;
50+
///
51+
/// let mut buf = Bytes::from(vec![0x04, 0x0a, 0x02, 0x01, 0x02]);
52+
/// let len = prost::decode_length_delimiter(&mut buf).unwrap();
53+
/// let message_buf = buf.split_to(len);
54+
///
55+
/// assert_eq!(len, 4);
56+
/// assert_eq!(&message_buf[..], [0x0a, 0x02, 0x01, 0x02]);
57+
/// ```
4558
pub fn decode_length_delimiter(mut buf: impl Buf) -> Result<usize, DecodeError> {
4659
let length = decode_varint(&mut buf)?;
4760
if length > usize::MAX as u64 {

0 commit comments

Comments
 (0)