|
|
|
@ -7027,7 +7027,7 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, |
|
|
|
|
if (!upb_MtDecoder_FieldIsPackable(field)) { |
|
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
|
"Cannot flip packed on unpackable field %" PRIu32, |
|
|
|
|
field->number); |
|
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
|
} |
|
|
|
|
field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; |
|
|
|
|
} |
|
|
|
@ -7035,11 +7035,12 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, |
|
|
|
|
if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { |
|
|
|
|
if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || |
|
|
|
|
!(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { |
|
|
|
|
upb_MdDecoder_ErrorJmp( |
|
|
|
|
&d->base, |
|
|
|
|
"Cannot flip ValidateUtf8 on field %" PRIu32 ", type=%d, mode=%d", |
|
|
|
|
field->number, (int)field->UPB_PRIVATE(descriptortype), |
|
|
|
|
(int)field->UPB_PRIVATE(mode)); |
|
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
|
"Cannot flip ValidateUtf8 on field %" PRIu32 |
|
|
|
|
", type=%d, mode=%d", |
|
|
|
|
upb_MiniTableField_Number(field), |
|
|
|
|
(int)field->UPB_PRIVATE(descriptortype), |
|
|
|
|
(int)field->UPB_PRIVATE(mode)); |
|
|
|
|
} |
|
|
|
|
field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; |
|
|
|
|
field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; |
|
|
|
@ -7052,12 +7053,12 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, |
|
|
|
|
if ((singular || required) && field->offset != kHasbitPresence) { |
|
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
|
"Invalid modifier(s) for repeated field %" PRIu32, |
|
|
|
|
field->number); |
|
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
|
} |
|
|
|
|
if (singular && required) { |
|
|
|
|
upb_MdDecoder_ErrorJmp( |
|
|
|
|
&d->base, "Field %" PRIu32 " cannot be both singular and required", |
|
|
|
|
field->number); |
|
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (singular) field->offset = kNoPresence; |
|
|
|
@ -7258,7 +7259,7 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, |
|
|
|
|
upb_MiniTableField* field = fields; |
|
|
|
|
*field_count += 1; |
|
|
|
|
fields = (char*)fields + field_size; |
|
|
|
|
field->number = ++last_field_number; |
|
|
|
|
field->UPB_PRIVATE(number) = ++last_field_number; |
|
|
|
|
last_field = field; |
|
|
|
|
upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts); |
|
|
|
|
} else if (kUpb_EncodedValue_MinModifier <= ch && |
|
|
|
@ -7460,10 +7461,11 @@ static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, |
|
|
|
|
const upb_MiniTableField* f, |
|
|
|
|
uint32_t expected_num) { |
|
|
|
|
const char* name = expected_num == 1 ? "key" : "val"; |
|
|
|
|
if (f->number != expected_num) { |
|
|
|
|
const uint32_t f_number = upb_MiniTableField_Number(f); |
|
|
|
|
if (f_number != expected_num) { |
|
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
|
"map %s did not have expected number (%d vs %d)", |
|
|
|
|
name, expected_num, (int)f->number); |
|
|
|
|
name, expected_num, f_number); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!upb_MiniTableField_IsScalar(f)) { |
|
|
|
@ -8241,7 +8243,7 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( |
|
|
|
|
|
|
|
|
|
// Ideal case: index into dense fields
|
|
|
|
|
if (i < m->UPB_PRIVATE(dense_below)) { |
|
|
|
|
UPB_ASSERT(m->UPB_PRIVATE(fields)[i].number == number); |
|
|
|
|
UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); |
|
|
|
|
return &m->UPB_PRIVATE(fields)[i]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -8250,7 +8252,7 @@ const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( |
|
|
|
|
int hi = m->UPB_PRIVATE(field_count) - 1; |
|
|
|
|
while (lo <= hi) { |
|
|
|
|
int mid = (lo + hi) / 2; |
|
|
|
|
uint32_t num = m->UPB_PRIVATE(fields)[mid].number; |
|
|
|
|
uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); |
|
|
|
|
if (num < number) { |
|
|
|
|
lo = mid + 1; |
|
|
|
|
continue; |
|
|
|
@ -12917,7 +12919,8 @@ static const char* _upb_Decoder_DecodeKnownGroup( |
|
|
|
|
const upb_MiniTableSub* subs, const upb_MiniTableField* field) { |
|
|
|
|
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); |
|
|
|
|
UPB_ASSERT(subl); |
|
|
|
|
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number); |
|
|
|
|
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, |
|
|
|
|
field->UPB_PRIVATE(number)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { |
|
|
|
@ -12954,7 +12957,8 @@ static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, |
|
|
|
|
// Unrecognized enum goes into unknown fields.
|
|
|
|
|
// For packed fields the tag could be arbitrarily far in the past,
|
|
|
|
|
// so we just re-encode the tag and value here.
|
|
|
|
|
const uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; |
|
|
|
|
const uint32_t tag = |
|
|
|
|
((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; |
|
|
|
|
upb_Message* unknown_msg = |
|
|
|
|
field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg |
|
|
|
|
: msg; |
|
|
|
@ -13214,7 +13218,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, |
|
|
|
|
if (size != 0) { |
|
|
|
|
char* buf; |
|
|
|
|
size_t size; |
|
|
|
|
uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited; |
|
|
|
|
uint32_t tag = |
|
|
|
|
((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; |
|
|
|
|
upb_EncodeStatus status = |
|
|
|
|
upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size); |
|
|
|
|
if (status != kUpb_EncodeStatus_Ok) { |
|
|
|
@ -13254,10 +13259,11 @@ static const char* _upb_Decoder_DecodeToSubMessage( |
|
|
|
|
} else if (field->presence < 0) { |
|
|
|
|
/* Oneof case */ |
|
|
|
|
uint32_t* oneof_case = _upb_Message_OneofCasePtr(msg, field); |
|
|
|
|
if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->number) { |
|
|
|
|
if (op == kUpb_DecodeOp_SubMessage && |
|
|
|
|
*oneof_case != field->UPB_PRIVATE(number)) { |
|
|
|
|
memset(mem, 0, sizeof(void*)); |
|
|
|
|
} |
|
|
|
|
*oneof_case = field->number; |
|
|
|
|
*oneof_case = field->UPB_PRIVATE(number); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Store into message. */ |
|
|
|
@ -13490,13 +13496,13 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, |
|
|
|
|
* since fields are usually in order. */ |
|
|
|
|
size_t last = *last_field_index; |
|
|
|
|
for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { |
|
|
|
|
if (t->UPB_PRIVATE(fields)[idx].number == field_number) { |
|
|
|
|
if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { |
|
|
|
|
goto found; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) { |
|
|
|
|
if (t->UPB_PRIVATE(fields)[idx].number == field_number) { |
|
|
|
|
if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { |
|
|
|
|
goto found; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -13523,7 +13529,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, |
|
|
|
|
return &none; /* Unknown field. */ |
|
|
|
|
|
|
|
|
|
found: |
|
|
|
|
UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].number == field_number); |
|
|
|
|
UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number); |
|
|
|
|
*last_field_index = idx; |
|
|
|
|
return &t->UPB_PRIVATE(fields)[idx]; |
|
|
|
|
} |
|
|
|
@ -13681,7 +13687,7 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, |
|
|
|
|
*op = _upb_Decoder_GetDelimitedOp(d, mt, field); |
|
|
|
|
return ptr; |
|
|
|
|
case kUpb_WireType_StartGroup: |
|
|
|
|
val->uint32_val = field->number; |
|
|
|
|
val->uint32_val = field->UPB_PRIVATE(number); |
|
|
|
|
if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { |
|
|
|
|
*op = kUpb_DecodeOp_SubMessage; |
|
|
|
|
_upb_Decoder_CheckUnlinked(d, mt, field, op); |
|
|
|
@ -15175,7 +15181,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_EndGroup); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); |
|
|
|
|
encode_TaggedMessagePtr(e, submsg, subm, &size); |
|
|
|
|
wire_type = kUpb_WireType_StartGroup; |
|
|
|
|
e->depth++; |
|
|
|
@ -15201,7 +15207,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, |
|
|
|
|
} |
|
|
|
|
#undef CASE |
|
|
|
|
|
|
|
|
|
encode_tag(e, f->number, wire_type); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), wire_type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
@ -15215,20 +15221,21 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define VARINT_CASE(ctype, encode) \ |
|
|
|
|
{ \
|
|
|
|
|
const ctype* start = _upb_array_constptr(arr); \
|
|
|
|
|
const ctype* ptr = start + arr->size; \
|
|
|
|
|
uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \
|
|
|
|
|
do { \
|
|
|
|
|
ptr--; \
|
|
|
|
|
encode_varint(e, encode); \
|
|
|
|
|
if (tag) encode_varint(e, tag); \
|
|
|
|
|
} while (ptr != start); \
|
|
|
|
|
} \
|
|
|
|
|
#define VARINT_CASE(ctype, encode) \ |
|
|
|
|
{ \
|
|
|
|
|
const ctype* start = _upb_array_constptr(arr); \
|
|
|
|
|
const ctype* ptr = start + arr->size; \
|
|
|
|
|
uint32_t tag = \
|
|
|
|
|
packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \
|
|
|
|
|
do { \
|
|
|
|
|
ptr--; \
|
|
|
|
|
encode_varint(e, encode); \
|
|
|
|
|
if (tag) encode_varint(e, tag); \
|
|
|
|
|
} while (ptr != start); \
|
|
|
|
|
} \
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) |
|
|
|
|
#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) |
|
|
|
|
|
|
|
|
|
switch (f->UPB_PRIVATE(descriptortype)) { |
|
|
|
|
case kUpb_FieldType_Double: |
|
|
|
@ -15267,7 +15274,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
ptr--; |
|
|
|
|
encode_bytes(e, ptr->data, ptr->size); |
|
|
|
|
encode_varint(e, ptr->size); |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_Delimited); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); |
|
|
|
|
} while (ptr != start); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -15280,9 +15287,9 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
do { |
|
|
|
|
size_t size; |
|
|
|
|
ptr--; |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_EndGroup); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); |
|
|
|
|
encode_TaggedMessagePtr(e, *ptr, subm, &size); |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_StartGroup); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); |
|
|
|
|
} while (ptr != start); |
|
|
|
|
e->depth++; |
|
|
|
|
return; |
|
|
|
@ -15298,7 +15305,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
ptr--; |
|
|
|
|
encode_TaggedMessagePtr(e, *ptr, subm, &size); |
|
|
|
|
encode_varint(e, size); |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_Delimited); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); |
|
|
|
|
} while (ptr != start); |
|
|
|
|
e->depth++; |
|
|
|
|
return; |
|
|
|
@ -15308,7 +15315,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
|
|
|
|
|
if (packed) { |
|
|
|
|
encode_varint(e, e->limit - e->ptr - pre_len); |
|
|
|
|
encode_tag(e, f->number, kUpb_WireType_Delimited); |
|
|
|
|
encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -15343,7 +15350,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
map, &sorted); |
|
|
|
|
upb_MapEntry ent; |
|
|
|
|
while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { |
|
|
|
|
encode_mapentry(e, f->number, layout, &ent); |
|
|
|
|
encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); |
|
|
|
|
} |
|
|
|
|
_upb_mapsorter_popmap(&e->sorter, &sorted); |
|
|
|
|
} else { |
|
|
|
@ -15354,7 +15361,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
upb_MapEntry ent; |
|
|
|
|
_upb_map_fromkey(key, &ent.data.k, map->key_size); |
|
|
|
|
_upb_map_fromvalue(val, &ent.data.v, map->val_size); |
|
|
|
|
encode_mapentry(e, f->number, layout, &ent); |
|
|
|
|
encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -15393,7 +15400,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, |
|
|
|
|
return _upb_Message_GetHasbitByField(msg, f); |
|
|
|
|
} else { |
|
|
|
|
// Field is in a oneof.
|
|
|
|
|
return _upb_Message_GetOneofCase(msg, f) == f->number; |
|
|
|
|
return _upb_Message_GetOneofCase(msg, f) == f->UPB_PRIVATE(number); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|