19 #ifndef __XRD_CL_BUFFER_HH__
20 #define __XRD_CL_BUFFER_HH__
39 Buffer( uint32_t size = 0 ): pBuffer(0), pSize(0), pCursor(0)
52 Steal( std::move( buffer ) );
60 Steal( std::move( buffer ) );
74 return pBuffer+offset;
82 return pBuffer+offset;
90 pBuffer = (
char *)realloc( pBuffer, size );
92 throw std::bad_alloc();
115 pBuffer = (
char *)malloc( size );
117 throw std::bad_alloc();
126 memset( pBuffer, 0, pSize );
164 void Append(
const char *buffer, uint32_t size )
166 uint32_t remaining = pSize-pCursor;
167 if( remaining < size )
170 memcpy( pBuffer+pCursor, buffer, size );
177 void Append(
const char *buffer, uint32_t size, uint32_t offset )
179 uint32_t remaining = pSize-offset;
180 if( remaining < size )
183 memcpy( pBuffer+offset, buffer, size );
208 memcpy( pBuffer, str.c_str(), str.length() );
209 pBuffer[str.length()] = 0;
217 char *bf =
new char[pSize+1];
219 memcpy( bf, pBuffer, pSize );
220 std::string tmp = bf;
228 void Grab(
char *buffer, uint32_t size )
240 char *buffer = pBuffer;
251 pBuffer = buffer.pBuffer;
254 pSize = buffer.pSize;
257 pCursor = buffer.pCursor;
Binary blob representation.
void Free()
Free the buffer.
char * GetBuffer(uint32_t offset=0)
Get the message buffer.
void FromString(const std::string str)
Fill the buffer from a string.
Buffer(uint32_t size=0)
Constructor.
void AdvanceCursor(uint32_t delta)
Advance the cursor.
void Grab(char *buffer, uint32_t size)
Grab a buffer allocated outside.
void Steal(Buffer &&buffer)
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Buffer(Buffer &&buffer)
Move Constructor.
void Append(const char *buffer, uint32_t size)
Append data at the position pointed to by the append cursor.
void ReAllocate(uint32_t size)
Reallocate the buffer to a new location of a given size.
void Allocate(uint32_t size)
Allocate the buffer.
void SetCursor(uint32_t cursor)
Set the cursor.
uint32_t GetCursor() const
Get append cursor.
uint32_t GetSize() const
Get the size of the message.
Buffer & operator=(Buffer &&buffer)
Move assignment operator.
void Append(const char *buffer, uint32_t size, uint32_t offset)
Append data at the given offset.
char * GetBufferAtCursor()
Get the buffer pointer at the append cursor.
virtual ~Buffer()
Destructor.
std::string ToString() const
Convert the buffer to a string.
const char * GetBufferAtCursor() const
Get the buffer pointer at the append cursor.
char * Release()
Release the buffer.