MCPcopy Index your code
hub / github.com/RustPython/RustPython / write_varint_be

Function write_varint_be

crates/compiler-core/src/varint.rs:35–54  ·  view source on GitHub ↗

Write a big-endian varint (used by exception tables).

(buf: &mut Vec<u8>, val: u32)

Source from the content-addressed store, hash-verified

33
34/// Write a big-endian varint (used by exception tables).
35pub fn write_varint_be(buf: &mut Vec<u8>, val: u32) -> usize {
36 let start_len = buf.len();
37 if val >= 1 << 30 {
38 buf.push(0x40 | ((val >> 30) & 0x3f) as u8);
39 }
40 if val >= 1 << 24 {
41 buf.push(0x40 | ((val >> 24) & 0x3f) as u8);
42 }
43 if val >= 1 << 18 {
44 buf.push(0x40 | ((val >> 18) & 0x3f) as u8);
45 }
46 if val >= 1 << 12 {
47 buf.push(0x40 | ((val >> 12) & 0x3f) as u8);
48 }
49 if val >= 1 << 6 {
50 buf.push(0x40 | ((val >> 6) & 0x3f) as u8);
51 }
52 buf.push((val & 0x3f) as u8);
53 buf.len() - start_len
54}
55
56/// Write a big-endian varint with the start marker (0x80) on the first byte.
57pub fn write_varint_with_start(data: &mut Vec<u8>, val: u32) {

Callers 3

write_varint_with_startFunction · 0.85
test_be_varint_roundtripFunction · 0.85
encode_exception_tableFunction · 0.85

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by 1

test_be_varint_roundtripFunction · 0.68