Skip to main content

encode_varint

Function encode_varint 

Source
pub fn encode_varint(value: u64, buf: &mut impl BufMut)
Expand description

Encode a varint to a buffer.

Terminates in at most 10 iterations (⌈ 64/7 ⌉) for any u64 input because value >>= 7 monotonically decreases and eventually satisfies value < 0x80. An unbounded loop is used intentionally: a bounded for _ in 0..10 adds loop-counter overhead that LLVM cannot eliminate (it cannot prove the inner return always fires), and this function is called for every tag and varint field on the encode hot path.