Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
industrial::byte_array::ByteArray Class Reference

The byte array wraps a traditional, fixed size, array of bytes (i.e. char*). More...

#include <byte_array.h>

List of all members.

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
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. WARNING: This method performs a memmove every time it is called (this is expensive).
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 WARNING: This method performs a memmove every time it is called (this is expensive).
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). 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 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

Detailed Description

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.

By default data using the load/unload methods is appended/removed from the end of the array. As long as the standard load/unload methods are uses, this is transparent to the user.

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 77 of file byte_array.h.


Constructor & Destructor Documentation

Default constructor.

This method creates and empty byte array.

Definition at line 56 of file byte_array.cpp.

Destructor.

Definition at line 64 of file byte_array.cpp.


Member Function Documentation

Deep-Copy.

This method creates a byte array containing a deep copy of the passed in buffer

Parameters:
bufferbuffer to copy

Definition at line 93 of file byte_array.cpp.

extends current buffer size

Parameters:
numberof bytes to extend
Returns:
true on success, false otherwise (new size is too large)

Definition at line 444 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 406 of file byte_array.cpp.

gets pointer to unload location (buffer_size + 1)

Parameters:
sizenew size
Returns:
pointer to load location (NULL if array is at max size)

Definition at line 477 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 411 of file byte_array.cpp.

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.

Returns:
char* pointer to the raw data

Definition at line 133 of file byte_array.cpp.

gets pointer to unload location (buffer_size - num_bytes)

The unload location is the beginning of the data item that is to be unloaded.

Returns:
pointer to load location (NULL is num_bytes > buffer_size_)

Definition at line 483 of file byte_array.cpp.

Initializes or Reinitializes an empty buffer.

This method sets all values to 0 and resets the buffer size.

Definition at line 68 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)

Parameters:
bufferpointer to byte buffer
byte_sizesize 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
Returns:
true on success, false otherwise (max array size exceeded).

Definition at line 74 of file byte_array.cpp.

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.

Returns:
true if byte swapping is enabled.

Definition at line 417 of file byte_array.cpp.

loads a boolean into the byte array

Parameters:
valueto load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 144 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)

Parameters:
valueto load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 149 of file byte_array.cpp.

loads an integer into the byte array. If byte swapping is enabled, then the bytes are swapped.

Parameters:
valueto load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 160 of file byte_array.cpp.

loads a complex SimpleSerialize into the byte array

Parameters:
valueto load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 171 of file byte_array.cpp.

loads a whole byte array into this byte array

Parameters:
valueto load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 177 of file byte_array.cpp.

loads a void* (treated as char*) into the byte array. WARNING: Byte swapping is not performed in this function.

Parameters:
valueto load number of bytes to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 183 of file byte_array.cpp.

sets current buffer size

Parameters:
sizenew size
Returns:
true on success, false otherwise (new size is too large)

Definition at line 425 of file byte_array.cpp.

shortens current buffer size

Parameters:
numberof bytes to shorten
Returns:
true on success, false otherwise (new size is less than 0)

Definition at line 453 of file byte_array.cpp.

unloads a boolean value from the byte array

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 222 of file byte_array.cpp.

unloads a double value from the byte array. If byte swapping is enabled, then the bytes are swapped.

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 229 of file byte_array.cpp.

unloads an integer value from the byte array. If byte swapping is enabled, then the bytes are swapped.

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 242 of file byte_array.cpp.

unloads a complex SimpleSerialize value from the byte array

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 254 of file byte_array.cpp.

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)

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 260 of file byte_array.cpp.

unloads a void* (treated as char*) from the byte array. WARNING: Byte swapping is not performed in this function.

Parameters:
valueto unload number of bytes to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 289 of file byte_array.cpp.

unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped. WARNING: This method performs a memmove every time it is called (this is expensive).

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 337 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 WARNING: This method performs a memmove every time it is called (this is expensive).

Parameters:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 349 of file byte_array.cpp.

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). WARNING: Byte swapping is not performed in this function.

Parameters:
valueto unload number of bytes to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 360 of file byte_array.cpp.


Friends And Related Function Documentation

friend class SimpleSerialize [friend]

Definition at line 82 of file byte_array.h.


Member Data Documentation

internal data buffer

Definition at line 345 of file byte_array.h.

current buffer size

Definition at line 350 of file byte_array.h.

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 340 of file byte_array.h.


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


simple_message
Author(s): Shaun Edwards
autogenerated on Sat Jun 8 2019 20:43:23