Yate
DataBlock Class Reference

A class that holds just a block of raw data. More...

#include <yateclass.h>

Inheritance diagram for DataBlock:
GenObject Base64

Public Member Functions

 DataBlock (unsigned int overAlloc=0)
 DataBlock (const DataBlock &value)
 DataBlock (const DataBlock &value, unsigned int overAlloc)
 DataBlock (void *value, unsigned int len, bool copyData=true, unsigned int overAlloc=0)
virtual ~DataBlock ()
void * data () const
unsigned char * data (unsigned int offs, unsigned int len=1) const
int at (unsigned int offs, int defvalue=-1) const
bool null () const
unsigned int length () const
unsigned int size () const
unsigned int overAlloc () const
void overAlloc (unsigned int bytes)
void clear (bool deleteData=true)
DataBlockassign (void *value, unsigned int len, bool copyData=true, unsigned int allocated=0)
bool change (unsigned int pos, const void *buf, unsigned int bufLen, unsigned int extra=0, int extraVal=0, bool mayOverlap=true)
bool change8hton (unsigned int pos, uint64_t value)
bool change4hton (unsigned int pos, uint32_t value)
bool change3hton (unsigned int pos, uint32_t value)
bool change2hton (unsigned int pos, uint16_t value)
bool changeHton (unsigned int pos, uint64_t value, uint8_t bytes)
bool changeLsb (unsigned int pos, uint64_t value, uint8_t bytes=8)
void append (const void *value, unsigned int len, bool mayOverlap=true)
void append (const DataBlock &value, bool mayOverlap=true)
void append (const String &value)
void appendBytes (unsigned int count, uint8_t val=0)
void append8hton (uint64_t value)
void append4hton (uint32_t value)
void append3hton (uint32_t value)
void append2hton (uint16_t value)
void appendHton (uint64_t value, uint8_t bytes)
void append8lsb (uint64_t value, uint8_t bytes=8)
void append1 (uint8_t value)
void insert (const void *buf, unsigned int bufLen, unsigned int pos=0, bool mayOverlap=true)
void insert (const DataBlock &value, unsigned int pos=0, bool mayOverlap=true)
void insertBytes (unsigned int count, unsigned int pos=0, uint8_t val=0)
void insert8hton (uint64_t value, unsigned int pos=0)
void insert4hton (uint32_t value, unsigned int pos=0)
void insert3hton (uint32_t value, unsigned int pos=0)
void insert2hton (uint16_t value, unsigned int pos=0)
void insertHton (uint64_t value, uint8_t bytes=8, unsigned int pos=0)
void insertLsb (uint64_t value, uint8_t bytes=8, unsigned int pos=0)
void insert1 (uint8_t value, unsigned int pos=0)
void resize (unsigned int len, bool keepData=false, bool reAlloc=true)
void truncate (unsigned int len, bool reAlloc=true)
void cut (unsigned int pos, unsigned int len, bool reAlloc=true)
void cut (int len)
int operator[] (signed int index) const
int operator[] (unsigned int index) const
DataBlockoperator= (const DataBlock &value)
DataBlockoperator+= (const DataBlock &value)
DataBlockoperator+= (const String &value)
bool convert (const DataBlock &src, const String &sFormat, const String &dFormat, unsigned maxlen=0)
bool changeHex (unsigned int pos, const char *data, unsigned int len, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
bool changeHex (unsigned int pos, const String &data, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
bool appendHex (const String &data, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
bool unHexify (const char *data, unsigned int len, char sep)
bool unHexify (const char *data, unsigned int len)
bool unHexify (const String &data)
StringsqlEscape (String &str, char extraEsc=0) const
String sqlEscape (char extraEsc) const
Public Member Functions inherited from GenObject
 GenObject ()
virtual ~GenObject ()
virtual bool alive () const
virtual void destruct ()
virtual const StringtoString () const
virtual const StringtraceId () const
virtual void * getObject (const String &name) const
NamedCountergetObjCounter () const
NamedCountersetObjCounter (NamedCounter *counter)

Static Public Member Functions

static const DataBlockempty ()
static StringsqlEscape (String &str, const void *data, unsigned int len, char extraEsc=0)
static void moveData (void *buf, unsigned int bufLen, unsigned int len, unsigned int dPos, unsigned int sPos, int fill=-1)
static void rebuildDataInsert (void *dest, unsigned int dLen, const void *src, unsigned int sLen, unsigned int pos, unsigned int space, int fill=-1)
static void rebuildDataRemove (void *dest, unsigned int dLen, const void *src, unsigned int sLen, unsigned int pos, unsigned int space, int fillAfter=-1)
static uint64_t ntoh8advance (const uint8_t *&buf)
static uint64_t ntoh8advance (const uint8_t *&buf, unsigned int &len)
static uint64_t ntoh8 (const uint8_t *buf)
static void hton8advance (uint8_t *&buf, uint64_t val)
static void hton8advance (uint8_t *&buf, uint64_t val, unsigned int &len)
static void hton8 (uint8_t *buf, uint64_t val)
static uint32_t ntoh4advance (const uint8_t *&buf)
static uint32_t ntoh4advance (const uint8_t *&buf, unsigned int &len)
static uint32_t ntoh4 (const uint8_t *buf)
static void hton4advance (uint8_t *&buf, uint32_t val)
static void hton4advance (uint8_t *&buf, uint32_t val, unsigned int &len)
static void hton4 (uint8_t *buf, uint32_t val)
static uint32_t ntoh3advance (const uint8_t *&buf)
static uint32_t ntoh3advance (const uint8_t *&buf, unsigned int &len)
static uint32_t ntoh3 (const uint8_t *buf)
static void hton3advance (uint8_t *&buf, uint32_t val)
static void hton3advance (uint8_t *&buf, uint32_t val, unsigned int &len)
static void hton3 (uint8_t *buf, uint32_t val)
static uint16_t ntoh2advance (const uint8_t *&buf)
static uint16_t ntoh2advance (const uint8_t *&buf, unsigned int &len)
static uint16_t ntoh2 (const uint8_t *buf)
static void hton2advance (uint8_t *&buf, uint16_t val)
static void hton2advance (uint8_t *&buf, uint16_t val, unsigned int &len)
static void hton2 (uint8_t *buf, uint16_t val)
static uint64_t ntohAdvance (const uint8_t *&buf, uint8_t bytes)
static uint64_t ntohAdvance (const uint8_t *&buf, unsigned int &len, uint8_t bytes)
static uint64_t ntoh (const uint8_t *buf, uint8_t bytes)
static void htonAdvance (uint8_t *&buf, uint64_t val, uint8_t bytes)
static void htonAdvance (uint8_t *&buf, uint64_t val, unsigned int &len, uint8_t bytes)
static void hton (uint8_t *buf, uint64_t val, uint8_t bytes)
static uint64_t lsbAdvance (const uint8_t *&buf, uint8_t bytes)
static uint64_t lsbAdvance (const uint8_t *&buf, unsigned int &len, uint8_t bytes)
static uint64_t lsb (const uint8_t *buf, uint8_t bytes)
static void lsbSetAdvance (uint8_t *&buf, uint64_t val, uint8_t bytes)
static void lsbSetAdvance (uint8_t *&buf, uint64_t val, unsigned int &len, uint8_t bytes)
static void lsbSet (uint8_t *buf, uint64_t val, uint8_t bytes)
Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
static bool getObjCounting ()
static void setObjCounting (bool enable)
static NamedCountergetObjCounter (const String &name, bool create=true)
static ObjListgetObjCounters ()

Detailed Description

A class that holds just a block of raw data.

The DataBlock holds a data buffer with no specific formatting.

Constructor & Destructor Documentation

◆ DataBlock() [1/4]

DataBlock ( unsigned int overAlloc = 0)

Constructs an empty data block

Parameters
overAllocHow many bytes of memory to overallocate

References overAlloc().

Referenced by append(), assign(), Base64::Base64(), convert(), DataBlock(), DataBlock(), Base64::decode(), empty(), insert(), operator+=(), operator+=(), Base64::operator<<(), and operator=().

◆ DataBlock() [2/4]

DataBlock ( const DataBlock & value)

Copy constructor

Parameters
valueData block to copy from

References DataBlock().

◆ DataBlock() [3/4]

DataBlock ( const DataBlock & value,
unsigned int overAlloc )

Copy constructor with overallocation

Parameters
valueData block to copy from
overAllocHow many bytes of memory to overallocate

References DataBlock(), and overAlloc().

◆ DataBlock() [4/4]

DataBlock ( void * value,
unsigned int len,
bool copyData = true,
unsigned int overAlloc = 0 )

Constructs an initialized data block

Parameters
valueData to assign, may be NULL to fill with zeros
lenLength of data, may be zero (then value is ignored)
copyDataTrue to make a copy of the data, false to just insert the pointer
overAllocHow many bytes of memory to overallocate

References overAlloc().

◆ ~DataBlock()

virtual ~DataBlock ( )
virtual

Destroys the data, disposes the memory.

Member Function Documentation

◆ append() [1/3]

void append ( const DataBlock & value,
bool mayOverlap = true )
inline

Append data to the current block

Parameters
valueData to append
mayOverlapSet it to false if you are sure the buffer it's not inside current block

References change(), data(), DataBlock(), and length().

◆ append() [2/3]

void append ( const String & value)
inline

Append a String to the current block

Parameters
valueString to append

References String::c_str(), change(), length(), and String::length().

◆ append() [3/3]

void append ( const void * value,
unsigned int len,
bool mayOverlap = true )
inline

Append data to the current block

Parameters
valueData to append
lenLength of data
mayOverlapSet it to false if you are sure the buffer it's not inside current block

References change(), and length().

Referenced by append1(), operator+=(), operator+=(), Base64::operator<<(), and Base64::operator<<().

◆ append1()

void append1 ( uint8_t value)
inline

Append 1 byte to the current block

Parameters
valueValue to append

References append().

◆ append2hton()

void append2hton ( uint16_t value)
inline

Append unsigned integer data to the current block using network byte order

Parameters
valueValue to append

References change2hton(), and length().

◆ append3hton()

void append3hton ( uint32_t value)
inline

Append unsigned integer data to the current block using network byte order

Parameters
valueValue to append

References change3hton(), and length().

◆ append4hton()

void append4hton ( uint32_t value)
inline

Append unsigned integer data to the current block using network byte order

Parameters
valueValue to append

References change4hton(), and length().

◆ append8hton()

void append8hton ( uint64_t value)
inline

Append unsigned integer data to the current block using network byte order

Parameters
valueValue to append

References change8hton(), and length().

◆ append8lsb()

void append8lsb ( uint64_t value,
uint8_t bytes = 8 )
inline

Append unsigned integer data to the current block using LSB byte order

Parameters
valueValue to append
bytesNumber of bytes to handle

References changeLsb(), and length().

◆ appendBytes()

void appendBytes ( unsigned int count,
uint8_t val = 0 )
inline

Append bytes to current block

Parameters
countNumber of bytes to append
valValue to fill

References insertBytes(), and length().

◆ appendHex()

bool appendHex ( const String & data,
char sep = 0,
bool guessSep = true,
bool emptyOk = true,
int * res = 0 )
inline

Append data in current 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
dataInput character string
sepSeparator character used between octets. 0 if no separator is expected or should be guessed
guessSepGuess separator value. Ignored if 'sep' is non 0
emptyOkReturn success on empty hex buffer, false otherwise
resOptional pointer to be filled with result. Negative on failure, number of used bytes otherwise
Returns
True on success, false on failure (invalid hex string, empty hex buffer or memory allocation error)

References changeHex(), data(), and length().

◆ appendHton()

void appendHton ( uint64_t value,
uint8_t bytes )
inline

Append unsigned integer data to the current block using network byte order

Parameters
valueValue to append
bytesNumber of bytes to handle

References changeHton(), and length().

◆ assign()

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

Assign data to the object

Parameters
valueData to assign, may be NULL to fill with zeros
lenLength of data, may be zero (then value is ignored)
copyDataTrue to make a copy of the data, false to just insert the pointer
allocatedReal allocated data length in case it should not be copied

References DataBlock().

Referenced by operator=().

◆ at()

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

Get the value of a single byte inside the stored data

Parameters
offsByte offset inside the stored data
defvalueDefault value to return if offset is outside data
Returns
Byte value at offset (0-255) or defvalue if offset outside data

Referenced by operator[](), and operator[]().

◆ change()

bool change ( unsigned int pos,
const void * buf,
unsigned int bufLen,
unsigned int extra = 0,
int extraVal = 0,
bool mayOverlap = true )

Change the current block. Insert or append data and/or fill with value

Parameters
posBuffer position, append at end if past buffer end
bufData to copy
bufLenData length, ignored if 'buf' is NULL
extraNumber of extra filled bytes to handle after given buffer
extraValValue to fill
mayOverlapSet it to false if a buffer is given and you are sure it's not inside current block
Returns
True on success, false on failure (memory allocation error)

Referenced by append(), append(), append(), change2hton(), change3hton(), change4hton(), change8hton(), changeHton(), changeLsb(), insert(), and insertBytes().

◆ change2hton()

bool change2hton ( unsigned int pos,
uint16_t value )
inline

Change (append or insert unsigned integer data) to the current block using network byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
Returns
True on success, false on failure (memory allocation error)

References change(), and hton2().

Referenced by append2hton(), and insert2hton().

◆ change3hton()

bool change3hton ( unsigned int pos,
uint32_t value )
inline

Change (append or insert unsigned integer data) to the current block using network byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
Returns
True on success, false on failure (memory allocation error)

References change(), and hton3().

Referenced by append3hton(), and insert3hton().

◆ change4hton()

bool change4hton ( unsigned int pos,
uint32_t value )
inline

Change (append or insert unsigned integer data) to the current block using network byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
Returns
True on success, false on failure (memory allocation error)

References change(), and hton4().

Referenced by append4hton(), and insert4hton().

◆ change8hton()

bool change8hton ( unsigned int pos,
uint64_t value )
inline

Change (append or insert unsigned integer data) to the current block using network byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
Returns
True on success, false on failure (memory allocation error)

References change(), and hton8().

Referenced by append8hton(), and insert8hton().

◆ changeHex() [1/2]

bool changeHex ( unsigned int pos,
const char * data,
unsigned int len,
char sep = 0,
bool guessSep = true,
bool emptyOk = true,
int * res = 0 )

Change data data in current block from a hexadecimal string representation. Append or insert. 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
posPosition to insert, append if past buffer end
dataInput character string
lenLength of the input string
sepSeparator character used between octets. 0 if no separator is expected or should be guessed
guessSepGuess separator value. Ignored if 'sep' is non 0
emptyOkReturn success on empty hex buffer, false otherwise
resOptional pointer to be filled with result. Negative on failure, number of used bytes otherwise
Returns
True on success, false on failure (invalid hex string, empty hex buffer or memory allocation error)

References data().

Referenced by appendHex(), changeHex(), unHexify(), and unHexify().

◆ changeHex() [2/2]

bool changeHex ( unsigned int pos,
const String & data,
char sep = 0,
bool guessSep = true,
bool emptyOk = true,
int * res = 0 )
inline

Change data data in current block from a hexadecimal string representation. Append or insert. 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
posPosition to insert, append if past buffer end
dataInput character string
sepSeparator character used between octets. 0 if no separator is expected or should be guessed
guessSepGuess separator value. Ignored if 'sep' is non 0
emptyOkReturn success on empty hex buffer, false otherwise
resOptional pointer to be filled with result. Negative on failure, number of used bytes otherwise
Returns
True on success, false on failure (invalid hex string, empty hex buffer or memory allocation error)

References changeHex(), and data().

◆ changeHton()

bool changeHton ( unsigned int pos,
uint64_t value,
uint8_t bytes )
inline

Change (append or insert unsigned integer data) to the current block using network byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
bytesNumber of bytes to handle
Returns
True on success, false on failure (memory allocation error)

References change(), and hton().

Referenced by appendHton(), and insertHton().

◆ changeLsb()

bool changeLsb ( unsigned int pos,
uint64_t value,
uint8_t bytes = 8 )
inline

Change (append or insert unsigned integer data) to the current block using LSB byte order

Parameters
posBuffer position, append at end if past buffer end
valueValue to set
bytesNumber of bytes to handle
Returns
True on success, false on failure (memory allocation error)

References change(), and lsbSet().

Referenced by append8lsb(), and insertLsb().

◆ clear()

void clear ( bool deleteData = true)

Clear the data and optionally free the memory

Parameters
deleteDataTrue to free the deta block, false to just forget it

Referenced by cut(), truncate(), unHexify(), and unHexify().

◆ convert()

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

Convert data from a different format

Parameters
srcSource data block
sFormatName of the source format
dFormatName of the destination format
maxlenMaximum amount to convert, 0 to use source
Returns
True if converted successfully, false on failure

References DataBlock().

◆ cut() [1/2]

void cut ( int len)
inline

Cut off a number of bytes from the data block

Parameters
lenAmount to cut, positive to cut from end, negative to cut from start of block.

References clear(), cut(), and length().

◆ cut() [2/2]

void cut ( unsigned int pos,
unsigned int len,
bool reAlloc = true )

Cut off a number of bytes from the data block

Parameters
posBlock position
lenAmount to cut. Clear block if all data is removed
reAllocRe-allocate buffer. Set it it to false to move/reset data only This parameter is ignored if data is cleared

Referenced by cut(), and truncate().

◆ data() [1/2]

◆ data() [2/2]

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

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

Parameters
offsByte offset inside the stored data
lenNumber of bytes that must be valid starting at offset
Returns
A pointer to the data or NULL if the range is not available.

◆ empty()

const DataBlock & empty ( )
static

A static empty data block

References DataBlock().

◆ hton()

void hton ( uint8_t * buf,
uint64_t val,
uint8_t bytes )
inlinestatic

Convert bytes value from host byte order to network byte order.

Parameters
bufBuffer pointer. Assumed to be valid
valThe value
bytesThe number of bytes to convert

References htonAdvance().

Referenced by changeHton().

◆ hton2()

void hton2 ( uint8_t * buf,
uint16_t val )
inlinestatic

Convert 2 bytes value from host byte order to network byte order.

Parameters
bufBuffer pointer. Assumed to be valid
valThe value

References hton2advance().

Referenced by change2hton().

◆ hton2advance() [1/2]

void hton2advance ( uint8_t *& buf,
uint16_t val )
inlinestatic

Convert 2 bytes value from host byte order to network byte order. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value

Referenced by hton2(), and hton2advance().

◆ hton2advance() [2/2]

void hton2advance ( uint8_t *& buf,
uint16_t val,
unsigned int & len )
inlinestatic

Convert 2 bytes value from host byte order to network byte order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid

References hton2advance().

◆ hton3()

void hton3 ( uint8_t * buf,
uint32_t val )
inlinestatic

Convert 3 bytes value from host byte order to network byte order.

Parameters
bufBuffer pointer. Assumed to be valid
valThe value

References hton3advance().

Referenced by change3hton().

◆ hton3advance() [1/2]

void hton3advance ( uint8_t *& buf,
uint32_t val )
inlinestatic

Convert 3 bytes value from host byte order to network byte order. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value

Referenced by hton3(), and hton3advance().

◆ hton3advance() [2/2]

void hton3advance ( uint8_t *& buf,
uint32_t val,
unsigned int & len )
inlinestatic

Convert 3 bytes value from host byte order to network byte order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid

References hton3advance().

◆ hton4()

void hton4 ( uint8_t * buf,
uint32_t val )
inlinestatic

Convert 4 bytes value from host byte order to network byte order.

Parameters
bufBuffer pointer. Assumed to be valid
valThe value

References hton4advance().

Referenced by change4hton().

◆ hton4advance() [1/2]

void hton4advance ( uint8_t *& buf,
uint32_t val )
inlinestatic

Convert 4 bytes value from host byte order to network byte order. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value

Referenced by hton4(), and hton4advance().

◆ hton4advance() [2/2]

void hton4advance ( uint8_t *& buf,
uint32_t val,
unsigned int & len )
inlinestatic

Convert 4 bytes value from host byte order to network byte order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid

References hton4advance().

◆ hton8()

void hton8 ( uint8_t * buf,
uint64_t val )
inlinestatic

Convert 8 bytes value from host byte order to network byte order.

Parameters
bufBuffer pointer. Assumed to be valid
valThe value

References hton8advance().

Referenced by change8hton().

◆ hton8advance() [1/2]

void hton8advance ( uint8_t *& buf,
uint64_t val )
inlinestatic

Convert 8 bytes value from host byte order to network byte order

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value

Referenced by hton8(), hton8advance(), and htonAdvance().

◆ hton8advance() [2/2]

void hton8advance ( uint8_t *& buf,
uint64_t val,
unsigned int & len )
inlinestatic

Convert 8 bytes value from host byte order to network byte order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid

References hton8advance().

◆ htonAdvance() [1/2]

void htonAdvance ( uint8_t *& buf,
uint64_t val,
uint8_t bytes )
inlinestatic

Convert bytes value from host byte order to network byte order. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
bytesThe number of bytes to convert

References hton8advance().

Referenced by hton(), and htonAdvance().

◆ htonAdvance() [2/2]

void htonAdvance ( uint8_t *& buf,
uint64_t val,
unsigned int & len,
uint8_t bytes )
inlinestatic

Convert bytes value from host byte order to network byte order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid
bytesThe number of bytes to convert

References htonAdvance().

◆ insert() [1/2]

void insert ( const DataBlock & value,
unsigned int pos = 0,
bool mayOverlap = true )
inline

Insert data before the current block

Parameters
valueData to insert
posBuffer position
mayOverlapSet it to false if you are sure the buffer it's not inside current block

References data(), DataBlock(), insert(), and length().

◆ insert() [2/2]

void insert ( const void * buf,
unsigned int bufLen,
unsigned int pos = 0,
bool mayOverlap = true )
inline

Insert data in the current block

Parameters
bufData to copy
bufLenData length
posBuffer position
mayOverlapSet it to false if you are sure the buffer it's not inside current block

References change().

Referenced by insert(), and insert1().

◆ insert1()

void insert1 ( uint8_t value,
unsigned int pos = 0 )
inline

Insert 1 byte in the current block

Parameters
valueValue to insert
posBuffer position, append at end if greater than current length

References insert().

◆ insert2hton()

void insert2hton ( uint16_t value,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using network byte order

Parameters
valueValue to insert
posBuffer position, append at end if greater than current length

References change2hton().

◆ insert3hton()

void insert3hton ( uint32_t value,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using network byte order

Parameters
valueValue to insert
posBuffer position, append at end if greater than current length

References change3hton().

◆ insert4hton()

void insert4hton ( uint32_t value,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using network byte order

Parameters
valueValue to insert
posBuffer position, append at end if greater than current length

References change4hton().

◆ insert8hton()

void insert8hton ( uint64_t value,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using network byte order

Parameters
valueValue to insert
posBuffer position, append at end if greater than current length

References change8hton().

◆ insertBytes()

void insertBytes ( unsigned int count,
unsigned int pos = 0,
uint8_t val = 0 )
inline

Insert bytes in current block

Parameters
countNumber of bytes to insert
posBuffer position
valValue to fill

References change().

Referenced by appendBytes().

◆ insertHton()

void insertHton ( uint64_t value,
uint8_t bytes = 8,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using network byte order

Parameters
valueValue to insert
bytesNumber of bytes to handle
posBuffer position, append at end if greater than current length

References changeHton().

◆ insertLsb()

void insertLsb ( uint64_t value,
uint8_t bytes = 8,
unsigned int pos = 0 )
inline

Insert unsigned integer data in the current block using LSB byte order

Parameters
valueValue to insert
bytesNumber of bytes to handle
posBuffer position, append at end if greater than current length

References changeLsb().

◆ length()

◆ lsb()

uint64_t lsb ( const uint8_t * buf,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to LSB unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in LSB order

References lsbAdvance().

◆ lsbAdvance() [1/2]

uint64_t lsbAdvance ( const uint8_t *& buf,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to LSB unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in LSB order

Referenced by lsb(), and lsbAdvance().

◆ lsbAdvance() [2/2]

uint64_t lsbAdvance ( const uint8_t *& buf,
unsigned int & len,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to LSB unsigned int. Advance in buffer, decrease buffer length

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in LSB order

References lsbAdvance().

◆ lsbSet()

void lsbSet ( uint8_t * buf,
uint64_t val,
uint8_t bytes )
inlinestatic

Set value in buffer using LSB order

Parameters
bufBuffer pointer. Assumed to be valid
valThe value
bytesThe number of bytes to convert

References lsbSetAdvance().

Referenced by changeLsb().

◆ lsbSetAdvance() [1/2]

void lsbSetAdvance ( uint8_t *& buf,
uint64_t val,
uint8_t bytes )
inlinestatic

Set value in buffer using LSB order. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
bytesThe number of bytes to convert

Referenced by lsbSet(), and lsbSetAdvance().

◆ lsbSetAdvance() [2/2]

void lsbSetAdvance ( uint8_t *& buf,
uint64_t val,
unsigned int & len,
uint8_t bytes )
inlinestatic

Set value in buffer using LSB order. Advance in buffer, increase length

Parameters
bufBuffer pointer reference. Assumed to be valid
valThe value
lenBuffer length. Assumed to be valid
bytesThe number of bytes to convert

References lsbSetAdvance().

◆ moveData()

void moveData ( void * buf,
unsigned int bufLen,
unsigned int len,
unsigned int dPos,
unsigned int sPos,
int fill = -1 )
static

Safely move data in the same buffer. No change is done if destination and source position are the same

Parameters
bufBuffer pointer
bufLenBuffer length
lenNumber of items to copy (move)
dPosDestination buffer position
sPosSource buffer position
fillValue to reset empty (moved) memory if not negative

◆ ntoh()

uint64_t ntoh ( const uint8_t * buf,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to host byte order unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in machine byte order

References ntohAdvance().

◆ ntoh2()

uint16_t ntoh2 ( const uint8_t * buf)
inlinestatic

Convert 2 bytes from buffer to host byte order unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
Returns
First 2 bytes value in machine byte order

References ntoh2advance().

◆ ntoh2advance() [1/2]

uint16_t ntoh2advance ( const uint8_t *& buf)
inlinestatic

Convert 2 bytes from buffer to host byte order unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
Returns
First 2 bytes value in machine byte order

Referenced by ntoh2(), and ntoh2advance().

◆ ntoh2advance() [2/2]

uint16_t ntoh2advance ( const uint8_t *& buf,
unsigned int & len )
inlinestatic

Convert 2 bytes from buffer to host byte order unsigned int. Advance in buffer, decrease buffer length

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
Returns
First 2 bytes value in machine byte order

References ntoh2advance().

◆ ntoh3()

uint32_t ntoh3 ( const uint8_t * buf)
inlinestatic

Convert 3 bytes from buffer to host byte order unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
Returns
First 3 bytes value in machine byte order

References ntoh3advance().

◆ ntoh3advance() [1/2]

uint32_t ntoh3advance ( const uint8_t *& buf)
inlinestatic

Convert 3 bytes from buffer to host byte order unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
Returns
First 3 bytes value in machine byte order

Referenced by ntoh3(), and ntoh3advance().

◆ ntoh3advance() [2/2]

uint32_t ntoh3advance ( const uint8_t *& buf,
unsigned int & len )
inlinestatic

Convert 3 bytes from buffer to host byte order unsigned int. Advance in buffer, decrease buffer length

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
Returns
First 3 bytes value in machine byte order

References ntoh3advance().

◆ ntoh4()

uint32_t ntoh4 ( const uint8_t * buf)
inlinestatic

Convert 4 bytes from buffer to host byte order unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
Returns
First 4 bytes value in machine byte order

References ntoh4advance().

◆ ntoh4advance() [1/2]

uint32_t ntoh4advance ( const uint8_t *& buf)
inlinestatic

Convert 4 bytes from buffer to host byte order unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
Returns
First 4 bytes value in machine byte order

Referenced by ntoh4(), and ntoh4advance().

◆ ntoh4advance() [2/2]

uint32_t ntoh4advance ( const uint8_t *& buf,
unsigned int & len )
inlinestatic

Convert 4 bytes from buffer to host byte order unsigned int. Advance in buffer, decrease buffer length

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
Returns
First 4 bytes value in machine byte order

References ntoh4advance().

◆ ntoh8()

uint64_t ntoh8 ( const uint8_t * buf)
inlinestatic

Convert 8 bytes from buffer to host byte order unsigned int

Parameters
bufBuffer pointer. Assumed to be valid
Returns
First 8 bytes value in machine byte order

References ntoh8advance().

◆ ntoh8advance() [1/2]

uint64_t ntoh8advance ( const uint8_t *& buf)
inlinestatic

Convert 8 bytes from buffer to host byte order unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
Returns
First 8 bytes value in machine byte order

Referenced by ntoh8(), ntoh8advance(), and ntohAdvance().

◆ ntoh8advance() [2/2]

uint64_t ntoh8advance ( const uint8_t *& buf,
unsigned int & len )
inlinestatic

Convert 8 bytes from buffer to host byte order unsigned int. Advance in buffer, decrease buffer length.

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
Returns
First 8 bytes value in machine byte order

References ntoh8advance().

◆ ntohAdvance() [1/2]

uint64_t ntohAdvance ( const uint8_t *& buf,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to host byte order unsigned int. Advance in buffer

Parameters
bufBuffer pointer reference. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in machine byte order

References ntoh8advance().

Referenced by ntoh(), and ntohAdvance().

◆ ntohAdvance() [2/2]

uint64_t ntohAdvance ( const uint8_t *& buf,
unsigned int & len,
uint8_t bytes )
inlinestatic

Convert bytes from buffer to host byte order unsigned int. Advance in buffer, decrease buffer length

Parameters
bufBuffer pointer reference. Assumed to be valid
lenBuffer length. Assumed to be valid
bytesThe number of bytes to convert
Returns
First 'bytes' value in machine byte order

References ntohAdvance().

◆ null()

bool null ( ) const
inline

Checks if the block holds a NULL pointer.

Returns
True if the block holds NULL, false otherwise.

◆ operator+=() [1/2]

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

Appending operator.

References append(), and DataBlock().

◆ operator+=() [2/2]

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

Appending operator for Strings.

References append(), and DataBlock().

◆ operator=()

DataBlock & operator= ( const DataBlock & value)
inline

Assignment operator.

References assign(), data(), DataBlock(), and length().

◆ operator[]() [1/2]

int operator[] ( signed int index) const
inline

Byte indexing operator with signed parameter

Parameters
indexIndex of the byte to retrieve
Returns
Byte value at offset (0-255) or -1 if index outside data

References at().

◆ operator[]() [2/2]

int operator[] ( unsigned int index) const
inline

Byte indexing operator with unsigned parameter

Parameters
indexIndex of the byte to retrieve
Returns
Byte value at offset (0-255) or -1 if index outside data

References at().

◆ overAlloc() [1/2]

unsigned int overAlloc ( ) const
inline

Get the memory overallocation setting.

Returns
Amount of memory that will be overallocated.

Referenced by DataBlock(), DataBlock(), and DataBlock().

◆ overAlloc() [2/2]

void overAlloc ( unsigned int bytes)
inline

Set the memory overallocation.

Parameters
bytesHow many bytes of memory to overallocate

◆ rebuildDataInsert()

void rebuildDataInsert ( void * dest,
unsigned int dLen,
const void * src,
unsigned int sLen,
unsigned int pos,
unsigned int space,
int fill = -1 )
static

Rebuild a data buffer after data was inserted. It is assumed the destination and source don't overlap

Parameters
destDestination buffer
dLenDestination buffer length
srcSource buffer
sLenSource buffer length
posInsert position
spaceAmount of inserted space
fillValue to reset inserted memory if not negative

◆ rebuildDataRemove()

void rebuildDataRemove ( void * dest,
unsigned int dLen,
const void * src,
unsigned int sLen,
unsigned int pos,
unsigned int space,
int fillAfter = -1 )
static

Rebuild a data buffer after data was removed. It is assumed the destination and source don't overlap

Parameters
destDestination buffer
dLenDestination buffer length
srcSource buffer
sLenSource buffer length
posRemove position
spaceAmount of removed space
fillAfterValue to reset memory until buffer end if not negative

◆ resize()

void resize ( unsigned int len,
bool keepData = false,
bool reAlloc = true )

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

Parameters
lenRequired block size. Clear if 0
keepDataKeep old data This parameter is ignored if data is cleared
reAllocRe-allocate buffer. Set it it to false to move/reset data only This parameter is ignored if data is cleared

◆ size()

unsigned int size ( ) const
inline

Get the length of the allocated data

Returns
The length of the allocated data

◆ sqlEscape() [1/3]

String sqlEscape ( char extraEsc) const
inline

Create an escaped string suitable for use in SQL queries

Parameters
extraEscCharacter to escape other than the default ones
Returns
A string with binary zeros and other special characters escaped

References sqlEscape().

◆ sqlEscape() [2/3]

String & sqlEscape ( String & str,
char extraEsc = 0 ) const
inline

Add block values as escaped string suitable for use in SQL queries. Escape binary zeros and other special characters

Parameters
strDestination string
extraEscCharacter to escape other than the default ones
Returns
Destination string reference

References data(), length(), and sqlEscape().

Referenced by sqlEscape(), and sqlEscape().

◆ sqlEscape() [3/3]

String & sqlEscape ( String & str,
const void * data,
unsigned int len,
char extraEsc = 0 )
static

Add block values as escaped string suitable for use in SQL queries. Escape binary zeros and other special characters

Parameters
strDestination string
dataBinary data buffer
lenBuffer length
extraEscCharacter to escape other than the default ones
Returns
Destination string reference

References data().

◆ truncate()

void truncate ( unsigned int len,
bool reAlloc = true )
inline

Truncate the data block

Parameters
lenThe maximum length to keep
reAllocRe-allocate buffer. Set it it to false to move/reset data only This parameter is ignored if data is cleared

References clear(), cut(), and length().

◆ unHexify() [1/3]

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

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
dataInput character string
lenLength of the input string
Returns
True if the input string was succesfully parsed, false otherwise

References changeHex(), clear(), data(), and length().

◆ unHexify() [2/3]

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

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
dataInput character string
lenLength of the input string
sepSeparator character used between octets. 0 if no separator is expected
Returns
True if the input string was succesfully parsed, false otherwise

References changeHex(), clear(), data(), and length().

Referenced by unHexify(), and SliceVector< Complex >::unHexify().

◆ unHexify() [3/3]

bool unHexify ( const String & data)
inline

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

Parameters
dataInput character string
Returns
True if the input string was succesfully parsed, false otherwise

References data(), and unHexify().


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