MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / write_varint

Function write_varint

nodedb-codec/src/delta.rs:43–55  ·  view source on GitHub ↗

Write a varint (LEB128-encoded u64) to a buffer.

(buf: &mut Vec<u8>, mut value: u64)

Source from the content-addressed store, hash-verified

41
42/// Write a varint (LEB128-encoded u64) to a buffer.
43fn write_varint(buf: &mut Vec<u8>, mut value: u64) {
44 loop {
45 let mut byte = (value & 0x7F) as u8;
46 value >>= 7;
47 if value != 0 {
48 byte |= 0x80;
49 }
50 buf.push(byte);
51 if value == 0 {
52 break;
53 }
54 }
55}
56
57/// Read a varint (LEB128-encoded u64) from a byte slice.
58///

Callers 2

encodeFunction · 0.70
varint_roundtripFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by 1

varint_roundtripFunction · 0.56