te::dt::ByteArray Class Reference

A class for representing binary data. More...

#include <ByteArray.h>

Inheritance diagram for te::dt::ByteArray:
te::dt::AbstractData

Public Member Functions

 ByteArray ()
 It creates a new empty byte array. More...
 
 ByteArray (std::size_t capacity)
 It creates a new byte array and allocates size bytes. More...
 
 ByteArray (char *data, std::size_t size)
 It creates a new byte array taking the ownership of the external data buffer. More...
 
 ByteArray (char *data, std::size_t capacity, std::size_t usedBytes)
 It creates a new byte array taking the ownership of the external data buffer. More...
 
 ByteArray (const ByteArray &rhs)
 Copy constructor. More...
 
std::size_t bytesUsed () const
 It returns the number of used bytes in the internal buffer. More...
 
std::size_t capacity () const
 It returns the size of the internal buffer. More...
 
void clear ()
 It clears the byte array. More...
 
AbstractDataclone () const
 It creates a new clone of the byte array. More...
 
void copy (char *data, std::size_t size)
 It copies the data from the given pointer to the byte array. More...
 
void copy (char *data, std::size_t size, std::size_t offset)
 It copies the data from the given pointer to the byte array. More...
 
char * getData () const
 It returns the data array. More...
 
int getTypeCode () const
 The type code for byte array data: BYTE_ARRAY_TYPE. More...
 
ByteArrayoperator= (const ByteArray &rhs)
 Assignment operator. More...
 
void setBytesUsed (std::size_t size)
 It sets the number of used bytes in the internal buffer. More...
 
void take (char *data, std::size_t size)
 It takes the ownership of the external data buffer. More...
 
void take (char *data, std::size_t capacity, std::size_t usedBytes)
 It takes the ownership of the external data buffer. More...
 
std::string toString () const
 It returns the byte array in an string notation. More...
 
 ~ByteArray ()
 Destructor. More...
 

Private Attributes

std::size_t m_bytesOccupied
 The number of bytes occupied in the buffer. More...
 
std::size_t m_capacity
 The number of bytes allocated by the internal buffer. More...
 
char * m_data
 The buffer data. More...
 

Detailed Description

A class for representing binary data.

A byte array can be used as a container for binary data.

See also
AbstractData, DataType, DateTime, SimpleData, CompositeData

Definition at line 51 of file ByteArray.h.

Constructor & Destructor Documentation

◆ ByteArray() [1/5]

te::dt::ByteArray::ByteArray ( )

It creates a new empty byte array.

◆ ByteArray() [2/5]

te::dt::ByteArray::ByteArray ( std::size_t  capacity)

It creates a new byte array and allocates size bytes.

Parameters
capacityThe number of bytes for the internal data buffer.

◆ ByteArray() [3/5]

te::dt::ByteArray::ByteArray ( char *  data,
std::size_t  size 
)

It creates a new byte array taking the ownership of the external data buffer.

Parameters
dataThe data array.
sizeThe number of bytes in the data array. This value will be also the capacity of the byte array buffer.
Note
The byte array will take the ownership of the given data.

◆ ByteArray() [4/5]

te::dt::ByteArray::ByteArray ( char *  data,
std::size_t  capacity,
std::size_t  usedBytes 
)

It creates a new byte array taking the ownership of the external data buffer.

Parameters
dataThe data array.
capacityThe number of bytes available in the data buffer, it must be greater than or equal to usedBytes.
usedBytesThe number of used bytes in the given data buffer.
Note
The byte array will take the ownership of the given data.

◆ ByteArray() [5/5]

te::dt::ByteArray::ByteArray ( const ByteArray rhs)

Copy constructor.

Parameters
rhsThe right-hand-side instance.

◆ ~ByteArray()

te::dt::ByteArray::~ByteArray ( )

Destructor.

Member Function Documentation

◆ bytesUsed()

std::size_t te::dt::ByteArray::bytesUsed ( ) const

It returns the number of used bytes in the internal buffer.

Returns
The number of used bytes in the internal buffer.

Referenced by operator<<().

◆ capacity()

std::size_t te::dt::ByteArray::capacity ( ) const

It returns the size of the internal buffer.

Returns
The number of bytes in the internal buffer.

◆ clear()

void te::dt::ByteArray::clear ( )

It clears the byte array.

◆ clone()

AbstractData* te::dt::ByteArray::clone ( ) const
virtual

It creates a new clone of the byte array.

Returns
A new clone of the byte array. The caller will take its ownership.

Implements te::dt::AbstractData.

◆ copy() [1/2]

void te::dt::ByteArray::copy ( char *  data,
std::size_t  size 
)

It copies the data from the given pointer to the byte array.

Parameters
dataThe data array to be copied.
sizeThe number of bytes to be copied from the input array.
Note
It will drop the internal buffer if its capacity is less than size bytes.

Referenced by operator<<().

◆ copy() [2/2]

void te::dt::ByteArray::copy ( char *  data,
std::size_t  size,
std::size_t  offset 
)

It copies the data from the given pointer to the byte array.

Parameters
dataThe data array to be copied.
sizeThe number of bytes to be copied from the input array.
offsetAn offset in the internal data buffer.
Note
It will expand the internal buffer if its capacity is less than offset + size bytes.
After this operation the number of bytes ocupied will be set to offset + size.

◆ getData()

char* te::dt::ByteArray::getData ( ) const

It returns the data array.

Returns
The data array.
Note
Don't free the returned pointer (it belongs to the byte array object).

◆ getTypeCode()

int te::dt::ByteArray::getTypeCode ( ) const
inlinevirtual

The type code for byte array data: BYTE_ARRAY_TYPE.

Returns
The type code for byte array data: BYTE_ARRAY_TYPE.

Implements te::dt::AbstractData.

Definition at line 198 of file ByteArray.h.

References te::dt::BYTE_ARRAY_TYPE.

◆ operator=()

ByteArray& te::dt::ByteArray::operator= ( const ByteArray rhs)

Assignment operator.

Parameters
rhsThe right-hand-side instance.
Returns
A reference to this byte array.

◆ setBytesUsed()

void te::dt::ByteArray::setBytesUsed ( std::size_t  size)

It sets the number of used bytes in the internal buffer.

Parameters
sizeThe number of used bytes in the internal buffer.

◆ take() [1/2]

void te::dt::ByteArray::take ( char *  data,
std::size_t  size 
)

It takes the ownership of the external data buffer.

Parameters
dataThe data array.
sizeThe number of bytes in the array of data. This value will be also the capacity of the byte array buffer.
Note
The byte array will take the ownership of the given data.
It will drop the internal buffer before taking the data argument.

◆ take() [2/2]

void te::dt::ByteArray::take ( char *  data,
std::size_t  capacity,
std::size_t  usedBytes 
)

It takes the ownership of the external data buffer.

Parameters
dataThe data array.
capacityThe number of bytes available in the data buffer, it must be greater than or equal to usedBytes.
usedBytesThe number of used bytes in the given data buffer.
Note
The byte array will take the ownership of the given data.
It will drop the internal buffer before taking the data argument.

◆ toString()

std::string te::dt::ByteArray::toString ( ) const
virtual

It returns the byte array in an string notation.

Returns
An hex-string encoded version of the internal data buffer.

Implements te::dt::AbstractData.

Member Data Documentation

◆ m_bytesOccupied

std::size_t te::dt::ByteArray::m_bytesOccupied
private

The number of bytes occupied in the buffer.

Definition at line 213 of file ByteArray.h.

◆ m_capacity

std::size_t te::dt::ByteArray::m_capacity
private

The number of bytes allocated by the internal buffer.

Definition at line 212 of file ByteArray.h.

◆ m_data

char* te::dt::ByteArray::m_data
private

The buffer data.

Definition at line 211 of file ByteArray.h.


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