Handling the frame header
The frame header is made of a frame header descriptor and some other fields, which may or may not be present. The frame header descriptor is a single byte containing a set of flags which indicate which optional fields are present, and how large they are:
Frame_Content_Size_flag(2 bits): whether the frame content size field is present, and its size (0, 1, 2, 4 or 8 bytes);Single_Segment_flag(1 bit): if set, the window descriptor field is absent and the window size is the frame content size (which must then be present);Content_Checksum_flag(1 bit): whether a 4 byte checksum follows the last block of the frame;Dictionary_ID_flag(2 bits): whether the dictionary ID field is present, and its size (0, 1, 2 or 4 bytes);- one bit is reserved and must be 0 (return an error otherwise), and one bit is unused.
The optional fields following the descriptor are, in order:
- the window descriptor (1 byte), from which the window size is computed as described in the RFC — this is the maximum distance a sequence will be able to look back in the already decoded data;
- the dictionary ID, which references a dictionary shared between the compressor and the decompressor. Dictionaries are out of the scope of this project: if this field is present and non-zero,
decode()will return an error (dictionaries do not prevent parsing the frame, so--infokeeps working); - the frame content size, the size of the decompressed data (note the special encoding of the 2 byte variant, to which 256 must be added).
✅ Implement a
frame::FrameHeaderstructure type containing the fields of a frame header (you may want a separateFrameHeaderDescriptortype for the flags).
✅ Implement
FrameHeader::parse()in order to parse the frame header, and write tests to check the parsing behaviour, including the detection of a non-zero reserved bit.
✅ Add a
FrameHeader::window_size()method returning the window size as au64: computed from the window descriptor if present, or equal to the frame content size otherwise. It will be needed when decoding blocks and sequences.