Module fluke_hpack::encoder
source · Expand description
Implements all functionality related to encoding header blocks using HPACK.
Clients should use the Encoder
struct as the API for performing HPACK
encoding.
§Examples
Encodes a header using a literal encoding.
use fluke_hpack::Encoder;
let mut encoder = Encoder::new();
let headers = vec![
(&b"custom-key"[..], &b"custom-value"[..]),
];
// First encoding...
let result = encoder.encode(headers);
// The result is a literal encoding of the header name and value, with an
// initial byte representing the type of the encoding
// (incremental indexing).
assert_eq!(
vec![0x40,
10, b'c', b'u', b's', b't', b'o', b'm', b'-', b'k', b'e', b'y',
12, b'c', b'u', b's', b't', b'o', b'm', b'-', b'v', b'a', b'l',
b'u', b'e'],
result);
Encodes some pseudo-headers that are already found in the static table.
use fluke_hpack::Encoder;
let mut encoder = Encoder::new();
let headers = vec![
(&b":method"[..], &b"GET"[..]),
(&b":path"[..], &b"/"[..]),
];
// The headers are encoded by providing their index (with a bit flag
// indicating that the indexed representation is used).
assert_eq!(encoder.encode(headers), vec![2 | 0x80, 4 | 0x80]);
Structs§
- Represents an HPACK encoder. Allows clients to encode arbitrary header sets and tracks the encoding context. That is, encoding subsequent header sets will use the context built by previous encode calls.
Functions§
- Encode an integer to the representation defined by HPACK.
- 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 lastprefix_size
bits will be cleared and overwritten by the integer’s representation (in other words, only the first8 - prefix_size
bits from theleading_bits
octet are reflected in the first octet emitted by the function.