cuprate_epee_encoding

Function write_varint

Source
pub fn write_varint<B: BufMut>(number: u64, w: &mut B) -> Result<()>
Expand description

Write an epee variable sized number into w.

use cuprate_epee_encoding::write_varint;

let mut buf = vec![];

for (number, expected_bytes) in [
    (63, [252].as_slice()),
    (64, [1, 1].as_slice()),
    (16_383, [253, 255].as_slice()),
    (16_384, [2, 0, 1, 0].as_slice()),
    (1_073_741_823, [254, 255, 255, 255].as_slice()),
    (1_073_741_824, [3, 0, 0, 0, 1, 0, 0, 0].as_slice()),
] {
    buf.clear();
    write_varint(number, &mut buf);
    assert_eq!(buf.as_slice(), expected_bytes);
}