27 #include "../common/HexUtils.h"
59 m_bytesOccupied(usedBytes)
64 : m_capacity(rhs.m_capacity),
65 m_bytesOccupied(rhs.m_bytesOccupied)
88 m_data =
new char[m_capacity];
116 m_bytesOccupied = size;
124 m_capacity = capacity;
125 m_bytesOccupied = usedBytes;
130 if(size > m_capacity)
133 m_data =
new char[size];
137 m_bytesOccupied = size;
139 memcpy(m_data, data, size);
144 if((offset + size) > m_capacity)
146 std::size_t newCapacity = offset + size;
148 char* newData =
new char[newCapacity];
150 memcpy(newData, m_data, offset);
152 memcpy(newData + offset, data, size);
154 take(newData, newCapacity);
158 memcpy(m_data + offset, data, size);
160 m_bytesOccupied = offset + size;
171 return m_bytesOccupied;
176 m_bytesOccupied = size;
194 if(m_bytesOccupied == 0)
195 return std::string(
"");
199 std::string result(hexStr);
std::size_t bytesUsed() const
It returns the number of used bytes in the internal buffer.
A class for representing binary data.
char * Binary2Hex(const char *s, std::size_t size)
Each char from the array of characters in binary format is converted into a pair of hex characters...
char * m_data
The buffer data.
std::string toString() const
It returns the byte array in an string notation.
char * getData() const
It returns the data array.
AbstractData * clone() const
It creates a new clone of the byte array.
A base class for values that can be retrieved from the data access module.
ByteArray()
It creates a new empty byte array.
ByteArray & operator=(const ByteArray &rhs)
Assignment operator.
std::size_t capacity() const
It returns the size of the internal buffer.
std::size_t m_bytesOccupied
The number of bytes occupied in the buffer.
std::size_t m_capacity
The number of bytes allocated by the internal buffer.
void copy(char *data, std::size_t size)
It copies the data from the given pointer to the byte array.
void setBytesUsed(std::size_t size)
It sets the number of used bytes in the internal buffer.
void clear()
It clears the byte array.
A class for representing binary data.
void take(char *data, std::size_t size)
It takes the ownership of the external data buffer.