nRF Connect SDK API 3.3.99
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
239const void *nrf_rpc_decode_str_ptr_and_len(struct nrf_rpc_cbor_ctx *ctx, size_t *len);
240
248char *nrf_rpc_decode_str_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len);
249
258void *nrf_rpc_decode_buffer(struct nrf_rpc_cbor_ctx *ctx, void *buffer, size_t buffer_size);
259
267const void *nrf_rpc_decode_buffer_ptr_and_size(struct nrf_rpc_cbor_ctx *ctx, size_t *size);
268
276void *nrf_rpc_decode_buffer_into_scratchpad(struct nrf_rpc_scratchpad *scratchpad, size_t *len);
277
290void *nrf_rpc_decode_callbackd(struct nrf_rpc_cbor_ctx *ctx, void *handler);
291
301void *nrf_rpc_decode_callback_call(struct nrf_rpc_cbor_ctx *ctx);
302
310void nrf_rpc_decoder_invalid(struct nrf_rpc_cbor_ctx *ctx, int err);
311
319bool nrf_rpc_decode_valid(const struct nrf_rpc_cbor_ctx *ctx);
320
330bool nrf_rpc_decoding_done_and_check(const struct nrf_rpc_group *group,
331 struct nrf_rpc_cbor_ctx *ctx);
332
339void nrf_rpc_rsp_decode_bool(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
340 void *handler_data);
341
352void nrf_rpc_rsp_decode_uint(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
353 void *result, size_t result_size);
354
364void nrf_rpc_rsp_decode_u8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
365 void *handler_data);
366
376void nrf_rpc_rsp_decode_u16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
377 void *handler_data);
378
388void nrf_rpc_rsp_decode_u32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
389 void *handler_data);
390
401void nrf_rpc_rsp_decode_int(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
402 void *result, size_t result_size);
403
413void nrf_rpc_rsp_decode_i8(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
414 void *handler_data);
415
425void nrf_rpc_rsp_decode_i16(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
426 void *handler_data);
427
437void nrf_rpc_rsp_decode_i32(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
438 void *handler_data);
439
446void nrf_rpc_rsp_decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
447 void *handler_data);
448
454void nrf_rpc_rsp_send_int(const struct nrf_rpc_group *group, int32_t response);
455
461void nrf_rpc_rsp_send_uint(const struct nrf_rpc_group *group, uint32_t response);
462
468void nrf_rpc_rsp_send_bool(const struct nrf_rpc_group *group, bool response);
469
474void nrf_rpc_rsp_send_void(const struct nrf_rpc_group *group);
475
476#ifdef __cplusplus
477}
478#endif
479
482#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.
const void * nrf_rpc_decode_str_ptr_and_len(struct nrf_rpc_cbor_ctx *ctx, size_t *len)
Decode a string pointer and length. Moves CBOR pointer past string on success.
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