5#ifndef OPENTITAN_SW_DEVICE_LIB_UJSON_UJSON_H_
6#define OPENTITAN_SW_DEVICE_LIB_UJSON_UJSON_H_
9#include "sw/device/lib/base/status.h"
21 status_t (*
putbuf)(
void *,
const char *, size_t);
35#define UJSON_INIT(context_, getc_, putbuf_, flushbuf_) \
37 .io_context = (void *)(context_), \
38 .putbuf_ = (putbuf_), \
39 .flushbuf_ = (flushbuf_), \
42 .crc32 = UINT32_MAX, \
54ujson_t ujson_init(
void *context, status_t (*getc)(
void *),
55 status_t (*putbuf)(
void *,
const char *,
size_t),
56 status_t (*flushbuf)(
void *));
64status_t ujson_getc(ujson_t *uj);
73status_t ujson_ungetc(ujson_t *uj,
char ch);
83status_t ujson_putbuf(ujson_t *uj,
const char *buf,
size_t len);
96status_t ujson_flushbuf(ujson_t *uj);
103void ujson_crc32_reset(ujson_t *uj);
114uint32_t ujson_crc32_finish(ujson_t *uj);
123bool ujson_streq(
const char *a,
const char *b);
135status_t ujson_consume(ujson_t *uj,
char ch);
148status_t ujson_consume_maybe(ujson_t *uj,
char ch);
164status_t ujson_parse_qs(ujson_t *uj,
char *str,
size_t len);
174status_t ujson_parse_integer(ujson_t *uj,
void *result,
size_t rsz);
179status_t ujson_deserialize_uint64_t(ujson_t *uj, uint64_t *value);
180status_t ujson_deserialize_uint32_t(ujson_t *uj, uint32_t *value);
181status_t ujson_deserialize_uint16_t(ujson_t *uj, uint16_t *value);
182status_t ujson_deserialize_uint8_t(ujson_t *uj, uint8_t *value);
183status_t ujson_deserialize_size_t(ujson_t *uj,
size_t *value);
184status_t ujson_deserialize_int64_t(ujson_t *uj, int64_t *value);
185status_t ujson_deserialize_int32_t(ujson_t *uj, int32_t *value);
186status_t ujson_deserialize_int16_t(ujson_t *uj, int16_t *value);
187status_t ujson_deserialize_int8_t(ujson_t *uj, int8_t *value);
196status_t ujson_deserialize_bool(ujson_t *uj,
bool *value);
205status_t ujson_deserialize_status_t(ujson_t *uj, status_t *value);
214status_t ujson_serialize_string(ujson_t *uj,
const char *buf);
223status_t ujson_serialize_uint64_t(ujson_t *uj,
const uint64_t *value);
224status_t ujson_serialize_uint32_t(ujson_t *uj,
const uint32_t *value);
225status_t ujson_serialize_uint16_t(ujson_t *uj,
const uint16_t *value);
226status_t ujson_serialize_uint8_t(ujson_t *uj,
const uint8_t *value);
227status_t ujson_serialize_size_t(ujson_t *uj,
const size_t *value);
228status_t ujson_serialize_int64_t(ujson_t *uj,
const int64_t *value);
229status_t ujson_serialize_int32_t(ujson_t *uj,
const int32_t *value);
230status_t ujson_serialize_int16_t(ujson_t *uj,
const int16_t *value);
231status_t ujson_serialize_int8_t(ujson_t *uj,
const int8_t *value);
240status_t ujson_serialize_bool(ujson_t *uj,
const bool *value);
249status_t ujson_serialize_status_t(ujson_t *uj,
const status_t *value);