CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
ByteSource Class Reference

Byte decoding sink. More...

#include <cc/ByteSource>

Public Member Functions

 ByteSource (const Stream &source, const Bytes &buffer, ByteOrder endian=ByteOrder::LittleEndian)
 Open a new ByteSource.
 
 ByteSource (const Stream &source, ByteOrder endian=ByteOrder::LittleEndian)
 Open a new ByteSource.
 
 ByteSource (const Bytes &buffer, ByteOrder endian=ByteOrder::LittleEndian)
 Open a new ByteSource.
 
bool readByte (Out< uint8_t > x)
 Read byte into x and return true if successful.
 
bool readChar (Out< char > ch)
 Read character into x and return true if successful.
 
void read (Out< Bytes > span)
 Read a fixed number of bytes (N)
 
Bytes readSpan (int n)
 Read n bytes.
 
String readCString ()
 Read a zero-terminated C-string.
 
bool prefetch ()
 Fill input buffer and return true if more bytes can be read.
 
uint8_t readUInt8 ()
 Read a byte.
 
uint16_t readUInt16 ()
 Read a 2-byte word.
 
uint32_t readUInt32 ()
 Read a 4-byte word.
 
uint64_t readUInt64 ()
 Read an 8-byte word.
 
int8_t readInt8 ()
 Read a signed byte.
 
int16_t readInt16 ()
 Read a signed 2-byte word.
 
int32_t readInt32 ()
 Read a signed 4-byte word.
 
int64_t readInt64 ()
 Read a signed 8-byte word.
 
Stream source () const
 Data source to read bytes from.
 
const Bytesbuffer () const
 The input buffer.
 
ByteOrder endian () const
 Byte-order for decoding multi-byte words.
 
void setEndian (ByteOrder endian)
 Set byte-order
 
long long currentOffset () const
 Total number of bytes read.
 

Detailed Description

Byte decoding sink.

Exceptions
InputExhaustion

Constructor & Destructor Documentation

◆ ByteSource() [1/3]

ByteSource ( const Stream & source,
const Bytes & buffer,
ByteOrder endian = ByteOrder::LittleEndian )

Open a new ByteSource.

Parameters
sourceData source to write bytes from
bufferInput buffer to use
endianEndianess for reading multi-byte words

◆ ByteSource() [2/3]

ByteSource ( const Stream & source,
ByteOrder endian = ByteOrder::LittleEndian )

Open a new ByteSource.

Parameters
sourceData source to write bytes from
endianEndianess for reading multi-byte words

◆ ByteSource() [3/3]

ByteSource ( const Bytes & buffer,
ByteOrder endian = ByteOrder::LittleEndian )

Open a new ByteSource.

Parameters
bufferInput buffer to read bytes from
endianEndianess for reading multi-byte words

Member Function Documentation

◆ readByte()

bool readByte ( Out< uint8_t > x)

Read byte into x and return true if successful.

◆ readChar()

bool readChar ( Out< char > ch)

Read character into x and return true if successful.

◆ read()

void read ( Out< Bytes > span)

Read a fixed number of bytes (N)

Parameters
spantarget buffer (N = span->count())

◆ readSpan()

Bytes readSpan ( int n)

Read n bytes.

◆ readCString()

String readCString ( )

Read a zero-terminated C-string.

◆ prefetch()

bool prefetch ( )

Fill input buffer and return true if more bytes can be read.

◆ readUInt8()

uint8_t readUInt8 ( )

Read a byte.

◆ readUInt16()

uint16_t readUInt16 ( )

Read a 2-byte word.

◆ readUInt32()

uint32_t readUInt32 ( )

Read a 4-byte word.

◆ readUInt64()

uint64_t readUInt64 ( )

Read an 8-byte word.

◆ readInt8()

int8_t readInt8 ( )

Read a signed byte.

◆ readInt16()

int16_t readInt16 ( )

Read a signed 2-byte word.

◆ readInt32()

int32_t readInt32 ( )

Read a signed 4-byte word.

◆ readInt64()

int64_t readInt64 ( )

Read a signed 8-byte word.

◆ source()

Stream source ( ) const

Data source to read bytes from.

◆ buffer()

const Bytes & buffer ( ) const

The input buffer.

◆ endian()

ByteOrder endian ( ) const

Byte-order for decoding multi-byte words.

◆ setEndian()

void setEndian ( ByteOrder endian)

Set byte-order

◆ currentOffset()

long long currentOffset ( ) const

Total number of bytes read.