Skip to main content

decode_usize

Function decode_usize 

Source
pub fn decode_usize(buf: &mut ReadBuf<'_>) -> Result<usize>
Expand description

Decode a usize varint from buf.

The bytes are parsed as a u64 varint and then converted, so the accepted wire format is the same on every target.

§Errors

The cursor is unchanged on error.

§Example

use wire_codec::{varint, ReadBuf};
let mut buf = ReadBuf::new(&[0x05, b'h', b'e', b'l', b'l', b'o']);
let len = varint::decode_usize(&mut buf).unwrap();
assert_eq!(buf.read_bytes(len).unwrap(), b"hello");