|
|
@ -7099,10 +7099,10 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, |
|
|
|
type -= kUpb_EncodedType_RepeatedBase; |
|
|
|
type -= kUpb_EncodedType_RepeatedBase; |
|
|
|
field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; |
|
|
|
field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; |
|
|
|
field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; |
|
|
|
field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; |
|
|
|
field->offset = kNoPresence; |
|
|
|
field->UPB_PRIVATE(offset) = kNoPresence; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; |
|
|
|
field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; |
|
|
|
field->offset = kHasbitPresence; |
|
|
|
field->UPB_PRIVATE(offset) = kHasbitPresence; |
|
|
|
if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { |
|
|
|
if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { |
|
|
|
field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; |
|
|
|
field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; |
|
|
|
} else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { |
|
|
|
} else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { |
|
|
@ -7150,7 +7150,7 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, |
|
|
|
bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; |
|
|
|
bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; |
|
|
|
|
|
|
|
|
|
|
|
// Validate.
|
|
|
|
// Validate.
|
|
|
|
if ((singular || required) && field->offset != kHasbitPresence) { |
|
|
|
if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { |
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
upb_MdDecoder_ErrorJmp(&d->base, |
|
|
|
"Invalid modifier(s) for repeated field %" PRIu32, |
|
|
|
"Invalid modifier(s) for repeated field %" PRIu32, |
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
upb_MiniTableField_Number(field)); |
|
|
@ -7161,9 +7161,9 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, |
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
upb_MiniTableField_Number(field)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (singular) field->offset = kNoPresence; |
|
|
|
if (singular) field->UPB_PRIVATE(offset) = kNoPresence; |
|
|
|
if (required) { |
|
|
|
if (required) { |
|
|
|
field->offset = kRequiredPresence; |
|
|
|
field->UPB_PRIVATE(offset) = kRequiredPresence; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -7250,7 +7250,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, |
|
|
|
" to oneof, no such field number.", |
|
|
|
" to oneof, no such field number.", |
|
|
|
field_num); |
|
|
|
field_num); |
|
|
|
} |
|
|
|
} |
|
|
|
if (f->offset != kHasbitPresence) { |
|
|
|
if (f->UPB_PRIVATE(offset) != kHasbitPresence) { |
|
|
|
upb_MdDecoder_ErrorJmp( |
|
|
|
upb_MdDecoder_ErrorJmp( |
|
|
|
&d->base, |
|
|
|
&d->base, |
|
|
|
"Cannot add repeated, required, or singular field %" PRIu32 |
|
|
|
"Cannot add repeated, required, or singular field %" PRIu32 |
|
|
@ -7265,7 +7265,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, |
|
|
|
item->rep = rep; |
|
|
|
item->rep = rep; |
|
|
|
} |
|
|
|
} |
|
|
|
// Prepend this field to the linked list.
|
|
|
|
// Prepend this field to the linked list.
|
|
|
|
f->offset = item->field_index; |
|
|
|
f->UPB_PRIVATE(offset) = item->field_index; |
|
|
|
item->field_index = (f - d->fields) + kOneofBase; |
|
|
|
item->field_index = (f - d->fields) + kOneofBase; |
|
|
|
return ptr; |
|
|
|
return ptr; |
|
|
|
} |
|
|
|
} |
|
|
@ -7442,7 +7442,7 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { |
|
|
|
int n = d->table->UPB_PRIVATE(field_count); |
|
|
|
int n = d->table->UPB_PRIVATE(field_count); |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
upb_MiniTableField* f = &d->fields[i]; |
|
|
|
upb_MiniTableField* f = &d->fields[i]; |
|
|
|
if (f->offset >= kOneofBase) continue; |
|
|
|
if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; |
|
|
|
upb_LayoutItem item = {.field_index = i, |
|
|
|
upb_LayoutItem item = {.field_index = i, |
|
|
|
.rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, |
|
|
|
.rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, |
|
|
|
.type = kUpb_LayoutItemType_Field}; |
|
|
|
.type = kUpb_LayoutItemType_Field}; |
|
|
@ -7470,9 +7470,9 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
upb_MiniTableField* field = |
|
|
|
upb_MiniTableField* field = |
|
|
|
(upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; |
|
|
|
(upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; |
|
|
|
if (field->offset == kRequiredPresence) { |
|
|
|
if (field->UPB_PRIVATE(offset) == kRequiredPresence) { |
|
|
|
field->presence = ++last_hasbit; |
|
|
|
field->presence = ++last_hasbit; |
|
|
|
} else if (field->offset == kNoPresence) { |
|
|
|
} else if (field->UPB_PRIVATE(offset) == kNoPresence) { |
|
|
|
field->presence = 0; |
|
|
|
field->presence = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -7486,7 +7486,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
for (int i = 0; i < n; i++) { |
|
|
|
upb_MiniTableField* field = |
|
|
|
upb_MiniTableField* field = |
|
|
|
(upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; |
|
|
|
(upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; |
|
|
|
if (field->offset == kHasbitPresence) { |
|
|
|
if (field->UPB_PRIVATE(offset) == kHasbitPresence) { |
|
|
|
field->presence = ++last_hasbit; |
|
|
|
field->presence = ++last_hasbit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -7524,9 +7524,10 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { |
|
|
|
upb_MiniTableField* f = &d->fields[item->field_index]; |
|
|
|
upb_MiniTableField* f = &d->fields[item->field_index]; |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
f->presence = ~item->offset; |
|
|
|
f->presence = ~item->offset; |
|
|
|
if (f->offset == kUpb_LayoutItem_IndexSentinel) break; |
|
|
|
if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; |
|
|
|
UPB_ASSERT(f->offset - kOneofBase < d->table->UPB_PRIVATE(field_count)); |
|
|
|
UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < |
|
|
|
f = &d->fields[f->offset - kOneofBase]; |
|
|
|
d->table->UPB_PRIVATE(field_count)); |
|
|
|
|
|
|
|
f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -7536,14 +7537,14 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { |
|
|
|
switch (item->type) { |
|
|
|
switch (item->type) { |
|
|
|
case kUpb_LayoutItemType_OneofField: |
|
|
|
case kUpb_LayoutItemType_OneofField: |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
uint16_t next_offset = f->offset; |
|
|
|
uint16_t next_offset = f->UPB_PRIVATE(offset); |
|
|
|
f->offset = item->offset; |
|
|
|
f->UPB_PRIVATE(offset) = item->offset; |
|
|
|
if (next_offset == kUpb_LayoutItem_IndexSentinel) break; |
|
|
|
if (next_offset == kUpb_LayoutItem_IndexSentinel) break; |
|
|
|
f = &d->fields[next_offset - kOneofBase]; |
|
|
|
f = &d->fields[next_offset - kOneofBase]; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case kUpb_LayoutItemType_Field: |
|
|
|
case kUpb_LayoutItemType_Field: |
|
|
|
f->offset = item->offset; |
|
|
|
f->UPB_PRIVATE(offset) = item->offset; |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -7614,8 +7615,8 @@ static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, |
|
|
|
// NOTE: sync with mini_table/message_internal.h.
|
|
|
|
// NOTE: sync with mini_table/message_internal.h.
|
|
|
|
const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; |
|
|
|
const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; |
|
|
|
const size_t hasbit_size = 8; |
|
|
|
const size_t hasbit_size = 8; |
|
|
|
d->fields[0].offset = hasbit_size; |
|
|
|
d->fields[0].UPB_PRIVATE(offset) = hasbit_size; |
|
|
|
d->fields[1].offset = hasbit_size + kv_size; |
|
|
|
d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; |
|
|
|
d->table->UPB_PRIVATE(size) = |
|
|
|
d->table->UPB_PRIVATE(size) = |
|
|
|
UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); |
|
|
|
UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); |
|
|
|
|
|
|
|
|
|
|
@ -7740,7 +7741,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( |
|
|
|
upb_MiniTableField* f = &ext->UPB_PRIVATE(field); |
|
|
|
upb_MiniTableField* f = &ext->UPB_PRIVATE(field); |
|
|
|
|
|
|
|
|
|
|
|
f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; |
|
|
|
f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; |
|
|
|
f->offset = 0; |
|
|
|
f->UPB_PRIVATE(offset) = 0; |
|
|
|
f->presence = 0; |
|
|
|
f->presence = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { |
|
|
|
if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { |
|
|
@ -13186,7 +13187,7 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
wireval* val, int op) { |
|
|
|
wireval* val, int op) { |
|
|
|
upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); |
|
|
|
upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); |
|
|
|
upb_Array* arr = *arrp; |
|
|
|
upb_Array* arr = *arrp; |
|
|
|
void* mem; |
|
|
|
void* mem; |
|
|
|
|
|
|
|
|
|
|
@ -13277,8 +13278,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { |
|
|
|
const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; |
|
|
|
const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; |
|
|
|
char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; |
|
|
|
char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; |
|
|
|
char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; |
|
|
|
char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; |
|
|
|
UPB_ASSERT(key_field->offset == offsetof(upb_MapEntryData, k)); |
|
|
|
UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); |
|
|
|
UPB_ASSERT(val_field->offset == offsetof(upb_MapEntryData, v)); |
|
|
|
UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); |
|
|
|
upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); |
|
|
|
upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); |
|
|
|
if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); |
|
|
|
if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -13289,7 +13290,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
wireval* val) { |
|
|
|
wireval* val) { |
|
|
|
upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); |
|
|
|
upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); |
|
|
|
upb_Map* map = *map_p; |
|
|
|
upb_Map* map = *map_p; |
|
|
|
upb_MapEntry ent; |
|
|
|
upb_MapEntry ent; |
|
|
|
UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); |
|
|
|
UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); |
|
|
@ -13352,7 +13353,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( |
|
|
|
upb_Decoder* d, const char* ptr, upb_Message* msg, |
|
|
|
upb_Decoder* d, const char* ptr, upb_Message* msg, |
|
|
|
const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, |
|
|
|
const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, |
|
|
|
int op) { |
|
|
|
int op) { |
|
|
|
void* mem = UPB_PTR_AT(msg, field->offset, void); |
|
|
|
void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); |
|
|
|
int type = field->UPB_PRIVATE(descriptortype); |
|
|
|
int type = field->UPB_PRIVATE(descriptortype); |
|
|
|
|
|
|
|
|
|
|
|
if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && |
|
|
|
if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && |
|
|
@ -15325,7 +15326,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, |
|
|
|
static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
static void encode_array(upb_encstate* e, const upb_Message* msg, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); |
|
|
|
const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); |
|
|
|
bool packed = upb_MiniTableField_IsPacked(f); |
|
|
|
bool packed = upb_MiniTableField_IsPacked(f); |
|
|
|
size_t pre_len = e->limit - e->ptr; |
|
|
|
size_t pre_len = e->limit - e->ptr; |
|
|
|
|
|
|
|
|
|
|
@ -15448,7 +15449,7 @@ static void encode_mapentry(upb_encstate* e, uint32_t number, |
|
|
|
static void encode_map(upb_encstate* e, const upb_Message* msg, |
|
|
|
static void encode_map(upb_encstate* e, const upb_Message* msg, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableSub* subs, |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); |
|
|
|
const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); |
|
|
|
const upb_MiniTable* layout = |
|
|
|
const upb_MiniTable* layout = |
|
|
|
upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); |
|
|
|
upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); |
|
|
|
UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); |
|
|
|
UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); |
|
|
@ -15483,7 +15484,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
const upb_MiniTableField* f) { |
|
|
|
if (f->presence == 0) { |
|
|
|
if (f->presence == 0) { |
|
|
|
// Proto3 presence or map/array.
|
|
|
|
// Proto3 presence or map/array.
|
|
|
|
const void* mem = UPB_PTR_AT(msg, f->offset, void); |
|
|
|
const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); |
|
|
|
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { |
|
|
|
switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { |
|
|
|
case kUpb_FieldRep_1Byte: { |
|
|
|
case kUpb_FieldRep_1Byte: { |
|
|
|
char ch; |
|
|
|
char ch; |
|
|
@ -15528,7 +15529,8 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, |
|
|
|
encode_map(e, msg, subs, field); |
|
|
|
encode_map(e, msg, subs, field); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case kUpb_FieldMode_Scalar: |
|
|
|
case kUpb_FieldMode_Scalar: |
|
|
|
encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); |
|
|
|
encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, |
|
|
|
|
|
|
|
field); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
UPB_UNREACHABLE(); |
|
|
|
UPB_UNREACHABLE(); |
|
|
|