Function anjay_ret_bytes_begin
Defined in File io.h
Function Documentation
-
anjay_ret_bytes_ctx_t *anjay_ret_bytes_begin(anjay_output_ctx_t *ctx, size_t length)
Marks the beginning of raw data returned from the data model handler. Used in conjunction with anjay_ret_bytes_append to return a large blob of data in multiple chunks.
Example: file content in the response.
FILE *file; size_t filesize; // initialize file and filesize anjay_ret_bytes_ctx_t *bytes_ctx = anjay_ret_bytes_begin(ctx, filesize); if (!bytes_ctx) { // handle error } size_t bytes_read; char buffer[1024]; while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) { if (anjay_ret_bytes_append(bytes_ctx, buffer, bytes_read)) { // handle error } }
If a zero-length value is to be returned, it is safe both not to call anjay_ret_bytes_append at all, or to call it any number of times with a
lengthargument equal to zero.- Parameters:
ctx – Output context to write data into.
length – Size of the data to be written.
- Returns:
Output context used to return the data or NULL in case of error.