macro_rules! encode_fixed_sint_arr {
($func:ident, $num_ty:ty, $bits:literal) => { ... };
}
Expand description
Builds custom signed integer encode functions with the max byte length of byte arrays used.
The macro’s 3 parameters are:
- The name of the function.
- The type to return.
- The number of encoded BITS to decode.
leb128fmt::encode_fixed_sint_arr!(encode_fixed_s33, i64, 33);
let result = encode_fixed_s33(0);
assert_eq!(Some([0x80, 0x80, 0x80, 0x80, 0x00]), result);
let result = encode_fixed_s33(4_294_967_295);
assert_eq!(Some([0xFF, 0xFF, 0xFF, 0xFF, 0x0F]), result);
let result = encode_fixed_s33(-4_294_967_296);
assert_eq!(Some([0x80, 0x80, 0x80, 0x80, 0x70]), result);
let result = encode_fixed_s33(-1);
assert_eq!(Some([0xFF, 0xFF, 0xFF, 0xFF, 0x7F]), result);