-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c41d59c
commit c740f37
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef ALLOCX_BUFFER_H | ||
#define ALLOCX_BUFFER_H | ||
|
||
#include "allocx_core_types.h" | ||
#include "allocx_atomic.h" | ||
#include "allocx_errors.h" | ||
|
||
typedef struct AllocXBuffer | ||
{ | ||
mem_ptr_t memory_start; // Start of the buffer | ||
usize capacity; // Total capacity of the buffer | ||
usize start; // Read position | ||
usize end; // Write position | ||
} AllocXBuffer; | ||
|
||
/** | ||
* Initialize a buffer with the specified capacity. | ||
* @param buf Pointer to AllocXBuffer | ||
* @param capacity Size of the buffer in bytes | ||
* @return ALLOCX_SUCCESS on success, or an appropriate error code | ||
*/ | ||
allocx_error_t allocx_buffer_init(AllocXBuffer *buf, usize capacity); | ||
|
||
/** | ||
* Free resources associated with the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
*/ | ||
void allocx_buffer_destroy(AllocXBuffer *buf); | ||
|
||
/** | ||
* Reset the buffer for reuse. | ||
* @param buf Pointer to AllocXBuffer | ||
*/ | ||
void allocx_buffer_reset(AllocXBuffer *buf); | ||
|
||
/** | ||
* Get the size of data currently in the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
* @return Size of data in bytes | ||
*/ | ||
usize allocx_buffer_size(const AllocXBuffer *buf); | ||
|
||
/** | ||
* Get the remaining space in the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
* @return Remaining space in bytes | ||
*/ | ||
usize allocx_buffer_remaining(const AllocXBuffer *buf); | ||
|
||
/** | ||
* Write a single byte to the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
* @param byte Byte to write | ||
*/ | ||
void allocx_buffer_put(AllocXBuffer *buf, u8 byte); | ||
|
||
/** | ||
* Peek at a single byte from the buffer without advancing the read pointer. | ||
* @param buf Pointer to AllocXBuffer | ||
* @return The byte at the current read position | ||
*/ | ||
u8 allocx_buffer_peek(const AllocXBuffer *buf); | ||
|
||
/** | ||
* Read a single byte from the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
* @return The byte read | ||
*/ | ||
u8 allocx_buffer_get(AllocXBuffer *buf); | ||
|
||
/** | ||
* Compact the buffer to make room for more data. | ||
* Moves remaining data to the start of the buffer. | ||
* @param buf Pointer to AllocXBuffer | ||
*/ | ||
void allocx_buffer_compact(AllocXBuffer *buf); | ||
|
||
/** | ||
* Append data from one buffer to another. | ||
* @param dst Destination buffer | ||
* @param src Source buffer | ||
* @return ALLOCX_SUCCESS on success, or an error code | ||
*/ | ||
allocx_error_t allocx_buffer_append(AllocXBuffer *dst, const AllocXBuffer *src); | ||
|
||
#endif // ALLOCX_BUFFER_H |