icy

BitWriter

Class for reading/writing binary streams.

#include <buffer.h>

class BitWriter

Defined in src/base/include/icy/buffer.h:450

Subclassed by
DynamicBitWriter

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.

Friends

NameDescription
operator<< inline

operator<<

inline

friend inline std::ostream & operator<<(std::ostream & stream, const BitWriter & wr)

Defined in src/base/include/icy/buffer.h:574

Public Methods

ReturnNameDescription
BitWriterConstructs a [BitWriter](#bitwriter) over a raw byte array with a fixed capacity.
BitWriterConstructs a [BitWriter](#bitwriter) backed by a [Buffer](base.html#buffer). Writes are bounded by the buffer's capacity; use [DynamicBitWriter](icy-DynamicBitWriter.html#dynamicbitwriter) for auto-resize.
BitWriterConstructs a [BitWriter](#bitwriter) over a [MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6) with a fixed capacity.
~BitWriter virtual
voidput virtualAppend bytes to the buffer. Throws a std::out_of_range exception if reading past the limit.
voidputAppends the contents of a string. Throws std::out_of_range if capacity is exceeded.
voidputU8Appends an unsigned 8-bit integer. Throws std::out_of_range if capacity is exceeded.
voidputU16Appends an unsigned 16-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
voidputU24Appends the low 24 bits of a 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
voidputU32Appends an unsigned 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
voidputU64Appends an unsigned 64-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.
boolupdate virtualUpdate a byte range. Throws a std::out_of_range exception if reading past the limit.
boolupdateOverwrites a previously written string at the given absolute position.
boolupdateU8Overwrites a uint8_t at the given absolute position.
boolupdateU16Overwrites a uint16_t at the given absolute position, with byte-order conversion.
boolupdateU24Overwrites 3 bytes (low 24 bits of val) at the given absolute position, with byte-order conversion.
boolupdateU32Overwrites a uint32_t at the given absolute position, with byte-order conversion.
boolupdateU64Overwrites a uint64_t at the given absolute position, with byte-order conversion.
voidseekSet position pointer to absolute position. Throws a std::out_of_range exception if the value exceeds the limit.
voidskipSet position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit.
size_tlimit const nodiscardReturns the write limit.
size_tposition const inline nodiscardReturns the current write position.
size_tavailable const nodiscardReturns the number of elements between the current write position and the limit.
char *begin inline nodiscardReturns a pointer to the start of the write buffer.
char *current inline nodiscardReturns a pointer to the current write position.
const char *begin const inline nodiscardReturns a const pointer to the start of the write buffer.
const char *current const inline nodiscardReturns a const pointer to the current write position.
ByteOrderorder const inlineReturns the byte order used for multi-byte integer writes.
std::stringtoStringReturns all bytes written so far as a std::string.

BitWriter

BitWriter(char * bytes, size_t size, ByteOrder order = ByteOrder::Network)

Defined in src/base/include/icy/buffer.h:457

Constructs a [BitWriter](#bitwriter) over a raw byte array with a fixed capacity.

Parameters

ParameterTypeDescription
byteschar *Pointer to the writable buffer. Must remain valid for the writer's lifetime.
sizesize_tCapacity of the buffer in bytes.
orderByteOrderByte order used for multi-byte integer writes.

BitWriter

BitWriter(Buffer & buf, ByteOrder order = ByteOrder::Network)

Defined in src/base/include/icy/buffer.h:463

Constructs a [BitWriter](#bitwriter) backed by a [Buffer](base.html#buffer). Writes are bounded by the buffer's capacity; use [DynamicBitWriter](icy-DynamicBitWriter.html#dynamicbitwriter) for auto-resize.

Parameters

ParameterTypeDescription
bufBuffer &Source buffer. Must remain valid for the writer's lifetime.
orderByteOrderByte order used for multi-byte integer writes.

BitWriter

BitWriter(MutableBuffer & pod, ByteOrder order = ByteOrder::Network)

Defined in src/base/include/icy/buffer.h:468

Constructs a [BitWriter](#bitwriter) over a [MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6) with a fixed capacity.

Parameters

ParameterTypeDescription
podMutableBuffer &Source mutable buffer. Must remain valid for the writer's lifetime.
orderByteOrderByte order used for multi-byte integer writes.

~BitWriter

virtual

virtual ~BitWriter()

Defined in src/base/include/icy/buffer.h:469


put

virtual

virtual void put(const char * val, size_t len)

Defined in src/base/include/icy/buffer.h:473

Append bytes to the buffer. Throws a std::out_of_range exception if reading past the limit.

Reimplemented by


put

void put(const std::string & val)

Defined in src/base/include/icy/buffer.h:476

Appends the contents of a string. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valconst std::string &String whose bytes are appended.

putU8

void putU8(uint8_t val)

Defined in src/base/include/icy/buffer.h:480

Appends an unsigned 8-bit integer. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valuint8_tValue to write.

putU16

void putU16(uint16_t val)

Defined in src/base/include/icy/buffer.h:484

Appends an unsigned 16-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valuint16_tValue to write.

putU24

void putU24(uint32_t val)

Defined in src/base/include/icy/buffer.h:488

Appends the low 24 bits of a 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valuint32_tValue to write (only the lower 3 bytes are written).

putU32

void putU32(uint32_t val)

Defined in src/base/include/icy/buffer.h:492

Appends an unsigned 32-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valuint32_tValue to write.

putU64

void putU64(uint64_t val)

Defined in src/base/include/icy/buffer.h:496

Appends an unsigned 64-bit integer with byte-order conversion. Throws std::out_of_range if capacity is exceeded.

Parameters

ParameterTypeDescription
valuint64_tValue to write.

update

virtual

virtual bool update(const char * val, size_t len, size_t pos)

Defined in src/base/include/icy/buffer.h:500

Update a byte range. Throws a std::out_of_range exception if reading past the limit.

Reimplemented by


update

bool update(const std::string & val, size_t pos)

Defined in src/base/include/icy/buffer.h:505

Overwrites a previously written string at the given absolute position.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valconst std::string &String to write.
possize_tAbsolute byte offset to overwrite at.

updateU8

bool updateU8(uint8_t val, size_t pos)

Defined in src/base/include/icy/buffer.h:511

Overwrites a uint8_t at the given absolute position.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valuint8_tValue to write.
possize_tAbsolute byte offset to overwrite at.

updateU16

bool updateU16(uint16_t val, size_t pos)

Defined in src/base/include/icy/buffer.h:517

Overwrites a uint16_t at the given absolute position, with byte-order conversion.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valuint16_tValue to write.
possize_tAbsolute byte offset to overwrite at.

updateU24

bool updateU24(uint32_t val, size_t pos)

Defined in src/base/include/icy/buffer.h:523

Overwrites 3 bytes (low 24 bits of val) at the given absolute position, with byte-order conversion.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valuint32_tValue to write.
possize_tAbsolute byte offset to overwrite at.

updateU32

bool updateU32(uint32_t val, size_t pos)

Defined in src/base/include/icy/buffer.h:529

Overwrites a uint32_t at the given absolute position, with byte-order conversion.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valuint32_tValue to write.
possize_tAbsolute byte offset to overwrite at.

updateU64

bool updateU64(uint64_t val, size_t pos)

Defined in src/base/include/icy/buffer.h:535

Overwrites a uint64_t at the given absolute position, with byte-order conversion.

Returns

True on success, false if the range exceeds available space.

Parameters

ParameterTypeDescription
valuint64_tValue to write.
possize_tAbsolute byte offset to overwrite at.

seek

void seek(size_t val)

Defined in src/base/include/icy/buffer.h:539

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)

Defined in src/base/include/icy/buffer.h:543

Set position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit.


limit

const nodiscard

[[nodiscard]] size_t limit() const

Defined in src/base/include/icy/buffer.h:546

Returns the write limit.


position

const inline nodiscard

[[nodiscard]] inline size_t position() const

Defined in src/base/include/icy/buffer.h:549

Returns the current write position.


available

const nodiscard

[[nodiscard]] size_t available() const

Defined in src/base/include/icy/buffer.h:553

Returns the number of elements between the current write position and the limit.


begin

inline nodiscard

[[nodiscard]] inline char * begin()

Defined in src/base/include/icy/buffer.h:556

Returns a pointer to the start of the write buffer.


current

inline nodiscard

[[nodiscard]] inline char * current()

Defined in src/base/include/icy/buffer.h:559

Returns a pointer to the current write position.


begin

const inline nodiscard

[[nodiscard]] inline const char * begin() const

Defined in src/base/include/icy/buffer.h:562

Returns a const pointer to the start of the write buffer.


current

const inline nodiscard

[[nodiscard]] inline const char * current() const

Defined in src/base/include/icy/buffer.h:565

Returns a const pointer to the current write position.


order

const inline

inline ByteOrder order() const

Defined in src/base/include/icy/buffer.h:568

Returns the byte order used for multi-byte integer writes.


toString

std::string toString()

Defined in src/base/include/icy/buffer.h:572

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

ReturnNameDescription
size_t_position
size_t_limit
ByteOrder_order
char *_bytes

_position

size_t _position

Defined in src/base/include/icy/buffer.h:582


_limit

size_t _limit

Defined in src/base/include/icy/buffer.h:583


_order

ByteOrder _order

Defined in src/base/include/icy/buffer.h:584


_bytes

char * _bytes

Defined in src/base/include/icy/buffer.h:585

Protected Methods

ReturnNameDescription
voidinit virtual

init

virtual

virtual void init(char * bytes, size_t size, ByteOrder order)

Defined in src/base/include/icy/buffer.h:580