istream_consume()
#
Consumes data from the provided buffer (bf
) and processes it into the istream. The function stops when the specified amount of data (len
) is consumed or when the delimiter or required number of bytes is matched, triggering the configured event if applicable.
Prototype
PUBLIC size_t istream_consume(
istream_h istream,
char *bf,
size_t len
);
Parameters
Key |
Type |
Description |
---|---|---|
|
|
The handle to the istream where the data will be consumed. |
|
|
The input buffer containing the data to process. |
|
|
The length of the input buffer ( |
Return Value
Returns the number of bytes successfully consumed from the buffer.
Notes
If the istream is configured to read until a specified number of bytes (
num_bytes
):Data is appended to the internal gbuffer until the required number of bytes is reached.
Once the requirement is met, the associated event is triggered.
If the istream is configured to read until a delimiter:
Data is appended byte-by-byte to the internal gbuffer.
The delimiter is matched against the end of the gbuffer’s data.
If the delimiter is found, the associated event is triggered.
The function performs the following checks:
If
len
is0
, the function immediately returns0
.If the internal gbuffer is
NULL
, the function logs an error and returns0
.If the internal gbuffer becomes full while appending data, an error is logged, and the process stops.
When the event is triggered:
The current gbuffer is passed to the event handler.
A new gbuffer is created to continue processing subsequent data.
The
event
must be preconfigured using functions such asistream_read_until_delimiter
oristream_read_until_num_bytes
.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples