CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
String Consumers

Functions

bool sbufStrOut (StreamBuffer *sb, string *strout)
 
bool sbufStrCRegisterPush (StreamBuffer *sb, string *strout)
 

Detailed Description

Functions for using strings as stream buffer data sinks.

Function Documentation

◆ sbufStrCRegisterPush()

bool sbufStrCRegisterPush ( StreamBuffer *  sb,
string *  strout 
)

bool sbufStrCRegisterPush(StreamBuffer *sb, string *strout)

Registers a string as a consumer with the stream buffer in push mode.

In push mode, data is automatically appended to the string as it becomes available from the producer. Use this instead of sbufStrOut() when you need the producer and consumer to operate asynchronously.

Note: This function appends to the string rather than overwriting it.

Parameters
sbThe stream buffer
stroutString to append output data to
Returns
true on success, false if registration failed

◆ sbufStrOut()

bool sbufStrOut ( StreamBuffer *  sb,
string *  strout 
)

bool sbufStrOut(StreamBuffer *sb, string *strout)

Consumes all available data from the buffer and outputs to a string.

Reads data from the stream buffer until the producer finishes (EOF) and writes it to the output string, overwriting any existing contents.

IMPORTANT: The stream buffer is invalidated after this call.

Parameters
sbThe stream buffer (invalidated after call)
stroutOutput string (will be overwritten)
Returns
true on success, false on error

Example:

StreamBuffer *sb = sbufCreate(4096);
sbufStrPRegisterPull(sb, inputData);
string output = 0;
sbufStrOut(sb, &output);
// use output
strDestroy(&output);
StreamBuffer * sbufCreate(size_t targetsz)
bool sbufStrOut(StreamBuffer *sb, string *strout)
bool sbufStrPRegisterPull(StreamBuffer *sb, strref str)
void strDestroy(strhandle ps)