27 #ifndef Common_StaticBuffer_h
28 #define Common_StaticBuffer_h
65 size_t aligned_len = (len %
alignment) == 0 ? len :
68 base = (uint8_t *)vptr;
71 base =
new uint8_t[len];
175 void set(uint8_t *data, uint32_t len,
bool take_ownership =
true) {
179 own = take_ownership;
211 int cmp = memcmp(sb1.
base, sb2.
base, len);
212 return (cmp==0) ? sb1.
size < sb2.
size : cmp < 0;
228 return !(sb1 == sb2);
238 #endif // Common_StaticBuffer_h
A memory buffer of static size.
StaticBuffer()
Constructor.
StaticBuffer & operator=(DynamicBuffer &dbuf)
Assignment operator for DynamicBuffer.
void set(uint8_t *data, uint32_t len, bool take_ownership=true)
Sets data pointer; the existing buffer is discarded and deleted.
StaticBuffer(StaticBuffer &other)
Copy constructor.
StaticBuffer(DynamicBuffer &dbuf)
Constructor; takes ownership from a DynamicBuffer.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
A dynamic, resizable and reference counted memory buffer.
StaticBuffer(size_t len, size_t alignment=0)
Constructor.
A dynamic, resizable memory buffer.
uint32_t size
The size of the allocated memory buffer (base)
Logging routines and macros.
StaticBuffer & operator=(StaticBuffer &other)
Assignment operator.
bool operator==(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
void free()
Clears the data; if this object is owner of the data then the allocated buffer is delete[]d...
bool own
If true then the buffer (base) will be released when going out of scope; if false then the caller has...
bool operator!=(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
bool operator<(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
StaticBuffer(void *data, uint32_t len, bool take_ownership=true)
Constructor; assigns an existing buffer and can take ownership of that buffer.
bool equal(double a, double b)
Compare doubles that may have been serialized and unserialized.
uint8_t * base
Pointer to the allocated memory buffer.
size_t fill() const
Returns the size of the used portion.
~StaticBuffer()
Destructor; if "own" is true then the buffer will be delete[]d.
std::shared_ptr< StaticBuffer > StaticBufferPtr
Smart pointer to StaticBuffer.