NAP
Public Member Functions | List of all members
MemoryStream Class Reference

#include </opt/build/repo/nap/utility/src/utility/memorystream.h>

Public Member Functions

 MemoryStream (const uint8_t *buffer, uint32_t length)
 
bool isDone () const
 
bool hasAvailable (uint32_t size)
 
void read (void *data, uint32_t length)
 
template<class T >
void read (T &data)
 
template<class T >
const T read ()
 
void readString (std::string &string)
 

Description

A MemoryStream allows you to read data from a memory buffer

Constructor & Destructor Documentation

◆ MemoryStream()

MemoryStream ( const uint8_t *  buffer,
uint32_t  length 
)

Constructor

Parameters
bufferThe buffer to read from
lengthThe length of the buffer we're reading from

Member Function Documentation

◆ hasAvailable()

bool hasAvailable ( uint32_t  size)

Checks whether the specified amount of bytes is available for reading

Parameters
sizeThe number of bytes desired for reading
Returns
True if the specified number of bytes can be read, false if not

◆ isDone()

bool isDone ( ) const

Checks whether all data in this stream has been read

Returns
True if all data has been read, false if not

◆ read() [1/3]

const T read ( )

Helper function to read a primitive of type T from the stream (returns by value)

Returns
The data that was read

◆ read() [2/3]

void read ( T &  data)

Helper function to read a primitive of type T from the stream

Parameters
dataThe buffer to read to

◆ read() [3/3]

void read ( void *  data,
uint32_t  length 
)

Function to read the specified number of bytes from the stream to a buffer

Parameters
dataThe buffer to read to
lengthThe number of bytes to read

◆ readString()

void readString ( std::string &  string)

Helper function to read a string from the stream

Parameters
stringThe string to read the data to