static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef) { if (f->type_ == UPB_TYPE(MESSAGE) || f->type_ == UPB_TYPE(GROUP)) return upb_dyncast_msgdef(subdef) != NULL; else if (f->type_ == UPB_TYPE(ENUM)) return upb_dyncast_enumdef(subdef) != NULL; else { assert(false); return false; } }
static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef, upb_status *s) { if (f->type_ == UPB_TYPE_MESSAGE) { if (upb_dyncast_msgdef(subdef)) return true; upb_status_seterrmsg(s, "invalid subdef type for this submessage field"); return false; } else if (f->type_ == UPB_TYPE_ENUM) { if (upb_dyncast_enumdef(subdef)) return true; upb_status_seterrmsg(s, "invalid subdef type for this enum field"); return false; } else { upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); return false; } }
const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) { const upb_def *def = upb_fielddef_subdef(f); return def ? upb_dyncast_enumdef(def) : NULL; }
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { upb_value v; upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ? upb_value_getptr(v) : NULL; return def ? upb_dyncast_enumdef(def) : NULL; }