Skip to main content

encode

Function encode 

Source
pub fn encode<N>(num: N, buffer: &mut [u8]) -> usize
Expand description

Encode a unsigned integer into an unsigned varint and write it into the buffer. Returns the number of bytes written.

§Panics

Panics if the buffers size is not enough for the encoded value. Make sure you check it with encoded_len

§Example

let mut buf= [0; 3];
let len = encode(0x4000_u16, &mut buf);
assert_eq!(buf.as_slice(), &[0x80, 0x80, 0x01]);
assert_eq!(len, 3);