$search
The byte array wraps a traditional, fixed size, array of bytes (i.e. char*). More...
#include <byte_array.h>
Public Member Functions | |
ByteArray (void) | |
Default constructor. | |
void | copyFrom (ByteArray &buffer) |
Deep-Copy. | |
unsigned int | getBufferSize () |
gets current buffer size | |
unsigned int | getMaxBufferSize () |
gets current buffer size | |
char * | getRawDataPtr () |
returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations | |
bool | init (const char *buffer, const industrial::shared_types::shared_int byte_size) |
initializes byte array from char* buffer | |
void | init () |
Initializes or Reinitializes and empty buffer. | |
bool | load (void *value, const industrial::shared_types::shared_int byte_size) |
loads a void* (treated as char*) into the byte array | |
bool | load (ByteArray &value) |
loads a whole byte array into this byte array | |
bool | load (industrial::simple_serialize::SimpleSerialize &value) |
loads a complex SimpleSerialize into the byte array | |
bool | load (industrial::shared_types::shared_int value) |
loads an integer into the byte array | |
bool | load (industrial::shared_types::shared_real value) |
loads a double into the byte array | |
bool | load (industrial::shared_types::shared_bool value) |
loads a boolean into the byte array | |
bool | unload (void *value, const industrial::shared_types::shared_int byteSize) |
unloads a void* (treated as char*) 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 (industrial::simple_serialize::SimpleSerialize &value) |
unloads a complex SimpleSerialize value from the byte array | |
bool | unload (industrial::shared_types::shared_int &value) |
unloads an integer value from the byte array | |
bool | unload (industrial::shared_types::shared_real &value) |
unloads a double value from the byte array | |
bool | unload (industrial::shared_types::shared_bool &value) |
unloads a boolean value from the byte array | |
bool | unloadFront (void *value, const industrial::shared_types::shared_int byteSize) |
unloads a void* (treated as char*) from the beginning of the array. WARNING: This method performs a memmove every time it is called (this is expensive). | |
~ByteArray (void) | |
Destructor. | |
Private Member Functions | |
bool | extendBufferSize (const industrial::shared_types::shared_int size) |
extends current buffer size | |
char * | getLoadPtr () |
gets pointer to unload location (buffer_size + 1) | |
char * | getUnloadPtr (const industrial::shared_types::shared_int num_bytes) |
gets pointer to unload location (buffer_size - num_bytes) | |
bool | setBufferSize (const industrial::shared_types::shared_int size) |
sets current buffer size | |
bool | shortenBufferSize (industrial::shared_types::shared_int size) |
shortens current buffer size | |
Private Attributes | |
char | buffer_ [MAX_SIZE] |
internal data buffer | |
industrial::shared_types::shared_int | buffer_size_ |
current buffer size | |
Static Private Attributes | |
static const industrial::shared_types::shared_int | MAX_SIZE = 1024 |
maximum array size (WARNING: THIS VALUE SHOULD NOT EXCEED THE MAX 32-BIT INTEGER SIZE) | |
Friends | |
class | SimpleSerialize |
The byte array wraps a traditional, fixed size, array of bytes (i.e. char*).
The byte array wraps a traditional, fixed size, 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.
A fixed size array is used for simplicity (i.e. avoiding re-implementing the STL vector class for those systems that don't have access to the STL, i.e. Motoman robotics Motoplus compiler.
THIS CLASS IS NOT THREAD-SAFE
Definition at line 87 of file byte_array.h.
industrial::byte_array::ByteArray::ByteArray | ( | void | ) |
Default constructor.
This method creates and empty byte array.
Definition at line 55 of file byte_array.cpp.
industrial::byte_array::ByteArray::~ByteArray | ( | void | ) |
Destructor.
Definition at line 60 of file byte_array.cpp.
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 89 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::extendBufferSize | ( | const industrial::shared_types::shared_int | size | ) | [private] |
extends current buffer size
number | of bytes to extend |
unsigned int industrial::byte_array::ByteArray::getBufferSize | ( | ) |
char * industrial::byte_array::ByteArray::getLoadPtr | ( | ) | [private] |
gets pointer to unload location (buffer_size + 1)
size | new size |
Definition at line 375 of file byte_array.cpp.
unsigned int industrial::byte_array::ByteArray::getMaxBufferSize | ( | ) |
char * industrial::byte_array::ByteArray::getRawDataPtr | ( | ) |
returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations
This function returns a pointer to the actual raw data stored within the class. Care should be taken not to modified the data oustide of the class. This method of providing a reference to private class data is used in order to avoid dynamic memory allocation that would be required to return a copy.
Definition at line 102 of file byte_array.cpp.
char* industrial::byte_array::ByteArray::getUnloadPtr | ( | const industrial::shared_types::shared_int | num_bytes | ) | [private] |
gets pointer to unload location (buffer_size - num_bytes)
The unload location is the beginning of the data item that is to be unloaded.
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. If the byte size is greater than the max buffer size then only the max buffer amount of bytes is copied |
void industrial::byte_array::ByteArray::init | ( | ) |
Initializes or Reinitializes and empty buffer.
This method sets all values to 0 and resets the buffer size.
Definition at line 64 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
value | to load number of bytes to load |
bool industrial::byte_array::ByteArray::load | ( | ByteArray & | value | ) |
loads a whole byte array into this byte array
value | to load |
Definition at line 134 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 128 of file byte_array.cpp.
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_int | value | ) |
loads an integer into the byte array
value | to load |
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_real | value | ) |
loads a double into the byte array
value | to load |
bool industrial::byte_array::ByteArray::load | ( | industrial::shared_types::shared_bool | value | ) |
loads a boolean into the byte array
value | to load |
bool industrial::byte_array::ByteArray::setBufferSize | ( | const industrial::shared_types::shared_int | size | ) | [private] |
sets current buffer size
size | new size |
bool industrial::byte_array::ByteArray::shortenBufferSize | ( | industrial::shared_types::shared_int | size | ) | [private] |
shortens current buffer size
number | of bytes to shorten |
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
value | to unload number of bytes to unload |
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 |
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 194 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
value | value to unload |
bool industrial::byte_array::ByteArray::unload | ( | industrial::shared_types::shared_real & | value | ) |
unloads a double value from the byte array
value | value to unload |
bool industrial::byte_array::ByteArray::unload | ( | industrial::shared_types::shared_bool & | value | ) |
unloads a boolean value from the byte array
value | value to unload |
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: This method performs a memmove every time it is called (this is expensive).
value | to unload number of bytes to unload |
Definition at line 267 of file byte_array.cpp.
friend class SimpleSerialize [friend] |
Definition at line 92 of file byte_array.h.
char industrial::byte_array::ByteArray::buffer_[MAX_SIZE] [private] |
internal data buffer
Definition at line 328 of file byte_array.h.
industrial::shared_types::shared_int industrial::byte_array::ByteArray::buffer_size_ [private] |
current buffer size
Definition at line 333 of file byte_array.h.
const industrial::shared_types::shared_int industrial::byte_array::ByteArray::MAX_SIZE = 1024 [static, private] |
maximum array size (WARNING: THIS VALUE SHOULD NOT EXCEED THE MAX 32-BIT INTEGER SIZE)
The byte array class uses shared 32-bit types, so the buffer size cannot be larger than this. Ideally this value would be relatively small as passing large amounts of data is not desired.
Definition at line 323 of file byte_array.h.