pub fn encode_varint_scalar<W: Write>(writer: W, value: u32) -> Result<usize>Expand description
Encode a u32 as varint, writing to the provided writer.
Varint encoding uses 7 bits per byte, with the high bit set to indicate continuation. This provides compact representation for small values.
§Arguments
writer- Any type implementing Write (Vec, File, etc.) value- The u32 value to encode
§Returns
Number of bytes written (1-5)
§Examples
use sqlitegraph::hnsw::serialization::encode_varint_scalar;
let mut buffer = Vec::new();
let bytes_written = encode_varint_scalar(&mut buffer, 300).unwrap();
assert_eq!(bytes_written, 2);
assert_eq!(buffer, vec![0xAC, 0x02]);§Encoding Format
- 1 byte: Values < 128 (0x00 to 0x7F)
- 2 bytes: Values < 16384 (0x80 0x01 to 0x7F 0x7F)
- 3-5 bytes: Larger values up to u32::MAX