#ifndef _CSTREAM_H_ #define _CSTREAM_H_ #include #include #include struct b_stream; struct b_compressor; enum cstream_flags { CSTREAM_CURSOR_MOVED = 0x01u, }; struct b_cstream { enum cstream_flags s_flags; struct b_stream *s_endpoint; struct b_compressor *s_compressor; /* s_in is the input buffer, and s_out is the output buffer. * * the input buffer holds data that will be provided to the * (de)compression function. in compression mode, this data is provided * by the code using the cstream (via b_cstream_write). in decompression * mode, this data is read from s_endpoint. * * the output buffer holds data produced by the (de)compression * function. in compression mode, this data will be written to * s_endpoint. in decompression mode, this data will be returned to the * code using the cstream (via b_cstream_read) * * heavy usage of cstream's compressed sections facility can result * in the input buffer holding uncompressed data while the stream is in * decompression mode. this is handled by the uncompressed read code path. */ struct b_ringbuffer s_in, s_out; enum b_compression_mode s_mode; unsigned int s_compression_depth; /* tracks the number of bytes read from or written to the endpoint. * this counter is not reset at the beginning/end of each section. * * during compressed sections, this counter is incremented by the number * of compressed bytes written/consumed. * * during uncompressed sections, this counter is incremented by the * number of uncompressed bytes written/returned. * * this does not include bytes read/written while the cursor is moved. */ size_t s_tx_bytes; /* tracks the number of compressed bytes that have passed through this * stream in the current section. * * in compression mode, this tracks the number of post-compression bytes * that have been written to the endpoint within the current section, * including any bytes written during end_compression_section() * * in decompression mode, this tracks the number of compressed bytes * that were decompressed while reading the current section. it does not * include any uncompressed bytes that may have been read from the * endpoint while reading a compressed section due to cstream's * read-ahead caching behaviour. */ size_t s_tx_bytes_compressed; /* tracks the number of uncompressed bytes that have passed through this * stream in the current section. * * in compression mode, this tracks the number of bytes given to * b_cstream_write * * in decompression mode, this tracks the number of bytes returned by * b_cstream_read */ size_t s_tx_bytes_uncompressed; /* when the endpoint cursor is moved, the previous cursor position is * saved here so it can be restored later */ size_t s_cursor; }; #endif