CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Consumer Functions

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)
 

Detailed Description

Functions for the consumer side of stream buffer operations.

Function Documentation

◆ sbufCAvail()

size_t sbufCAvail ( StreamBuffer *  sb)

size_t sbufCAvail(StreamBuffer *sb)

Returns how much data is currently buffered and ready to consume.

Parameters
sbThe stream buffer
Returns
Number of bytes available

◆ sbufCFeed()

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.

Parameters
sbThe stream buffer
minszMinimum bytes to ensure are buffered
Returns
true if request satisfied, false if producer finished before providing enough

◆ sbufCFinish()

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.

Parameters
sbThe stream buffer (invalidated after call)

◆ sbufCPeek()

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).

Parameters
sbThe stream buffer
bufBuffer to read into
offOffset from start of available data
szNumber of bytes to peek
Returns
true on success, false if not enough data available

◆ sbufCRead()

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.

Parameters
sbThe stream buffer
bufBuffer to read into
szNumber of bytes to read
bytesreadOutput: actual number of bytes read
Returns
true if any data was read, false on error or no data available

◆ sbufCRegisterPull()

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().

Parameters
sbThe stream buffer
ccleanupOptional cleanup callback for ctx
ctxOptional user context passed to cleanup
Returns
true on success, false if already registered or invalid mode

◆ sbufCRegisterPush()

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.

Parameters
sbThe stream buffer
cnotifyNotification callback
ccleanupOptional cleanup callback for ctx
ctxOptional user context passed to callbacks
Returns
true on success, false if already registered or invalid mode

◆ sbufCRegisterPushDirect()

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.

Parameters
sbThe stream buffer
cpushPush callback to receive data
ccleanupOptional cleanup callback for ctx
ctxOptional user context passed to callbacks
Returns
true on success, false if already registered or invalid mode

◆ sbufCSend()

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.

Parameters
sbThe stream buffer
funcSend callback to receive data
szMaximum bytes to send
Returns
true on success

◆ sbufCSkip()

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.

Parameters
sbThe stream buffer
bytesNumber of bytes to skip
Returns
true on success, false if not enough data available