|
CX Framework
Cross-platform C utility framework
|
Functions | |
| bool | sbufCRegisterPull (StreamBuffer *sb, sbufCleanupCB ccleanup, void *ctx) |
| bool | sbufCRegisterPush (StreamBuffer *sb, sbufNotifyCB cnotify, sbufCleanupCB ccleanup, void *ctx) |
| bool | sbufCRegisterPushDirect (StreamBuffer *sb, sbufPushCB cpush, sbufCleanupCB ccleanup, void *ctx) |
| size_t | sbufCAvail (StreamBuffer *sb) |
| bool | sbufCRead (StreamBuffer *sb, uint8 *buf, size_t sz, size_t *bytesread) |
| bool | sbufCPeek (StreamBuffer *sb, uint8 *buf, size_t off, size_t sz) |
| bool | sbufCFeed (StreamBuffer *sb, size_t minsz) |
| bool | sbufCSend (StreamBuffer *sb, sbufSendCB func, size_t sz) |
| bool | sbufCSkip (StreamBuffer *sb, size_t bytes) |
| void | sbufCFinish (StreamBuffer *sb) |
Functions for the consumer side of stream buffer operations.
| size_t sbufCAvail | ( | StreamBuffer * | sb | ) |
size_t sbufCAvail(StreamBuffer *sb)
Returns how much data is currently buffered and ready to consume.
| sb | The stream buffer |
| bool sbufCFeed | ( | StreamBuffer * | sb, |
| size_t | minsz | ||
| ) |
bool sbufCFeed(StreamBuffer *sb, size_t minsz)
For pull mode only - feeds the buffer until it has at least the requested bytes.
Similar to sbufCRead() but doesn't consume the data. Useful for peek-ahead operations. Keeps calling producer until enough data is available or producer finishes.
| sb | The stream buffer |
| minsz | Minimum bytes to ensure are buffered |
| void sbufCFinish | ( | StreamBuffer * | sb | ) |
void sbufCFinish(StreamBuffer *sb)
Marks the consumer as finished.
CRITICAL: The consumer MUST NOT access the stream buffer after calling this function as it may be immediately deallocated.
| sb | The stream buffer (invalidated after call) |
| bool sbufCPeek | ( | StreamBuffer * | sb, |
| uint8 * | buf, | ||
| size_t | off, | ||
| size_t | sz | ||
| ) |
bool sbufCPeek(StreamBuffer *sb, uint8 *buf, size_t off, size_t sz)
Peeks at data in the buffer without consuming it.
Pull mode: Only reads unconsumed data already in buffer, does NOT call producer.
Push mode: Reads from buffered data.
Never short-reads; fails if insufficient data is available (check sbufCAvail first).
| sb | The stream buffer |
| buf | Buffer to read into |
| off | Offset from start of available data |
| sz | Number of bytes to peek |
| bool sbufCRead | ( | StreamBuffer * | sb, |
| uint8 * | buf, | ||
| size_t | sz, | ||
| size_t * | bytesread | ||
| ) |
bool sbufCRead(StreamBuffer *sb, uint8 *buf, size_t sz, size_t *bytesread)
Reads data from the stream buffer.
Pull mode: Repeatedly calls the producer's callback to satisfy the request. Only short-reads when producer finishes (EOF).
Push mode: Returns only buffered data. Fails if requesting more than available.
| sb | The stream buffer |
| buf | Buffer to read into |
| sz | Number of bytes to read |
| bytesread | Output: actual number of bytes read |
| bool sbufCRegisterPull | ( | StreamBuffer * | sb, |
| sbufCleanupCB | ccleanup, | ||
| void * | ctx | ||
| ) |
bool sbufCRegisterPull(StreamBuffer *sb, sbufCleanupCB ccleanup, void *ctx)
Registers a consumer with the stream buffer in pull mode.
In pull mode, the consumer explicitly reads data using sbufCRead() or sbufCSend().
| sb | The stream buffer |
| ccleanup | Optional cleanup callback for ctx |
| ctx | Optional user context passed to cleanup |
| bool sbufCRegisterPush | ( | StreamBuffer * | sb, |
| sbufNotifyCB | cnotify, | ||
| sbufCleanupCB | ccleanup, | ||
| void * | ctx | ||
| ) |
bool sbufCRegisterPush(StreamBuffer *sb, sbufNotifyCB cnotify, sbufCleanupCB ccleanup, void *ctx)
Registers a consumer with the stream buffer in push mode with notifications.
The notify callback is called when data becomes available. The consumer then uses sbufCRead() or sbufCSend() to retrieve the data.
| sb | The stream buffer |
| cnotify | Notification callback |
| ccleanup | Optional cleanup callback for ctx |
| ctx | Optional user context passed to callbacks |
| bool sbufCRegisterPushDirect | ( | StreamBuffer * | sb, |
| sbufPushCB | cpush, | ||
| sbufCleanupCB | ccleanup, | ||
| void * | ctx | ||
| ) |
bool sbufCRegisterPushDirect(StreamBuffer *sb, sbufPushCB cpush, sbufCleanupCB ccleanup, void *ctx)
Registers a consumer with the stream buffer in direct push mode.
In direct mode, data is pushed immediately to the consumer's callback without buffering. The consumer must process data immediately as it will not be retained.
| sb | The stream buffer |
| cpush | Push callback to receive data |
| ccleanup | Optional cleanup callback for ctx |
| ctx | Optional user context passed to callbacks |
| bool sbufCSend | ( | StreamBuffer * | sb, |
| sbufSendCB | func, | ||
| size_t | sz | ||
| ) |
bool sbufCSend(StreamBuffer *sb, sbufSendCB func, size_t sz)
Sends data from buffer to callback with zero-copy optimization.
The callback may be invoked multiple times with different chunks.
Push mode: More efficient than sbufCRead() as it avoids an extra copy by passing pointers to internal buffer directly to the callback.
Pull mode: Functions like sbufCRead(), calling producer to fill buffer before invoking the callback.
| sb | The stream buffer |
| func | Send callback to receive data |
| sz | Maximum bytes to send |
| bool sbufCSkip | ( | StreamBuffer * | sb, |
| size_t | bytes | ||
| ) |
bool sbufCSkip(StreamBuffer *sb, size_t bytes)
Skips over bytes in the buffer without reading them.
Can be used in conjunction with sbufCPeek() to peek ahead and then skip.
| sb | The stream buffer |
| bytes | Number of bytes to skip |