Encapsulates an array of primitive type char in an object and provides methods to operate on binary data.
More...
|
| | ByteArray (void) |
| |
| | ByteArray (int len) |
| |
| | ByteArray (const char *data, int len) |
| |
| | ByteArray (const char *str) |
| |
| | ByteArray (int val, int len) |
| |
| | ByteArray (const ByteArray &ba) |
| |
| virtual | ~ByteArray (void) |
| |
| void | clear (void) |
| |
| int | length (void) const |
| |
| char * | get (void) |
| |
| const char * | get (void) const |
| |
| void | set (const char *data, int len) |
| |
| void | append (const char *data, int len) |
| |
| void | append (const ByteArray &ba) |
| |
| void | insert (const char *data, int len, int offset) |
| |
| void | fill (char value, int len, int offset) |
| |
| int | getInt (int def_val=0) const |
| |
| void | setInt (int val, int len) |
| |
| void | appendInt (int val, int len) |
| |
| void | getString (char *str, int max_size) const |
| |
| void | setString (const char *str) |
| |
| void | appendString (const char *str) |
| |
| std::string | toString (void) const |
| |
| std::string | toHexString (void) const |
| |
| int | compare (const ByteArray &ba) const |
| |
| ByteArray | sub (int offset, int len=-1) const |
| |
| ByteArray | lstrip (void) const |
| |
| ByteArray | rstrip (const std::set< char > &charsToBeStripped) const |
| |
| void | read (const char *filename) |
| |
| void | write (const char *filename) const |
| |
| void | xtrace (const char *text=0) const |
| |
| ByteArray & | operator= (const ByteArray &ba) |
| |
| const ByteArray & | operator+= (const ByteArray &ba) |
| |
| const ByteArray & | operator|= (const ByteArray &ba) |
| |
| const ByteArray & | operator^= (const ByteArray &ba) |
| |
| char & | operator[] (int idx) |
| |
Encapsulates an array of primitive type char in an object and provides methods to operate on binary data.
The following example illustrates the usage of the ByteArray class:
c.
write(
"d:/temp/byte.array");
Encapsulates an array of primitive type char in an object and provides methods to operate on binary d...
Definition: sw/cxi_api_c/def/bytearray.h:22
void xtrace(const char *text=0) const
Definition: bytearray.cpp:611
ByteArray(void)
Definition: bytearray.cpp:89
void write(const char *filename) const
Definition: bytearray.cpp:593
◆ ByteArray() [1/6]
Default Constructor: creates empty byte array.
◆ ByteArray() [2/6]
Overload Contructor: creates byte array with given size.
- Parameters
-
| len | size of new byte array |
◆ ByteArray() [3/6]
Overload Contructor: creates byte array from given data.
- Parameters
-
| data | pointer to data to be set |
| len | length of data to be set |
◆ ByteArray() [4/6]
Overload Contructor: creates byte array from given C-string.
- Parameters
-
◆ ByteArray() [5/6]
Overload Contructor: creates byte array from given integer value.
- Parameters
-
| val | integer value to be converted |
| len | number of bytes to be converted [1..4] |
◆ ByteArray() [6/6]
Copy Constructor: creates byte array from given byte array.
◆ ~ByteArray()
Destructor: frees the internal data buffer.
◆ clear()
Frees internal data buffer
◆ length()
| int length |
( |
void |
| ) |
const |
Returns length of data.
- Returns
- size of internal data buffer
◆ get() [1/2]
Returns data.
- Returns
- pointer to internal data buffer
◆ get() [2/2]
| const char * get |
( |
void |
| ) |
const |
Returns data.
- Returns
- pointer to internal data buffer
◆ set()
| void set |
( |
const char * |
data, |
|
|
int |
len |
|
) |
| |
Creates byte array from given parameters.
- Parameters
-
| data | pointer to data to be set |
| len | length of data to be set |
- Exceptions
-
◆ append() [1/2]
| void append |
( |
const char * |
data, |
|
|
int |
len |
|
) |
| |
Appends given data to byte array.
- Parameters
-
| data | pointer to data to be appended |
| len | length o data to be appended |
- Exceptions
-
◆ append() [2/2]
Appends given byte array
- Parameters
-
- Exceptions
-
◆ insert()
| void insert |
( |
const char * |
data, |
|
|
int |
len, |
|
|
int |
offset |
|
) |
| |
Inserts given data at given poistion
- Parameters
-
| data | data to be inserted |
| len | data length |
| offset | insertation position |
- Exceptions
-
◆ fill()
| void fill |
( |
char |
value, |
|
|
int |
len, |
|
|
int |
offset |
|
) |
| |
Fills portion of byte array with given pattern.
- Parameters
-
| value | pattern to be set |
| len | length of area the be filled |
| offset | start of ares to be filled |
- Exceptions
-
◆ getInt()
| int getInt |
( |
int |
def_val = 0 | ) |
const |
Returns big-endian representation of byte array as integer.
The conversion regards up to 4 bytes, succeeding bytes in the data buffer are omitted.
- Parameters
-
| def_val | default value to be return if the byte array doesn't contain data (size == 0) |
◆ setInt()
| void setInt |
( |
int |
val, |
|
|
int |
len |
|
) |
| |
Loads byte array with big-endian representation of the given integer.
- Parameters
-
| val | integer value to be converted |
| len | number of bytes to be converted [1..4] |
- Exceptions
-
◆ appendInt()
| void appendInt |
( |
int |
val, |
|
|
int |
len |
|
) |
| |
Appends big-endian representation of the given integer to byte array.
- Parameters
-
| val | integer value to be converted |
| len | number of bytes to be converted [1..4] |
- Exceptions
-
◆ getString()
| void getString |
( |
char * |
str, |
|
|
int |
max_size |
|
) |
| const |
Returns byte array data as zero-terminated C-string.
- Parameters
-
| str | pointer to buffer where string is stored |
| max_size | size of buffer |
◆ setString()
| void setString |
( |
const char * |
str | ) |
|
Creates byte array from given C-string.
- Parameters
-
| str | zero-terminated C-string to be loaded. |
◆ appendString()
| void appendString |
( |
const char * |
str | ) |
|
Appends given C-string to byte array.
- Parameters
-
| str | zero-terminated C-string to be appended |
- Exceptions
-
◆ toString()
| std::string toString |
( |
void |
| ) |
const |
Returns string representation of byte array without trailing zeros.
◆ toHexString()
| std::string toHexString |
( |
void |
| ) |
const |
Returns hexadecimal representation of byte array.
◆ compare()
Compares byte array with another
- Parameters
-
| ba | byte array to be compared |
- Returns
- zero if content of both arrays is the same
- positive if given byte array is greater
- negative if given byte array is smaller
◆ sub()
| ByteArray sub |
( |
int |
offset, |
|
|
int |
len = -1 |
|
) |
| const |
Returns portion of the byte array
- Parameters
-
| offset | zero base offset |
| len | number of bytes to be copied |
- Returns
- byte array containing desired portion
- Exceptions
-
◆ lstrip()
Strips leading zeros
- Returns
- stripped byte array
◆ rstrip()
| ByteArray rstrip |
( |
const std::set< char > & |
charsToBeStripped | ) |
const |
Strips character from rear
- Returns
- stripped byte array
◆ read()
| void read |
( |
const char * |
filename | ) |
|
Reads byte array from file
- Parameters
-
| filename | name of file to be read |
- Exceptions
-
◆ write()
| void write |
( |
const char * |
filename | ) |
const |
Writes byte array to file
- Parameters
-
| filename | name of file to be written |
- Exceptions
-
◆ xtrace()
| void xtrace |
( |
const char * |
text = 0 | ) |
const |
Prints content of byte array to stdout. The binary data is converted to hexadecimal notation.
- Parameters
-
◆ operator=()
Copies one instance of byte array to another.
- Parameters
-
- Exceptions
-
◆ operator+=()
Appends given byte array.
- Parameters
-
| ba | byte array to be appended |
- Exceptions
-
◆ operator|=()
ORs the given byte array
- Parameters
-
| ba | byte array to be ORed Note:
- size of both byte array have to be equal
|
- Exceptions
-
◆ operator^=()
XORs the given byte array
- Parameters
-
| ba | byte array to be XORed Note:
- size of both byte array have to be equal
|
- Exceptions
-
◆ operator[]()
| char & operator[] |
( |
int |
idx | ) |
|
Get one byte from array.
- Parameters
-
- Returns
- desired byte
◆ operator+ [1/2]
Concatenates two byte arrays.
- Parameters
-
| ba1 | first byte array |
| ba2 | second byte array to be concatenated |
- Returns
- concatenated byte array
- Exceptions
-
◆ operator+ [2/2]
Concatenates two byte arrays.
- Parameters
-
| ba1 | first byte array |
| ba2 | second byte array to be concatenated |
- Returns
- concatenated byte array
- Exceptions
-