Home
Base module

BitWriter

Class for reading/writing binary streams.

BitWriter

#include <icy/buffer.h>
class BitWriter

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

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.

List of all members

NameKindOwner
operator<<friendDeclared here
BitWriterfunctionDeclared here
BitWriterfunctionDeclared here
BitWriterfunctionDeclared here
~BitWriterfunctionDeclared here
putfunctionDeclared here
putfunctionDeclared here
putU8functionDeclared here
putU16functionDeclared here
putU24functionDeclared here
putU32functionDeclared here
putU64functionDeclared here
updatefunctionDeclared here
updatefunctionDeclared here
updateU8functionDeclared here
updateU16functionDeclared here
updateU24functionDeclared here
updateU32functionDeclared here
updateU64functionDeclared here
seekfunctionDeclared here
skipfunctionDeclared here
limitfunctionDeclared here
positionfunctionDeclared here
availablefunctionDeclared here
beginfunctionDeclared here
currentfunctionDeclared here
beginfunctionDeclared here
currentfunctionDeclared here
orderfunctionDeclared here
toStringfunctionDeclared here
_positionvariableDeclared here
_limitvariableDeclared here
_ordervariableDeclared here
_bytesvariableDeclared here
initfunctionDeclared here

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. 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.
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 constReturns the write limit.
size_tposition const inlineReturns the current write position.
size_tavailable constReturns the number of elements between the current write position and the limit.
char *begin inlineReturns a pointer to the start of the write buffer.
char *current inlineReturns a pointer to the current write position.
const char *begin const inlineReturns a const pointer to the start of the write buffer.
const char *current const inlineReturns 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

  • 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

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

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

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

  • buf Source buffer. Must remain valid for the writer's lifetime.

  • order Byte 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

  • pod Source mutable buffer. Must remain valid for the writer's lifetime.

  • order Byte order used for multi-byte integer writes.


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

  • val 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

  • val Value 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

  • val Value 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

  • val Value 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

  • val Value 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

  • val Value 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.

Parameters

  • val String to write.

  • pos Absolute 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)

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

Overwrites a uint8_t at the given absolute position.

Parameters

  • val Value to write.

  • pos Absolute 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)

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

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

Parameters

  • val Value to write.

  • pos Absolute 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)

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.

Parameters

  • val Value to write.

  • pos Absolute 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)

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

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

Parameters

  • val Value to write.

  • pos Absolute 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)

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

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

Parameters

  • val Value to write.

  • pos Absolute byte offset to overwrite at.

Returns

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


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

size_t limit() const

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

Returns the write limit.


position

const inline

inline size_t position() const

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

Returns the current write position.


available

const

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

inline char * begin()

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

Returns a pointer to the start of the write buffer.


current

inline

inline char * current()

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

Returns a pointer to the current write position.


begin

const inline

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

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