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
Error::UnexpectedEofifbufis exhausted before the terminator byte.Error::VarintOverflowif the value overflowsu64, or does not fit inusizeon this target (values aboveu32::MAXon 32-bit hosts).
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");