From 4b0c4ca7fb0aa9207af3398e04534b23fbb88f27 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Fri, 9 Sep 2016 14:03:25 -0700 Subject: New upb_msg code and Lua bindings around it. There are still some things that are unfinished, but we are at parity with what Lua had before. --- upb/def.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'upb/def.c') diff --git a/upb/def.c b/upb/def.c index 92e89e0..bd8c129 100644 --- a/upb/def.c +++ b/upb/def.c @@ -133,7 +133,8 @@ upb_def *upb_def_dup(const upb_def *def, const void *o) { case UPB_DEF_ENUM: return upb_enumdef_upcast_mutable( upb_enumdef_dup(upb_downcast_enumdef(def), o)); - default: UPB_ASSERT(false); return NULL; + default: + UPB_UNREACHABLE(); } } @@ -283,6 +284,7 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the * lowest indexes, but we do not publicly guarantee this. */ upb_msg_field_iter j; + upb_msg_oneof_iter k; int i; uint32_t selector; int n = upb_msgdef_numfields(m); @@ -367,6 +369,13 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { #undef TRY #endif + for(upb_msg_oneof_begin(&k, m), i = 0; + !upb_msg_oneof_done(&k); + upb_msg_oneof_next(&k), i++) { + upb_oneofdef *o = upb_msg_iter_oneof(&k); + o->index = i; + } + upb_gfree(fields); return true; } @@ -1833,6 +1842,10 @@ int upb_oneofdef_numfields(const upb_oneofdef *o) { return upb_strtable_count(&o->ntof); } +uint32_t upb_oneofdef_index(const upb_oneofdef *o) { + return o->index; +} + bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, const void *ref_donor, upb_status *s) { -- cgit v1.2.3