pub struct Encoder<'a> { /* fields omitted */ }
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.
This is the main API for performing HPACK encoding of headers.
Encoding a header two times in a row produces two different
representations, due to the utilization of HPACK compression.
use hpack::Encoder;
let mut encoder = Encoder::new();
let headers = vec![
(b"custom-key".to_vec(), b"custom-value".to_vec()),
];
let result = encoder.encode(&headers);
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);
let result = encoder.encode(&headers);
assert_eq!(vec![0x80 | 62], result);
Creates a new Encoder
with a default static table, as defined by the
HPACK spec (Appendix A).
Encodes the given headers using the HPACK rules and returns a newly
allocated Vec
containing the bytes representing the encoded header
set.
The encoder so far supports only a single, extremely simple encoding
strategy, whereby each header is represented as an indexed header if
already found in the header table and a literal otherwise. When a
header isn't found in the table, it is added if the header name wasn't
found either (i.e. there are never two header names with different
values in the produced header table). Strings are always encoded as
literals (Huffman encoding is not used).
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static