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.
byte_buffer.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
21 #ifndef BYTE_BUFFER_H
22 #define BYTE_BUFFER_H
23 
24 #include <stdarg.h>
25 #include <stddef.h>
26 
28 #include "typedefs.h"
29 
35 typedef struct ByteBuffer
36 {
38  char *bb_data_p;
39  size_t bb_size;
40  size_t bb_current_index;
41 } ByteBuffer;
42 
43 
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50 
51 
60 
61 
69 
70 
81 GRASSROOTS_UTIL_API bool ResizeByteBuffer (ByteBuffer *buffer_p, size_t new_size);
82 
83 
94 GRASSROOTS_UTIL_API bool ExtendByteBuffer (ByteBuffer *buffer_p, size_t increment);
95 
96 
107 GRASSROOTS_UTIL_API bool AppendToByteBuffer (ByteBuffer *buffer_p, const void *data_p, const size_t data_length);
108 
109 
119 GRASSROOTS_UTIL_API bool AppendStringToByteBuffer (ByteBuffer *buffer_p, const char * const value_s);
120 
121 
133 GRASSROOTS_UTIL_API bool AppendStringsToByteBuffer (ByteBuffer *buffer_p, const char *value_s, ...);
134 
135 
147 GRASSROOTS_UTIL_API bool AppendVarArgsToByteBuffer (ByteBuffer *buffer_p, const char *value_s, va_list args);
148 
149 
158 
159 
167 GRASSROOTS_UTIL_API size_t GetRemainingSpaceInByteBuffer (const ByteBuffer * const buffer_p);
168 
169 
177 GRASSROOTS_UTIL_API size_t GetByteBufferSize (const ByteBuffer * const buffer_p);
178 
179 
187 GRASSROOTS_UTIL_API const char *GetByteBufferData (const ByteBuffer * const buffer_p);
188 
189 
190 
199 GRASSROOTS_UTIL_API char *DetachByteBufferData (ByteBuffer * const buffer_p);
200 
201 
202 
211 GRASSROOTS_UTIL_API void RemoveFromByteBuffer (ByteBuffer *buffer_p, size_t size);
212 
213 
223 GRASSROOTS_UTIL_API void ReplaceCharsInByteBuffer (ByteBuffer *buffer_p, char old_data, char new_data);
224 
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 
231 
232 #endif /* #ifndef BYTE_BUFFER_H */
grassroots_util_library.h
ByteBuffer::AppendStringToByteBuffer
bool AppendStringToByteBuffer(ByteBuffer *buffer_p, const char *const value_s)
Append a string to a ByteBuffer's data buffer.
ByteBuffer::AppendStringsToByteBuffer
bool AppendStringsToByteBuffer(ByteBuffer *buffer_p, const char *value_s,...)
Append a varargs array of strings to a ByteBuffer's data buffer.
ByteBuffer::ReplaceCharsInByteBuffer
void ReplaceCharsInByteBuffer(ByteBuffer *buffer_p, char old_data, char new_data)
Replace each instance of a character within a ByteBuffer with another.
ByteBuffer::ResetByteBuffer
void ResetByteBuffer(ByteBuffer *buffer_p)
Clear any data stored in a ByteBuffer.
ByteBuffer::RemoveFromByteBuffer
void RemoveFromByteBuffer(ByteBuffer *buffer_p, size_t size)
Remove data from the end of a byte buffer.
ByteBuffer::GetByteBufferData
const char * GetByteBufferData(const ByteBuffer *const buffer_p)
Get the data stored in a ByteBuffer.
ByteBuffer::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.
typedefs.h
ByteBuffer::GetByteBufferSize
size_t GetByteBufferSize(const ByteBuffer *const buffer_p)
Get the currently used size of a ByteBuffer's data buffer.
ByteBuffer::ResizeByteBuffer
bool ResizeByteBuffer(ByteBuffer *buffer_p, size_t new_size)
Resize a ByteBuffer.
ByteBuffer::ExtendByteBuffer
bool ExtendByteBuffer(ByteBuffer *buffer_p, size_t increment)
Increase the size of a ByteBuffer's data buffer.
ByteBuffer::DetachByteBufferData
char * DetachByteBufferData(ByteBuffer *const buffer_p)
Get the data stored in a ByteBuffer and free a ByteBuffer.
ByteBuffer::AppendToByteBuffer
bool AppendToByteBuffer(ByteBuffer *buffer_p, const void *data_p, const size_t data_length)
Append some data to a ByteBuffer's data buffer.
ByteBuffer::GetRemainingSpaceInByteBuffer
size_t GetRemainingSpaceInByteBuffer(const ByteBuffer *const buffer_p)
Get the remaining space in a ByteBuffer's data buffer.
ByteBuffer::AllocateByteBuffer
ByteBuffer * AllocateByteBuffer(size_t initial_size)
Allocate a ByteBuffer.
ByteBuffer
A datatype to allow an automatically growing buffer for appending data to.
Definition: byte_buffer.h:35
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
ByteBuffer::FreeByteBuffer
void FreeByteBuffer(ByteBuffer *buffer_p)
Free a ByteBuffer.