26 #include <sys/param.h>
29 const char* format, va_list args);
34 .
data = (uint8_t*)(data), .len = len
41 .
data = (uint8_t*)str, .len = strlen(str)
47 for (
size_t i = 0; i < array.
len; i++) {
48 array.
data[i] = (uint8_t)(i & 0x0FFu);
54 assert(array.
data != NULL);
55 assert(start < array.
len);
56 assert(start + len <= array.
len);
58 .data = &array.
data[start], .len = len
64 assert(buffer != NULL);
73 .array = (
ByteArray) {.data = (uint8_t*)data, .len = max_len},
119 assert(buffer != NULL);
125 assert(remaining >= 0);
126 size_t len = MIN(max_len, (
size_t)remaining);
137 assert(buffer != NULL);
139 assert(data != NULL);
145 assert(buffer != NULL);
151 assert(buffer != NULL);
153 assert(array.
data != NULL);
164 assert(buffer != NULL);
166 assert(bufferToAppend.
array.
data != NULL);
178 assert(buffer != NULL);
181 int len = strlen(str);
197 long extraLen = vsnprintf(start, remainingLen, format, args);
198 if (startLen + extraLen >= maxLen) {
207 assert(buffer != NULL);
212 va_start(args, format);
218 return failed ? NULL : buffer;
226 va_start(args, format);
237 assert(buffer != NULL);
242 for (
size_t i = 0; i < len; i++) {
264 assert(data != NULL);
ByteArray ByteArray_CreateWithCString(const char *str)
ByteBuffer * ByteBuffer_AppendCString(ByteBuffer *buffer, const char *str)
Structure for handling generic arrays of bytes.
ByteBuffer ByteBuffer_CreateAndAppendDummyData(void *data, size_t max_len, size_t len)
Structure for an embedded ByteArray as a buffer.
void ByteBuffer_Reset(ByteBuffer *buffer)
long ByteBuffer_BytesRemaining(const ByteBuffer buffer)
ByteBuffer * ByteBuffer_AppendFormattedCString(ByteBuffer *buffer, const char *format,...)
ByteBuffer * ByteBuffer_AppendArray(ByteBuffer *buffer, const ByteArray array)
ByteBuffer ByteBuffer_CreateWithArray(ByteArray array)
ByteArray ByteBuffer_Consume(ByteBuffer *buffer, size_t max_len)
void ByteBuffer_Free(ByteBuffer buffer)
ByteBuffer ByteBuffer_Malloc(size_t size)
ByteBuffer ByteBuffer_Create(void *data, size_t max_len, size_t used)
ByteBuffer * ByteBuffer_AppendBuffer(ByteBuffer *buffer, const ByteBuffer bufferToAppend)
bool ByteBuffer_IsNull(ByteBuffer const buffer)
ByteBuffer ByteBuffer_CreateAndAppend(void *data, size_t max_len, const void *value, size_t value_len)
ByteBuffer * ByteBuffer_AppendDummyData(ByteBuffer *buffer, size_t len)
ByteArray array
ByteArray holding allocated array w/length = allocated size.
ByteBuffer * ByteBuffer_Append(ByteBuffer *buffer, const void *data, size_t len)
void ByteArray_FillWithDummyData(ByteArray array)
static ByteBuffer * append_formatted_cstring_va_list(ByteBuffer *buffer, const char *format, va_list args)
size_t len
Number of bytes in the data field.
#define BYTE_ARRAY_NONE
Convenience macro to represent an empty array with no data.
ByteArray ByteArray_Create(void *data, size_t len)
uint8_t * data
Pointer to an allocated array of data bytes.
ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len)
ByteBuffer ByteBuffer_CreateAndAppendFormattedCString(void *data, size_t max_len, const char *format,...)
size_t bytesUsed
Reflects the number of bytes used from the array
ByteBuffer ByteBuffer_CreateAndAppendArray(void *data, size_t max_len, const ByteArray value)
ByteBuffer ByteBuffer_CreateAndAppendCString(void *data, size_t max_len, const char *value)
ByteBuffer ByteBuffer_MallocAndAppend(const void *data, size_t len)