dtarray_int32
Fixed-capacity int32 array with pack and unpack helpers.
This group of functions provides fixed-capacity int32 storage with byte-level serialization. Use it where array size is known at creation and serialized I/O binary is deterministic.
Mini-guide
- Creates instances with a fixed element count by allocating one contiguous block.
- Access the
itemspointer directly for element storage. - Dispose instances when done.
- Serialize by computing pack length before writing to a buffer.
- Deserialize by unpacking into an existing array capacity.
Example
dtarray_int32_t* arr = NULL;
dterr_t* err = dtarray_int32_create(&arr, 4);
arr->items[0] = 10;
arr->items[1] = 20;
if (!err)
{
int32_t len = dtarray_int32_pack_length(arr);
uint8_t buffer[64];
dtarray_int32_pack(arr, buffer, 0, sizeof(buffer));
dtarray_int32_unpack(arr, buffer, 0, sizeof(buffer));
dtarray_int32_dispose(arr);
}
Data structures
dtarray_int32_t
Represents a fixed-capacity array of int32 values with contiguous storage.
Members:
int32_t countTotal element count and logical capacity.
int32_t* itemsPointer to the first element within the same allocation.
Functions
dtarray_int32_create
Allocates and initializes a fixed-capacity array instance.
Params:
dtarray_int32_t** array_int32Output pointer that receives the new instance.
int32_t countNumber of elements to allocate as fixed capacity.
Return: dterr_t* Error object on failure, or null on success.
dtarray_int32_dispose
Releases all storage owned by an array instance.
Params:
dtarray_int32_t* selfInstance to dispose, or null.
Return: void No return value.
dtarray_int32_pack
Serializes the array into a byte buffer starting at a given offset.
Params:
const dtarray_int32_t* selfSource array to serialize.
uint8_t* outputDestination buffer for packed bytes.
int32_t offsetStarting offset into the destination buffer.
int32_t buflenTotal size of the destination buffer.
Return: int32_t Number of bytes written, or a negative value on failure.
dtarray_int32_pack_length
Computes the number of bytes required to serialize the array.
Params:
const dtarray_int32_t* selfSource array whose packed length is queried.
Return: int32_t Required byte count, or a negative value on invalid input.
dtarray_int32_unpack
Deserializes array contents from a byte buffer starting at a given offset.
Params:
dtarray_int32_t* selfDestination array with fixed capacity.
const uint8_t* inputSource buffer containing packed data.
int32_t offsetStarting offset into the source buffer.
int32_t buflenTotal size of the source buffer.
Return: int32_t Number of bytes consumed, or a negative value on failure.