object.h
Go to the documentation of this file.
1 #ifndef MPACK_OBJECT_H
2 #define MPACK_OBJECT_H
3 
4 #include "mpack_core.h"
5 #include "conv.h"
6 
7 #ifndef MPACK_MAX_OBJECT_DEPTH
8 # define MPACK_MAX_OBJECT_DEPTH 32
9 #endif
10 
11 #define MPACK_PARENT_NODE(n) (((n) - 1)->pos == (size_t)-1 ? NULL : (n) - 1)
12 
13 #define MPACK_THROW(parser) \
14  do { \
15  parser->status = MPACK_EXCEPTION; \
16  return; \
17  } while (0)
18 
19 enum {
22 };
23 
24 /* Storing integer in pointers in undefined behavior according to the C
25  * standard. Define a union type to accomodate arbitrary user data associated
26  * with nodes(and with requests in rpc.h). */
27 typedef union {
28  void *p;
31  double d;
32 } mpack_data_t;
33 
34 typedef struct mpack_node_s {
36  size_t pos;
37  /* flag to determine if the key was visited when traversing a map */
39  /* allow 2 instances mpack_data_t per node. the reason is that when
40  * serializing, the user may need to keep track of traversal state besides the
41  * parent node reference */
43 } mpack_node_t;
44 
45 #define MPACK_PARSER_STRUCT(c) \
46  struct { \
47  mpack_data_t data; \
48  mpack_uint32_t size, capacity; \
49  int status; \
50  int exiting; \
51  mpack_tokbuf_t tokbuf; \
52  mpack_node_t items[c + 1]; \
53  }
54 
55 /* Some compilers warn against anonymous structs:
56  * https://github.com/libmpack/libmpack/issues/6 */
57 typedef MPACK_PARSER_STRUCT(0) mpack_one_parser_t;
58 
59 #define MPACK_PARSER_STRUCT_SIZE(c) \
60  (sizeof(mpack_node_t) * c + \
61  sizeof(mpack_one_parser_t))
62 
63 typedef MPACK_PARSER_STRUCT(MPACK_MAX_OBJECT_DEPTH) mpack_parser_t;
64 typedef void(*mpack_walk_cb)(mpack_parser_t *w, mpack_node_t *n);
65 
66 MPACK_API void mpack_parser_init(mpack_parser_t *p, mpack_uint32_t c)
68 
69 MPACK_API int mpack_parse_tok(mpack_parser_t *walker, mpack_token_t tok,
70  mpack_walk_cb enter_cb, mpack_walk_cb exit_cb)
71  FUNUSED FNONULL_ARG((1,3,4));
72 MPACK_API int mpack_unparse_tok(mpack_parser_t *walker, mpack_token_t *tok,
73  mpack_walk_cb enter_cb, mpack_walk_cb exit_cb)
74  FUNUSED FNONULL_ARG((1,2,3,4));
75 
76 MPACK_API int mpack_parse(mpack_parser_t *parser, const char **b, size_t *bl,
77  mpack_walk_cb enter_cb, mpack_walk_cb exit_cb)
78  FUNUSED FNONULL_ARG((1,2,3,4,5));
79 MPACK_API int mpack_unparse(mpack_parser_t *parser, char **b, size_t *bl,
80  mpack_walk_cb enter_cb, mpack_walk_cb exit_cb)
81  FUNUSED FNONULL_ARG((1,2,3,4,5));
82 
83 MPACK_API void mpack_parser_copy(mpack_parser_t *d, mpack_parser_t *s)
85 
86 #endif /* MPACK_OBJECT_H */
MPACK_NOMEM
@ MPACK_NOMEM
Definition: object.h:21
mpack_node_s::pos
size_t pos
Definition: object.h:36
mpack_node_s::tok
mpack_token_t tok
Definition: object.h:35
mpack_data_t::u
mpack_uintmax_t u
Definition: object.h:29
mpack_node_s
Definition: object.h:34
mpack_walk_cb
void(* mpack_walk_cb)(mpack_parser_t *w, mpack_node_t *n)
Definition: object.h:64
mpack_parser_copy
MPACK_API int MPACK_API int MPACK_API int MPACK_API int MPACK_API void mpack_parser_copy(mpack_parser_t *d, mpack_parser_t *s) FUNUSED FNONULL
Definition: object.c:131
mpack_sintmax_t
mpack_sint32_t mpack_sintmax_t
Definition: conv.h:13
p
char_u * p
Definition: eval.c:2013
conv.h
FNONULL
#define FNONULL
Definition: mpack_core.h:19
mpack_parse_tok
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
mpack_core.h
MPACK_MAX_OBJECT_DEPTH
#define MPACK_MAX_OBJECT_DEPTH
Definition: object.h:8
mpack_parser_init
MPACK_API void mpack_parser_init(mpack_parser_t *p, mpack_uint32_t c) FUNUSED FNONULL
Definition: object.c:12
mpack_unparse_tok
MPACK_API int 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
MPACK_EXCEPTION
@ MPACK_EXCEPTION
Definition: object.h:20
void
void(WINAPI *pClosePseudoConsole)(HPCON)
mpack_data_t::i
mpack_sintmax_t i
Definition: object.h:30
mpack_node_s::key_visited
int key_visited
Definition: object.h:38
n
int n
Definition: funcs.c:8562
FUNUSED
#define FUNUSED
Definition: mpack_core.h:21
MPACK_PARSER_STRUCT
#define MPACK_PARSER_STRUCT(c)
Definition: object.h:45
w
QUEUE * w
Definition: typval.c:1300
mpack_data_t::d
double d
Definition: object.h:31
mpack_unparse
MPACK_API int MPACK_API int MPACK_API int 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
s
char_u * s
Definition: eval.c:764
mpack_node_t
struct mpack_node_s mpack_node_t
mpack_node_s::data
mpack_data_t data[2]
Definition: object.h:42
mpack_data_t
Definition: object.h:27
FNONULL_ARG
#define FNONULL_ARG(x)
Definition: mpack_core.h:20
mpack_uintmax_t
mpack_uint32_t mpack_uintmax_t
Definition: conv.h:14
mpack_data_t::p
void * p
Definition: object.h:28
mpack_token_s
Definition: mpack_core.h:61
MPACK_ERROR
@ MPACK_ERROR
Definition: mpack_core.h:42
mpack_parse
MPACK_API int MPACK_API int 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
MPACK_API
#define MPACK_API
Definition: mpack_core.h:5