zephyr/lib
Christoph Winklhofer a5e295c452 json: improve parsing and serializing of integers
Add support for parsing and serializing of following integer types:
'int8_t', 'uint8_t', 'int16_t', 'uint16_t' and 'uint32_t'.

The generic integer token JSON_TOK_INT and JSON_TOK_UINT, in combination
with the field size (set by JSON_OBJ_DESCR_PRIM) allows to parse different
integer types, for example:

struct foo {
  int64_t i64;
  uint32_t u32;
  int16_t i16;
  uint8_t u8;
};

struct json_obj_descr foo_descr[] = {
  JSON_OBJ_DESCR_PRIM(struct foo, i64, JSON_TOK_INT),
  JSON_OBJ_DESCR_PRIM(struct foo, u32, JSON_TOK_UINT),
  JSON_OBJ_DESCR_PRIM(struct foo, i16, JSON_TOK_INT),
  JSON_OBJ_DESCR_PRIM(struct foo, u8, JSON_TOK_UINT),
};

These tokens also support parsing and serializing enums:

enum unsigned_enum { UA=0, UB=1, UC=2 };
enum signed_enum { SA=-1, SB=0, SC=1 };

struct foo {
  enum unsigned_enum u;
  enum signed_enum s;
};

struct json_obj_descr foo_descr[] = {
  JSON_OBJ_DESCR_PRIM(struct foo, u, JSON_TOK_UINT),
  JSON_OBJ_DESCR_PRIM(struct foo, s, JSON_TOK_INT),
};

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-11 06:32:50 +02:00
..
acpi lib: fix typo in multiple directories 2025-01-28 00:06:18 +01:00
cpp cpp: Add c++ version number 2025-02-10 15:57:26 +00:00
crc lib: crc: add crc8_rohc for CRC-8/ROHC variant calculation 2024-10-09 09:48:00 +02:00
hash lib: hash: use new c++ Kconfig symbols 2023-07-26 14:53:51 +02:00
heap kernel: sys_heap: decouple realloc from aligned_realloc 2025-04-01 22:13:04 +02:00
libc libc: add comment to empty sys/cdefs.h file 2025-02-21 15:13:20 +00:00
mem_blocks lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00
net_buf lib: net_buf: remove deprecated net_buf_put() and net_buf_get() functions 2025-03-12 19:04:19 +01:00
open-amp lib: open-amp: optional copy of rsc_table to memory region 2025-03-24 12:17:53 +01:00
os lib/os/fdtable: Remove ifdef on NATIVE_POSIX 2025-03-12 02:27:36 +01:00
posix posix: remove deprecated kconfig options 2025-03-12 19:03:52 +01:00
runtime llvm: Add support for selecting runtime library 2023-08-03 19:35:11 +02:00
smf lib: smf: Fix handled bug causing events to not propagate. 2025-01-23 19:24:08 +01:00
utils json: improve parsing and serializing of integers 2025-04-11 06:32:50 +02:00
CMakeLists.txt lib: net_buf: move the network buffer implementation to lib 2024-09-07 11:19:05 -05:00
Kconfig lib: net_buf: move the network buffer implementation to lib 2024-09-07 11:19:05 -05:00