meta_json_parser.h (13551B)
1 #ifndef META_JSON_PARSER_H 2 #define META_JSON_PARSER_H 3 4 /* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */ 5 6 #include "flatcc_json_parser.h" 7 #include "flatcc_prologue.h" 8 9 /* 10 * Parses the default root table or struct of the schema and constructs a FlatBuffer. 11 * 12 * Builder `B` must be initialized. `ctx` can be null but will hold 13 * hold detailed error info on return when available. 14 * Returns 0 on success, or error code. 15 * `flags` : 0 by default, `flatcc_json_parser_f_skip_unknown` silently 16 * ignores unknown table and structs fields, and union types. 17 */ 18 static int meta_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx, 19 const char *buf, size_t bufsiz, int flags); 20 21 static const char *NdbEventMeta_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result); 22 static const char *meta_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, 23 int *value_type, uint64_t *value, int *aggregate); 24 static const char *meta_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, 25 int *value_type, uint64_t *value, int *aggregate); 26 27 static const char *NdbEventMeta_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result) 28 { 29 int more; 30 void *pval; 31 flatcc_builder_ref_t ref, *pref; 32 const char *mark; 33 uint64_t w; 34 35 *result = 0; 36 if (flatcc_builder_start_table(ctx->ctx, 6)) goto failed; 37 buf = flatcc_json_parser_object_start(ctx, buf, end, &more); 38 while (more) { 39 buf = flatcc_json_parser_symbol_start(ctx, buf, end); 40 w = flatcc_json_parser_symbol_part(buf, end); 41 if (w < 0x7265636569766564) { /* branch "received" */ 42 if ((w & 0xffffffffffff0000) == 0x71756f7465730000) { /* "quotes" */ 43 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6); 44 if (mark != buf) { 45 int32_t val = 0; 46 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 47 meta_local_json_parser_enum, 48 meta_global_json_parser_enum, 0 }; 49 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); 50 if (mark == buf) { 51 buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); 52 if (buf == mark || buf == end) goto failed; 53 } 54 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 55 if (!(pval = flatcc_builder_table_add(ctx->ctx, 2, 4, 4))) goto failed; 56 flatbuffers_int32_write_to_pe(pval, val); 57 } 58 } else { 59 goto pfguard1; 60 } 61 } else { /* "quotes" */ 62 goto pfguard1; 63 } /* "quotes" */ 64 goto endpfguard1; 65 pfguard1: 66 if (w == 0x7265616374696f6e) { /* descend "reaction" */ 67 buf += 8; 68 w = flatcc_json_parser_symbol_part(buf, end); 69 if ((w & 0xff00000000000000) == 0x7300000000000000) { /* "s" */ 70 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1); 71 if (mark != buf) { 72 int32_t val = 0; 73 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 74 meta_local_json_parser_enum, 75 meta_global_json_parser_enum, 0 }; 76 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); 77 if (mark == buf) { 78 buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); 79 if (buf == mark || buf == end) goto failed; 80 } 81 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 82 if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 4, 4))) goto failed; 83 flatbuffers_int32_write_to_pe(pval, val); 84 } 85 } else { 86 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 87 } 88 } else { /* "s" */ 89 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 90 } /* "s" */ 91 } else { /* descend "reaction" */ 92 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 93 } /* descend "reaction" */ 94 endpfguard1: 95 (void)0; 96 } else { /* branch "received" */ 97 if (w < 0x7265706f73747300) { /* branch "reposts" */ 98 if (w == 0x7265636569766564) { /* descend "received" */ 99 buf += 8; 100 w = flatcc_json_parser_symbol_part(buf, end); 101 if ((w & 0xffffff0000000000) == 0x5f61740000000000) { /* "_at" */ 102 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3); 103 if (mark != buf) { 104 int32_t val = 0; 105 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 106 meta_local_json_parser_enum, 107 meta_global_json_parser_enum, 0 }; 108 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); 109 if (mark == buf) { 110 buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); 111 if (buf == mark || buf == end) goto failed; 112 } 113 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 114 if (!(pval = flatcc_builder_table_add(ctx->ctx, 0, 4, 4))) goto failed; 115 flatbuffers_int32_write_to_pe(pval, val); 116 } 117 } else { 118 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 119 } 120 } else { /* "_at" */ 121 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 122 } /* "_at" */ 123 } else { /* descend "received" */ 124 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 125 } /* descend "received" */ 126 } else { /* branch "reposts" */ 127 if (w < 0x7a61705f746f7461) { /* branch "zap_tota" */ 128 if ((w & 0xffffffffffffff00) == 0x7265706f73747300) { /* "reposts" */ 129 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7); 130 if (mark != buf) { 131 int32_t val = 0; 132 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 133 meta_local_json_parser_enum, 134 meta_global_json_parser_enum, 0 }; 135 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); 136 if (mark == buf) { 137 buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); 138 if (buf == mark || buf == end) goto failed; 139 } 140 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 141 if (!(pval = flatcc_builder_table_add(ctx->ctx, 3, 4, 4))) goto failed; 142 flatbuffers_int32_write_to_pe(pval, val); 143 } 144 } else { 145 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 146 } 147 } else { /* "reposts" */ 148 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 149 } /* "reposts" */ 150 } else { /* branch "zap_tota" */ 151 if (w == 0x7a61705f746f7461) { /* descend "zap_tota" */ 152 buf += 8; 153 w = flatcc_json_parser_symbol_part(buf, end); 154 if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */ 155 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1); 156 if (mark != buf) { 157 int64_t val = 0; 158 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 159 meta_local_json_parser_enum, 160 meta_global_json_parser_enum, 0 }; 161 buf = flatcc_json_parser_int64(ctx, (mark = buf), end, &val); 162 if (mark == buf) { 163 buf = flatcc_json_parser_symbolic_int64(ctx, (mark = buf), end, symbolic_parsers, &val); 164 if (buf == mark || buf == end) goto failed; 165 } 166 if (val != INT64_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 167 if (!(pval = flatcc_builder_table_add(ctx->ctx, 5, 8, 8))) goto failed; 168 flatbuffers_int64_write_to_pe(pval, val); 169 } 170 } else { 171 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 172 } 173 } else { /* "l" */ 174 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 175 } /* "l" */ 176 } else { /* descend "zap_tota" */ 177 if ((w & 0xffffffff00000000) == 0x7a61707300000000) { /* "zaps" */ 178 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 4); 179 if (mark != buf) { 180 int32_t val = 0; 181 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { 182 meta_local_json_parser_enum, 183 meta_global_json_parser_enum, 0 }; 184 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val); 185 if (mark == buf) { 186 buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val); 187 if (buf == mark || buf == end) goto failed; 188 } 189 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { 190 if (!(pval = flatcc_builder_table_add(ctx->ctx, 4, 4, 4))) goto failed; 191 flatbuffers_int32_write_to_pe(pval, val); 192 } 193 } else { 194 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 195 } 196 } else { /* "zaps" */ 197 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); 198 } /* "zaps" */ 199 } /* descend "zap_tota" */ 200 } /* branch "zap_tota" */ 201 } /* branch "reposts" */ 202 } /* branch "received" */ 203 buf = flatcc_json_parser_object_end(ctx, buf, end, &more); 204 } 205 if (ctx->error) goto failed; 206 if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed; 207 return buf; 208 failed: 209 return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime); 210 } 211 212 static inline int NdbEventMeta_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid) 213 { 214 return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, NdbEventMeta_parse_json_table); 215 } 216 217 static const char *meta_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, 218 int *value_type, uint64_t *value, int *aggregate) 219 { 220 /* Scope has no enum / union types to look up. */ 221 return buf; /* unmatched; */ 222 } 223 224 static const char *meta_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end, 225 int *value_type, uint64_t *value, int *aggregate) 226 { 227 /* Global scope has no enum / union types to look up. */ 228 return buf; /* unmatched; */ 229 } 230 231 static int meta_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx, 232 const char *buf, size_t bufsiz, int flags) 233 { 234 flatcc_json_parser_t parser; 235 flatcc_builder_ref_t root; 236 237 ctx = ctx ? ctx : &parser; 238 flatcc_json_parser_init(ctx, B, buf, buf + bufsiz, flags); 239 if (flatcc_builder_start_buffer(B, 0, 0, 0)) return -1; 240 NdbEventMeta_parse_json_table(ctx, buf, buf + bufsiz, &root); 241 if (ctx->error) { 242 return ctx->error; 243 } 244 if (!flatcc_builder_end_buffer(B, root)) return -1; 245 ctx->end_loc = buf; 246 return 0; 247 } 248 249 #include "flatcc_epilogue.h" 250 #endif /* META_JSON_PARSER_H */