BitReader
BitReader
#include <icy/buffer.h>class BitReaderDefined in src/base/include/icy/buffer.h:273
Class for reading binary streams.
List of all members
| Name | Kind | Owner |
|---|---|---|
operator<< | friend | Declared here |
BitReader | function | Declared here |
BitReader | function | Declared here |
BitReader | function | Declared here |
~BitReader | function | Declared here |
get | function | Declared here |
get | function | Declared here |
getU8 | function | Declared here |
getU16 | function | Declared here |
getU24 | function | Declared here |
getU32 | function | Declared here |
getU64 | function | Declared here |
peek | function | Declared here |
peekU8 | function | Declared here |
peekU16 | function | Declared here |
peekU24 | function | Declared here |
peekU32 | function | Declared here |
peekU64 | function | Declared here |
skipToChar | function | Declared here |
skipWhitespace | function | Declared here |
skipToNextLine | function | Declared here |
skipNextWord | function | Declared here |
readNextWord | function | Declared here |
readNextNumber | function | Declared here |
readLine | function | Declared here |
readToNext | function | Declared here |
seek | function | Declared here |
skip | function | Declared here |
limit | function | Declared here |
position | function | Declared here |
available | function | Declared here |
begin | function | Declared here |
current | function | Declared here |
order | function | Declared here |
toString | function | Declared here |
_position | variable | Declared here |
_limit | variable | Declared here |
_order | variable | Declared here |
_bytes | variable | Declared here |
init | function | Declared here |
Friends
| Name | Description |
|---|---|
operator<< inline |
operator<<
inline
friend inline std::ostream & operator<<(std::ostream & stream, const BitReader & buf)Defined in src/base/include/icy/buffer.h:423
Public Methods
| Return | Name | Description |
|---|---|---|
BitReader | Constructs a [BitReader](#bitreader) over a raw byte array. | |
BitReader | Constructs a [BitReader](#bitreader) over a Buffer. | |
BitReader | Constructs a [BitReader](#bitreader) over a [ConstBuffer](icy-ConstBuffer.html#constbuffer-6). | |
void | get | Reads a value from the BitReader. Returns false if there isn't enough data left for the specified type. Throws a std::out_of_range exception if reading past the limit. Reads len raw bytes into val. Throws std::out_of_range if insufficient data remains. |
void | get | Reads len bytes and appends them to val. Throws std::out_of_range if insufficient data remains. |
void | getU8 | Reads an unsigned 8-bit integer. Throws std::out_of_range if insufficient data remains. |
void | getU16 | Reads an unsigned 16-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains. |
void | getU24 | Reads an unsigned 24-bit integer into a 32-bit variable, applying byte-order conversion. Throws std::out_of_range if insufficient data remains. |
void | getU32 | Reads an unsigned 32-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains. |
void | getU64 | Reads an unsigned 64-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains. |
char | peek | Peeks at the current byte without advancing the position. |
uint8_t | peekU8 | Peeks at the current byte as a uint8_t without advancing the position. |
uint16_t | peekU16 | Peeks at the next two bytes as a uint16_t without advancing the position. |
uint32_t | peekU24 | Peeks at the next three bytes as a uint32_t without advancing the position. |
uint32_t | peekU32 | Peeks at the next four bytes as a uint32_t without advancing the position. |
uint64_t | peekU64 | Peeks data from the BitReader. -1 is returned if reading past boundary. |
size_t | skipToChar | Advances the position until the given character is found, stopping before it. |
size_t | skipWhitespace | Advances the position past any leading space characters. |
size_t | skipToNextLine | Advances the position past the end of the current line (past the newline). |
size_t | skipNextWord | Advances the position past the next whitespace-delimited word. |
size_t | readNextWord | Reads the next whitespace-delimited word into val. |
size_t | readNextNumber | Reads the next whitespace-delimited decimal number into val. |
size_t | readLine | Reads bytes up to (but not including) the next newline into val. |
size_t | readToNext | Reads bytes up to (but not including) the next occurrence of c into val. |
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 read limit. |
size_t | position const inline | Returns the current read position. |
size_t | available const | Returns the number of elements between the current position and the limit. |
const char * | begin const inline | Returns a pointer to the start of the buffer. |
const char * | current const inline | Returns a pointer to the current read position. |
ByteOrder | order const inline | Returns the byte order used for multi-byte integer reads. |
std::string | toString | Returns the remaining unread bytes as a std::string. |
BitReader
BitReader(const char * bytes, size_t size, ByteOrder order = ByteOrder::Network)Defined in src/base/include/icy/buffer.h:280
Constructs a [BitReader](#bitreader) over a raw byte array.
Parameters
bytesPointer to the start of the data. Must remain valid for the lifetime of the reader.sizeNumber of bytes available for reading.orderByte order used when reading multi-byte integer types.
BitReader
BitReader(const Buffer & buf, ByteOrder order = ByteOrder::Network)Defined in src/base/include/icy/buffer.h:285
Constructs a [BitReader](#bitreader) over a Buffer.
Parameters
bufSource buffer. Must remain valid for the lifetime of the reader.orderByte order used when reading multi-byte integer types.
BitReader
BitReader(const ConstBuffer & pod, ByteOrder order = ByteOrder::Network)Defined in src/base/include/icy/buffer.h:290
Constructs a [BitReader](#bitreader) over a [ConstBuffer](icy-ConstBuffer.html#constbuffer-6).
Parameters
podSource const buffer. Must remain valid for the lifetime of the reader.orderByte order used when reading multi-byte integer types.
get
void get(char * val, size_t len)Defined in src/base/include/icy/buffer.h:299
Reads a value from the BitReader. Returns false if there isn't enough data left for the specified type. Throws a std::out_of_range exception if reading past the limit. Reads len raw bytes into val. Throws std::out_of_range if insufficient data remains.
Parameters
valDestination buffer; must have capacity of at leastlenbytes.lenNumber of bytes to read.
get
void get(std::string & val, size_t len)Defined in src/base/include/icy/buffer.h:304
Reads len bytes and appends them to val. Throws std::out_of_range if insufficient data remains.
Parameters
valString to append the read bytes to.lenNumber of bytes to read.
getU8
void getU8(uint8_t & val)Defined in src/base/include/icy/buffer.h:308
Reads an unsigned 8-bit integer. Throws std::out_of_range if insufficient data remains.
Parameters
valOutput parameter receiving the read value.
getU16
void getU16(uint16_t & val)Defined in src/base/include/icy/buffer.h:312
Reads an unsigned 16-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
Parameters
valOutput parameter receiving the read value.
getU24
void getU24(uint32_t & val)Defined in src/base/include/icy/buffer.h:316
Reads an unsigned 24-bit integer into a 32-bit variable, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
Parameters
valOutput parameter receiving the read value.
getU32
void getU32(uint32_t & val)Defined in src/base/include/icy/buffer.h:320
Reads an unsigned 32-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
Parameters
valOutput parameter receiving the read value.
getU64
void getU64(uint64_t & val)Defined in src/base/include/icy/buffer.h:324
Reads an unsigned 64-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
Parameters
valOutput parameter receiving the read value.
peek
char peek()Defined in src/base/include/icy/buffer.h:328
Peeks at the current byte without advancing the position.
Returns
Current byte as char, or 0 if at the end of the buffer.
peekU8
uint8_t peekU8()Defined in src/base/include/icy/buffer.h:332
Peeks at the current byte as a uint8_t without advancing the position.
Returns
Current value, or 0 if at the end of the buffer.
peekU16
uint16_t peekU16()Defined in src/base/include/icy/buffer.h:336
Peeks at the next two bytes as a uint16_t without advancing the position.
Returns
Current value with byte-order conversion applied, or 0 on failure.
peekU24
uint32_t peekU24()Defined in src/base/include/icy/buffer.h:340
Peeks at the next three bytes as a uint32_t without advancing the position.
Returns
Current value with byte-order conversion applied, or 0 on failure.
peekU32
uint32_t peekU32()Defined in src/base/include/icy/buffer.h:344
Peeks at the next four bytes as a uint32_t without advancing the position.
Returns
Current value with byte-order conversion applied, or 0 on failure.
peekU64
uint64_t peekU64()Defined in src/base/include/icy/buffer.h:348
Peeks data from the BitReader. -1 is returned if reading past boundary.
skipToChar
size_t skipToChar(char c)Defined in src/base/include/icy/buffer.h:357
Advances the position until the given character is found, stopping before it.
Parameters
cCharacter to search for.
Returns
Number of bytes skipped.
skipWhitespace
size_t skipWhitespace()Defined in src/base/include/icy/buffer.h:361
Advances the position past any leading space characters.
Returns
Number of bytes skipped.
skipToNextLine
size_t skipToNextLine()Defined in src/base/include/icy/buffer.h:365
Advances the position past the end of the current line (past the newline).
Returns
Number of bytes skipped including the newline character.
skipNextWord
size_t skipNextWord()Defined in src/base/include/icy/buffer.h:369
Advances the position past the next whitespace-delimited word.
Returns
Number of bytes skipped.
readNextWord
size_t readNextWord(std::string & val)Defined in src/base/include/icy/buffer.h:374
Reads the next whitespace-delimited word into val.
Parameters
valString to receive the word.
Returns
Number of bytes consumed.
readNextNumber
size_t readNextNumber(unsigned int & val)Defined in src/base/include/icy/buffer.h:379
Reads the next whitespace-delimited decimal number into val.
Parameters
valOutput parameter receiving the parsed unsigned integer.
Returns
Number of bytes consumed.
readLine
size_t readLine(std::string & val)Defined in src/base/include/icy/buffer.h:384
Reads bytes up to (but not including) the next newline into val.
Parameters
valString to receive the line content.
Returns
Number of bytes consumed including the newline.
readToNext
size_t readToNext(std::string & val, char c)Defined in src/base/include/icy/buffer.h:390
Reads bytes up to (but not including) the next occurrence of c into val.
Parameters
valString to receive the read bytes.cDelimiter character to stop at.
Returns
Number of bytes consumed.
seek
void seek(size_t val)Defined in src/base/include/icy/buffer.h:394
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:398
Set position pointer to relative position. Throws a std::out_of_range exception if the value exceeds the limit.
limit
const
size_t limit() constDefined in src/base/include/icy/buffer.h:401
Returns the read limit.
position
const inline
inline size_t position() constDefined in src/base/include/icy/buffer.h:404
Returns the current read position.
available
const
size_t available() constDefined in src/base/include/icy/buffer.h:408
Returns the number of elements between the current position and the limit.
begin
const inline
inline const char * begin() constDefined in src/base/include/icy/buffer.h:411
Returns a pointer to the start of the buffer.
current
const inline
inline const char * current() constDefined in src/base/include/icy/buffer.h:414
Returns a pointer to the current read position.
order
const inline
inline ByteOrder order() constDefined in src/base/include/icy/buffer.h:417
Returns the byte order used for multi-byte integer reads.
toString
std::string toString()Defined in src/base/include/icy/buffer.h:421
Returns the remaining unread bytes as a std::string.
Returns
String containing bytes from the current position to the end.
Protected Attributes
_position
size_t _positionDefined in src/base/include/icy/buffer.h:431
_limit
size_t _limitDefined in src/base/include/icy/buffer.h:432
_order
ByteOrder _orderDefined in src/base/include/icy/buffer.h:433
_bytes
const char * _bytesDefined in src/base/include/icy/buffer.h:434
Protected Methods
| Return | Name | Description |
|---|---|---|
void | init |
init
void init(const char * bytes, size_t size, ByteOrder order)