diff options
| author | eunhhu <[email protected]> | 2026-09-27 08:15:05 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-27 08:15:05 +0100 |
| commit | 25397ebb79fb554f4fa795603ee84d2aede83594 (patch) | |
| tree | 3e473e9dafdbfa07ede3e07ea6bba199a62ab0e4 /prototypes/connections/message-json.h | |
| parent | 24a07a0bbfe98924b339f4ffeeaef093e74f73fb (diff) | |
| download | pure-25397ebb79fb554f4fa795603ee84d2aede83594.tar.gz pure-25397ebb79fb554f4fa795603ee84d2aede83594.zip | |
Read JSON messages in message-json.c, for requests and answers alike
The in-place JSON reader of pure-serve's request bodies moves into its
own file with a small interface (pure_json_message, pure_json_fixed,
pure_json_space), so the delivery client can read an API's answers
with it. It gains a lenient mode for answers: a member that names no
field is skipped, value and all. Requests read as before.
Diffstat (limited to 'prototypes/connections/message-json.h')
| -rw-r--r-- | prototypes/connections/message-json.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/prototypes/connections/message-json.h b/prototypes/connections/message-json.h new file mode 100644 index 0000000..61211d6 --- /dev/null +++ b/prototypes/connections/message-json.h @@ -0,0 +1,26 @@ +#ifndef PURE_MESSAGE_JSON_H +#define PURE_MESSAGE_JSON_H +#include "module.h" + +/* A message's fields from a JSON object read in place (docs/research/082-json-in-place.md): + * a u32 or a number for a fixed field (put into the prefix), a string for + * bytes or text (left where it is: an escaped one is unescaped over itself, + * which never makes it longer), a group's fields as an object inside. */ +typedef struct { + const PureModule *module; + const PureInputShape *shape; + unsigned char *payload; /* the prefix; a string's start is counted from here */ + unsigned char *table; /* for each field, its start and size (u32le each) */ + const bool *given; /* fields given elsewhere (a request's query), or NULL */ + bool lenient; /* a member naming no field is skipped, value and all (an API's answer) */ + bool seen[PURE_MODULE_FIELDS]; +} PureJsonMessage; + +/* The object at json[*at] (its opening brace), *at moved past it: NULL, or + * what is wrong ("json", "json_field": unknown or given twice, "json_type"). */ +const char *pure_json_message(PureJsonMessage *, unsigned char *json, size_t size, size_t *at); +size_t pure_json_space(const unsigned char *json, size_t at, size_t size); +/* A fixed field's value from its text (a query value or a JSON number) into + * the prefix: a u32 in range, or a finite number. */ +bool pure_json_fixed(const PureField *field, const unsigned char *text, size_t size, unsigned char *prefix); +#endif |
