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

The byte array wraps a dynamic array of bytes (i.e. char). More...

#include <byte_array.h>

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

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.


Member Function Documentation

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

Deprecated:
This is unsafe with dynamic buffer sizing. Use copyTo(vector<char>) instead.
Returns:
char* pointer to the raw data

Deep-Copy.

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

Parameters:
bufferbuffer 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.

Parameters:
outvector to copy into

Definition at line 98 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 387 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 392 of file byte_array.cpp.

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)

Parameters:
bufferpointer to byte buffer
byte_sizesize of buffer to copy.
Returns:
true on success, false otherwise (max array size exceeded).

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

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

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.

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

Definition at line 158 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 169 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 175 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 191 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 233 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 240 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 253 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 265 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 272 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 295 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.

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

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

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

Definition at line 346 of file byte_array.cpp.

unloads a void* (treated as char*) from the beginning of the 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 358 of file byte_array.cpp.


Friends And Related Function Documentation

friend class SimpleSerialize [friend]

Definition at line 85 of file byte_array.h.


Member Data Documentation

std::deque<char> industrial::byte_array::ByteArray::buffer_ [private]

internal data buffer

Definition at line 339 of file byte_array.h.

temporary continuous buffer for getRawDataPtr() use

Definition at line 344 of file byte_array.h.


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


simple_message
Author(s): Shaun Edwards
autogenerated on Tue Jan 17 2017 21:10:02