Byte array utility class. More...
#include <byte_array.h>
Public Member Functions | |
CByteArray () | |
Class constructor. More... | |
CByteArray (const CByteArray &c_byte_array) | |
Class copy constructor. More... | |
CByteArray (const UInt8 *pun_buffer, size_t un_size) | |
Class constructor. More... | |
CByteArray (size_t un_size, UInt8 un_value=0) | |
Class constructor. More... | |
size_t | Size () const |
Returns the current size of the byte array. More... | |
void | Resize (size_t un_size, UInt8 un_value=0) |
Resizes the byte array to the wanted size. More... | |
void | Swap (CByteArray &c_other) |
Swaps the content of this byte array with the content of the passed one. More... | |
bool | Empty () const |
Returns true if the byte array is empty. More... | |
const UInt8 * | ToCArray () const |
Returns the contents of the byte array as a const c-style array. More... | |
UInt8 * | ToCArray () |
Returns the contents of the byte array as a c-style array. More... | |
void | Clear () |
Clears the byte array. More... | |
void | Zero () |
Sets the contents of the byte array to all zeros. More... | |
CByteArray & | operator= (const CByteArray &c_byte_array) |
Assignment operator. More... | |
UInt8 & | operator[] (size_t un_index) |
Read/write index operator. More... | |
UInt8 | operator[] (size_t un_index) const |
Read-only index operator. More... | |
bool | operator== (const CByteArray &c_byte_array) const |
Equality comparison operator. More... | |
CByteArray & | AddBuffer (const UInt8 *pun_buffer, size_t un_size) |
Appends bytes to the byte array. More... | |
CByteArray & | FetchBuffer (UInt8 *pun_buffer, size_t un_size) |
Moves elements from the byte array into the passed buffer. More... | |
template<typename T > | |
T | PopFront () |
Removes data from the beginning of the byte array and returns it. More... | |
CByteArray * | operator() (size_t un_start, ssize_t un_end=-1) |
Returns a new byte array that corresponds to a part of this byte array. More... | |
CByteArray & | operator<< (UInt8 un_value) |
Appends a 8-bit unsigned integer to the byte array. More... | |
CByteArray & | operator>> (UInt8 &un_value) |
Moves an 8-bit unsigned integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (SInt8 n_value) |
Appends a 8-bit signed integer to the byte array. More... | |
CByteArray & | operator>> (SInt8 &n_value) |
Moves an 8-bit signed integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (UInt16 un_value) |
Appends a 16-bit unsigned integer to the byte array. More... | |
CByteArray & | operator>> (UInt16 &un_value) |
Moves a 16-bit unsigned integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (SInt16 n_value) |
Appends a 16-bit signed integer to the byte array. More... | |
CByteArray & | operator>> (SInt16 &n_value) |
Moves a 16-bit signed integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (UInt32 un_value) |
Appends a 32-bit unsigned integer to the byte array. More... | |
CByteArray & | operator>> (UInt32 &un_value) |
Moves a 32-bit unsigned integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (SInt32 n_value) |
Appends a 32-bit signed integer to the byte array. More... | |
CByteArray & | operator>> (SInt32 &n_value) |
Moves a 32-bit signed integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (UInt64 un_value) |
Appends a 64-bit unsigned integer to the byte array. More... | |
CByteArray & | operator>> (UInt64 &un_value) |
Moves a 64-bit unsigned integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (SInt64 n_value) |
Appends a 64-bit signed integer to the byte array. More... | |
CByteArray & | operator>> (SInt64 &n_value) |
Moves a 64-bit signed integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (unsigned long int un_value) |
Appends an unsigned long integer to the byte array. More... | |
CByteArray & | operator>> (unsigned long int &un_value) |
Moves an unsigned long integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (signed long int n_value) |
Appends a signed long integer to the byte array. More... | |
CByteArray & | operator>> (signed long int &n_value) |
Moves a signed long integer from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (double f_value) |
Appends a double to the byte array. More... | |
CByteArray & | operator>> (double &f_value) |
Moves a double from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (float f_value) |
Appends a float to the byte array. More... | |
CByteArray & | operator>> (float &f_value) |
Moves a float from the beginning of the byte array to the target variable. More... | |
CByteArray & | operator<< (const std::string &str_value) |
Appends a std::string to the byte array. More... | |
CByteArray & | operator>> (std::string &str_value) |
Moves a std::string from the beginning of the byte array to the target variable. More... | |
Byte array utility class.
This class is useful for serializing any kind of data into a byte array, to be then streamed to something. It internally stores the data in network order.
Definition at line 28 of file byte_array.h.
|
inline |
Class constructor.
Definition at line 35 of file byte_array.h.
|
inline |
Class copy constructor.
Definition at line 40 of file byte_array.h.
argos::CByteArray::CByteArray | ( | const UInt8 * | pun_buffer, |
size_t | un_size | ||
) |
Class constructor.
Copies the given buffer into the byte array. The original buffer can be safely deleted.
pun_buffer | the original buffer to copy from. |
un_size | the size of the original buffer. |
Definition at line 65 of file byte_array.cpp.
argos::CByteArray::CByteArray | ( | size_t | un_size, |
UInt8 | un_value = 0 |
||
) |
Class constructor.
Creates a byte array that contains un_size
copies of un_value
.
un_size | the initial size of the byte array. |
un_value | the value to use to populate the byte array. |
Definition at line 73 of file byte_array.cpp.
CByteArray & argos::CByteArray::AddBuffer | ( | const UInt8 * | pun_buffer, |
size_t | un_size | ||
) |
Appends bytes to the byte array.
The contents of the buffer can be erased, since this method copies them.
pun_buffer | the byte buffer to copy from. |
un_size | the size of the byte buffer. |
Definition at line 105 of file byte_array.cpp.
|
inline |
Clears the byte array.
After calling this method, the byte array is empty.
Definition at line 134 of file byte_array.h.
|
inline |
Returns true
if the byte array is empty.
true
if the byte array is empty. Definition at line 100 of file byte_array.h.
CByteArray & argos::CByteArray::FetchBuffer | ( | UInt8 * | pun_buffer, |
size_t | un_size | ||
) |
Moves elements from the byte array into the passed buffer.
The elements whose values were written into the target buffer are removed from the byte array.
pun_buffer | the byte buffer to write into. |
un_size | the size of the target byte buffer. |
Definition at line 116 of file byte_array.cpp.
CByteArray * argos::CByteArray::operator() | ( | size_t | un_start, |
ssize_t | un_end = -1 |
||
) |
Returns a new byte array that corresponds to a part of this byte array.
The returned array is a copy from the element at position un_start
up to the element at position un_end-1
.
un_start | The start index |
un_end | The end index, or -1 to indicate the end of the array |
Definition at line 129 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | const std::string & | str_value | ) |
Appends a std::string
to the byte array.
str_value | the value of the std::string . |
Definition at line 499 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | double | f_value | ) |
Appends a double to the byte array.
This method assumes that floating-point numbers are represented in the IEEE754 standard.
f_value | the value of the double. |
Definition at line 403 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | float | f_value | ) |
Appends a float to the byte array.
This method assumes that floating-point numbers are represented in the IEEE754 standard.
f_value | the value of the float. |
Definition at line 481 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | signed long int | n_value | ) |
Appends a signed long integer to the byte array.
This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.
n_value | the value of the signed long integer. |
Definition at line 377 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | SInt16 | n_value | ) |
Appends a 16-bit signed integer to the byte array.
n_value | the value of the 16-bit signed integer. |
Definition at line 199 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | SInt32 | n_value | ) |
Appends a 32-bit signed integer to the byte array.
n_value | the value of the 32-bit signed integer. |
Definition at line 251 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | SInt64 | n_value | ) |
Appends a 64-bit signed integer to the byte array.
n_value | the value of the 64-bit signed integer. |
Definition at line 315 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | SInt8 | n_value | ) |
Appends a 8-bit signed integer to the byte array.
n_value | the value of the 8-bit signed integer. |
Definition at line 157 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | UInt16 | un_value | ) |
Appends a 16-bit unsigned integer to the byte array.
un_value | the value of the 16-bit unsigned integer. |
Definition at line 175 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | UInt32 | un_value | ) |
Appends a 32-bit unsigned integer to the byte array.
un_value | the value of the 32-bit unsigned integer. |
Definition at line 223 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | UInt64 | un_value | ) |
Appends a 64-bit unsigned integer to the byte array.
un_value | the value of the 64-bit unsigned integer. |
Definition at line 279 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | UInt8 | un_value | ) |
Appends a 8-bit unsigned integer to the byte array.
un_value | the value of the 8-bit unsigned integer. |
Definition at line 139 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | unsigned long int | un_value | ) |
Appends an unsigned long integer to the byte array.
This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.
un_value | the value of the unsigned long integer. |
Definition at line 351 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator= | ( | const CByteArray & | c_byte_array | ) |
Assignment operator.
Deep-copies the given byte array into the current byte array.
Definition at line 88 of file byte_array.cpp.
bool argos::CByteArray::operator== | ( | const CByteArray & | c_byte_array | ) | const |
Equality comparison operator.
true
if the content of this array and the given one are identical. Definition at line 98 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | double & | f_value | ) |
Moves a double from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array. This method assumes that floating-point numbers are represented in the IEEE754 standard.
f_value | the buffer for the double. |
Definition at line 444 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | float & | f_value | ) |
Moves a float from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array. This method assumes that floating-point numbers are represented in the IEEE754 standard.
f_value | the buffer for the float. |
Definition at line 489 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | signed long int & | n_value | ) |
Moves a signed long integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array. This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.
n_value | the buffer for the signed long integer. |
Definition at line 390 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | SInt16 & | n_value | ) |
Moves a 16-bit signed integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
n_value | the buffer for the 16-bit signed integer. |
Definition at line 210 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | SInt32 & | n_value | ) |
Moves a 32-bit signed integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
n_value | the buffer for the 32-bit signed integer. |
Definition at line 264 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | SInt64 & | n_value | ) |
Moves a 64-bit signed integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
n_value | the buffer for the 64-bit signed integer. |
Definition at line 332 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | SInt8 & | n_value | ) |
Moves an 8-bit signed integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
n_value | the buffer for the 8-bit unsigned integer. |
Definition at line 165 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | std::string & | str_value | ) |
Moves a std::string
from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
str_value | the buffer for the std::string . |
Definition at line 512 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | UInt16 & | un_value | ) |
Moves a 16-bit unsigned integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
un_value | the buffer for the 16-bit unsigned integer. |
Definition at line 186 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | UInt32 & | un_value | ) |
Moves a 32-bit unsigned integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
un_value | the buffer for the 32-bit unsigned integer. |
Definition at line 236 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | UInt64 & | un_value | ) |
Moves a 64-bit unsigned integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
un_value | the buffer for the 64-bit unsigned integer. |
Definition at line 296 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | UInt8 & | un_value | ) |
Moves an 8-bit unsigned integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array.
un_value | the buffer for the 8-bit unsigned integer. |
Definition at line 147 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator>> | ( | unsigned long int & | un_value | ) |
Moves an unsigned long integer from the beginning of the byte array to the target variable.
The element whose value was written into the target buffer are removed from the byte array. This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.
un_value | the buffer for the unsigned long integer. |
Definition at line 364 of file byte_array.cpp.
|
inline |
Read/write index operator.
un_index | the index of the wanted element. |
CARGoSException | if the passed index is out of bounds. |
Definition at line 157 of file byte_array.h.
|
inline |
Read-only index operator.
un_index | the index of the wanted element. |
CARGoSException | if the passed index is out of bounds. |
Definition at line 168 of file byte_array.h.
|
inline |
Removes data from the beginning of the byte array and returns it.
For example:
CByteArray b; // ... fill into b ... UInt32 i = PopFront<UInt32>();
Definition at line 209 of file byte_array.h.
|
inline |
Resizes the byte array to the wanted size.
If the new size is smaller than the old one, the first un_size elements are kept, and the extra ones are erased. If the new size is greater than the old one, new elements are added to the byte array and initialized with un_value. This operation could entail a reallocation of the internal storage structure, which would invalide the pointer returned by ToCArray().
un_size | The new size. |
un_value | The init value for the padding elements. |
Definition at line 83 of file byte_array.h.
|
inline |
Returns the current size of the byte array.
Definition at line 66 of file byte_array.h.
|
inline |
Swaps the content of this byte array with the content of the passed one.
c_other | The byte array to swap content with. |
Definition at line 92 of file byte_array.h.
|
inline |
Returns the contents of the byte array as a c-style array.
The returned pointer is valid under two conditions: (i) the CByteArray object has not been deallocated, and (ii) the contents of the byte array have not been changed. If the byte array is empty, this method returns NULL
.
Definition at line 124 of file byte_array.h.
|
inline |
Returns the contents of the byte array as a const c-style array.
The returned pointer is valid under two conditions: (i) the CByteArray object has not been deallocated, and (ii) the contents of the byte array have not been changed. If the byte array is empty, this method returns NULL
.
Definition at line 112 of file byte_array.h.
void argos::CByteArray::Zero | ( | ) |
Sets the contents of the byte array to all zeros.
This method does not change the size of the byte array.
Definition at line 81 of file byte_array.cpp.