2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef GIMBAL_BYTE_ARRAY_H
19#define GIMBAL_BYTE_ARRAY_H
21#include "../strings/gimbal_string_view.h"
23#define GBL_SELF_TYPE GblByteArray
28
29
30
31
32
33
34
35
42
43
44
45
57
58
59
60
76
77
78
79
99
100
101
102
114
115
116
117
139#define GblByteArray_create(...)
140 GblByteArray_createDefault_
(__VA_ARGS__)
141#define GblByteArray_createDefault_(...)
143#define GblByteArray_createDefault__(bytes, data, ctx, ...)
144 (GblByteArray_create
)(bytes, data, ctx)
uint32_t GblHash
Type representing a calculated numeric hash across the codebase.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
Reference-counted resizable array of bytes.
GblRefCount GblByteArray_unref(GblByteArray *pSelf)
Decrements the reference counter of the given GblByteArray by 1, destroying it upon hitting 0.
GBL_RESULT GblByteArray_prepend(GblByteArray *pSelf, size_t bytes, const void *pData)
Prepends bytes from pData to the beginning of the given GblByteArray, returning a status code.
const char * GblByteArray_cString(const GblByteArray *pSelf)
Returns the GblByteArray as a C string, or NULL if it's not NULL-terminated.
GblBool GblByteArray_equals(const GblByteArray *pSelf, const GblByteArray *pRhs)
Returns GBL_TRUE if the values stored within the two byte arrays are all equal.
GBL_RESULT GblByteArray_append(GblByteArray *pSelf, size_t bytes, const void *pData)
Appends bytes from pData to the end of the given GblByteArray, returning a status code.
int GblByteArray_compare(const GblByteArray *pSelf, const GblByteArray *pRhs)
Compares the two byte arrays with semantics similar to memcmp(), returning the result.
GBL_RESULT GblByteArray_insert(GblByteArray *pSelf, size_t offset, size_t bytes, const void *pData)
Inserts bytes into the given GblByteArray at offset, copying from pData, returning a status code and ...
GblHash GblByteArray_hash(const GblByteArray *pSelf)
Computes a hash over the GblByteArray, returning its value.
GBL_RESULT GblByteArray_shrink(GblByteArray *pSelf, size_t bytes)
Shrinks the given GblByteArray by the given number of bytes, returning a status code.
GBL_RESULT GblByteArray_resize(GblByteArray *pSelf, size_t bytes)
Resizes the given GblByteArray to a size of bytes, appending byte values of 0 when growing,...
GBL_RESULT GblByteArray_set(GblByteArray *pSelf, size_t bytes, const void *pData)
Resizes the GblByteArray to bytes, copying pData over into its internal array.
void * GblByteArray_data(const GblByteArray *pSelf)
Returns the data pointer of the GblByteArray (GblByteArray::pData)
GBL_RESULT GblByteArray_move(GblByteArray *pSelf, GblByteArray *pOther)
Frees the existing allocation and takes the allocation from pOther, clearing it.
size_t GblByteArray_size(const GblByteArray *pSelf)
Returns the size of the GblByteArray (GblByteArray::size)
GblStringView GblByteArray_stringView(const GblByteArray *pSelf)
Returns a GblStringView spanning the bytes of the GblByteArray.
GblContext * GblByteArray_context(const GblByteArray *pSelf)
Returns the GblContext pointer the GblByteArray was constructed with.
GBL_RESULT GblByteArray_acquire(GblByteArray *pSelf, size_t bytes, void *pData)
Frees the existing allocation and takes the allocation given by pData with the given size.
GblRefCount GblByteArray_refCount(const GblByteArray *pSelf)
Returns the current number of active references to the given GblByteArray.
GblBool GblByteArray_empty(const GblByteArray *pSelf)
Return GBL_TRUE if the given GblByteArray is empty (0 bytes)
GBL_RESULT GblByteArray_release(GblByteArray *pSelf, size_t *pSize, void **ppData)
Releases the internal allocation resource, copying it and its size out, clearing them from pSelf.
GBL_RESULT GblByteArray_erase(GblByteArray *pSelf, size_t offset, size_t bytes)
Erases bytes from the given GblByteArray starting at offset, returning a status code.
GblByteArray * GblByteArray_ref(GblByteArray *pSelf)
Increments the reference counter of the given GblByteArray by 1, returning back a pointer to it.
GBL_RESULT GblByteArray_grow(GblByteArray *pSelf, size_t bytes)
Grows the given GblByteArray by the given number of bytes, filling the new ones with 0s,...
GBL_RESULT GblByteArray_write(GblByteArray *pSelf, size_t offset, size_t bytes, const void *pIn)
Attempts to write a range of bytes starting at offset, copying from pIn, returning a result code.
GBL_RESULT GblByteArray_read(const GblByteArray *pSelf, size_t offset, size_t bytes, void *pOut)
Attempts to read a range of bytes starting at offset, copying them to pOut, returning a result code.
GblByteArray * GblByteArray_create(size_t size, const void *pData, GblContext *pCtx)
Creates and returns a new GblByteArray, with the given size and optional initial data and context.
GBL_RESULT GblByteArray_clear(GblByteArray *pSelf)
Clears all bytes from the given GblByteArray, freeing its allocation and resetting its size to 0.
uint8_t GblByteArray_at(const GblByteArray *pSelf, size_t index)
Returns the value of the byte located at the given index, raising an error upon out-of-range access.
size_t size
Size of the pData structure.
GBL_RESULT GblByteArray_copy(GblByteArray *pSelf, const GblByteArray *pOther)
Frees the existing allocation and copies over the allocation and size from pOther.
uint8_t * pData
Actual data payload, contiguously-allocated array of bytes.