MCPcopy Create free account
hub / github.com/git/git / encode_varint

Function encode_varint

src/varint.rs:41–60  ·  view source on GitHub ↗
(value: u64, buf: *mut u8)

Source from the content-addressed store, hash-verified

39/// `buf` must either be null or point to at least 16 bytes of memory.
40#[no_mangle]
41pub unsafe extern "C" fn encode_varint(value: u64, buf: *mut u8) -> u8 {
42 let mut varint: [u8; 16] = [0; 16];
43 let mut pos = varint.len() - 1;
44
45 varint[pos] = (value & 127) as u8;
46
47 let mut value = value >> 7;
48 while value != 0 {
49 pos -= 1;
50 value -= 1;
51 varint[pos] = 128 | (value & 127) as u8;
52 value >>= 7;
53 }
54
55 if !buf.is_null() {
56 std::ptr::copy_nonoverlapping(varint.as_ptr().add(pos), buf, varint.len() - pos);
57 }
58
59 (varint.len() - pos) as u8
60}
61
62#[cfg(test)]
63mod tests {

Callers

nothing calls this directly

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected