[−][src]Function httlib_hpack::decode_integer
pub fn decode_integer(
buf: &mut Vec<u8>,
val: &mut u32,
prefix_size: u8
) -> Result<usize, DecoderError>
Decodes an integer number encoded with a given prefix size (in bits) based on the pseudocode provided by the HPACK specification ([5.1]).
The method assumes that the buffer buf
contains the integer to be decoded,
with the first byte representing the octet that contains the prefix. The
result is written into dst
and the number of bytes from the buffer that
were used is returned.
The HPACK integer representation allows for values of indefinite size. As
specified by the HPACK specification, an implementation has to set a limit
for integer values it accepts, as well as for the encoded length. This
implementation's maximum number of supported octets is set to 5
and is
chosen such that the maximum allowed value
can never overflow an unsigned
32-bit integer. The maximum value of any integer that can be encoded with
5
octets is ~2^28.
The prefix
is a parameter of the integer representation. The prefix size
must be between 1 and 8 bits. An integer starting at an octet boundary will
have an 8-bit prefix.
Integer value encoded within the 5-bit prefix (5.1., figure 2):
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| ? | ? | ? | value |
+---+---+---+-------------------+
Integer value encoded after the 5-bit prefix (5.1., figure 3):
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| ? | ? | ? | 1 1 1 1 1 |
+---+---+---+-------------------+
| 1 | Value-(2^N-1) LSB |
+---+---------------------------+
...
+---+---------------------------+
| 0 | Value-(2^N-1) MSB |
+---+---------------------------+