leb128fmt

Macro encode_sint_arr

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

Builds custom signed integer encode functions.

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_sint_arr!(encode_s33, i64, 33);

let result = encode_s33(0);
assert_eq!(Some(([0x00, 0x00, 0x00, 0x00, 0x00], 1)), result);

let result = encode_s33(4_294_967_295);
assert_eq!(Some(([0xFF, 0xFF, 0xFF, 0xFF, 0x0F], 5)), result);

let result = encode_s33(-4_294_967_296);
assert_eq!(Some(([0x80, 0x80, 0x80, 0x80, 0x70], 5)), result);

let result = encode_s33(-1);
assert_eq!(Some(([0x7F, 0x00, 0x00, 0x00, 0x00], 1)), result);