|
|
|
@ -38,6 +38,9 @@ struct upb_MessageDef { |
|
|
|
|
upb_inttable itof; |
|
|
|
|
upb_strtable ntof; |
|
|
|
|
|
|
|
|
|
// Looking up fields by json name.
|
|
|
|
|
upb_strtable jtof; |
|
|
|
|
|
|
|
|
|
/* All nested defs.
|
|
|
|
|
* MEM: We could save some space here by putting nested defs in a contiguous |
|
|
|
|
* region and calculating counts from offsets or vice-versa. */ |
|
|
|
@ -63,9 +66,6 @@ struct upb_MessageDef { |
|
|
|
|
bool in_message_set; |
|
|
|
|
bool is_sorted; |
|
|
|
|
upb_WellKnown well_known_type; |
|
|
|
|
#if UINTPTR_MAX == 0xffffffff |
|
|
|
|
uint32_t padding; // Increase size to a multiple of 8.
|
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void assign_msg_wellknowntype(upb_MessageDef* m) { |
|
|
|
@ -208,16 +208,16 @@ bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, |
|
|
|
|
const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( |
|
|
|
|
const upb_MessageDef* m, const char* name, size_t size) { |
|
|
|
|
upb_value val; |
|
|
|
|
const upb_FieldDef* f; |
|
|
|
|
|
|
|
|
|
if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { |
|
|
|
|
return upb_value_getconstptr(val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); |
|
|
|
|
if (!f) f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD_JSONNAME); |
|
|
|
|
|
|
|
|
|
return f; |
|
|
|
|
return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { |
|
|
|
@ -397,17 +397,25 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, |
|
|
|
|
_upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); |
|
|
|
|
if (!ok) _upb_DefBuilder_OomErr(ctx); |
|
|
|
|
|
|
|
|
|
if (strcmp(shortname, json_name) != 0) { |
|
|
|
|
if (upb_strtable_lookup(&m->ntof, json_name, &v)) { |
|
|
|
|
_upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); |
|
|
|
|
} |
|
|
|
|
// TODO: Once editions is supported this should turn into a
|
|
|
|
|
// check on LEGACY_BEST_EFFORT
|
|
|
|
|
if (strcmp(shortname, json_name) != 0 && |
|
|
|
|
upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3 && |
|
|
|
|
upb_strtable_lookup(&m->ntof, json_name, &v)) { |
|
|
|
|
_upb_DefBuilder_Errf( |
|
|
|
|
ctx, "duplicate json_name for (%s) with original field name (%s)", |
|
|
|
|
shortname, json_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const size_t json_size = strlen(json_name); |
|
|
|
|
const upb_value json_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD_JSONNAME); |
|
|
|
|
ok = _upb_MessageDef_Insert(m, json_name, json_size, json_v, ctx->arena); |
|
|
|
|
if (!ok) _upb_DefBuilder_OomErr(ctx); |
|
|
|
|
if (upb_strtable_lookup(&m->jtof, json_name, &v)) { |
|
|
|
|
_upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const size_t json_size = strlen(json_name); |
|
|
|
|
ok = upb_strtable_insert(&m->jtof, json_name, json_size, |
|
|
|
|
upb_value_constptr(f), ctx->arena); |
|
|
|
|
if (!ok) _upb_DefBuilder_OomErr(ctx); |
|
|
|
|
|
|
|
|
|
if (upb_inttable_lookup(&m->itof, field_number, NULL)) { |
|
|
|
|
_upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); |
|
|
|
|
} |
|
|
|
@ -660,6 +668,9 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, |
|
|
|
|
ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); |
|
|
|
|
if (!ok) _upb_DefBuilder_OomErr(ctx); |
|
|
|
|
|
|
|
|
|
ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); |
|
|
|
|
if (!ok) _upb_DefBuilder_OomErr(ctx); |
|
|
|
|
|
|
|
|
|
UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); |
|
|
|
|
|
|
|
|
|
m->oneof_count = n_oneof; |
|
|
|
|