The byte array wraps a dynamic array of bytes (i.e. char). More...
#include <byte_array.h>
Public Member Functions | |
__attribute__ ((deprecated("This ptr will be invalid once buffer is changed. Please use: copyTo(vector<char>) instead."))) char *getRawDataPtr() | |
returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations More... | |
ByteArray (void) | |
Default constructor. More... | |
void | copyFrom (ByteArray &buffer) |
Deep-Copy. More... | |
void | copyTo (std::vector< char > &out) |
Copy to std::vector, for raw-ptr access. More... | |
unsigned int | getBufferSize () |
gets current buffer size More... | |
unsigned int | getMaxBufferSize () |
gets current buffer size More... | |
void | init () |
Initializes or Reinitializes an empty buffer. More... | |
bool | init (const char *buffer, const industrial::shared_types::shared_int byte_size) |
initializes byte array from char* buffer More... | |
bool | load (ByteArray &value) |
loads a whole byte array into this byte array More... | |
bool | load (industrial::shared_types::shared_bool value) |
loads a boolean into the byte array More... | |
bool | load (industrial::shared_types::shared_int value) |
loads an integer into the byte array. If byte swapping is enabled, then the bytes are swapped. More... | |
bool | load (industrial::shared_types::shared_real value) |
loads a float on the byte array. If byte swapping is enabled, then the bytes are swapped (this assumes a common float representation) More... | |
bool | load (industrial::simple_serialize::SimpleSerialize &value) |
loads a complex SimpleSerialize into the byte array More... | |
bool | load (void *value, const industrial::shared_types::shared_int byte_size) |
loads a void* (treated as char*) into the byte array. WARNING: Byte swapping is not performed in this function. More... | |
bool | unload (ByteArray &value, const industrial::shared_types::shared_int byte_size) |
unloads a partial byte array from the byte array into the passed in byte array (this is done using the byte array load method so any data in the passed in byte array remains intact) More... | |
bool | unload (industrial::shared_types::shared_bool &value) |
unloads a boolean value from the byte array More... | |
bool | unload (industrial::shared_types::shared_int &value) |
unloads an integer value from the byte array. If byte swapping is enabled, then the bytes are swapped. More... | |
bool | unload (industrial::shared_types::shared_real &value) |
unloads a double value from the byte array. If byte swapping is enabled, then the bytes are swapped. More... | |
bool | unload (industrial::simple_serialize::SimpleSerialize &value) |
unloads a complex SimpleSerialize value from the byte array More... | |
bool | unload (void *value, const industrial::shared_types::shared_int byteSize) |
unloads a void* (treated as char*) from the byte array. WARNING: Byte swapping is not performed in this function. More... | |
bool | unloadFront (industrial::shared_types::shared_int &value) |
unloads an integer value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped More... | |
bool | unloadFront (industrial::shared_types::shared_real &value) |
unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped. More... | |
bool | unloadFront (void *value, const industrial::shared_types::shared_int byteSize) |
unloads a void* (treated as char*) from the beginning of the array. WARNING: Byte swapping is not performed in this function. More... | |
~ByteArray (void) | |
Destructor. More... | |
Static Public Member Functions | |
static bool | isByteSwapEnabled () |
returns true if byte swapping is enabled (this is a global option set by compiler flag). This function gives the status of the compiler flag. More... | |
Private Attributes | |
std::deque< char > | buffer_ |
internal data buffer More... | |
std::vector< char > | getRawDataPtr_buffer_ |
temporary continuous buffer for getRawDataPtr() use More... | |
Friends | |
class | SimpleSerialize |
The byte array wraps a dynamic array of bytes (i.e. char).
It provides convenient methods for loading and unloading data types to and from the byte array. The class acts as an interface definition to raw data (in case the underlying structure of the raw data changes). It's intended use is for socket communications.
By default data using the load/unload methods is appended/removed from the end of the array. Methods are also provided to load/unload from the front of the array. As long as the matching load/unload methods are used, this is transparent to the user.
The internals of ByteArray have been updated to use a dynamically-allocated STL class, for safety and performance reasons. This may limit cross-platform usage of this class (e.g. in the MotoPlus compiler).
THIS CLASS IS NOT THREAD-SAFE
Definition at line 80 of file byte_array.h.
industrial::byte_array::ByteArray::ByteArray | ( | void | ) |
Default constructor.
This method creates and empty byte array.
Definition at line 50 of file byte_array.cpp.
industrial::byte_array::ByteArray::~ByteArray | ( | void | ) |
Destructor.
Definition at line 58 of file byte_array.cpp.
industrial::byte_array::ByteArray::__attribute__ | ( | (deprecated("This ptr will be invalid once buffer is changed. Please use: copyTo(vector<char>) instead.")) | ) |
returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations
void industrial::byte_array::ByteArray::copyFrom | ( | ByteArray & | buffer | ) |
Deep-Copy.
This method creates a byte array containing a deep copy of the passed in buffer
buffer | buffer to copy |
Definition at line 86 of file byte_array.cpp.
void industrial::byte_array::ByteArray::copyTo | ( | std::vector< char > & | out | ) |
Copy to std::vector, for raw-ptr access.
This method copies the ByteArray data to a std::vector.
out | vector to copy into |
Definition at line 98 of file byte_array.cpp.
unsigned int industrial::byte_array::ByteArray::getBufferSize | ( | ) |
unsigned int industrial::byte_array::ByteArray::getMaxBufferSize | ( | ) |
void industrial::byte_array::ByteArray::init | ( | ) |
Initializes or Reinitializes an empty buffer.
This method resets the buffer size to zero (empty).
Definition at line 62 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::init | ( | const char * | buffer, |
const industrial::shared_types::shared_int | byte_size | ||
) |
initializes byte array from char* buffer
This method creates a byte array containing a copy of the passed in buffer (up to byteSize)
buffer | pointer to byte buffer |
byte_size | size of buffer to copy. |
Definition at line 67 of file byte_array.cpp.
|
static |
returns true if byte swapping is enabled (this is a global option set by compiler flag). This function gives the status of the compiler flag.
Definition at line 398 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | ByteArray & | value | ) |
loads a whole byte array into this byte array
value | to load |
Definition at line 175 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_bool | value | ) |
loads a boolean into the byte array
value | to load |
Definition at line 142 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_int | value | ) |
loads an integer into the byte array. If byte swapping is enabled, then the bytes are swapped.
value | to load |
Definition at line 158 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_real | value | ) |
loads a float on the byte array. If byte swapping is enabled, then the bytes are swapped (this assumes a common float representation)
value | to load |
Definition at line 147 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | industrial::simple_serialize::SimpleSerialize & | value | ) |
loads a complex SimpleSerialize into the byte array
value | to load |
Definition at line 169 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | void * | value, |
const industrial::shared_types::shared_int | byte_size | ||
) |
loads a void* (treated as char*) into the byte array. WARNING: Byte swapping is not performed in this function.
value | to load \byte_syze number of bytes to load |
Definition at line 191 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | ByteArray & | value, |
const industrial::shared_types::shared_int | byte_size | ||
) |
unloads a partial byte array from the byte array into the passed in byte array (this is done using the byte array load method so any data in the passed in byte array remains intact)
value | value to unload |
Definition at line 272 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | industrial::shared_types::shared_bool & | value | ) |
unloads a boolean value from the byte array
value | value to unload |
Definition at line 233 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | industrial::shared_types::shared_int & | value | ) |
unloads an integer value from the byte array. If byte swapping is enabled, then the bytes are swapped.
value | value to unload |
Definition at line 253 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | industrial::shared_types::shared_real & | value | ) |
unloads a double value from the byte array. If byte swapping is enabled, then the bytes are swapped.
value | value to unload |
Definition at line 240 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | industrial::simple_serialize::SimpleSerialize & | value | ) |
unloads a complex SimpleSerialize value from the byte array
value | value to unload |
Definition at line 265 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unload | ( | void * | value, |
const industrial::shared_types::shared_int | byteSize | ||
) |
unloads a void* (treated as char*) from the byte array. WARNING: Byte swapping is not performed in this function.
value | to unload \byte_syze number of bytes to unload |
Definition at line 295 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unloadFront | ( | industrial::shared_types::shared_int & | value | ) |
unloads an integer value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped
value | value to unload |
Definition at line 346 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unloadFront | ( | industrial::shared_types::shared_real & | value | ) |
unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped.
value | value to unload |
Definition at line 334 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::unloadFront | ( | void * | value, |
const industrial::shared_types::shared_int | byteSize | ||
) |
unloads a void* (treated as char*) from the beginning of the array. WARNING: Byte swapping is not performed in this function.
value | to unload \byte_syze number of bytes to unload |
Definition at line 358 of file byte_array.cpp.
|
friend |
Definition at line 85 of file byte_array.h.
|
private |
internal data buffer
Definition at line 341 of file byte_array.h.
|
private |
temporary continuous buffer for getRawDataPtr() use
Definition at line 346 of file byte_array.h.