19 #ifndef GNASH_SIMPLEBUFFER_H 20 #define GNASH_SIMPLEBUFFER_H 56 _data.reset(
new std::uint8_t[_capacity]);
72 bool empty()
const {
return _size==0; }
75 size_t size()
const {
return _size; }
81 std::uint8_t*
data() {
return _data.get(); }
84 const std::uint8_t*
data()
const {
return _data.get(); }
96 if ( _capacity >= newCapacity )
return;
99 _capacity = std::max(newCapacity, _capacity*2);
101 std::unique_ptr<std::uint8_t[]> tmp;
104 _data.reset(
new std::uint8_t[_capacity]);
108 if ( _size ) std::copy(tmp.get(), tmp.get()+_size, _data.get());
125 const std::uint8_t* newData =
126 reinterpret_cast<const std::uint8_t*
>(inData);
127 size_t curSize = _size;
129 std::copy(newData, newData+size, _data.get()+curSize);
130 assert(_size == curSize+size);
143 _data[_size - 1] =
b;
157 _data[_size - 2] = s >> 8;
158 _data[_size - 1] = s & 0xff;
172 _data[_size - 4] = l >> 24;
173 _data[_size - 3] = (l >> 16) & 0xff;
174 _data[_size - 2] = (l >> 8) & 0xff;
175 _data[_size - 1] = l & 0xff;
188 size_t incomingDataSize = buf.
size();
189 const std::uint8_t* incomingData = buf.
data();
190 append(incomingData, incomingDataSize);
197 std::unique_ptr<std::uint8_t[]> _data;
203 #endif // GNASH_SIMPLEBUFFER_H void append(const SimpleBuffer &buf)
Append data to the buffer.
Definition: SimpleBuffer.h:186
void resize(size_t newSize)
Resize the buffer.
Definition: SimpleBuffer.h:87
size_t capacity() const
Return capacity of the buffer.
Definition: SimpleBuffer.h:78
void appendByte(const std::uint8_t b)
Append a byte to the buffer.
Definition: SimpleBuffer.h:140
const std::uint8_t * data() const
Get a pointer to start of data. May be NULL if size==0.
Definition: SimpleBuffer.h:84
void append(const void *inData, size_t size)
Append data to the buffer.
Definition: SimpleBuffer.h:123
Definition: GnashKey.h:158
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
bool empty() const
Return true if buffer is empty.
Definition: SimpleBuffer.h:72
SimpleBuffer(size_t capacity=0)
Construct a SimpleBuffer with an optional initial capacity.
Definition: SimpleBuffer.h:49
size_t size() const
Return size of the buffer.
Definition: SimpleBuffer.h:75
std::uint8_t * data()
Get a pointer to start of data. May be NULL if size==0.
Definition: SimpleBuffer.h:81
void appendNetworkShort(const std::uint16_t s)
Append 2 bytes to the buffer.
Definition: SimpleBuffer.h:154
SimpleBuffer & operator=(const SimpleBuffer &b)=delete
Definition: GnashKey.h:148
void appendNetworkLong(const std::uint32_t l)
Append 4 bytes to the buffer.
Definition: SimpleBuffer.h:169
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
Definition: GnashKey.h:165
void reserve(size_t newCapacity)
Ensure at least 'newCapacity' bytes are allocated for this buffer.
Definition: SimpleBuffer.h:94