#include <icy/buffer.h>Class for reading binary streams.
| 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(const char * bytes, size_t size, ByteOrder order)Constructs a [BitReader](#bitreader) over a raw byte array.
bytes Pointer to the start of the data. Must remain valid for the lifetime of the reader.
size Number of bytes available for reading.
order Byte order used when reading multi-byte integer types.
BitReader(const Buffer & buf, ByteOrder order)Constructs a [BitReader](#bitreader) over a Buffer.
buf Source buffer. Must remain valid for the lifetime of the reader.
order Byte order used when reading multi-byte integer types.
BitReader(const ConstBuffer & pod, ByteOrder order)Constructs a [BitReader](#bitreader) over a [ConstBuffer](icy-ConstBuffer.html#constbuffer-6).
pod Source const buffer. Must remain valid for the lifetime of the reader.
order Byte order used when reading multi-byte integer types.
void get(char * val, size_t len)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.
val Destination buffer; must have capacity of at least len bytes.
len Number of bytes to read.
void get(std::string & val, size_t len)Reads len bytes and appends them to val. Throws std::out_of_range if insufficient data remains.
val String to append the read bytes to.
len Number of bytes to read.
void getU8(uint8_t & val)Reads an unsigned 8-bit integer. Throws std::out_of_range if insufficient data remains.
val Output parameter receiving the read value.void getU16(uint16_t & val)Reads an unsigned 16-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
val Output parameter receiving the read value.void getU24(uint32_t & val)Reads an unsigned 24-bit integer into a 32-bit variable, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
val Output parameter receiving the read value.void getU32(uint32_t & val)Reads an unsigned 32-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
val Output parameter receiving the read value.void getU64(uint64_t & val)Reads an unsigned 64-bit integer, applying byte-order conversion. Throws std::out_of_range if insufficient data remains.
val Output parameter receiving the read value.char peek()Peeks at the current byte without advancing the position.
Current byte as char, or 0 if at the end of the buffer.
uint8_t peekU8()Peeks at the current byte as a uint8_t without advancing the position.
Current value, or 0 if at the end of the buffer.
uint16_t peekU16()Peeks at the next two bytes as a uint16_t without advancing the position.
Current value with byte-order conversion applied, or 0 on failure.
uint32_t peekU24()Peeks at the next three bytes as a uint32_t without advancing the position.
Current value with byte-order conversion applied, or 0 on failure.
uint32_t peekU32()Peeks at the next four bytes as a uint32_t without advancing the position.
Current value with byte-order conversion applied, or 0 on failure.
uint64_t peekU64()Peeks data from the BitReader. -1 is returned if reading past boundary.
size_t skipToChar(char c)Advances the position until the given character is found, stopping before it.
c Character to search for.Number of bytes skipped.
size_t skipWhitespace()Advances the position past any leading space characters.
Number of bytes skipped.
size_t skipToNextLine()Advances the position past the end of the current line (past the newline).
Number of bytes skipped including the newline character.
size_t skipNextWord()Advances the position past the next whitespace-delimited word.
Number of bytes skipped.
size_t readNextWord(std::string & val)Reads the next whitespace-delimited word into val.
val String to receive the word.Number of bytes consumed.
size_t readNextNumber(unsigned int & val)Reads the next whitespace-delimited decimal number into val.
val Output parameter receiving the parsed unsigned integer.Number of bytes consumed.
size_t readLine(std::string & val)Reads bytes up to (but not including) the next newline into val.
val String to receive the line content.Number of bytes consumed including the newline.
size_t readToNext(std::string & val, char c)Reads bytes up to (but not including) the next occurrence of c into val.
val String to receive the read bytes.
c Delimiter character to stop at.
Number of bytes consumed.
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 read limit.
const inline
inline size_t position() constReturns the current read position.
const
size_t available() constReturns the number of elements between the current position and the limit.
const inline
inline const char * begin() constReturns a pointer to the start of the buffer.
const inline
inline const char * current() constReturns a pointer to the current read position.
const inline
inline ByteOrder order() constReturns the byte order used for multi-byte integer reads.
std::string toString()Returns the remaining unread bytes as a std::string.
String containing bytes from the current position to the end.
size_t _positionsize_t _limitByteOrder _orderconst char * _bytes| Return | Name | Description |
|---|---|---|
void | init |
void init(const char * bytes, size_t size, ByteOrder order)