class BufferedBitstreamWriter

Wraps a Bitstream and a DataStream.

Buffers the written data in the bitstream and then on request flushes the data into the data stream.

Public

Constructors

BufferedBitstreamWriter

BufferedBitstreamWriter(Bitstream *bitstream, const SPtr<DataStream> &dataStream, uint32_t bufferSize, uint32_t flushAfter)

Constructs a new instance of the object.

bitstream
Bitstream into which the buffered data will be written.
dataStream
Data stream from which to read the data.
bufferSize
Initial size of the write buffer, in bytes.
flushAfter
Number of bytes after which the write buffer will be flushed to the data stream.

Methods

WriteBits

uint64_t WriteBits(const Bitstream::QuantType *data, uint64_t count)

Writes bits from the provided buffer into the stream at the current cursor location and advances the cursor.

data
Buffer to write the data from. Must have enough capacity to store bits.
count
Number of bits to write.

Returns: Number of bits written.

WriteBytes

uint32_t WriteBytes(Bitstream::QuantType *data, uint32_t count)

Writes bytes from the provided buffer into the stream at the current cursor location and advances the cursor.

data
Buffer to write the data from. Must have enough capacity to store bytes.
count
Number of bytes to write.

Returns: Number of bytes written.

WriteVarInt

uint32_t WriteVarInt(uint32_t value)

Encodes a 32-bit integer value as a base-128 varint and writes it to the stream.

Write is performed at the current cursor location and advances the cursor. Varints are a method of serializing integers using one or more bytes, where smaller values use less bytes. Returns the number of bits written.

Align

void Align(uint32_t count = 1)

Aligns the read/write cursor to a byte boundary. determines the alignment in bytes.

Note the requested alignment might not be achieved if count > 1 and it would move the cursor past the capacity of the buffer, as the cursor will be clamped to buffer end regardless of alignment.

Returns number of bits skipped due to alignment.

Flush

void Flush(bool force)

Flushes the write buffer to the output stream if a certain buffer length is reached.

GetDataStream

const SPtr<DataStream> &GetDataStream() const

Returns the underlying data stream.

GetBitstream

Bitstream &GetBitstream() const

Returns the underlying bitstream.

Private

Fields

mBitstream

Bitstream * mBitstream

mDataStream

SPtr<DataStream> mDataStream

mFlushAfter

uint64_t mFlushAfter