Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
industrial::byte_array::ByteArray Class Reference

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
 

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

◆ ByteArray()

industrial::byte_array::ByteArray::ByteArray ( void  )

Default constructor.

This method creates and empty byte array.

Definition at line 50 of file byte_array.cpp.

◆ ~ByteArray()

industrial::byte_array::ByteArray::~ByteArray ( void  )

Destructor.

Definition at line 58 of file byte_array.cpp.

Member Function Documentation

◆ __attribute__()

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

◆ copyFrom()

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

Parameters
bufferbuffer to copy

Definition at line 86 of file byte_array.cpp.

◆ copyTo()

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.

◆ getBufferSize()

unsigned int industrial::byte_array::ByteArray::getBufferSize ( )

gets current buffer size

Returns
buffer size

Definition at line 387 of file byte_array.cpp.

◆ getMaxBufferSize()

unsigned int industrial::byte_array::ByteArray::getMaxBufferSize ( )

gets current buffer size

Returns
buffer size

Definition at line 392 of file byte_array.cpp.

◆ init() [1/2]

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.

◆ init() [2/2]

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.

◆ isByteSwapEnabled()

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.

Returns
true if byte swapping is enabled.

Definition at line 398 of file byte_array.cpp.

◆ load() [1/6]

bool industrial::byte_array::ByteArray::load ( ByteArray value)

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.

◆ load() [2/6]

bool industrial::byte_array::ByteArray::load ( industrial::shared_types::shared_bool  value)

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.

◆ load() [3/6]

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.

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.

◆ load() [4/6]

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)

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.

◆ load() [5/6]

bool industrial::byte_array::ByteArray::load ( industrial::simple_serialize::SimpleSerialize value)

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.

◆ load() [6/6]

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.

Parameters
valueto load \byte_syze 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.

◆ unload() [1/6]

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)

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

Definition at line 272 of file byte_array.cpp.

◆ unload() [2/6]

bool industrial::byte_array::ByteArray::unload ( industrial::shared_types::shared_bool value)

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.

◆ unload() [3/6]

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.

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

Definition at line 253 of file byte_array.cpp.

◆ unload() [4/6]

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.

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

Definition at line 240 of file byte_array.cpp.

◆ unload() [5/6]

bool industrial::byte_array::ByteArray::unload ( industrial::simple_serialize::SimpleSerialize value)

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.

◆ unload() [6/6]

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.

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

Definition at line 295 of file byte_array.cpp.

◆ unloadFront() [1/3]

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

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

Definition at line 346 of file byte_array.cpp.

◆ unloadFront() [2/3]

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.

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

Definition at line 334 of file byte_array.cpp.

◆ unloadFront() [3/3]

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.

Parameters
valueto unload \byte_syze 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

◆ SimpleSerialize

friend class SimpleSerialize
friend

Definition at line 85 of file byte_array.h.

Member Data Documentation

◆ buffer_

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

internal data buffer

Definition at line 341 of file byte_array.h.

◆ getRawDataPtr_buffer_

std::vector<char> industrial::byte_array::ByteArray::getRawDataPtr_buffer_
private

temporary continuous buffer for getRawDataPtr() use

Definition at line 346 of file byte_array.h.


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


simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53