MCPcopy Create free account
hub / github.com/RustCrypto/utils / encode_vlq

Function encode_vlq

blobby/src/encode.rs:7–28  ·  view source on GitHub ↗
(mut val: usize, buf: &mut [u8; 4])

Source from the content-addressed store, hash-verified

5/// Returns the slice within `buf` that holds the value.
6#[allow(clippy::cast_possible_truncation)]
7fn encode_vlq(mut val: usize, buf: &mut [u8; 4]) -> &[u8] {
8 macro_rules! step {
9 ($n:expr) => {
10 buf[$n] = if $n == 3 {
11 (val & (VAL_MASK as usize)) as u8
12 } else {
13 val -= 1;
14 NEXT_MASK | (val & (VAL_MASK as usize)) as u8
15 };
16 val >>= 7;
17 if val == 0 {
18 return &buf[$n..];
19 }
20 };
21 }
22
23 step!(3);
24 step!(2);
25 step!(1);
26 step!(0);
27 panic!("integer is too big")
28}
29
30/// Encode the given collection of binary blobs in .blb format into `writer`.
31/// Returns the encoded data together with a count of the number of blobs included in the index.

Callers 2

encode_blobsFunction · 0.85
encode_decodeFunction · 0.85

Calls

no outgoing calls

Tested by 1

encode_decodeFunction · 0.68