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 | |
ByteArray (void) | |
Default constructor. | |
void | copyFrom (ByteArray &buffer) |
Deep-Copy. | |
void | copyTo (std::vector< char > &out) |
Copy to std::vector, for raw-ptr access. | |
unsigned int | getBufferSize () |
gets current buffer size | |
unsigned int | getMaxBufferSize () |
gets current buffer size | |
void | init () |
Initializes or Reinitializes an empty buffer. | |
bool | init (const char *buffer, const industrial::shared_types::shared_int byte_size) |
initializes byte array from char* buffer | |
bool | load (industrial::shared_types::shared_bool value) |
loads a boolean into the byte array | |
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) | |
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. | |
bool | load (industrial::simple_serialize::SimpleSerialize &value) |
loads a complex SimpleSerialize into the byte array | |
bool | load (ByteArray &value) |
loads a whole byte array into this byte array | |
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. | |
bool | unload (industrial::shared_types::shared_bool &value) |
unloads a boolean value from the byte array | |
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. | |
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. | |
bool | unload (industrial::simple_serialize::SimpleSerialize &value) |
unloads a complex SimpleSerialize value from the byte array | |
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) | |
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. | |
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. | |
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 | |
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. | |
~ByteArray (void) | |
Destructor. | |
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. | |
Private Attributes | |
std::deque< char > | buffer_ |
internal data buffer | |
std::vector< char > | getRawDataPtr_buffer_ |
temporary continuous buffer for getRawDataPtr() use | |
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.
Default constructor.
This method creates and empty byte array.
Definition at line 50 of file byte_array.cpp.
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 | ( | ) |
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.
bool industrial::byte_array::ByteArray::isByteSwapEnabled | ( | ) | [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.
loads a boolean into the byte array
value | to load |
Definition at line 142 of file byte_array.cpp.
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.
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::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 | ( | 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 | ( | 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 number of bytes to load |
Definition at line 191 of file byte_array.cpp.
unloads a boolean value from the byte array
value | value to unload |
Definition at line 233 of file byte_array.cpp.
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.
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::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 | ( | 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 | ( | 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 number of bytes to unload |
Definition at line 295 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.
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 | ( | 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 number of bytes to unload |
Definition at line 358 of file byte_array.cpp.
friend class SimpleSerialize [friend] |
Definition at line 85 of file byte_array.h.
std::deque<char> industrial::byte_array::ByteArray::buffer_ [private] |
internal data buffer
Definition at line 339 of file byte_array.h.
std::vector<char> industrial::byte_array::ByteArray::getRawDataPtr_buffer_ [private] |
temporary continuous buffer for getRawDataPtr() use
Definition at line 344 of file byte_array.h.