# class DataBlock | A class that holds just a block of raw data. More...
Full name | `TelEngine::DataBlock`
Definition | `#include <yateclass.h>`
Inherits | TelEngine::GenObject [public ]
Inherited by | Base64
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- DataBlock ()
- DataBlock (const DataBlock& value)
- DataBlock (void* value, unsigned int len, bool copyData = true)
- virtual ~DataBlock ()
- virtual void* getObject (const String& name) const
- inline void* data () const
- inline unsigned char* data (unsigned int offs, unsigned int len = 1) const
- inline int at (unsigned int offs, int defvalue = -1) const
- inline bool null () const
- inline unsigned int length () const
- void clear (bool deleteData = true)
- DataBlock& assign (void* value, unsigned int len, bool copyData = true)
- inline void append (void* value, unsigned int len)
- void append (const DataBlock& value)
- void append (const String& value)
- void insert (const DataBlock& value)
- inline void resize (unsigned int len)
- void truncate (unsigned int len)
- void cut (int len)
- inline int operator[] (signed int index) const
- inline int operator[] (unsigned int index) const
- DataBlock& operator= (const DataBlock& value)
- inline DataBlock& operator+= (const DataBlock& value)
- inline DataBlock& operator+= (const String& value)
- bool convert (const DataBlock& src, const String& sFormat, const String& dFormat, unsigned maxlen = 0)
- bool unHexify (const char* data, unsigned int len, char sep)
- bool unHexify (const char* data, unsigned int len)
- inline bool unHexify (const String& data)
- String sqlEscape (char extraEsc) const

#### Public Static Methods

- static const DataBlock& empty ()

## Detailed Description

The DataBlock holds a data buffer with no specific formatting.

DataBlock () | ### DataBlock

Constructs an empty data block

DataBlock (const DataBlock& value) | ### DataBlock

Copy constructor

DataBlock (void* value, unsigned int len, bool copyData = true) | ### DataBlock

Constructs an initialized data block

Parameters:

value | Data to assign, may be NULL to fill with zeros
len | Length of data, may be zero (then value is ignored)
copyData | True to make a copy of the data, false to just insert the pointer

~DataBlock () | ### ~DataBlock

[virtual]

Destroys the data, disposes the memory.

void* getObject (const String& name) | ### getObject

[const virtual]

Get a pointer to a derived class given that class name

Parameters:

name | Name of the class we are asking for

Returns: Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

const DataBlock& empty () | ### empty

[static]

A static empty data block

inline void* data () | ### data

[const]

Get a pointer to the stored data.

Returns: A pointer to the data or NULL.

inline unsigned char* data (unsigned int offs, unsigned int len = 1) | ### data

[const]

Get a pointer to a byte range inside the stored data.

Parameters:

offs | Byte offset inside the stored data
len | Number of bytes that must be valid starting at offset

Returns: A pointer to the data or NULL if the range is not available.

inline int at (unsigned int offs, int defvalue = -1) | ### at

[const]

Get the value of a single byte inside the stored data

Parameters:

offs | Byte offset inside the stored data
defvalue | Default value to return if offset is outside data

Returns: Byte value at offset (0-255) or defvalue if offset outside data

inline bool null () | ### null

[const]

Checks if the block holds a NULL pointer.

Returns: True if the block holds NULL, false otherwise.

inline unsigned int length () | ### length

[const]

Get the length of the stored data.

Returns: The length of the stored data, zero for NULL.

void clear (bool deleteData = true) | ### clear

Clear the data and optionally free the memory

Parameters:

deleteData | True to free the deta block, false to just forget it

DataBlock& assign (void* value, unsigned int len, bool copyData = true) | ### assign

Assign data to the object

Parameters:

value | Data to assign, may be NULL to fill with zeros
len | Length of data, may be zero (then value is ignored)
copyData | True to make a copy of the data, false to just insert the pointer

inline void append (void* value, unsigned int len) | ### append

Append data to the current block

Parameters:

value | Data to append
len | Length of data

void append (const DataBlock& value) | ### append

Append data to the current block

Parameters:

value | Data to append

void append (const String& value) | ### append

Append a String to the current block

Parameters:

value | String to append

void insert (const DataBlock& value) | ### insert

Insert data before the current block

Parameters:

value | Data to insert

inline void resize (unsigned int len) | ### resize

Resize (re-alloc or free) this block if required size is not the same as the current one

Parameters:

len | Required block size

void truncate (unsigned int len) | ### truncate

Truncate the data block

Parameters:

len | The maximum length to keep

void cut (int len) | ### cut

Cut off a number of bytes from the data block

Parameters:

len | Amount to cut, positive to cut from end, negative to cut from start of block

inline int operator[] (signed int index) | ### operator[]

[const]

Byte indexing operator with signed parameter

Parameters:

index | Index of the byte to retrieve

Returns: Byte value at offset (0-255) or -1 if index outside data

inline int operator[] (unsigned int index) | ### operator[]

[const]

Byte indexing operator with unsigned parameter

Parameters:

index | Index of the byte to retrieve

Returns: Byte value at offset (0-255) or -1 if index outside data

DataBlock& operator= (const DataBlock& value) | ### operator=

Assignment operator.

inline DataBlock& operator+= (const DataBlock& value) | ### operator+=

Appending operator.

inline DataBlock& operator+= (const String& value) | ### operator+=

Appending operator for Strings.

bool convert (const DataBlock& src, const String& sFormat, const String& dFormat, unsigned maxlen = 0) | ### convert

Convert data from a different format

Parameters:

src | Source data block
sFormat | Name of the source format
dFormat | Name of the destination format
maxlen | Maximum amount to convert, 0 to use source

Returns: True if converted successfully, false on failure

bool unHexify (const char* data, unsigned int len, char sep) | ### unHexify

Build this data block from a hexadecimal string representation. Each octet must be represented in the input string with 2 hexadecimal characters. If a separator is specified, the octets in input string must be separated using exactly 1 separator. Only 1 leading or 1 trailing separators are allowed.

Parameters:

data | Input character string
len | Length of the input string
sep | Separator character used between octets. 0 if no separator is expected

Returns: True if the input string was succesfully parsed, false otherwise

bool unHexify (const char* data, unsigned int len) | ### unHexify

Build this data block from a hexadecimal string representation. Each octet must be represented in the input string with 2 hexadecimal characters. This method guesses if separators are used. If so the octets in input string must be separated using exactly 1 separator. Only 1 leading or 1 trailing separators are allowed.

Parameters:

data | Input character string
len | Length of the input string

Returns: True if the input string was succesfully parsed, false otherwise

inline bool unHexify (const String& data) | ### unHexify

Build this data block from a hexadecimal string representation. This version parses a String and guesses separators presence.

Parameters:

data | Input character string

Returns: True if the input string was succesfully parsed, false otherwise

String sqlEscape (char extraEsc) | ### sqlEscape

[const]

Create an escaped string suitable for use in SQL queries

Parameters:

extraEsc | Character to escape other than the default ones

Returns: A string with binary zeros and other special characters escaped

Generated by: paulc on bussard on Fri May 8 12:37:22 2015, using kdoc 2.0a54.