BitWriter
BitWriter
#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.
Public Methods
| 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
BitWriter(char * bytes, size_t size, ByteOrder order)Constructs a [BitWriter](#bitwriter) over a raw byte array with a fixed capacity.
Parameters
bytesPointer to the writable buffer. Must remain valid for the writer's lifetime.sizeCapacity of the buffer in bytes.orderByte order used for multi-byte integer writes.
BitWriter
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.
Parameters
bufSource buffer. Must remain valid for the writer's lifetime.orderByte order used for multi-byte integer writes.
BitWriter
BitWriter(MutableBuffer & pod, ByteOrder order)Constructs a [BitWriter](#bitwriter) over a [MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6) with a fixed capacity.
Parameters
podSource mutable buffer. Must remain valid for the writer's lifetime.orderByte order used for multi-byte integer writes.
put
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.
put
void put(const std::string & val)Appends the contents of a string. Throws std::out_of_range if capacity is exceeded.
Parameters
valString whose bytes are appended.
putU8
void putU8(uint8_t val)Appends an unsigned 8-bit integer. Throws std::out_of_range if capacity is exceeded.
Parameters
valValue to write.
putU16
void putU16(uint16_t val)Appends an unsigned 16-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
Parameters
valValue to write.
putU24
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.
Parameters
valValue to write (only the lower 3 bytes are written).
putU32
void putU32(uint32_t val)Appends an unsigned 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
Parameters
valValue to write.
putU64
void putU64(uint64_t val)Appends an unsigned 64-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
Parameters
valValue to write.
update
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.
update
bool update(const std::string & val, size_t pos)Overwrites a previously written string at the given absolute position.
Parameters
valString to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
updateU8
bool updateU8(uint8_t val, size_t pos)Overwrites a uint8_t at the given absolute position.
Parameters
valValue to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
updateU16
bool updateU16(uint16_t val, size_t pos)Overwrites a uint16_t at the given absolute position, with byte-order conversion.
Parameters
valValue to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
updateU24
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.
Parameters
valValue to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
updateU32
bool updateU32(uint32_t val, size_t pos)Overwrites a uint32_t at the given absolute position, with byte-order conversion.
Parameters
valValue to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
updateU64
bool updateU64(uint64_t val, size_t pos)Overwrites a uint64_t at the given absolute position, with byte-order conversion.
Parameters
valValue to write.posAbsolute byte offset to overwrite at.
Returns
True on success, false if the range exceeds available space.
seek
void seek(size_t val)Set position pointer to absolute position. Throws a std::out_of_range exception if the value exceeds the limit.
skip
void skip(size_t size)Set position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit.
limit
const
size_t limit() constReturns the write limit.
position
const inline
inline size_t position() constReturns the current write position.
available
const
size_t available() constReturns the number of elements between the current write position and the limit.
begin
inline
inline char * begin()Returns a pointer to the start of the write buffer.
current
inline
inline char * current()Returns a pointer to the current write position.
begin
const inline
inline const char * begin() constReturns a const pointer to the start of the write buffer.
current
const inline
inline const char * current() constReturns a const pointer to the current write position.
order
const inline
inline ByteOrder order() constReturns the byte order used for multi-byte integer writes.
toString
std::string toString()Returns all bytes written so far as a std::string.
Returns
String containing bytes from the start of the buffer up to the current position.
Protected Attributes
_position
size_t _position_limit
size_t _limit_order
ByteOrder _order_bytes
char * _bytesProtected Methods
| Return | Name | Description |
|---|---|---|
void | init virtual |
init
virtual
virtual void init(char * bytes, size_t size, ByteOrder order)