My Project
Public Member Functions | List of all members
NPL::WebSocket::ByteBuffer Class Reference

Public Member Functions

 ByteBuffer (uint32_t size=DEFAULT_SIZE)
 ByteBuffer constructor Reserves specified size in internal vector. More...
 
 ByteBuffer (uint8_t *arr, uint32_t size)
 ByteBuffer constructor Consume an entire uint8_t array of length len in the ByteBuffer. More...
 
virtual ~ByteBuffer ()
 ByteBuffer Deconstructor. More...
 
uint32_t bytesRemaining ()
 Bytes Remaining Returns the number of bytes from the current read position till the end of the buffer. More...
 
void clear ()
 Clear Clears out all data from the internal vector (original preallocated size remains), resets the positions to 0.
 
ByteBufferclone ()
 Clone Allocate an exact copy of the ByteBuffer on the heap and return a pointer. More...
 
bool equals (ByteBuffer *other)
 Equals, test for data equivilancy Compare this ByteBuffer to another by looking at each byte in the internal buffers and making sure they are the same. More...
 
void resize (uint32_t newSize)
 Resize Reallocates memory for the internal buffer of size newSize. More...
 
uint32_t size ()
 Size Returns the size of the internal buffer...not necessarily the length of bytes used as data! More...
 
uint32_t capacity ()
 
void reserve (uint32_t newCapacity)
 
template<typename T >
int32_t find (T key, uint32_t start=0)
 
void replace (uint8_t key, uint8_t rep, uint32_t start=0, bool firstOccuranceOnly=false)
 Replace Replace occurance of a particular uint8_t, key, with the uint8_t rep. More...
 
uint8_t peek ()
 
uint8_t get ()
 
uint8_t get (uint32_t index)
 
void getBytes (uint8_t *buf, uint32_t len)
 
char getChar ()
 
char getChar (uint32_t index)
 
double getDouble ()
 
double getDouble (uint32_t index)
 
float getFloat ()
 
float getFloat (uint32_t index)
 
uint32_t getInt ()
 
uint32_t getInt (uint32_t index)
 
uint64_t getLong ()
 
uint64_t getLong (uint32_t index)
 
uint16_t getShort ()
 
uint16_t getShort (uint32_t index)
 
void put (ByteBuffer *src)
 
void put (uint8_t b)
 
void put (uint8_t b, uint32_t index)
 
void putBytes (uint8_t *b, uint32_t len)
 
void putBytes (uint8_t *b, uint32_t len, uint32_t index)
 
void putChar (char value)
 
void putChar (char value, uint32_t index)
 
void putDouble (double value)
 
void putDouble (double value, uint32_t index)
 
void putFloat (float value)
 
void putFloat (float value, uint32_t index)
 
void putInt (uint32_t value)
 
void putInt (uint32_t value, uint32_t index)
 
void putLong (uint64_t value)
 
void putLong (uint64_t value, uint32_t index)
 
void putShort (uint16_t value)
 
void putShort (uint16_t value, uint32_t index)
 
void setReadPos (uint32_t r)
 
uint32_t getReadPos ()
 
void setWritePos (uint32_t w)
 
uint32_t getWritePos ()
 
void setName (std::string n)
 
std::string getName ()
 
void printInfo ()
 
void printAH ()
 
void printAscii ()
 
void printHex ()
 
void printPosition ()
 

Constructor & Destructor Documentation

§ ByteBuffer() [1/2]

ByteBuffer::ByteBuffer ( uint32_t  size = DEFAULT_SIZE)

ByteBuffer constructor Reserves specified size in internal vector.

Parameters
sizeSize (in bytes) of space to preallocate internally. Default is set in DEFAULT_SIZE

§ ByteBuffer() [2/2]

ByteBuffer::ByteBuffer ( uint8_t *  arr,
uint32_t  size 
)

ByteBuffer constructor Consume an entire uint8_t array of length len in the ByteBuffer.

Parameters
arruint8_t array of data (should be of length len)
sizeSize of space to allocate

§ ~ByteBuffer()

ByteBuffer::~ByteBuffer ( )
virtual

ByteBuffer Deconstructor.

Member Function Documentation

§ bytesRemaining()

uint32_t ByteBuffer::bytesRemaining ( )

Bytes Remaining Returns the number of bytes from the current read position till the end of the buffer.

Returns
Number of bytes from rpos to the end (size())

§ clone()

ByteBuffer * ByteBuffer::clone ( )

Clone Allocate an exact copy of the ByteBuffer on the heap and return a pointer.

Returns
A pointer to the newly cloned ByteBuffer. NULL if no more memory available

§ equals()

bool ByteBuffer::equals ( ByteBuffer other)

Equals, test for data equivilancy Compare this ByteBuffer to another by looking at each byte in the internal buffers and making sure they are the same.

Parameters
otherA pointer to a ByteBuffer to compare to this one
Returns
True if the internal buffers match. False if otherwise

§ replace()

void ByteBuffer::replace ( uint8_t  key,
uint8_t  rep,
uint32_t  start = 0,
bool  firstOccuranceOnly = false 
)

Replace Replace occurance of a particular uint8_t, key, with the uint8_t rep.

Parameters
keyuint8_t to find for replacement
repuint8_t to replace the found key with
startIndex to start from. By default, start is 0
firstOccuranceOnlyIf true, only replace the first occurance of the key. If false, replace all occurances. False by default

§ resize()

void ByteBuffer::resize ( uint32_t  newSize)

Resize Reallocates memory for the internal buffer of size newSize.

Read and write positions will also be reset

Parameters
newSizeThe amount of memory to allocate

§ size()

uint32_t ByteBuffer::size ( )

Size Returns the size of the internal buffer...not necessarily the length of bytes used as data!

Returns
size of the internal buffer

The documentation for this class was generated from the following files: