Foundations
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#ifndef INCLUDED_C_FASTBYTERINGBUFFER_H
|
||||
#define INCLUDED_C_FASTBYTERINGBUFFER_H
|
||||
|
||||
#ifndef INCLUDED_C_TYPES_H
|
||||
#include <c_Types.h>
|
||||
#endif /*INCLUDED_C_TYPES_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
uint8_t* buffer; // 連續的位元組陣列
|
||||
c_size_t capacity; // 必為 2 的冪次方 (e.g., 16, 32, 64, 256)
|
||||
c_size_t mask; // 快取 (capacity - 1),用來進行位元與運算
|
||||
c_size_t head; // 讀取指標
|
||||
c_size_t tail; // 寫入指標
|
||||
c_bool_t is_full; // 狀態區分旗標
|
||||
} c_FastByteRingBuffer_t;
|
||||
|
||||
c_err_t c_FastByteRingBuffer_Init(c_FastByteRingBuffer_t* self, c_size_t capacity);
|
||||
void c_FastByteRingBuffer_Destroy(c_FastByteRingBuffer_t* self);
|
||||
|
||||
c_err_t c_FastByteRingBuffer_WriteByte(c_FastByteRingBuffer_t* self, uint8_t byte);
|
||||
c_err_t c_FastByteRingBuffer_ReadByte(c_FastByteRingBuffer_t* self, uint8_t* out_byte);
|
||||
|
||||
/*
|
||||
* Writes a bulk buffer span into the fast ring buffer without overwriting existing data.
|
||||
* @param self: The fast ring buffer instance.
|
||||
* @param src: Source byte array pointer.
|
||||
* @param len: Number of bytes to transfer.
|
||||
* @return The actual number of bytes written into the buffer.
|
||||
*/
|
||||
c_size_t c_FastByteRingBuffer_WriteBuffer(c_FastByteRingBuffer_t* self, const uint8_t* src, c_size_t len);
|
||||
|
||||
c_size_t c_FastByteRingBuffer_ReadBuffer(c_FastByteRingBuffer_t* self, uint8_t* dest, c_size_t len);
|
||||
|
||||
c_size_t c_FastByteRingBuffer_GetSize(const c_FastByteRingBuffer_t* self);
|
||||
c_bool_t c_FastByteRingBuffer_IsEmpty(const c_FastByteRingBuffer_t* self);
|
||||
c_bool_t c_FastByteRingBuffer_IsFull(const c_FastByteRingBuffer_t* self);
|
||||
|
||||
|
||||
/* 新增的進階控制接口 */
|
||||
void c_FastByteRingBuffer_WriteByteOverwrite(c_FastByteRingBuffer_t* self, uint8_t byte);
|
||||
c_size_t c_FastByteRingBuffer_WriteBufferOverwrite(c_FastByteRingBuffer_t* self, const uint8_t* src, c_size_t len);
|
||||
|
||||
c_err_t c_FastByteRingBuffer_PeekByte(const c_FastByteRingBuffer_t* self, uint8_t* out_byte);
|
||||
c_size_t c_FastByteRingBuffer_PeekBuffer(const c_FastByteRingBuffer_t* self, uint8_t* dest, c_size_t len);
|
||||
|
||||
c_size_t c_FastByteRingBuffer_Discard(c_FastByteRingBuffer_t* self, c_size_t len);
|
||||
const uint8_t* c_FastByteRingBuffer_GetReadPtr(const c_FastByteRingBuffer_t* self, c_size_t* out_contiguous_len);
|
||||
uint8_t* c_FastByteRingBuffer_GetWritePtr(const c_FastByteRingBuffer_t* self, c_size_t* out_contiguous_len);
|
||||
|
||||
|
||||
c_index_t c_FastByteRingBuffer_IndexOfByte(const c_FastByteRingBuffer_t* self, uint8_t target);
|
||||
c_index_t c_FastByteRingBuffer_IndexOfBuffer(const c_FastByteRingBuffer_t* self, const uint8_t* pattern, c_size_t pattern_len);
|
||||
c_index_t c_FastByteRingBuffer_LastIndexOfBuffer(const c_FastByteRingBuffer_t* self, const uint8_t* pattern, c_size_t pattern_len);
|
||||
|
||||
c_size_t c_FastByteRingBuffer_ReadUntilToken(c_FastByteRingBuffer_t* self, const uint8_t* token, c_size_t token_len, uint8_t* dest, c_size_t dest_max_len);
|
||||
c_err_t c_FastByteRingBuffer_GetAtRelative(const c_FastByteRingBuffer_t* self, c_size_t relative_offset, uint8_t* out_byte);
|
||||
c_bool_t c_FastByteRingBuffer_Is(const c_FastByteRingBuffer_t* self, c_index_t offset, uint8_t value);
|
||||
int c_FastByteRingBuffer_Memcmp(const c_FastByteRingBuffer_t* self, c_size_t offset, const uint8_t* buffer, c_size_t len);
|
||||
c_err_t c_FastByteRingBuffer_Strtoul(const c_FastByteRingBuffer_t* self, c_size_t offset, int base, unsigned long* out_value, c_size_t* out_end_offset);
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_FASTBYTERINGBUFFER_H*/
|
||||
Reference in New Issue
Block a user