From c8f46480bc0bfd07c8a69d61e365706e3184abc9 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 4 Sep 2021 16:59:26 +0200 Subject: build: vendor libmpack source from libmpack/libmpack 22b1fd90285117c995728511f9525d29520a8c82 --- src/mpack/object.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/mpack/object.h (limited to 'src/mpack/object.h') diff --git a/src/mpack/object.h b/src/mpack/object.h new file mode 100644 index 0000000000..3a4c0a484e --- /dev/null +++ b/src/mpack/object.h @@ -0,0 +1,86 @@ +#ifndef MPACK_OBJECT_H +#define MPACK_OBJECT_H + +#include "core.h" +#include "conv.h" + +#ifndef MPACK_MAX_OBJECT_DEPTH +# define MPACK_MAX_OBJECT_DEPTH 32 +#endif + +#define MPACK_PARENT_NODE(n) (((n) - 1)->pos == (size_t)-1 ? NULL : (n) - 1) + +#define MPACK_THROW(parser) \ + do { \ + parser->status = MPACK_EXCEPTION; \ + return; \ + } while (0) + +enum { + MPACK_EXCEPTION = -1, + MPACK_NOMEM = MPACK_ERROR + 1 +}; + +/* Storing integer in pointers in undefined behavior according to the C + * standard. Define a union type to accomodate arbitrary user data associated + * with nodes(and with requests in rpc.h). */ +typedef union { + void *p; + mpack_uintmax_t u; + mpack_sintmax_t i; + double d; +} mpack_data_t; + +typedef struct mpack_node_s { + mpack_token_t tok; + size_t pos; + /* flag to determine if the key was visited when traversing a map */ + int key_visited; + /* allow 2 instances mpack_data_t per node. the reason is that when + * serializing, the user may need to keep track of traversal state besides the + * parent node reference */ + mpack_data_t data[2]; +} mpack_node_t; + +#define MPACK_PARSER_STRUCT(c) \ + struct { \ + mpack_data_t data; \ + mpack_uint32_t size, capacity; \ + int status; \ + int exiting; \ + mpack_tokbuf_t tokbuf; \ + mpack_node_t items[c + 1]; \ + } + +/* Some compilers warn against anonymous structs: + * https://github.com/libmpack/libmpack/issues/6 */ +typedef MPACK_PARSER_STRUCT(0) mpack_one_parser_t; + +#define MPACK_PARSER_STRUCT_SIZE(c) \ + (sizeof(mpack_node_t) * c + \ + sizeof(mpack_one_parser_t)) + +typedef MPACK_PARSER_STRUCT(MPACK_MAX_OBJECT_DEPTH) mpack_parser_t; +typedef void(*mpack_walk_cb)(mpack_parser_t *w, mpack_node_t *n); + +MPACK_API void mpack_parser_init(mpack_parser_t *p, mpack_uint32_t c) + FUNUSED FNONULL; + +MPACK_API int mpack_parse_tok(mpack_parser_t *walker, mpack_token_t tok, + mpack_walk_cb enter_cb, mpack_walk_cb exit_cb) + FUNUSED FNONULL_ARG((1,3,4)); +MPACK_API int mpack_unparse_tok(mpack_parser_t *walker, mpack_token_t *tok, + mpack_walk_cb enter_cb, mpack_walk_cb exit_cb) + FUNUSED FNONULL_ARG((1,2,3,4)); + +MPACK_API int mpack_parse(mpack_parser_t *parser, const char **b, size_t *bl, + mpack_walk_cb enter_cb, mpack_walk_cb exit_cb) + FUNUSED FNONULL_ARG((1,2,3,4,5)); +MPACK_API int mpack_unparse(mpack_parser_t *parser, char **b, size_t *bl, + mpack_walk_cb enter_cb, mpack_walk_cb exit_cb) + FUNUSED FNONULL_ARG((1,2,3,4,5)); + +MPACK_API void mpack_parser_copy(mpack_parser_t *d, mpack_parser_t *s) + FUNUSED FNONULL; + +#endif /* MPACK_OBJECT_H */ -- cgit From ad8eda3f5b7db424de912ac748bce6b02e43f64f Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 9 Sep 2021 14:57:27 +0200 Subject: fix(ci): don't enrage the CI Gods by calling a file 'core.*' --- src/mpack/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mpack/object.h') diff --git a/src/mpack/object.h b/src/mpack/object.h index 3a4c0a484e..5327e56e18 100644 --- a/src/mpack/object.h +++ b/src/mpack/object.h @@ -1,7 +1,7 @@ #ifndef MPACK_OBJECT_H #define MPACK_OBJECT_H -#include "core.h" +#include "mpack_core.h" #include "conv.h" #ifndef MPACK_MAX_OBJECT_DEPTH -- cgit