ByteStream
ByteStream

A stream of bytes that is used to easily store and retrieve data

Functions
ByteStream
ByteStream(
bool bigEndiantrue
)

Default constructor to create a ByteStream object

Parameters
bigEndian
bool

Whether this ByteStream contains floating point data in big endian (true) or little endian(false) (default of true)

ByteStream
explicit ByteStream(
Bytes bytesToCopy,
bool bigEndiantrue
)

Constructor to create a ByteStream object, passing in the bytes to store in the stream

Parameters
bytesToCopy

The vector of bytes to copy into the ByteStream

bigEndian
bool

Whether this ByteStream contains floating point data in big endian (true) or little endian(false) (default of true)

~ByteStream
virtual ~ByteStream()

Default destructor for the ByteStream object

Variables
m_bytes
Bytes m_bytes

The data stream object that holds all the bytes

m_bigEndian
bool m_bigEndian

Whether the ByteStream is big endian (true) or little endian (false)

Operators
[]

Accesses a single byte of the ByteStream

Parameters
index

The 0-based index into the ByteStream

Returns

The single byte in the ByteStream located at the requested index

Exceptions
See Also

read_uint8

==

Checks that two ByteStream objects are equal by comparing their data vectors

Returns

true if the two ByteStreams are identical, false otherwise

Functions
append_uint8
void append_uint8(
uint8 value
)

Appends a 1-byte unsigned integer to the byte stream

Parameters
value
uint8

The 1-byte uint8 to be added to the byte stream

append_int16
void append_int16(
int16 value
)

Appends a 2-byte signed integer to the byte stream

Parameters
value
int16

The 2-byte int16 to be added to the byte stream

append_uint16
void append_uint16(
uint16 value
)

Appends a 2-byte unsigned integer to the byte stream

Parameters
value
uint16

The 2-byte uint16 to be added to the byte stream

append_uint32
void append_uint32(
uint32 value
)

Appends a 4-byte unsigned integer to the byte stream

Parameters
value
uint32

The 4-byte uint32 to be added to the byte stream

append_float
void append_float(
float value
)

Appends a 4-byte float to the byte stream

Parameters
valye

The 4-byte float to be added to the byte stream

append_double
void append_double(
double value
)

Appends an 8-byte double to the byte stream

Parameters
valye

The 8-byte double to be added to the byte stream

append_string
void append_string(
const std::string &str
)

Appends a string to the byte stream.

Parameters
str
const std::string&

The string to append to the byte stream.

appendBytes
void appendBytes(
const Bytes &bytes
)

Appends a vector of bytes (uint8) to the end of the current ByteStream

Parameters
bytes
const Bytes&

The bytes to be appended to the byte stream

appendByteStream
void appendByteStream(
const ByteStream &otherStream
)

Appends the entire contents of a ByteStream to the end of the current ByteStream

Parameters
otherStream
const ByteStream&

The ByteStream to be appended to the current ByteStream

read_int8
int8 read_int8(
std::size_t position
) const

Reads a 1-byte signed integer from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The 1-byte int8 at the requested position

Exceptions
read_uint8
uint8 read_uint8(
std::size_t position
) const

Reads a 1-byte unsigned integer from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The 1-byte uint8 at the requested position

Exceptions
read_int16
int16 read_int16(
std::size_t position
) const

Reads a 2-byte signed integer from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The int16 at the requested position

Exceptions
read_uint16
uint16 read_uint16(
std::size_t position
) const

Reads a 2-byte unsigned integer from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The uint16 at the requested position

Exceptions
read_uint32
uint32 read_uint32(
std::size_t position
) const

Reads a 4-byte unsigned integer from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The uint32 at the requested position

Exceptions
read_float
float read_float(
std::size_t position
) const

Reads a 4-byte float from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The float at the requested position

Exceptions
read_double
double read_double(
std::size_t position
) const

Reads an 8-byte double from the byte stream

Parameters
position
std::size_t

The 0-based position to read from

Returns

The double at the requested position

Exceptions
read_string
std::string read_string(
std::size_t position,
std::size_t length
) const

Reads a string of the specified length from the byte stream

Parameters
position
std::size_t

The 0-based position to start reading from

length
std::size_t

The size (number of characters) to read for

Returns

The string at the requested position of the requested length

Exceptions

-std::out_of_range: The index + length requested is out of range

data
Bytes& data()

Gets the byte stream as a vector of bytes (Bytes)

Returns

The byte stream as a vector of bytes (Bytes)

data
const Bytes& data() const

Gets the byte stream as a vector of bytes (Bytes)

Returns

The byte stream as a vector of bytes (Bytes)

size
std::size_t size() const

Gets the size of the byte stream (equivalent of std::vector.size())

Returns

The size of the byte stream (number of bytes)

clear
void clear()

Clears the byte stream (equivalent of std::vector.clear())

empty
bool empty()

Checks whether the vector is empty. (equivalent of std::vector::empty())

Returns

true if the vector is empty (size is 0), false otherwise.

resize
void resize(
std::size_t size
)

Resizes the byte stream (equivalent of std::vector.resize())

set
void set(
const Bytes &bytes
)

Sets the underlying bytes to the given Bytes.

begin
Bytes::iterator begin()

Gets an iterator referring to the first element in the ByteStream (equivalent of std::vector::begin())

Returns

An iterator referring to the first element in the ByteStream

end
Bytes::iterator end()

Gets an iterator referring to the "past-the-end" element in the ByteStream. (equivalent of std::vector::begin())

Returns

An iterator referring to the "past-the-end" element in the ByteStream

calculateSimpleChecksum
uint16 calculateSimpleChecksum(
std::size_t from,
std::size_t to
) const

Calculates the simple checksum (simple addition of bytes)on the ByteStream

Parameters
from
std::size_t

The 0-based starting position in the bytes vector to start calculating the checksum (includes this byte)

to
std::size_t

The 0-based end position in the bytes vector to end calculating the checksum (includes this byte)

Returns

The simple checksum (addition of bytes) of the ByteStream

Exceptions
calculateFletcherChecksum
uint16 calculateFletcherChecksum(
std::size_t from,
std::size_t to
) const

Calculates the Fletcher checksum (position dependent checksum) on the ByteStream

Parameters
from
std::size_t

The 0-based starting position in the bytes vector to start calculating the checksum (includes this byte)

to
std::size_t

The 0-based end position in the bytes vector to end calculating the checksum (includes this byte)

Returns

The Fletcher checksum of the ByteStream

Exceptions
verifyBytesInStream
void verifyBytesInStream(
std::size_t position,
std::size_t length
) const

Checks that the current bytestream can read the requested data

Parameters
position
std::size_t

The 0-based start position that is desired to read data from

length
std::size_t

The amount of bytes desired to read

Exceptions