damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

profile_json_parser.h (23391B)


      1 #ifndef PROFILE_JSON_PARSER_H
      2 #define PROFILE_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 profile_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 *NdbProfile_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
     22 static const char *NdbProfileRecord_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
     23 static const char *profile_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
     24 int *value_type, uint64_t *value, int *aggregate);
     25 static const char *profile_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
     26         int *value_type, uint64_t *value, int *aggregate);
     27 
     28 static const char *NdbProfile_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
     29 {
     30     int more;
     31     void *pval;
     32     flatcc_builder_ref_t ref, *pref;
     33     const char *mark;
     34     uint64_t w;
     35 
     36     *result = 0;
     37     if (flatcc_builder_start_table(ctx->ctx, 12)) goto failed;
     38     buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
     39     while (more) {
     40         buf = flatcc_json_parser_symbol_start(ctx, buf, end);
     41         w = flatcc_json_parser_symbol_part(buf, end);
     42         if (w < 0x6c75643036000000) { /* branch "lud06" */
     43             if (w < 0x64616d75735f646f) { /* branch "damus_do" */
     44                 if ((w & 0xffffffffffff0000) == 0x62616e6e65720000) { /* "banner" */
     45                     buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6);
     46                     if (mark != buf) {
     47                         buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
     48                         if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 4))) goto failed;
     49                         *pref = ref;
     50                     } else {
     51                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
     52                     }
     53                 } else { /* "banner" */
     54                     if ((w & 0xffffffffff000000) == 0x61626f7574000000) { /* "about" */
     55                         buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
     56                         if (mark != buf) {
     57                             buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
     58                             if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 2))) goto failed;
     59                             *pref = ref;
     60                         } else {
     61                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
     62                         }
     63                     } else { /* "about" */
     64                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
     65                     } /* "about" */
     66                 } /* "banner" */
     67             } else { /* branch "damus_do" */
     68                 if (w == 0x64616d75735f646f) { /* descend "damus_do" */
     69                     buf += 8;
     70                     w = flatcc_json_parser_symbol_part(buf, end);
     71                     if (w == 0x6e6174696f6e5f76) { /* descend "nation_v" */
     72                         buf += 8;
     73                         w = flatcc_json_parser_symbol_part(buf, end);
     74                         if ((w & 0xff00000000000000) == 0x3200000000000000) { /* "2" */
     75                             buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
     76                             if (mark != buf) {
     77                                 int32_t val = 0;
     78                                 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
     79                                         profile_local_json_parser_enum,
     80                                         profile_global_json_parser_enum, 0 };
     81                                 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val);
     82                                 if (mark == buf) {
     83                                     buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val);
     84                                     if (buf == mark || buf == end) goto failed;
     85                                 }
     86                                 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) {
     87                                     if (!(pval = flatcc_builder_table_add(ctx->ctx, 10, 4, 4))) goto failed;
     88                                     flatbuffers_int32_write_to_pe(pval, val);
     89                                 }
     90                             } else {
     91                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
     92                             }
     93                         } else { /* "2" */
     94                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
     95                         } /* "2" */
     96                     } else { /* descend "nation_v" */
     97                         if ((w & 0xffffffffffff0000) == 0x6e6174696f6e0000) { /* "nation" */
     98                             buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6);
     99                             if (mark != buf) {
    100                                 int32_t val = 0;
    101                                 static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
    102                                         profile_local_json_parser_enum,
    103                                         profile_global_json_parser_enum, 0 };
    104                                 buf = flatcc_json_parser_int32(ctx, (mark = buf), end, &val);
    105                                 if (mark == buf) {
    106                                     buf = flatcc_json_parser_symbolic_int32(ctx, (mark = buf), end, symbolic_parsers, &val);
    107                                     if (buf == mark || buf == end) goto failed;
    108                                 }
    109                                 if (val != INT32_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) {
    110                                     if (!(pval = flatcc_builder_table_add(ctx->ctx, 9, 4, 4))) goto failed;
    111                                     flatbuffers_int32_write_to_pe(pval, val);
    112                                 }
    113                             } else {
    114                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    115                             }
    116                         } else { /* "nation" */
    117                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    118                         } /* "nation" */
    119                     } /* descend "nation_v" */
    120                 } else { /* descend "damus_do" */
    121                     if (w == 0x646973706c61795f) { /* descend "display_" */
    122                         buf += 8;
    123                         w = flatcc_json_parser_symbol_part(buf, end);
    124                         if ((w & 0xffffffff00000000) == 0x6e616d6500000000) { /* "name" */
    125                             buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 4);
    126                             if (mark != buf) {
    127                                 buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    128                                 if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 5))) goto failed;
    129                                 *pref = ref;
    130                             } else {
    131                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    132                             }
    133                         } else { /* "name" */
    134                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    135                         } /* "name" */
    136                     } else { /* descend "display_" */
    137                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    138                     } /* descend "display_" */
    139                 } /* descend "damus_do" */
    140             } /* branch "damus_do" */
    141         } else { /* branch "lud06" */
    142             if (w < 0x6e69703035000000) { /* branch "nip05" */
    143                 if (w < 0x6c75643136000000) { /* branch "lud16" */
    144                     if ((w & 0xffffffffff000000) == 0x6c75643036000000) { /* "lud06" */
    145                         buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
    146                         if (mark != buf) {
    147                             buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    148                             if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 11))) goto failed;
    149                             *pref = ref;
    150                         } else {
    151                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    152                         }
    153                     } else { /* "lud06" */
    154                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    155                     } /* "lud06" */
    156                 } else { /* branch "lud16" */
    157                     if ((w & 0xffffffff00000000) == 0x6e616d6500000000) { /* "name" */
    158                         buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 4);
    159                         if (mark != buf) {
    160                             buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    161                             if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
    162                             *pref = ref;
    163                         } else {
    164                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    165                         }
    166                     } else { /* "name" */
    167                         if ((w & 0xffffffffff000000) == 0x6c75643136000000) { /* "lud16" */
    168                             buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
    169                             if (mark != buf) {
    170                                 buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    171                                 if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 3))) goto failed;
    172                                 *pref = ref;
    173                             } else {
    174                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    175                             }
    176                         } else { /* "lud16" */
    177                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    178                         } /* "lud16" */
    179                     } /* "name" */
    180                 } /* branch "lud16" */
    181             } else { /* branch "nip05" */
    182                 if (w < 0x7069637475726500) { /* branch "picture" */
    183                     if ((w & 0xffffffffff000000) == 0x6e69703035000000) { /* "nip05" */
    184                         buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
    185                         if (mark != buf) {
    186                             buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    187                             if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 8))) goto failed;
    188                             *pref = ref;
    189                         } else {
    190                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    191                         }
    192                     } else { /* "nip05" */
    193                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    194                     } /* "nip05" */
    195                 } else { /* branch "picture" */
    196                     if (w < 0x7265616374696f6e) { /* branch "reaction" */
    197                         if ((w & 0xffffffffffffff00) == 0x7069637475726500) { /* "picture" */
    198                             buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
    199                             if (mark != buf) {
    200                                 buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    201                                 if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 7))) goto failed;
    202                                 *pref = ref;
    203                             } else {
    204                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    205                             }
    206                         } else { /* "picture" */
    207                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    208                         } /* "picture" */
    209                     } else { /* branch "reaction" */
    210                         if (w == 0x7265616374696f6e) { /* descend "reaction" */
    211                             buf += 8;
    212                             w = flatcc_json_parser_symbol_part(buf, end);
    213                             if ((w & 0xff00000000000000) == 0x7300000000000000) { /* "s" */
    214                                 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
    215                                 if (mark != buf) {
    216                                     uint8_t val = 0;
    217                                     static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
    218                                             profile_local_json_parser_enum,
    219                                             profile_global_json_parser_enum, 0 };
    220                                     buf = flatcc_json_parser_bool(ctx, (mark = buf), end, &val);
    221                                     if (mark == buf) {
    222                                         buf = flatcc_json_parser_symbolic_bool(ctx, (mark = buf), end, symbolic_parsers, &val);
    223                                         if (buf == mark || buf == end) goto failed;
    224                                     }
    225                                     if (val != UINT8_C(1) || (ctx->flags & flatcc_json_parser_f_force_add)) {
    226                                         if (!(pval = flatcc_builder_table_add(ctx->ctx, 6, 1, 1))) goto failed;
    227                                         flatbuffers_bool_write_to_pe(pval, val);
    228                                     }
    229                                 } else {
    230                                     buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    231                                 }
    232                             } else { /* "s" */
    233                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    234                             } /* "s" */
    235                         } else { /* descend "reaction" */
    236                             if ((w & 0xffffffffffffff00) == 0x7765627369746500) { /* "website" */
    237                                 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
    238                                 if (mark != buf) {
    239                                     buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    240                                     if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 1))) goto failed;
    241                                     *pref = ref;
    242                                 } else {
    243                                     buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    244                                 }
    245                             } else { /* "website" */
    246                                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    247                             } /* "website" */
    248                         } /* descend "reaction" */
    249                     } /* branch "reaction" */
    250                 } /* branch "picture" */
    251             } /* branch "nip05" */
    252         } /* branch "lud06" */
    253         buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
    254     }
    255     if (ctx->error) goto failed;
    256     if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
    257     return buf;
    258 failed:
    259     return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
    260 }
    261 
    262 static inline int NdbProfile_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
    263 {
    264     return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, NdbProfile_parse_json_table);
    265 }
    266 
    267 static const char *NdbProfileRecord_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
    268 {
    269     int more;
    270     void *pval;
    271     flatcc_builder_ref_t ref, *pref;
    272     const char *mark;
    273     uint64_t w;
    274 
    275     *result = 0;
    276     if (flatcc_builder_start_table(ctx->ctx, 4)) goto failed;
    277     buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
    278     while (more) {
    279         buf = flatcc_json_parser_symbol_start(ctx, buf, end);
    280         w = flatcc_json_parser_symbol_part(buf, end);
    281         if (w < 0x6e6f74655f6b6579) { /* branch "note_key" */
    282             if ((w & 0xffffffffff000000) == 0x6c6e75726c000000) { /* "lnurl" */
    283                 buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
    284                 if (mark != buf) {
    285                     buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
    286                     if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 3))) goto failed;
    287                     *pref = ref;
    288                 } else {
    289                     buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    290                 }
    291             } else { /* "lnurl" */
    292                 buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    293             } /* "lnurl" */
    294         } else { /* branch "note_key" */
    295             if (w < 0x70726f66696c6500) { /* branch "profile" */
    296                 if (w == 0x6e6f74655f6b6579) { /* "note_key" */
    297                     buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 8);
    298                     if (mark != buf) {
    299                         uint64_t val = 0;
    300                         static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
    301                                 profile_local_json_parser_enum,
    302                                 profile_global_json_parser_enum, 0 };
    303                         buf = flatcc_json_parser_uint64(ctx, (mark = buf), end, &val);
    304                         if (mark == buf) {
    305                             buf = flatcc_json_parser_symbolic_uint64(ctx, (mark = buf), end, symbolic_parsers, &val);
    306                             if (buf == mark || buf == end) goto failed;
    307                         }
    308                         if (val != UINT64_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) {
    309                             if (!(pval = flatcc_builder_table_add(ctx->ctx, 2, 8, 8))) goto failed;
    310                             flatbuffers_uint64_write_to_pe(pval, val);
    311                         }
    312                     } else {
    313                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    314                     }
    315                 } else { /* "note_key" */
    316                     buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    317                 } /* "note_key" */
    318             } else { /* branch "profile" */
    319                 if ((w & 0xffffffffffffff00) == 0x70726f66696c6500) { /* "profile" */
    320                     buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
    321                     if (mark != buf) {
    322                         buf = NdbProfile_parse_json_table(ctx, buf, end, &ref);
    323                         if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
    324                         *pref = ref;
    325                     } else {
    326                         goto pfguard1;
    327                     }
    328                 } else { /* "profile" */
    329                     goto pfguard1;
    330                 } /* "profile" */
    331                 goto endpfguard1;
    332 pfguard1:
    333                 if (w == 0x7265636569766564) { /* descend "received" */
    334                     buf += 8;
    335                     w = flatcc_json_parser_symbol_part(buf, end);
    336                     if ((w & 0xffffff0000000000) == 0x5f61740000000000) { /* "_at" */
    337                         buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3);
    338                         if (mark != buf) {
    339                             uint64_t val = 0;
    340                             static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
    341                                     profile_local_json_parser_enum,
    342                                     profile_global_json_parser_enum, 0 };
    343                             buf = flatcc_json_parser_uint64(ctx, (mark = buf), end, &val);
    344                             if (mark == buf) {
    345                                 buf = flatcc_json_parser_symbolic_uint64(ctx, (mark = buf), end, symbolic_parsers, &val);
    346                                 if (buf == mark || buf == end) goto failed;
    347                             }
    348                             if (val != UINT64_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) {
    349                                 if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 8, 8))) goto failed;
    350                                 flatbuffers_uint64_write_to_pe(pval, val);
    351                             }
    352                         } else {
    353                             buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    354                         }
    355                     } else { /* "_at" */
    356                         buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    357                     } /* "_at" */
    358                 } else { /* descend "received" */
    359                     buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
    360                 } /* descend "received" */
    361 endpfguard1:
    362                 (void)0;
    363             } /* branch "profile" */
    364         } /* branch "note_key" */
    365         buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
    366     }
    367     if (ctx->error) goto failed;
    368     if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
    369     return buf;
    370 failed:
    371     return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
    372 }
    373 
    374 static inline int NdbProfileRecord_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
    375 {
    376     return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, NdbProfileRecord_parse_json_table);
    377 }
    378 
    379 static const char *profile_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
    380         int *value_type, uint64_t *value, int *aggregate)
    381 {
    382     /* Scope has no enum / union types to look up. */
    383     return buf; /* unmatched; */
    384 }
    385 
    386 static const char *profile_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
    387         int *value_type, uint64_t *value, int *aggregate)
    388 {
    389     /* Global scope has no enum / union types to look up. */
    390     return buf; /* unmatched; */
    391 }
    392 
    393 static int profile_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
    394         const char *buf, size_t bufsiz, int flags)
    395 {
    396     flatcc_json_parser_t parser;
    397     flatcc_builder_ref_t root;
    398 
    399     ctx = ctx ? ctx : &parser;
    400     flatcc_json_parser_init(ctx, B, buf, buf + bufsiz, flags);
    401     if (flatcc_builder_start_buffer(B, 0, 0, 0)) return -1;
    402     NdbProfileRecord_parse_json_table(ctx, buf, buf + bufsiz, &root);
    403     if (ctx->error) {
    404         return ctx->error;
    405     }
    406     if (!flatcc_builder_end_buffer(B, root)) return -1;
    407     ctx->end_loc = buf;
    408     return 0;
    409 }
    410 
    411 #include "flatcc_epilogue.h"
    412 #endif /* PROFILE_JSON_PARSER_H */