Class RawData

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class RawData

Summary
Public Methods
RawData(value)
RawData(data, size, binary)
void clear()
inline unsigned int size() const
void append(c)
string toString(raw) const
bool fromString(value)
bool fromBinary(data, size)
string toHex(startPos, length) const
static string toHex(rawdata, size)
static inline string toHex(rawdata, size)
bool fromHex(hexdigits, size)
inline bool fromHex(value)
inline const char* getData() const
inline unsigned char operator[](pos)
Private Properties

#include <RawData.h >

Summary

Class to represent and manipulate arbitrary binary data. This class keeps the data in a data buffer.

Public Methods

RawData(value)

const string& value

the bytes to copy into the data buffer

Default value: ""


Constructor. Copy bytes of string into the data buffer.

If the provided value begins with 0x, then the string is interpreted as 2-digit hexadecimal byte values.

RawData(data, size, binary)

const char* data

the char* source of the data

unsigned int size

the number of bytes of data to copy

bool binary

false if char* is a series of 2-digit hexedecimal byte values, true if raw data

Default value: true


Constructor. Copy bytes from char* into the data buffer.

void clear()

Clear the data buffer so it's empty.

inline unsigned int size() const

Return the size of the data buffer in bytes.

Return value: data buffer size (in bytes)

void append(c)

unsigned char c

the new byte to add


Add another byte to the data buffer (at the end)

string toString(raw) const

bool raw

true if data buffer directly copied to returned string; false if data buffer converted to a series of 2-digit hexadecimal byte values

Default value: false


Convert to a hex string, e.g. 0x12345... or raw buffer inside string.  If a hex string, 0x is prepended.

Return value: the produced string

bool fromString(value)

const string& value

the string to copy into the data buffer.


Convert from a hex string or normal string.

If the provided value begins with 0x, then the string is interpreted as 2-digit hexadecimal byte values.

Return value: true if data converetd successfully, false if it failed (e.g. invalid 2-digit hex codes)

bool fromBinary(data, size)

const char* data

a pointer to the data to copy into the data buffer

unsigned int size

the number of bytes to copy into the data buffer


Copy data as binary from buffer.

Return value: true if successful, false if failed (because data==NULL and size >0)

string toHex(startPos, length) const

unsigned int startPos

Where to begin copying from the data buffer

Default value: 0

int length

How many bytes to copy (becomes 2 hex digits)

Default value: -1


Convert the data buffer to a hex string without leading 0x.

Provided parameters allow for extracting subsets of the data buffer.

Return value: the binary data as a string

static string toHex(rawdata, size)

const char* rawdata

A char* buffer to create a hex string for

unsigned int size

How many bytes to copy (becomes 2 hex digits)


Convert the data buffer to a hex string without leading 0x.

Provided parameters allow for extracting subsets of the data buffer.

Return value: the binary data as a string

static inline string toHex(rawdata, size)

unsigned int rawdata

An unsigned char* buffer to create a hex string for

unsigned int size

How many bytes to copy (becomes 2 hex digits)


Convert the data buffer to a hex string without leading 0x.

Provided parameters allow for extracting subsets of the data buffer.

Return value: the binary data as a string

bool fromHex(hexdigits, size)

const char* hexdigits

hexdigit text (with no leading 0x) to convert

int size

number of hex digits to convert (2 digits is size=1)

Default value: -1


Convert a string of hex digits to binary data

Return value: true if data copies, false it error

inline bool fromHex(value)

const string& value

the string to convert (a series of 2-digit hex numbers with no separator between them)


Convert a string of hex digits to binary data

Return value: true if data copies, false it error

inline const char* getData() const

Return data as a buffer of binary data

Return value: char* to raw data

inline unsigned char operator[](pos)

unsigned int pos

byte offset (0+) from start of buffer


Get a specific byte value at a specific location in the data buffer

Return value: the specific byte; return 0 if beyond buffer size

Private Properties

string rawdata

Our buffer of raw data collected so far