开始设计
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef INCLUDED_C_FASTBYTERINGBUFFER_H
|
||||
#define INCLUDED_C_FASTBYTERINGBUFFER_H
|
||||
|
||||
#ifndef INCLUDED_C_BASE_H
|
||||
#include <c_Base.h>
|
||||
#endif /*INCLUDED_C_BASE_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);
|
||||
|
||||
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);
|
||||
|
||||
#endif /*INCLUDED_C_FASTBYTERINGBUFFER_H*/
|
||||
Reference in New Issue
Block a user