static void onmreg(const void *c, upb_handlers *h) { const upb_msgdef *m = upb_handlers_msgdef(h); upb_msg_field_iter i; UPB_UNUSED(c); upb_handlers_setstartmsg(h, textprinter_startmsg, NULL); upb_handlers_setendmsg(h, textprinter_endmsg, NULL); for(upb_msg_field_begin(&i, m); !upb_msg_field_done(&i); upb_msg_field_next(&i)) { upb_fielddef *f = upb_msg_iter_field(&i); upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; upb_handlerattr_sethandlerdata(&attr, f); switch (upb_fielddef_type(f)) { case UPB_TYPE_INT32: upb_handlers_setint32(h, f, textprinter_putint32, &attr); break; case UPB_TYPE_INT64: upb_handlers_setint64(h, f, textprinter_putint64, &attr); break; case UPB_TYPE_UINT32: upb_handlers_setuint32(h, f, textprinter_putuint32, &attr); break; case UPB_TYPE_UINT64: upb_handlers_setuint64(h, f, textprinter_putuint64, &attr); break; case UPB_TYPE_FLOAT: upb_handlers_setfloat(h, f, textprinter_putfloat, &attr); break; case UPB_TYPE_DOUBLE: upb_handlers_setdouble(h, f, textprinter_putdouble, &attr); break; case UPB_TYPE_BOOL: upb_handlers_setbool(h, f, textprinter_putbool, &attr); break; case UPB_TYPE_STRING: case UPB_TYPE_BYTES: upb_handlers_setstartstr(h, f, textprinter_startstr, &attr); upb_handlers_setstring(h, f, textprinter_putstr, &attr); upb_handlers_setendstr(h, f, textprinter_endstr, &attr); break; case UPB_TYPE_MESSAGE: { const char *name = upb_fielddef_istagdelim(f) ? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f))) : upb_fielddef_name(f); upb_handlerattr_sethandlerdata(&attr, name); upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr); upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr); break; } case UPB_TYPE_ENUM: upb_handlers_setint32(h, f, textprinter_putenum, &attr); break; } } }
static void reghandlers(void *closure, upb_handlers *h) { UPB_UNUSED(closure); const upb_msgdef *m = upb_handlers_msgdef(h); if (m == GOOGLE_PROTOBUF_DESCRIPTORPROTO) { upb_handlers_setstartmsg(h, &msg_startmsg, NULL); upb_handlers_setendmsg(h, &msg_endmsg, NULL); upb_handlers_setstring(h, f(h, "name"), &msg_onname, NULL); upb_handlers_setendsubmsg(h, f(h, "field"), &msg_onendfield, NULL); upb_handlers_setendsubmsg(h, f(h, "extension"), &pushextension, NULL); } else if (m == GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO) { upb_handlers_setstartmsg(h, &file_startmsg, NULL); upb_handlers_setendmsg(h, &file_endmsg, NULL); upb_handlers_setstring(h, f(h, "package"), &file_onpackage, NULL); upb_handlers_setendsubmsg(h, f(h, "extension"), &pushextension, NULL); } else if (m == GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO) { upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); upb_handlers_setendmsg(h, &enumval_endmsg, NULL); upb_handlers_setstring(h, f(h, "name"), &enumval_onname, NULL); upb_handlers_setint32(h, f(h, "number"), &enumval_onnumber, NULL); } else if (m == GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO) { upb_handlers_setstartmsg(h, &enum_startmsg, NULL); upb_handlers_setendmsg(h, &enum_endmsg, NULL); upb_handlers_setstring(h, f(h, "name"), &enum_onname, NULL); } else if (m == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO) { upb_handlers_setstartmsg(h, &field_startmsg, NULL); upb_handlers_setendmsg(h, &field_endmsg, NULL); upb_handlers_setint32(h, f(h, "type"), &field_ontype, NULL); upb_handlers_setint32(h, f(h, "label"), &field_onlabel, NULL); upb_handlers_setint32(h, f(h, "number"), &field_onnumber, NULL); upb_handlers_setstring(h, f(h, "name"), &field_onname, NULL); upb_handlers_setstring(h, f(h, "type_name"), &field_ontypename, NULL); upb_handlers_setstring(h, f(h, "extendee"), &field_onextendee, NULL); upb_handlers_setstring(h, f(h, "default_value"), &field_ondefaultval, NULL); } else if (m == GOOGLE_PROTOBUF_FIELDOPTIONS) { upb_handlers_setbool(h, f(h, "lazy"), &field_onlazy, NULL); } }