#include <icy/buffer.h>Subclassed by:
DynamicBitWriter
Class for reading/writing binary streams.
Note that when using the constructor with the Buffer reference as an argument, the writer will dynamically expand the given buffer when writing passed the buffer capacity. All other cases will throw a std::out_of_range error when writing past the buffer capacity.
| Return | Name | Description |
|---|---|---|
BitWriter | Constructs a [BitWriter](#bitwriter) over a raw byte array with a fixed capacity. | |
BitWriter | Constructs a [BitWriter](#bitwriter) backed by a Buffer. Writes are bounded by the buffer's capacity; use [DynamicBitWriter](icy-DynamicBitWriter.html#dynamicbitwriter) for auto-resize. | |
BitWriter | Constructs a [BitWriter](#bitwriter) over a [MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6) with a fixed capacity. | |
void | put virtual | Append bytes to the buffer. Throws a std::out_of_range exception if reading past the limit. |
void | put | Appends the contents of a string. Throws std::out_of_range if capacity is exceeded. |
void | putU8 | Appends an unsigned 8-bit integer. Throws std::out_of_range if capacity is exceeded. |
void | putU16 | Appends an unsigned 16-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded. |
void | putU24 | Appends the low 24 bits of a 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded. |
void | putU32 | Appends an unsigned 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded. |
void | putU64 | Appends an unsigned 64-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded. |
bool | update virtual | Update a byte range. Throws a std::out_of_range exception if reading past the limit. |
bool | update | Overwrites a previously written string at the given absolute position. |
bool | updateU8 | Overwrites a uint8_t at the given absolute position. |
bool | updateU16 | Overwrites a uint16_t at the given absolute position, with byte-order conversion. |
bool | updateU24 | Overwrites 3 bytes (low 24 bits of val) at the given absolute position, with byte-order conversion. |
bool | updateU32 | Overwrites a uint32_t at the given absolute position, with byte-order conversion. |
bool | updateU64 | Overwrites a uint64_t at the given absolute position, with byte-order conversion. |
void | seek | Set position pointer to absolute position. Throws a std::out_of_range exception if the value exceeds the limit. |
void | skip | Set position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit. |
size_t | limit const | Returns the write limit. |
size_t | position const inline | Returns the current write position. |
size_t | available const | Returns the number of elements between the current write position and the limit. |
char * | begin inline | Returns a pointer to the start of the write buffer. |
char * | current inline | Returns a pointer to the current write position. |
const char * | begin const inline | Returns a const pointer to the start of the write buffer. |
const char * | current const inline | Returns a const pointer to the current write position. |
ByteOrder | order const inline | Returns the byte order used for multi-byte integer writes. |
std::string | toString | Returns all bytes written so far as a std::string. |
BitWriter(char * bytes, size_t size, ByteOrder order)Constructs a [BitWriter](#bitwriter) over a raw byte array with a fixed capacity.
bytes Pointer to the writable buffer. Must remain valid for the writer's lifetime.
size Capacity of the buffer in bytes.
order Byte order used for multi-byte integer writes.
BitWriter(Buffer & buf, ByteOrder order)Constructs a [BitWriter](#bitwriter) backed by a Buffer. Writes are bounded by the buffer's capacity; use [DynamicBitWriter](icy-DynamicBitWriter.html#dynamicbitwriter) for auto-resize.
buf Source buffer. Must remain valid for the writer's lifetime.
order Byte order used for multi-byte integer writes.
BitWriter(MutableBuffer & pod, ByteOrder order)Constructs a [BitWriter](#bitwriter) over a [MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6) with a fixed capacity.
pod Source mutable buffer. Must remain valid for the writer's lifetime.
order Byte order used for multi-byte integer writes.
virtual
virtual void put(const char * val, size_t len)Append bytes to the buffer. Throws a std::out_of_range exception if reading past the limit.
void put(const std::string & val)Appends the contents of a string. Throws std::out_of_range if capacity is exceeded.
val String whose bytes are appended.void putU8(uint8_t val)Appends an unsigned 8-bit integer. Throws std::out_of_range if capacity is exceeded.
val Value to write.void putU16(uint16_t val)Appends an unsigned 16-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
val Value to write.void putU24(uint32_t val)Appends the low 24 bits of a 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
val Value to write (only the lower 3 bytes are written).void putU32(uint32_t val)Appends an unsigned 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
val Value to write.void putU64(uint64_t val)Appends an unsigned 64-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
val Value to write.virtual
virtual bool update(const char * val, size_t len, size_t pos)Update a byte range. Throws a std::out_of_range exception if reading past the limit.
bool update(const std::string & val, size_t pos)Overwrites a previously written string at the given absolute position.
val String to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
bool updateU8(uint8_t val, size_t pos)Overwrites a uint8_t at the given absolute position.
val Value to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
bool updateU16(uint16_t val, size_t pos)Overwrites a uint16_t at the given absolute position, with byte-order conversion.
val Value to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
bool updateU24(uint32_t val, size_t pos)Overwrites 3 bytes (low 24 bits of val) at the given absolute position, with byte-order conversion.
val Value to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
bool updateU32(uint32_t val, size_t pos)Overwrites a uint32_t at the given absolute position, with byte-order conversion.
val Value to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
bool updateU64(uint64_t val, size_t pos)Overwrites a uint64_t at the given absolute position, with byte-order conversion.
val Value to write.
pos Absolute byte offset to overwrite at.
True on success, false if the range exceeds available space.
void seek(size_t val)Set position pointer to absolute position. Throws a std::out_of_range exception if the value exceeds the limit.
void skip(size_t size)Set position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit.
const
size_t limit() constReturns the write limit.
const inline
inline size_t position() constReturns the current write position.
const
size_t available() constReturns the number of elements between the current write position and the limit.
inline
inline char * begin()Returns a pointer to the start of the write buffer.
inline
inline char * current()Returns a pointer to the current write position.
const inline
inline const char * begin() constReturns a const pointer to the start of the write buffer.
const inline
inline const char * current() constReturns a const pointer to the current write position.
const inline
inline ByteOrder order() constReturns the byte order used for multi-byte integer writes.
std::string toString()Returns all bytes written so far as a std::string.
String containing bytes from the start of the buffer up to the current position.
size_t _positionsize_t _limitByteOrder _orderchar * _bytes| Return | Name | Description |
|---|---|---|
void | init virtual |
virtual
virtual void init(char * bytes, size_t size, ByteOrder order)