nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
nrf_rpc_serialize.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
14#ifndef NRF_RPC_SERIALIZE_H_
15#define NRF_RPC_SERIALIZE_H_
16
17#include <zephyr/net/buf.h>
18#include <zephyr/sys/util.h>
19#include <nrf_rpc_cbor.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
31#define NRF_RPC_SCRATCHPAD_ALIGN(size) WB_UP(size)
32
39#define NRF_RPC_SCRATCHPAD_DECLARE(_scratchpad, _ctx) \
40 (_scratchpad)->ctx = _ctx; \
41 uint32_t _scratchpad_size = nrf_rpc_decode_uint(_ctx); \
42 uint32_t _scratchpad_data[NRF_RPC_SCRATCHPAD_ALIGN(_scratchpad_size) / sizeof(uint32_t)]; \
43 net_buf_simple_init_with_data(&(_scratchpad)->buf, _scratchpad_data, _scratchpad_size); \
44 net_buf_simple_reset(&(_scratchpad)->buf)
45
48 /* CBOR decoding context */
49 struct nrf_rpc_cbor_ctx *ctx;
50
52 struct net_buf_simple buf;
53};
54
63static inline void *nrf_rpc_scratchpad_add(struct nrf_rpc_scratchpad *scratchpad, size_t size)
64{
65 return net_buf_simple_add(&scratchpad->buf, NRF_RPC_SCRATCHPAD_ALIGN(size));
66}
67
72void nrf_rpc_encode_null(struct nrf_rpc_cbor_ctx *ctx);
73
78void nrf_rpc_encode_undefined(struct nrf_rpc_cbor_ctx *ctx);
79
85void nrf_rpc_encode_bool(struct nrf_rpc_cbor_ctx *ctx, bool value);
86
92void nrf_rpc_encode_uint(struct nrf_rpc_cbor_ctx *ctx, uint32_t value);
93
99void nrf_rpc_encode_int(struct nrf_rpc_cbor_ctx *ctx, int32_t value);
100
106void nrf_rpc_encode_uint64(struct nrf_rpc_cbor_ctx *ctx, uint64_t value);
107
113void nrf_rpc_encode_int64(struct nrf_rpc_cbor_ctx *ctx, int64_t value);
114
121void nrf_rpc_encode_str(struct nrf_rpc_cbor_ctx *ctx, const char *value, int len);
122
129void nrf_rpc_encode_buffer(struct nrf_rpc_cbor_ctx *ctx, const void *data, size_t size);
130
139void nrf_rpc_encode_callback(struct nrf_rpc_cbor_ctx *ctx, void *callback);
140
146static inline void nrf_rpc_encode_callback_call(struct nrf_rpc_cbor_ctx *ctx, uint32_t slot)
147{
148 nrf_rpc_encode_uint(ctx, slot);
149}
150
156void nrf_rpc_encoder_invalid(struct nrf_rpc_cbor_ctx *ctx);
157
162void nrf_rpc_decode_skip(struct nrf_rpc_cbor_ctx *ctx);
163
171bool nrf_rpc_decode_is_null(struct nrf_rpc_cbor_ctx *ctx);
172
180bool nrf_rpc_decode_is_undefined(struct nrf_rpc_cbor_ctx *ctx);
181
188bool nrf_rpc_decode_bool(struct nrf_rpc_cbor_ctx *ctx);
189
196uint32_t nrf_rpc_decode_uint(struct nrf_rpc_cbor_ctx *ctx);
197
204int32_t nrf_rpc_decode_int(struct nrf_rpc_cbor_ctx *ctx);
205
212uint64_t nrf_rpc_decode_uint64(struct nrf_rpc_cbor_ctx *ctx);
213
220int64_t nrf_rpc_decode_int64(struct nrf_rpc_cbor_ctx *ctx);
221
230char *nrf_rpc_decode_str(struct nrf_rpc_cbor_ctx *ctx, char *buffer, size_t buffer_size);
231
239char *nrf_rpc_decode_str_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len);
240
249void *nrf_rpc_decode_buffer(struct nrf_rpc_cbor_ctx *ctx, void *buffer, size_t buffer_size);
250
258const void *nrf_rpc_decode_buffer_ptr_and_size(struct nrf_rpc_cbor_ctx *ctx, size_t *size);
259
267void *nrf_rpc_decode_buffer_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len);
268
281void *nrf_rpc_decode_callbackd(struct nrf_rpc_cbor_ctx *ctx, void *handler);
282
292void *nrf_rpc_decode_callback_call(struct nrf_rpc_cbor_ctx *ctx);
293
301void nrf_rpc_decoder_invalid(struct nrf_rpc_cbor_ctx *ctx, int err);
302
310bool nrf_rpc_decode_valid(const struct nrf_rpc_cbor_ctx *ctx);
311
321bool nrf_rpc_decoding_done_and_check(const struct nrf_rpc_group *group,
322 struct nrf_rpc_cbor_ctx *ctx);
323
330void nrf_rpc_rsp_decode_bool(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
331 void *handler_data);
332
343void nrf_rpc_rsp_decode_uint(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
344 void *result, size_t result_size);
345
355void nrf_rpc_rsp_decode_u8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
356 void *handler_data);
357
367void nrf_rpc_rsp_decode_u16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
368 void *handler_data);
369
379void nrf_rpc_rsp_decode_u32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
380 void *handler_data);
381
392void nrf_rpc_rsp_decode_int(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
393 void *result, size_t result_size);
394
404void nrf_rpc_rsp_decode_i8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
405 void *handler_data);
406
416void nrf_rpc_rsp_decode_i16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
417 void *handler_data);
418
428void nrf_rpc_rsp_decode_i32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
429 void *handler_data);
430
437void nrf_rpc_rsp_decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
438 void *handler_data);
439
445void nrf_rpc_rsp_send_int(const struct nrf_rpc_group *group, int32_t response);
446
452void nrf_rpc_rsp_send_uint(const struct nrf_rpc_group *group, uint32_t response);
453
459void nrf_rpc_rsp_send_bool(const struct nrf_rpc_group *group, bool response);
460
465void nrf_rpc_rsp_send_void(const struct nrf_rpc_group *group);
466
467#ifdef __cplusplus
468}
469#endif
470
473#endif /* NRF_RPC_SERIALIZE_H_ */
static void * nrf_rpc_scratchpad_add(struct nrf_rpc_scratchpad *scratchpad, size_t size)
Get the scratchpad item of a given size. The scratchpad item size will be round up to multiple of 4.
Definition: nrf_rpc_serialize.h:63
void nrf_rpc_rsp_decode_i16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as a signed 16-bit integer value.
#define NRF_RPC_SCRATCHPAD_ALIGN(size)
Get a scratchpad item size aligned to 4-byte boundary.
Definition: nrf_rpc_serialize.h:31
void nrf_rpc_rsp_send_uint(const struct nrf_rpc_group *group, uint32_t response)
Send response to a command as an unsigned integer value.
bool nrf_rpc_decode_bool(struct nrf_rpc_cbor_ctx *ctx)
Decode a boolean value.
void * nrf_rpc_decode_callback_call(struct nrf_rpc_cbor_ctx *ctx)
Decode callback slot.
void nrf_rpc_rsp_decode_int(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *result, size_t result_size)
Decode a command response as a signed integer value.
bool nrf_rpc_decode_is_null(struct nrf_rpc_cbor_ctx *ctx)
Check if value is a null. This function will not consume the value.
const void * nrf_rpc_decode_buffer_ptr_and_size(struct nrf_rpc_cbor_ctx *ctx, size_t *size)
Decode buffer pointer and length. Moves CBOR buffer pointer past buffer on success.
void nrf_rpc_encode_int(struct nrf_rpc_cbor_ctx *ctx, int32_t value)
Encode an integer value.
void nrf_rpc_encode_callback(struct nrf_rpc_cbor_ctx *ctx, void *callback)
Encode a callback.
void nrf_rpc_rsp_send_void(const struct nrf_rpc_group *group)
Send response to a command as a void.
void nrf_rpc_rsp_decode_u8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as an unsigned 8-bit integer value.
void * nrf_rpc_decode_callbackd(struct nrf_rpc_cbor_ctx *ctx, void *handler)
Decode a callback.
void * nrf_rpc_decode_buffer(struct nrf_rpc_cbor_ctx *ctx, void *buffer, size_t buffer_size)
Decode a buffer.
int32_t nrf_rpc_decode_int(struct nrf_rpc_cbor_ctx *ctx)
Decode a integer value.
void nrf_rpc_rsp_decode_i32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as a signed 32-bit integer value.
void nrf_rpc_decode_skip(struct nrf_rpc_cbor_ctx *ctx)
Skip one value to decode.
void nrf_rpc_encode_uint64(struct nrf_rpc_cbor_ctx *ctx, uint64_t value)
Encode an 64bits unsigned integer value.
void nrf_rpc_encode_buffer(struct nrf_rpc_cbor_ctx *ctx, const void *data, size_t size)
Encode a buffer.
void nrf_rpc_encoder_invalid(struct nrf_rpc_cbor_ctx *ctx)
Put encode into an invalid state. All further encoding on this encoder will be ignored....
void nrf_rpc_rsp_decode_u32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as an unsigned 32-bit integer value.
uint64_t nrf_rpc_decode_uint64(struct nrf_rpc_cbor_ctx *ctx)
Decode a 64bits unsigned integer value.
void nrf_rpc_encode_null(struct nrf_rpc_cbor_ctx *ctx)
Encode a null value.
void nrf_rpc_rsp_send_int(const struct nrf_rpc_group *group, int32_t response)
Send response to a command as an integer value.
void nrf_rpc_decoder_invalid(struct nrf_rpc_cbor_ctx *ctx, int err)
Put decoder into an invalid state and set error code that caused it. All further decoding on this dec...
void nrf_rpc_encode_undefined(struct nrf_rpc_cbor_ctx *ctx)
Encode an undefined value.
void nrf_rpc_encode_int64(struct nrf_rpc_cbor_ctx *ctx, int64_t value)
Encode an 64bits integer value.
void nrf_rpc_rsp_decode_i8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as a signed 8-bit integer value.
void nrf_rpc_rsp_send_bool(const struct nrf_rpc_group *group, bool response)
Send response to a command as a boolean value.
bool nrf_rpc_decode_is_undefined(struct nrf_rpc_cbor_ctx *ctx)
Check if value is an undefined. This function will not consume the value.
char * nrf_rpc_decode_str(struct nrf_rpc_cbor_ctx *ctx, char *buffer, size_t buffer_size)
Decode a string value.
static void nrf_rpc_encode_callback_call(struct nrf_rpc_cbor_ctx *ctx, uint32_t slot)
Encode a callback slot number.
Definition: nrf_rpc_serialize.h:146
void nrf_rpc_rsp_decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as a void value.
void nrf_rpc_rsp_decode_u16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as an unsigned 16-bit integer value.
int64_t nrf_rpc_decode_int64(struct nrf_rpc_cbor_ctx *ctx)
Decode a 64bits integer value.
uint32_t nrf_rpc_decode_uint(struct nrf_rpc_cbor_ctx *ctx)
Decode an unsigned integer value.
void nrf_rpc_rsp_decode_uint(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *result, size_t result_size)
Decode a command response as an unsigned integer value.
void nrf_rpc_rsp_decode_bool(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
Decode a command response as a boolean value.
void nrf_rpc_encode_str(struct nrf_rpc_cbor_ctx *ctx, const char *value, int len)
Encode a string value.
void nrf_rpc_encode_uint(struct nrf_rpc_cbor_ctx *ctx, uint32_t value)
Encode an unsigned integer value.
bool nrf_rpc_decoding_done_and_check(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx)
Signalize that decoding is done. Use this function when you finish decoding of the received serialize...
char * nrf_rpc_decode_str_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len)
bool nrf_rpc_decode_valid(const struct nrf_rpc_cbor_ctx *ctx)
Returns if decoder is in valid state.
void * nrf_rpc_decode_buffer_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len)
Decode buffer into a scratchpad.
void nrf_rpc_encode_bool(struct nrf_rpc_cbor_ctx *ctx, bool value)
Encode a boolean value.
struct net_buf_simple buf
Definition: nrf_rpc_serialize.h:52
struct nrf_rpc_cbor_ctx * ctx
Definition: nrf_rpc_serialize.h:49
Scratchpad structure.
Definition: nrf_rpc_serialize.h:47