Program Listing for File io.h
↰ Return to documentation for file (include_public/anjay/io.h)
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
}
}
// 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);
/*
* Copyright 2017-2026 AVSystem <avsystem@avsystem.com>
* AVSystem Anjay LwM2M SDK
* All rights reserved.
*
* Licensed under AVSystem Anjay LwM2M Client SDK - Non-Commercial License.
* See the attached LICENSE file for details.
*/
#ifndef ANJAY_INCLUDE_ANJAY_IO_H
#define ANJAY_INCLUDE_ANJAY_IO_H
#include <anjay/core.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct anjay_dm_list_ctx_struct anjay_dm_list_ctx_t;
void anjay_dm_emit(anjay_dm_list_ctx_t *ctx, uint16_t id);
typedef struct anjay_dm_resource_list_ctx_struct anjay_dm_resource_list_ctx_t;
typedef enum {
ANJAY_DM_RES_R,
ANJAY_DM_RES_W,
ANJAY_DM_RES_RW,
ANJAY_DM_RES_RM,
ANJAY_DM_RES_WM,
ANJAY_DM_RES_RWM,
ANJAY_DM_RES_E,
ANJAY_DM_RES_BS_RW
} anjay_dm_resource_kind_t;
typedef enum {
ANJAY_DM_RES_ABSENT = 0,
ANJAY_DM_RES_PRESENT = 1
} anjay_dm_resource_presence_t;
void anjay_dm_emit_res(anjay_dm_resource_list_ctx_t *ctx,
anjay_rid_t rid,
anjay_dm_resource_kind_t kind,
anjay_dm_resource_presence_t presence);
typedef struct anjay_output_ctx_struct anjay_output_ctx_t;
typedef struct anjay_ret_bytes_ctx_struct anjay_ret_bytes_ctx_t;
anjay_ret_bytes_ctx_t *anjay_ret_bytes_begin(anjay_output_ctx_t *ctx,
size_t length);
int anjay_ret_bytes_append(anjay_ret_bytes_ctx_t *ctx,
const void *data,
size_t length);
int anjay_ret_bytes(anjay_output_ctx_t *ctx, const void *data, size_t length);
int anjay_ret_string(anjay_output_ctx_t *ctx, const char *value);
int anjay_ret_i64(anjay_output_ctx_t *ctx, int64_t value);
static inline int anjay_ret_i32(anjay_output_ctx_t *ctx, int32_t value) {
return anjay_ret_i64(ctx, value);
}
#ifdef ANJAY_WITH_LWM2M11
int anjay_ret_u64(anjay_output_ctx_t *ctx, uint64_t value);
static inline int anjay_ret_u32(anjay_output_ctx_t *ctx, uint32_t value) {
return anjay_ret_u64(ctx, value);
}
#endif // ANJAY_WITH_LWM2M11
int anjay_ret_double(anjay_output_ctx_t *ctx, double value);
static inline int anjay_ret_float(anjay_output_ctx_t *ctx, float value) {
return anjay_ret_double(ctx, value);
}
int anjay_ret_bool(anjay_output_ctx_t *ctx, bool value);
int anjay_ret_objlnk(anjay_output_ctx_t *ctx, anjay_oid_t oid, anjay_iid_t iid);
#ifdef ANJAY_WITH_SECURITY_STRUCTURED
int anjay_ret_certificate_chain_info(
anjay_output_ctx_t *ctx,
avs_crypto_certificate_chain_info_t certificate_chain_info);
int anjay_ret_private_key_info(anjay_output_ctx_t *ctx,
avs_crypto_private_key_info_t private_key_info);
int anjay_ret_psk_identity_info(
anjay_output_ctx_t *ctx,
avs_crypto_psk_identity_info_t psk_identity_info);
int anjay_ret_psk_key_info(anjay_output_ctx_t *ctx,
avs_crypto_psk_key_info_t psk_key_info);
#endif // ANJAY_WITH_SECURITY_STRUCTURED
typedef struct anjay_input_ctx_struct anjay_input_ctx_t;
#define ANJAY_EXECUTE_GET_ARG_END 1
typedef struct anjay_execute_ctx_struct anjay_execute_ctx_t;
int anjay_execute_get_next_arg(anjay_execute_ctx_t *ctx,
int *out_arg,
bool *out_has_value);
int anjay_execute_get_arg_value(anjay_execute_ctx_t *ctx,
size_t *out_bytes_read,
char *out_buf,
size_t buf_size);
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);
#define ANJAY_BUFFER_TOO_SHORT 1
int anjay_get_string(anjay_input_ctx_t *ctx, char *out_buf, size_t buf_size);
int anjay_get_i32(anjay_input_ctx_t *ctx, int32_t *out);
int anjay_get_i64(anjay_input_ctx_t *ctx, int64_t *out);
#ifdef ANJAY_WITH_LWM2M11
int anjay_get_u32(anjay_input_ctx_t *ctx, uint32_t *out);
int anjay_get_u64(anjay_input_ctx_t *ctx, uint64_t *out);
#endif // ANJAY_WITH_LWM2M11
int anjay_get_float(anjay_input_ctx_t *ctx, float *out);
int anjay_get_double(anjay_input_ctx_t *ctx, double *out);
int anjay_get_bool(anjay_input_ctx_t *ctx, bool *out);
int anjay_get_objlnk(anjay_input_ctx_t *ctx,
anjay_oid_t *out_oid,
anjay_iid_t *out_iid);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*ANJAY_INCLUDE_ANJAY_IO_H*/