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

◆ DataBlock() [2/4]

DataBlock ( const DataBlock & value)

Copy constructor

Parameters
valueData block to copy from

◆ 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

◆ 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

◆ ~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 data(), 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(), 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

◆ append1()

void append1 ( uint8_t value)
inline

Append 1 byte to the current block

Parameters
valueValue to append

◆ append2hton()

void append2hton ( uint16_t value)
inline

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

Parameters
valueValue to append

◆ append3hton()

void append3hton ( uint32_t value)
inline

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

Parameters
valueValue to append

◆ append4hton()

void append4hton ( uint32_t value)
inline

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

Parameters
valueValue to append

◆ append8hton()

void append8hton ( uint64_t value)
inline

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

Parameters
valueValue to append

◆ 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

◆ 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

◆ 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)

◆ 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

◆ 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

◆ 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

◆ 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)

◆ 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)

◆ 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)

◆ 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)

◆ 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)

◆ 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)

◆ 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 String::c_str(), and String::length().

◆ 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)

◆ 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)

◆ 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

◆ 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

◆ 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.

◆ 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

◆ 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()

static const DataBlock & empty ( )
static

A static empty data block

◆ hton()

static 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

◆ hton2()

static 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

◆ hton2advance() [1/2]

static 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

◆ hton2advance() [2/2]

static 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

◆ hton3()

static 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

◆ hton3advance() [1/2]

static 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

◆ hton3advance() [2/2]

static 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

◆ hton4()

static 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

◆ hton4advance() [1/2]

static 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

◆ hton4advance() [2/2]

static 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

◆ hton8()

static 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

◆ hton8advance() [1/2]

static 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

◆ hton8advance() [2/2]

static 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

◆ htonAdvance() [1/2]

static 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

◆ htonAdvance() [2/2]

static 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

◆ 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(), 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ length()

◆ lsb()

static 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

◆ lsbAdvance() [1/2]

static 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

◆ lsbAdvance() [2/2]

static 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

◆ lsbSet()

static 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

◆ lsbSetAdvance() [1/2]

static 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

◆ lsbSetAdvance() [2/2]

static 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

◆ moveData()

static 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()

static 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

◆ ntoh2()

static 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

◆ ntoh2advance() [1/2]

static 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

◆ ntoh2advance() [2/2]

static 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

◆ ntoh3()

static 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

◆ ntoh3advance() [1/2]

static 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

◆ ntoh3advance() [2/2]

static 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

◆ ntoh4()

static 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

◆ ntoh4advance() [1/2]

static 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

◆ ntoh4advance() [2/2]

static 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

◆ ntoh8()

static 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

◆ ntoh8advance() [1/2]

static 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

◆ ntoh8advance() [2/2]

static 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

◆ ntohAdvance() [1/2]

static 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

◆ ntohAdvance() [2/2]

static 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

◆ 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.

◆ operator+=() [2/2]

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

Appending operator for Strings.

◆ operator=()

DataBlock & operator= ( const DataBlock & value)
inline

Assignment operator.

References data(), 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

◆ 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

◆ overAlloc() [1/2]

unsigned int overAlloc ( ) const
inline

Get the memory overallocation setting.

Returns
Amount of memory that will be overallocated.

◆ overAlloc() [2/2]

void overAlloc ( unsigned int bytes)
inline

Set the memory overallocation.

Parameters
bytesHow many bytes of memory to overallocate

◆ rebuildDataInsert()

static 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()

static 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

◆ 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

◆ sqlEscape() [3/3]

static 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

◆ 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

◆ 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

◆ 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

Referenced by SliceVector< Obj >::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 String::c_str(), and String::length().


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