Function anjay_get_bytes
Defined in File io.h
Function Documentation
-
int anjay_get_bytes(anjay_input_ctx_t *ctx, size_t *out_bytes_read, bool *out_message_finished, void *out_buf, size_t buf_size)
Reads a chunk of data blob from the request message.
Consecutive calls to this function will return successive chunks of the data blob. Reaching end of the data is signaled by setting the
out_message_finishedflag.A call to this function will always attempt to read as much data as possible.
Example: writing a large data blob to file.
FILE *file; // initialize file bool finished; size_t bytes_read; char buf[1024]; do { if (anjay_get_bytes(ctx, &bytes_read, &finished, buf, sizeof(buf)) || fwrite(buf, 1, bytes_read, file) < bytes_read) { // handle error } } while (!finished);
- Parameters:
ctx – Input context to operate on.
out_bytes_read – [out] Number of bytes read.
out_message_finished – [out] Set to true if there is no more data to read.
out_buf – [out] Buffer to read data into.
buf_size – Number of bytes available in
out_buf.
- Returns:
0 on success, a negative value in case of error.