Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
ByteBuffer Struct Reference

A datatype to allow an automatically growing buffer for appending data to. More...

#include <byte_buffer.h>

Public Member Functions

ByteBufferAllocateByteBuffer (size_t initial_size)
 Allocate a ByteBuffer. More...
 
void FreeByteBuffer (ByteBuffer *buffer_p)
 Free a ByteBuffer. More...
 
bool ResizeByteBuffer (ByteBuffer *buffer_p, size_t new_size)
 Resize a ByteBuffer. More...
 
bool ExtendByteBuffer (ByteBuffer *buffer_p, size_t increment)
 Increase the size of a ByteBuffer's data buffer. More...
 
bool AppendToByteBuffer (ByteBuffer *buffer_p, const void *data_p, const size_t data_length)
 Append some data to a ByteBuffer's data buffer. More...
 
bool AppendStringToByteBuffer (ByteBuffer *buffer_p, const char *const value_s)
 Append a string to a ByteBuffer's data buffer. More...
 
bool AppendStringsToByteBuffer (ByteBuffer *buffer_p, const char *value_s,...)
 Append a varargs array of strings to a ByteBuffer's data buffer. More...
 
bool AppendVarArgsToByteBuffer (ByteBuffer *buffer_p, const char *value_s, va_list args)
 Append a va_list of strings to a ByteBuffer's data buffer. More...
 
void ResetByteBuffer (ByteBuffer *buffer_p)
 Clear any data stored in a ByteBuffer. More...
 
size_t GetRemainingSpaceInByteBuffer (const ByteBuffer *const buffer_p)
 Get the remaining space in a ByteBuffer's data buffer. More...
 
size_t GetByteBufferSize (const ByteBuffer *const buffer_p)
 Get the currently used size of a ByteBuffer's data buffer. More...
 
const char * GetByteBufferData (const ByteBuffer *const buffer_p)
 Get the data stored in a ByteBuffer. More...
 
char * DetachByteBufferData (ByteBuffer *const buffer_p)
 Get the data stored in a ByteBuffer and free a ByteBuffer. More...
 
void RemoveFromByteBuffer (ByteBuffer *buffer_p, size_t size)
 Remove data from the end of a byte buffer. More...
 
void ReplaceCharsInByteBuffer (ByteBuffer *buffer_p, char old_data, char new_data)
 Replace each instance of a character within a ByteBuffer with another. More...
 

Detailed Description

A datatype to allow an automatically growing buffer for appending data to.

Member Function Documentation

◆ AllocateByteBuffer()

ByteBuffer * AllocateByteBuffer ( size_t  initial_size)

Allocate a ByteBuffer.

Parameters
initial_sizeThe initial size of the data buffer that this ByteBuffer will have.
Returns
The newly-allocated ByteBuffer or NULL on error.

◆ FreeByteBuffer()

void FreeByteBuffer ( ByteBuffer buffer_p)

Free a ByteBuffer.

Parameters
buffer_pThe ByteBuffer to free.

◆ ResizeByteBuffer()

bool ResizeByteBuffer ( ByteBuffer buffer_p,
size_t  new_size 
)

Resize a ByteBuffer.

The content of the data buffer will be preserved.

Parameters
buffer_pThe ByteBuffer to resize.
new_sizeThe new size of the ByteBuffer's data.
Returns
true if the resize was successful false upon failure. If the call failed, the contents of the data buffer are preserved.

◆ ExtendByteBuffer()

bool ExtendByteBuffer ( ByteBuffer buffer_p,
size_t  increment 
)

Increase the size of a ByteBuffer's data buffer.

The content of the data buffer will be preserved.

Parameters
buffer_pThe ByteBuffer to resize.
incrementThe amount to increase the ByteBuffer's data buffer.
Returns
true if the resize was successful false upon failure. If the call failed, the contents of the data buffer are preserved.

◆ AppendToByteBuffer()

bool AppendToByteBuffer ( ByteBuffer buffer_p,
const void *  data_p,
const size_t  data_length 
)

Append some data to a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer whose data buffer the new data will be appended to.
data_pThe data to append.
data_lengthThe length, in bytes, of the data to append.
Returns
true if the append was successful false upon failure. If the call failed, the contents of the data buffer are preserved.

◆ AppendStringToByteBuffer()

bool AppendStringToByteBuffer ( ByteBuffer buffer_p,
const char *const  value_s 
)

Append a string to a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer whose data buffer the string will be appended to.
value_sThe NULL terminated string to append.
Returns
true if the append was successful false upon failure. If the call failed, the contents of the data buffer are preserved.

◆ AppendStringsToByteBuffer()

bool AppendStringsToByteBuffer ( ByteBuffer buffer_p,
const char *  value_s,
  ... 
)

Append a varargs array of strings to a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer whose data buffer the string will be appended to.
value_sThe varags-style array of NULL terminated strings to append. The final entry in this varags-array must be a NULL.
Returns
true if the append was successful false upon failure. If the call failed, the contents of the data buffer are preserved.
See also
AppendVarArgsToByteBuffer

◆ AppendVarArgsToByteBuffer()

bool AppendVarArgsToByteBuffer ( ByteBuffer buffer_p,
const char *  value_s,
va_list  args 
)

Append a va_list of strings to a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer whose data buffer the string will be appended to.
value_sThe varargs-style array of NULL terminated strings to append. The final entry in this varargs-array must be a NULL.
argsThe varargs list of arguments used by value_s.
Returns
true if the append was successful false upon failure. If the call failed, the contents of the data buffer are preserved.

◆ ResetByteBuffer()

void ResetByteBuffer ( ByteBuffer buffer_p)

Clear any data stored in a ByteBuffer.

Parameters
buffer_pThe ByteBuffer who will have all of its data emptied.

◆ GetRemainingSpaceInByteBuffer()

size_t GetRemainingSpaceInByteBuffer ( const ByteBuffer *const  buffer_p)

Get the remaining space in a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer to get the remaining space for.
Returns
The space remaining by the ByteBuffer in bytes.

◆ GetByteBufferSize()

size_t GetByteBufferSize ( const ByteBuffer *const  buffer_p)

Get the currently used size of a ByteBuffer's data buffer.

Parameters
buffer_pThe ByteBuffer to get the space used for.
Returns
The space used by the ByteBuffer in bytes.

◆ GetByteBufferData()

const char * GetByteBufferData ( const ByteBuffer *const  buffer_p)

Get the data stored in a ByteBuffer.

Parameters
buffer_pThe ByteBuffer to get the data from.
Returns
The data as valid c-style string.

◆ DetachByteBufferData()

char * DetachByteBufferData ( ByteBuffer *const  buffer_p)

Get the data stored in a ByteBuffer and free a ByteBuffer.

Parameters
buffer_pThe ByteBuffer to get the data from which will be deallocated after this call.
Returns
The data as valid c-style string.

◆ RemoveFromByteBuffer()

void RemoveFromByteBuffer ( ByteBuffer buffer_p,
size_t  size 
)

Remove data from the end of a byte buffer.

Parameters
buffer_pThe ByteBuffer to remove the data from
sizeThe number of bytes to remove. If this is greater than the size of the ByteBuffer, then the ByteBUffer will be reset.

◆ ReplaceCharsInByteBuffer()

void ReplaceCharsInByteBuffer ( ByteBuffer buffer_p,
char  old_data,
char  new_data 
)

Replace each instance of a character within a ByteBuffer with another.

Parameters
buffer_pThe ByteBuffer to replace the character in.
old_dataThe character to be replaced.
new_dataThe replacement character.
See also
ReplaceChars

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