leb128fmt

Macro encode_fixed_uint_arr

Source
macro_rules! encode_fixed_uint_arr {
    ($func:ident, $num_ty:ty, $bits:literal) => { ... };
}
Expand description

Builds custom unsigned integer encode functions with the max byte length of byte arrays used.

The macro’s 3 parameters are:

  1. The name of the function.
  2. The type to return.
  3. The number of encoded BITS to decode.
leb128fmt::encode_fixed_uint_arr!(encode_fixed_u33, u64, 33);

let output = encode_fixed_u33(0);
assert_eq!(Some([0x80, 0x80, 0x80, 0x80, 0x00]), output);

let output = encode_fixed_u33(8589934591);
assert_eq!(Some([0xFF, 0xFF, 0xFF, 0xFF, 0x1F]), output);