zephyr/lib/utils
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
..
base64.c
bitarray.c lib: check null pointer before taking lock for bitarray 2024-06-14 19:18:28 +02:00
CMakeLists.txt lib: utils: add consistent overhead byte stuffing 2025-03-11 05:36:49 +01:00
cobs.c lib: utils: add consistent overhead byte stuffing 2025-03-11 05:36:49 +01:00
dec.c
hex.c coding guidelines: comply with MISRA Rule 12.1. 2024-06-13 20:28:23 -04:00
json.c json: improve parsing and serializing of integers 2025-04-11 06:32:50 +02:00
Kconfig json: improve parsing and serializing of 'float' and 'double' 2025-04-09 22:05:14 +02:00
notify.c
onoff.c
rb.c lib: avoided increments/decrements with side effects 2024-06-21 08:48:15 -04:00
ring_buffer.c ring_buffer: shrink size of struct ring_buf 2025-03-11 08:59:05 +01:00
timeutil.c sys: timeutil: expose and use macro for base year 2024-08-29 11:38:28 +02:00
utf8.c zephyr: Add zero-len check for utf8_trunc 2024-06-27 08:48:31 -04:00
winstream.c