hpack_codec

Crates.iohpack_codec
lib.rshpack_codec
version0.1.1
sourcesrc
created_at2017-09-18 06:03:22.605067
updated_at2019-11-12 14:11:08.751508
descriptionEncoder and Decoder for HPACK (RFC 7541)
homepagehttps://github.com/sile/hpack_codec
repositoryhttps://github.com/sile/hpack_codec
max_upload_size
id32109
size107,621
Takeru Ohta (sile)

documentation

README

hpack_codec

Crates.io: hpack_codec Documentation Build Status Code Coverage License: MIT

Encoder and Decoder for HPACK (RFC 7541).

Documentation

Examples

use hpack_codec::{Encoder, Decoder};
use hpack_codec::field::{HeaderField, LiteralHeaderField as Field};
use hpack_codec::table::{StaticEntry, Index};

// Encoding
let mut encoder = Encoder::new(4096);
let mut header = encoder.enter_header_block(Vec::new()).unwrap();
header.encode_field(StaticEntry::MethodGet).unwrap();
header.encode_field(Field::with_indexed_name(StaticEntry::Path, b"/hello")).unwrap();
header.encode_field(Field::new(b"foo", b"bar").with_indexing()).unwrap();
header.encode_field(Index::dynamic_table_offset() + 0).unwrap();
let encoded_data = header.finish();

// Decoding
let mut decoder = Decoder::new(4096);
let mut header = decoder.enter_header_block(&encoded_data[..]).unwrap();
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b":method", b"GET").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b":path", b"/hello").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b"foo", b"bar").ok());
assert_eq!(header.decode_field().unwrap(), HeaderField::new(b"foo", b"bar").ok());
Commit count: 35

cargo fmt