/// Extension trait providing QPACK-specific encoding methods for `Encoder`. /// /// This trait extends the standard [`neqo_common::Encoder`] with QPACK-specific /// methods for encoding integers with prefixes and literal strings with /// optional Huffman encoding. pubtrait Encoder { /// Encode an integer with a QPACK prefix according to RFC 7541 Section 5.1. fn encode_prefixed_encoded_int(&mutself, prefix: Prefix, val: u64) -> usize;
/// Encode a literal string with optional Huffman encoding according to RFC 7541 Section 5.2. fn encode_literal(&mutself, use_huffman: bool, prefix: Prefix, value: &[u8]);
}
impl<B> Encoder for neqo_common::Encoder<B> where
B: neqo_common::Buffer,
{ fn encode_prefixed_encoded_int(&mutself, prefix: Prefix, mut val: u64) -> usize { let first_byte_max: u8 = if prefix.len() == 0 { 0xff
} else {
(1 << (8 - prefix.len())) - 1
};
if val < u64::from(first_byte_max) { let v = u8::try_from(val).expect("first_byte_max is a u8 and val is smaller"); self.encode_byte((prefix.prefix() & !first_byte_max) | v); return1;
}
self.encode_byte(prefix.prefix() | first_byte_max);
val -= u64::from(first_byte_max);
letmut written = 1; letmut done = false; while !done { letmut b = (val & 0x7f) as u8; // Safe because of the mask.
val >>= 7; if val > 0 {
b |= 0x80;
} else {
done = true;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.