pub fn encode_integer_into<W: Write>(
value: usize,
prefix_size: u8,
leading_bits: u8,
writer: &mut W,
) -> Result<()>Expand description
Encode an integer to the representation defined by HPACK, writing it into
the provider io::Write instance. Also allows the caller to specify the
leading bits of the first octet. Any bits that are already set within the
last prefix_size bits will be cleared and overwritten by the integer’s
representation (in other words, only the first 8 - prefix_size bits from
the leading_bits octet are reflected in the first octet emitted by the
function.
§Example
use loona_hpack::encoder::encode_integer_into;
{
// No bits specified in the 3 most significant bits of the first octet
let mut vec = Vec::new();
encode_integer_into(10, 5, 0, &mut vec);
assert_eq!(vec, vec![10]);
}
{
// The most significant bit should be set; i.e. the 3 most significant
// bits are 100.
let mut vec = Vec::new();
encode_integer_into(10, 5, 0x80, &mut vec);
assert_eq!(vec, vec![0x8A]);
}
{
// The most leading bits number has a bit set within the last prefix-size
// bits -- they are ignored by the function
// bits are 100.
let mut vec = Vec::new();
encode_integer_into(10, 5, 0x10, &mut vec);
assert_eq!(vec, vec![0x0A]);
}
{
let mut vec = Vec::new();
encode_integer_into(1337, 5, 0, &mut vec);
assert_eq!(vec, vec![31, 154, 10]);
}