httlib_hpack/encoder/error.rs
1use std::fmt;
2use std::error;
3use httlib_huffman::{EncoderError as HuffmanError};
4
5/// Contains error options that can be encountered while performing the encoding
6/// of an HPACK header set.
7#[derive(Debug, PartialEq)]
8pub enum EncoderError {
9 /// Indicates that the encoder received an invalid ASCII character and is
10 /// thus unable to perform the (Huffman) encoding. Note that only ASCII
11 /// characters provided in the HPACK spec should be used.
12 InvalidInput,
13
14 /// Indicates that an invalid index was provided. According to the HPACK
15 /// specification, the index `0` must be treated as an invalid index number.
16 /// The first valid number is `1`.
17 InvalidIndex,
18
19 /// Indicates that an invalid prefix was provided (must be [1, 8]).
20 InvalidPrefix,
21
22 /// Indicates that the value of the integer being encoded exceeds a certain
23 /// threshold (5 bytes are chosen by this implementation). This can also
24 /// happen while encoding too long string.
25 IntegerOverflow,
26}
27
28impl From<HuffmanError> for EncoderError {
29 fn from(err: HuffmanError) -> Self {
30 match err {
31 HuffmanError::InvalidInput => Self::InvalidInput
32 }
33 }
34}
35
36impl fmt::Display for EncoderError {
37 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
38 match self {
39 Self::InvalidInput => write!(fmt, "Invalid input character."),
40 Self::InvalidIndex => write!(fmt, "Invalid index."),
41 Self::InvalidPrefix => write!(fmt, "Invalid prefix."),
42 Self::IntegerOverflow => write!(fmt, "Too many bytes."),
43 }
44 }
45}
46
47impl error::Error for EncoderError {}