rename the upb_MiniTable subtypes to follow the upb style guide:

upb_MiniTable_Enum -> upb_MiniTableEnum
upb_MiniTable_Extension -> upb_MiniTableExtension
upb_MiniTable_Field -> upb_MiniTableField
upb_MiniTable_File -> upb_MiniTableFile
upb_MiniTable_Sub -> upb_MiniTableSub

PiperOrigin-RevId: 486712960
pull/13171/head
Eric Salo 2 years ago committed by Copybara-Service
parent cb7a51938c
commit 75907f7af9
  1. 2
      docs/style-guide.md
  2. 8
      protos/protos.h
  3. 4
      python/extension_dict.c
  4. 12
      upb/extension_registry.c
  5. 6
      upb/extension_registry.h
  6. 22
      upb/fuzz_test_util.cc
  7. 26
      upb/mini_table/accessors.c
  8. 66
      upb/mini_table/accessors.h
  9. 38
      upb/mini_table/accessors_test.cc
  10. 4
      upb/mini_table/common.c
  11. 10
      upb/mini_table/common.h
  12. 74
      upb/mini_table/decode.c
  13. 16
      upb/mini_table/decode.h
  14. 16
      upb/mini_table/encode_test.cc
  15. 6
      upb/msg.c
  16. 63
      upb/msg_internal.h
  17. 2
      upb/reflection/def_builder_internal.h
  18. 12
      upb/reflection/def_pool.c
  19. 2
      upb/reflection/def_pool.h
  20. 4
      upb/reflection/def_pool_internal.h
  21. 12
      upb/reflection/enum_def.c
  22. 2
      upb/reflection/enum_def_internal.h
  23. 12
      upb/reflection/field_def.c
  24. 2
      upb/reflection/field_def.h
  25. 2
      upb/reflection/field_def_internal.h
  26. 6
      upb/reflection/file_def.c
  27. 2
      upb/reflection/file_def_internal.h
  28. 16
      upb/reflection/message.c
  29. 6
      upb/reflection/message_def.c
  30. 96
      upb/wire/decode.c
  31. 28
      upb/wire/encode.c
  32. 36
      upbc/file_layout.cc
  33. 36
      upbc/file_layout.h
  34. 36
      upbc/protoc-gen-upb.cc

@ -61,5 +61,5 @@ typedef struct {
const int32_t* _values; // List of values <0 or >63
uint64_t _mask; // Bits are set for acceptable value 0 <= x < 64
int _value_count;
} upb_MiniTable_Enum;
} upb_MiniTableEnum;
```

@ -159,14 +159,14 @@ typename T::CProxy CreateMessage(upb_Message* msg) {
class ExtensionMiniTableProvider {
public:
ExtensionMiniTableProvider(const upb_MiniTable_Extension* mini_table_ext)
ExtensionMiniTableProvider(const upb_MiniTableExtension* mini_table_ext)
: mini_table_ext_(mini_table_ext) {}
const upb_MiniTable_Extension* mini_table_ext() const {
const upb_MiniTableExtension* mini_table_ext() const {
return mini_table_ext_;
}
private:
const upb_MiniTable_Extension* mini_table_ext_;
const upb_MiniTableExtension* mini_table_ext_;
};
// -------------------------------------------------------------------
@ -183,7 +183,7 @@ class ExtensionIdentifier : public ExtensionMiniTableProvider {
using Extension = ExtensionType;
using Extendee = ExtendeeType;
ExtensionIdentifier(const upb_MiniTable_Extension* mini_table_ext)
ExtensionIdentifier(const upb_MiniTableExtension* mini_table_ext)
: ExtensionMiniTableProvider(mini_table_ext) {}
};

@ -73,8 +73,8 @@ static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self,
const upb_DefPool* symtab = upb_FileDef_Pool(file);
const upb_ExtensionRegistry* reg = upb_DefPool_ExtensionRegistry(symtab);
int64_t number = PyLong_AsLong(arg);
const upb_MiniTable_Extension* ext =
(upb_MiniTable_Extension*)upb_ExtensionRegistry_Lookup(reg, l, number);
const upb_MiniTableExtension* ext =
(upb_MiniTableExtension*)upb_ExtensionRegistry_Lookup(reg, l, number);
if (ext) {
const upb_FieldDef* f = upb_DefPool_FindExtensionByMiniTable(symtab, ext);
return PyUpb_FieldDescriptor_Get(f);

@ -55,13 +55,13 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) {
}
bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
const upb_MiniTable_Extension** e,
const upb_MiniTableExtension** e,
size_t count) {
char buf[EXTREG_KEY_SIZE];
const upb_MiniTable_Extension** start = e;
const upb_MiniTable_Extension** end = UPB_PTRADD(e, count);
const upb_MiniTableExtension** start = e;
const upb_MiniTableExtension** end = UPB_PTRADD(e, count);
for (; e < end; e++) {
const upb_MiniTable_Extension* ext = *e;
const upb_MiniTableExtension* ext = *e;
extreg_key(buf, ext->extendee, ext->field.number);
upb_value v;
if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) {
@ -77,14 +77,14 @@ bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
failure:
/* Back out the entries previously added. */
for (end = e, e = start; e < end; e++) {
const upb_MiniTable_Extension* ext = *e;
const upb_MiniTableExtension* ext = *e;
extreg_key(buf, ext->extendee, ext->field.number);
upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL);
}
return false;
}
const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup(
const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup(
const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) {
char buf[EXTREG_KEY_SIZE];
upb_value v;

@ -73,7 +73,7 @@ extern "C" {
*/
typedef struct upb_ExtensionRegistry upb_ExtensionRegistry;
typedef struct upb_MiniTable_Extension upb_MiniTable_Extension;
typedef struct upb_MiniTableExtension upb_MiniTableExtension;
// Creates a upb_ExtensionRegistry in the given arena.
// The arena must outlive any use of the extreg.
@ -85,12 +85,12 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena);
// Possible errors include OOM or an extension number that already exists.
// TODO: There is currently no way to determine the exact reason for failure.
bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
const upb_MiniTable_Extension** e,
const upb_MiniTableExtension** e,
size_t count);
// Looks up the extension (if any) defined for message type |t| and field
// number |num|. Returns the extension if found, otherwise NULL.
const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup(
const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup(
const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num);
#ifdef __cplusplus

@ -52,7 +52,7 @@ class Builder {
void BuildMessages();
void BuildEnums();
void BuildExtensions(upb_ExtensionRegistry** exts);
bool LinkExtension(upb_MiniTable_Extension* ext);
bool LinkExtension(upb_MiniTableExtension* ext);
void LinkMessages();
size_t NextLink() {
@ -67,7 +67,7 @@ class Builder {
: mini_tables_[NextLink() % mini_tables_.size()];
}
const upb_MiniTable_Enum* NextEnumTable() {
const upb_MiniTableEnum* NextEnumTable() {
return enum_tables_.empty()
? nullptr
: enum_tables_[NextLink() % enum_tables_.size()];
@ -76,7 +76,7 @@ class Builder {
const MiniTableFuzzInput* input_;
upb_Arena* arena_;
std::vector<const upb_MiniTable*> mini_tables_;
std::vector<const upb_MiniTable_Enum*> enum_tables_;
std::vector<const upb_MiniTableEnum*> enum_tables_;
size_t link_ = 0;
};
@ -96,14 +96,14 @@ void Builder::BuildEnums() {
upb::Status status;
enum_tables_.reserve(input_->enum_mini_descriptors.size());
for (const auto& d : input_->enum_mini_descriptors) {
upb_MiniTable_Enum* enum_table =
upb_MiniTableEnum* enum_table =
upb_MiniTable_BuildEnum(d.data(), d.size(), arena_, status.ptr());
if (enum_table) enum_tables_.push_back(enum_table);
}
}
bool Builder::LinkExtension(upb_MiniTable_Extension* ext) {
upb_MiniTable_Field* field = &ext->field;
bool Builder::LinkExtension(upb_MiniTableExtension* ext) {
upb_MiniTableField* field = &ext->field;
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {
auto mt = NextMiniTable();
@ -128,9 +128,9 @@ void Builder::BuildExtensions(upb_ExtensionRegistry** exts) {
const char* end = ptr + input_->extensions.size();
// Iterate through the buffer, building extensions as long as we can.
while (ptr < end) {
upb_MiniTable_Extension* ext = reinterpret_cast<upb_MiniTable_Extension*>(
upb_MiniTableExtension* ext = reinterpret_cast<upb_MiniTableExtension*>(
upb_Arena_Malloc(arena_, sizeof(*ext)));
upb_MiniTable_Sub sub;
upb_MiniTableSub sub;
const upb_MiniTable* extendee = NextMiniTable();
if (!extendee) break;
ptr = upb_MiniTable_BuildExtension(ptr, end - ptr, ext, extendee, sub,
@ -140,7 +140,7 @@ void Builder::BuildExtensions(upb_ExtensionRegistry** exts) {
if (upb_ExtensionRegistry_Lookup(*exts, ext->extendee, ext->field.number))
continue;
upb_ExtensionRegistry_AddArray(
*exts, const_cast<const upb_MiniTable_Extension**>(&ext), 1);
*exts, const_cast<const upb_MiniTableExtension**>(&ext), 1);
}
}
}
@ -150,8 +150,8 @@ void Builder::LinkMessages() {
upb_MiniTable* table = const_cast<upb_MiniTable*>(t);
// For each field that requires a sub-table, assign one as appropriate.
for (size_t i = 0; i < table->field_count; i++) {
upb_MiniTable_Field* field =
const_cast<upb_MiniTable_Field*>(&table->fields[i]);
upb_MiniTableField* field =
const_cast<upb_MiniTableField*>(&table->fields[i]);
if (link_ == input_->links.size()) link_ = 0;
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {

@ -35,7 +35,7 @@
#include "upb/msg.h"
#include "upb/port/def.inc"
static size_t _upb_MiniTable_Field_GetSize(const upb_MiniTable_Field* f) {
static size_t _upb_MiniTableField_Size(const upb_MiniTableField* f) {
static unsigned char sizes[] = {
0, /* 0 */
8, /* kUpb_FieldType_Double */
@ -61,7 +61,7 @@ static size_t _upb_MiniTable_Field_GetSize(const upb_MiniTable_Field* f) {
}
// Maps descriptor type to elem_size_lg2.
static int _upb_MiniTable_Field_CTypeLg2Size(const upb_MiniTable_Field* f) {
static int _upb_MiniTableField_CTypeLg2Size(const upb_MiniTableField* f) {
static const uint8_t sizes[] = {
-1, /* invalid descriptor type */
3, /* DOUBLE */
@ -87,8 +87,8 @@ static int _upb_MiniTable_Field_CTypeLg2Size(const upb_MiniTable_Field* f) {
}
bool upb_MiniTable_HasField(const upb_Message* msg,
const upb_MiniTable_Field* field) {
if (_upb_MiniTable_Field_InOneOf(field)) {
const upb_MiniTableField* field) {
if (_upb_MiniTableField_InOneOf(field)) {
return _upb_getoneofcase_field(msg, field) == field->number;
} else if (field->presence > 0) {
return _upb_hasbit_field(msg, field);
@ -100,23 +100,23 @@ bool upb_MiniTable_HasField(const upb_Message* msg,
}
void upb_MiniTable_ClearField(upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
char* mem = UPB_PTR_AT(msg, field->offset, char);
if (field->presence > 0) {
_upb_clearhas_field(msg, field);
} else if (_upb_MiniTable_Field_InOneOf(field)) {
} else if (_upb_MiniTableField_InOneOf(field)) {
uint32_t* oneof_case = _upb_oneofcase_field(msg, field);
if (*oneof_case != field->number) return;
*oneof_case = 0;
}
memset(mem, 0, _upb_MiniTable_Field_GetSize(field));
memset(mem, 0, _upb_MiniTableField_Size(field));
}
void* upb_MiniTable_ResizeArray(upb_Message* msg,
const upb_MiniTable_Field* field, size_t len,
const upb_MiniTableField* field, size_t len,
upb_Arena* arena) {
return _upb_Array_Resize_accessor2(
msg, field->offset, len, _upb_MiniTable_Field_CTypeLg2Size(field), arena);
msg, field->offset, len, _upb_MiniTableField_CTypeLg2Size(field), arena);
}
typedef struct {
@ -204,7 +204,7 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage(
}
upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
upb_Message* msg, const upb_MiniTable_Extension* ext_table,
upb_Message* msg, const upb_MiniTableExtension* ext_table,
int decode_options, upb_Arena* arena,
const upb_Message_Extension** extension) {
UPB_ASSERT(ext_table->field.descriptortype == kUpb_FieldType_Message);
@ -248,7 +248,7 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
}
upb_GetExtensionAsBytes_Status upb_MiniTable_GetExtensionAsBytes(
const upb_Message* msg, const upb_MiniTable_Extension* ext_table,
const upb_Message* msg, const upb_MiniTableExtension* ext_table,
int encode_options, upb_Arena* arena, const char** extension_data,
size_t* len) {
const upb_Message_Extension* msg_ext = _upb_Message_Getext(msg, ext_table);
@ -406,7 +406,7 @@ upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTable_Field* field, const upb_MiniTable* sub_mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
int decode_options, upb_Arena* arena) {
upb_FindUnknownRet unknown;
// We need to loop and merge unknowns that have matching tag field->number.
@ -454,7 +454,7 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// TODO(b/251007554): Optimize. Instead of converting messages one at a time,
// scan all unknown data once and compact.
upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMessageArray(
upb_Message* msg, const upb_MiniTable_Field* field,
upb_Message* msg, const upb_MiniTableField* field,
const upb_MiniTable* mini_table, int decode_options, upb_Arena* arena) {
upb_Array* repeated_messages = upb_MiniTable_GetMutableArray(msg, field);
// Find all unknowns with given field number and parse.

@ -38,15 +38,15 @@
extern "C" {
#endif
UPB_INLINE bool _upb_MiniTable_Field_InOneOf(const upb_MiniTable_Field* field) {
UPB_INLINE bool _upb_MiniTableField_InOneOf(const upb_MiniTableField* field) {
return field->presence < 0;
}
UPB_INLINE void _upb_MiniTable_SetPresence(upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
if (field->presence > 0) {
_upb_sethas_field(msg, field);
} else if (_upb_MiniTable_Field_InOneOf(field)) {
} else if (_upb_MiniTableField_InOneOf(field)) {
*_upb_oneofcase_field(msg, field) = field->number;
}
}
@ -54,19 +54,19 @@ UPB_INLINE void _upb_MiniTable_SetPresence(upb_Message* msg,
// EVERYTHING ABOVE THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
bool upb_MiniTable_HasField(const upb_Message* msg,
const upb_MiniTable_Field* field);
const upb_MiniTableField* field);
void upb_MiniTable_ClearField(upb_Message* msg,
const upb_MiniTable_Field* field);
const upb_MiniTableField* field);
UPB_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bool);
return *UPB_PTR_AT(msg, field->offset, bool);
}
UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
bool value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bool);
_upb_MiniTable_SetPresence(msg, field);
@ -74,7 +74,7 @@ UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
}
UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int32 ||
field->descriptortype == kUpb_FieldType_SInt32 ||
field->descriptortype == kUpb_FieldType_SFixed32 ||
@ -83,7 +83,7 @@ UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
}
UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int32 ||
field->descriptortype == kUpb_FieldType_SInt32 ||
@ -93,14 +93,14 @@ UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
}
UPB_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt32 ||
field->descriptortype == kUpb_FieldType_Fixed32);
return *UPB_PTR_AT(msg, field->offset, uint32_t);
}
UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
uint32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt32 ||
field->descriptortype == kUpb_FieldType_Fixed32);
@ -110,17 +110,17 @@ UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
const upb_MiniTable* msg_mini_table,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
UPB_ASSERT(upb_MiniTable_Enum_CheckValue(
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, field), value));
_upb_MiniTable_SetPresence(msg, field);
*UPB_PTR_AT(msg, field->offset, int32_t) = value;
}
UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
field->descriptortype == kUpb_FieldType_SInt64 ||
field->descriptortype == kUpb_FieldType_SFixed64);
@ -128,7 +128,7 @@ UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
}
UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
int64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
field->descriptortype == kUpb_FieldType_SInt64 ||
@ -138,14 +138,14 @@ UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
}
UPB_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
field->descriptortype == kUpb_FieldType_Fixed64);
return *UPB_PTR_AT(msg, field->offset, uint64_t);
}
UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
uint64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
field->descriptortype == kUpb_FieldType_Fixed64);
@ -154,13 +154,13 @@ UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
}
UPB_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
return *UPB_PTR_AT(msg, field->offset, float);
}
UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
float value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
_upb_MiniTable_SetPresence(msg, field);
@ -168,13 +168,13 @@ UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
}
UPB_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
return *UPB_PTR_AT(msg, field->offset, double);
}
UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
double value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
_upb_MiniTable_SetPresence(msg, field);
@ -182,14 +182,14 @@ UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
}
UPB_INLINE upb_StringView upb_MiniTable_GetString(
const upb_Message* msg, const upb_MiniTable_Field* field) {
const upb_Message* msg, const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
field->descriptortype == kUpb_FieldType_String);
return *UPB_PTR_AT(msg, field->offset, upb_StringView);
}
UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
upb_StringView value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
field->descriptortype == kUpb_FieldType_String);
@ -198,7 +198,7 @@ UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
}
UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
const upb_Message* msg, const upb_MiniTable_Field* field) {
const upb_Message* msg, const upb_MiniTableField* field) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group);
return *UPB_PTR_AT(msg, field->offset, const upb_Message*);
@ -206,7 +206,7 @@ UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTable_Field* field,
const upb_MiniTableField* field,
upb_Message* sub_message) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group);
@ -217,7 +217,7 @@ UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTable_Field* field, upb_Arena* arena) {
const upb_MiniTableField* field, upb_Arena* arena) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group);
upb_Message* sub_message = *UPB_PTR_AT(msg, field->offset, upb_Message*);
@ -233,17 +233,17 @@ UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
}
UPB_INLINE const upb_Array* upb_MiniTable_GetArray(
const upb_Message* msg, const upb_MiniTable_Field* field) {
const upb_Message* msg, const upb_MiniTableField* field) {
return (const upb_Array*)*UPB_PTR_AT(msg, field->offset, upb_Array*);
}
UPB_INLINE upb_Array* upb_MiniTable_GetMutableArray(
upb_Message* msg, const upb_MiniTable_Field* field) {
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Array*)*UPB_PTR_AT(msg, field->offset, upb_Array*);
}
void* upb_MiniTable_ResizeArray(upb_Message* msg,
const upb_MiniTable_Field* field, size_t len,
const upb_MiniTableField* field, size_t len,
upb_Arena* arena);
typedef enum {
kUpb_GetExtension_Ok,
@ -264,7 +264,7 @@ typedef enum {
// TODO(ferhat): Only supports extension fields that are messages,
// expand support to include non-message types.
upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
upb_Message* msg, const upb_MiniTable_Extension* ext_table,
upb_Message* msg, const upb_MiniTableExtension* ext_table,
int decode_options, upb_Arena* arena,
const upb_Message_Extension** extension);
@ -274,7 +274,7 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
// If an extension has already been decoded it will be re-encoded
// to bytes.
upb_GetExtensionAsBytes_Status upb_MiniTable_GetExtensionAsBytes(
const upb_Message* msg, const upb_MiniTable_Extension* ext_table,
const upb_Message* msg, const upb_MiniTableExtension* ext_table,
int encode_options, upb_Arena* arena, const char** extension_data,
size_t* len);
@ -314,7 +314,7 @@ typedef struct {
// using upb_MiniTable_SetMessage.
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTable_Field* field, const upb_MiniTable* sub_mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
int decode_options, upb_Arena* arena);
// Promotes all unknown data that matches field tag id to repeated messages
@ -324,7 +324,7 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// Since repeated messages can't be packed we remove each unknown that
// contains the target tag id.
upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMessageArray(
upb_Message* msg, const upb_MiniTable_Field* field,
upb_Message* msg, const upb_MiniTableField* field,
const upb_MiniTable* mini_table, int decode_options, upb_Arena* arena);
#ifdef __cplusplus

@ -65,12 +65,12 @@ const int32_t kTestInt32 = 567;
const int32_t kTestUInt32 = 0xF1234567;
const uint64_t kTestUInt64 = 0xFEDCBAFF87654321;
const upb_MiniTable_Field* find_proto3_field(int field_number) {
const upb_MiniTableField* find_proto3_field(int field_number) {
return upb_MiniTable_FindFieldByNumber(
&protobuf_test_messages_proto3_TestAllTypesProto3_msg_init, field_number);
}
const upb_MiniTable_Field* find_proto2_field(int field_number) {
const upb_MiniTableField* find_proto2_field(int field_number) {
return upb_MiniTable_FindFieldByNumber(
&protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, field_number);
}
@ -81,7 +81,7 @@ TEST(GeneratedCode, HazzersProto2) {
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
// Scalar/Boolean.
const upb_MiniTable_Field* optional_bool_field =
const upb_MiniTableField* optional_bool_field =
find_proto2_field(kFieldOptionalBool);
EXPECT_EQ(false, upb_MiniTable_HasField(msg, optional_bool_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true);
@ -93,7 +93,7 @@ TEST(GeneratedCode, HazzersProto2) {
protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg));
// String.
const upb_MiniTable_Field* optional_string_field =
const upb_MiniTableField* optional_string_field =
find_proto2_field(kFieldOptionalString);
EXPECT_EQ(false, upb_MiniTable_HasField(msg, optional_string_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string(
@ -110,7 +110,7 @@ TEST(GeneratedCode, HazzersProto2) {
.size);
// Message.
const upb_MiniTable_Field* optional_message_field =
const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage);
EXPECT_EQ(false, upb_MiniTable_HasField(msg, optional_message_field));
protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message(
@ -124,9 +124,9 @@ TEST(GeneratedCode, HazzersProto2) {
msg) == nullptr);
// One of.
const upb_MiniTable_Field* optional_oneof_uint32_field =
const upb_MiniTableField* optional_oneof_uint32_field =
find_proto2_field(kFieldOptionalOneOfUInt32);
const upb_MiniTable_Field* optional_oneof_string_field =
const upb_MiniTableField* optional_oneof_string_field =
find_proto2_field(kFieldOptionalOneOfString);
EXPECT_EQ(false, upb_MiniTable_HasField(msg, optional_oneof_uint32_field));
@ -153,7 +153,7 @@ TEST(GeneratedCode, ScalarsProto2) {
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
const upb_MiniTable_Field* optional_int32_field =
const upb_MiniTableField* optional_int32_field =
find_proto2_field(kFieldOptionalInt32);
EXPECT_EQ(
@ -167,7 +167,7 @@ TEST(GeneratedCode, ScalarsProto2) {
kTestInt32,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg));
const upb_MiniTable_Field* optional_uint32_field =
const upb_MiniTableField* optional_uint32_field =
find_proto2_field(kFieldOptionalUInt32);
EXPECT_EQ(
@ -187,9 +187,9 @@ TEST(GeneratedCode, ScalarProto3) {
protobuf_test_messages_proto3_TestAllTypesProto3* msg =
protobuf_test_messages_proto3_TestAllTypesProto3_new(arena);
const upb_MiniTable_Field* optional_int64_field =
const upb_MiniTableField* optional_int64_field =
find_proto3_field(kFieldProto3OptionalInt64);
const upb_MiniTable_Field* optional_uint64_field =
const upb_MiniTableField* optional_uint64_field =
find_proto3_field(kFieldProto3OptionalUInt64);
EXPECT_EQ(
@ -215,7 +215,7 @@ TEST(GeneratedCode, Strings) {
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
const upb_MiniTable_Field* optional_string_field =
const upb_MiniTableField* optional_string_field =
find_proto2_field(kFieldOptionalString);
// Test default.
@ -253,7 +253,7 @@ TEST(GeneratedCode, SubMessage) {
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
const upb_MiniTable_Field* optional_message_field =
const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage);
const upb_Message* test_message =
@ -276,7 +276,7 @@ TEST(GeneratedCode, SubMessage) {
upb_MiniTable_GetMessage(msg, optional_message_field);
EXPECT_EQ(true, sub_message != NULL);
const upb_MiniTable_Field* nested_message_a_field =
const upb_MiniTableField* nested_message_a_field =
upb_MiniTable_FindFieldByNumber(
&protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_msg_init,
kFieldOptionalNestedMessageA);
@ -315,7 +315,7 @@ TEST(GeneratedCode, RepeatedScalar) {
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
const upb_MiniTable_Field* repeated_int32_field =
const upb_MiniTableField* repeated_int32_field =
find_proto2_field(kFieldOptionalRepeatedInt32);
size_t len;
@ -367,7 +367,7 @@ TEST(GeneratedCode, GetMutableMessage) {
protobuf_test_messages_proto2_TestAllTypesProto2* msg =
protobuf_test_messages_proto2_TestAllTypesProto2_new(arena);
// Message.
const upb_MiniTable_Field* optional_message_field =
const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage);
upb_Message* msg1 = upb_MiniTable_GetMutableMessage(
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
@ -494,10 +494,10 @@ upb_MiniTable* CreateMiniTableWithEmptySubTables(upb_Arena* arena) {
EXPECT_EQ(status.ok, true);
// Initialize sub table to null. Not using upb_MiniTable_SetSubMessage
// since it checks ->ext on parameter.
upb_MiniTable_Sub* sub = const_cast<upb_MiniTable_Sub*>(
upb_MiniTableSub* sub = const_cast<upb_MiniTableSub*>(
&table->subs[table->fields[1].submsg_index]);
sub->submsg = nullptr;
sub = const_cast<upb_MiniTable_Sub*>(
sub = const_cast<upb_MiniTableSub*>(
&table->subs[table->fields[2].submsg_index]);
sub->submsg = nullptr;
return table;
@ -528,7 +528,7 @@ TEST(GeneratedCode, PromoteUnknownMessage) {
EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok);
// Update mini table and promote unknown to a message.
upb_MiniTable_SetSubMessage(mini_table,
(upb_MiniTable_Field*)&mini_table->fields[1],
(upb_MiniTableField*)&mini_table->fields[1],
&upb_test_ModelWithExtensions_msg_init);
const int decode_options =
UPB_DECODE_MAXDEPTH(100); // UPB_DECODE_ALIAS disabled.

@ -54,7 +54,7 @@ const int8_t _kUpb_FromBase92[] = {
73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
};
const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* table, uint32_t number) {
int n = table->field_count;
for (int i = 0; i < n; i++) {
@ -65,7 +65,7 @@ const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber(
return NULL;
}
upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) {
upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field) {
if (field->mode & kUpb_LabelFlags_IsAlternate) {
if (field->descriptortype == kUpb_FieldType_Int32) {
return kUpb_FieldType_Enum;

@ -51,18 +51,18 @@ typedef enum {
extern "C" {
#endif
const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* table, uint32_t number);
upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field);
upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field);
UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) {
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].submsg;
}
UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable(
const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) {
UPB_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].subenum;
}

@ -66,14 +66,14 @@ typedef struct {
typedef struct {
const char* end;
upb_MiniTable* table;
upb_MiniTable_Field* fields;
upb_MiniTableField* fields;
upb_MiniTablePlatform platform;
upb_LayoutItemVector vec;
upb_Arena* arena;
upb_Status* status;
// When building enums.
upb_MiniTable_Enum* enum_table;
upb_MiniTableEnum* enum_table;
uint32_t enum_value_count;
uint32_t enum_data_count;
uint32_t enum_data_capacity;
@ -130,7 +130,7 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d,
}
}
static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field,
static bool upb_MiniTable_HasSub(upb_MiniTableField* field,
uint64_t msg_modifiers) {
switch (field->descriptortype) {
case kUpb_FieldType_Message:
@ -148,12 +148,12 @@ static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field,
}
}
static bool upb_MtDecoder_FieldIsPackable(upb_MiniTable_Field* field) {
static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) {
return (field->mode & kUpb_FieldMode_Array) &&
_upb_FieldType_IsPackable(field->descriptortype);
}
static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field,
static void upb_MiniTable_SetTypeAndSub(upb_MiniTableField* field,
upb_FieldType type, uint32_t* sub_count,
uint64_t msg_modifiers,
bool is_proto3_enum) {
@ -200,7 +200,7 @@ static const char kUpb_EncodedToType[] = {
};
static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch,
upb_MiniTable_Field* field,
upb_MiniTableField* field,
uint64_t msg_modifiers,
uint32_t* sub_count) {
static const char kUpb_EncodedToFieldRep[] = {
@ -256,7 +256,7 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch,
static void upb_MtDecoder_ModifyField(upb_MtDecoder* d,
uint32_t message_modifiers,
uint32_t field_modifiers,
upb_MiniTable_Field* field) {
upb_MiniTableField* field) {
if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) {
if (!upb_MtDecoder_FieldIsPackable(field)) {
upb_MtDecoder_ErrorFormat(
@ -363,7 +363,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d,
ptr = upb_MiniTable_DecodeBase92Varint(
d, ptr, first_ch, kUpb_EncodedValue_MinOneofField,
kUpb_EncodedValue_MaxOneofField, &field_num);
upb_MiniTable_Field* f =
upb_MiniTableField* f =
(void*)upb_MiniTable_FindFieldByNumber(d->table, field_num);
if (!f) {
@ -418,7 +418,7 @@ static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d,
static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d,
const char* ptr, char first_ch,
upb_MiniTable_Field* last_field,
upb_MiniTableField* last_field,
uint64_t* msg_modifiers) {
uint32_t mod;
ptr = upb_MiniTable_DecodeBase92Varint(d, ptr, first_ch,
@ -451,7 +451,7 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr,
uint32_t* sub_count) {
uint64_t msg_modifiers = 0;
uint32_t last_field_number = 0;
upb_MiniTable_Field* last_field = NULL;
upb_MiniTableField* last_field = NULL;
bool need_dense_below = d->table != NULL;
d->end = UPB_PTRADD(ptr, len);
@ -463,7 +463,7 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr,
// For extensions, consume only a single field and then return.
return --ptr;
}
upb_MiniTable_Field* field = fields;
upb_MiniTableField* field = fields;
*field_count += 1;
fields = (char*)fields + field_size;
field->number = ++last_field_number;
@ -550,7 +550,7 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) {
// Add items for all non-oneof fields (oneofs were already added).
int n = d->table->field_count;
for (int i = 0; i < n; i++) {
upb_MiniTable_Field* f = &d->fields[i];
upb_MiniTableField* f = &d->fields[i];
if (f->offset >= kOneofBase) continue;
upb_LayoutItem item = {.field_index = i,
.rep = f->mode >> kUpb_FieldRep_Shift,
@ -576,7 +576,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MiniTable* ret) {
// First assign required fields, which must have the lowest hasbits.
for (int i = 0; i < n; i++) {
upb_MiniTable_Field* field = (upb_MiniTable_Field*)&ret->fields[i];
upb_MiniTableField* field = (upb_MiniTableField*)&ret->fields[i];
if (field->offset == kRequiredPresence) {
field->presence = ++last_hasbit;
} else if (field->offset == kNoPresence) {
@ -587,7 +587,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MiniTable* ret) {
// Next assign non-required hasbit fields.
for (int i = 0; i < n; i++) {
upb_MiniTable_Field* field = (upb_MiniTable_Field*)&ret->fields[i];
upb_MiniTableField* field = (upb_MiniTableField*)&ret->fields[i];
if (field->offset == kHasbitPresence) {
field->presence = ++last_hasbit;
}
@ -622,7 +622,7 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) {
// actual offsets will overwrite the links of the linked list.
for (upb_LayoutItem* item = d->vec.data; item < end; item++) {
if (item->type != kUpb_LayoutItemType_OneofCase) continue;
upb_MiniTable_Field* f = &d->fields[item->field_index];
upb_MiniTableField* f = &d->fields[item->field_index];
while (true) {
f->presence = ~item->offset;
if (f->offset == kUpb_LayoutItem_IndexSentinel) break;
@ -633,7 +633,7 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) {
// Assign offsets.
for (upb_LayoutItem* item = d->vec.data; item < end; item++) {
upb_MiniTable_Field* f = &d->fields[item->field_index];
upb_MiniTableField* f = &d->fields[item->field_index];
switch (item->type) {
case kUpb_LayoutItemType_OneofField:
while (true) {
@ -663,13 +663,13 @@ static void upb_MiniTable_BuildMapEntry(upb_MtDecoder* d,
upb_FieldType key_type,
upb_FieldType value_type,
bool value_is_proto3_enum) {
upb_MiniTable_Field* fields = upb_Arena_Malloc(d->arena, sizeof(*fields) * 2);
upb_MiniTableField* fields = upb_Arena_Malloc(d->arena, sizeof(*fields) * 2);
if (!fields) {
upb_MtDecoder_ErrorFormat(d, "OOM while building map mini table field");
UPB_UNREACHABLE();
}
upb_MiniTable_Sub* subs = NULL;
upb_MiniTableSub* subs = NULL;
if (value_is_proto3_enum) {
UPB_ASSERT(value_type == kUpb_FieldType_Enum);
// No sub needed.
@ -826,16 +826,16 @@ done:
return decoder.table;
}
static size_t upb_MiniTable_EnumSize(size_t count) {
return sizeof(upb_MiniTable_Enum) + count * sizeof(uint32_t);
static size_t upb_MiniTableEnum_Size(size_t count) {
return sizeof(upb_MiniTableEnum) + count * sizeof(uint32_t);
}
static upb_MiniTable_Enum* _upb_MiniTable_AddEnumDataMember(upb_MtDecoder* d,
uint32_t val) {
static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MtDecoder* d,
uint32_t val) {
if (d->enum_data_count == d->enum_data_capacity) {
size_t old_sz = upb_MiniTable_EnumSize(d->enum_data_capacity);
size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity);
d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2);
size_t new_sz = upb_MiniTable_EnumSize(d->enum_data_capacity);
size_t new_sz = upb_MiniTableEnum_Size(d->enum_data_capacity);
d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz);
upb_MtDecoder_CheckOutOfMemory(d, d->enum_table);
}
@ -844,7 +844,7 @@ static upb_MiniTable_Enum* _upb_MiniTable_AddEnumDataMember(upb_MtDecoder* d,
}
static void upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, uint32_t val) {
upb_MiniTable_Enum* table = d->enum_table;
upb_MiniTableEnum* table = d->enum_table;
d->enum_value_count++;
if (table->value_count || (val > 512 && d->enum_value_count < val / 32)) {
if (table->value_count == 0) {
@ -862,11 +862,11 @@ static void upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, uint32_t val) {
}
}
upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status) {
upb_MiniTableEnum* upb_MiniTable_BuildEnum(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status) {
upb_MtDecoder decoder = {
.enum_table = upb_Arena_Malloc(arena, upb_MiniTable_EnumSize(2)),
.enum_table = upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(2)),
.enum_value_count = 0,
.enum_data_count = 0,
.enum_data_capacity = 1,
@ -923,9 +923,9 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len,
}
const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
upb_MiniTable_Extension* ext,
upb_MiniTableExtension* ext,
const upb_MiniTable* extendee,
upb_MiniTable_Sub sub,
upb_MiniTableSub sub,
upb_Status* status) {
upb_MtDecoder decoder = {
.arena = NULL,
@ -950,7 +950,7 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL);
if (!ret || count != 1) return NULL;
upb_MiniTable_Field* f = &ext->field;
upb_MiniTableField* f = &ext->field;
f->mode |= kUpb_LabelFlags_IsExtension;
f->offset = 0;
@ -982,7 +982,7 @@ upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
}
void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
upb_MiniTable_Field* field,
upb_MiniTableField* field,
const upb_MiniTable* sub) {
UPB_ASSERT((uintptr_t)table->fields <= (uintptr_t)field &&
(uintptr_t)field <
@ -990,15 +990,15 @@ void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
if (sub->ext & kUpb_ExtMode_IsMapEntry) {
field->mode = (field->mode & ~kUpb_FieldMode_Mask) | kUpb_FieldMode_Map;
}
upb_MiniTable_Sub* table_sub = (void*)&table->subs[field->submsg_index];
upb_MiniTableSub* table_sub = (void*)&table->subs[field->submsg_index];
table_sub->submsg = sub;
}
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field,
const upb_MiniTable_Enum* sub) {
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
const upb_MiniTableEnum* sub) {
UPB_ASSERT((uintptr_t)table->fields <= (uintptr_t)field &&
(uintptr_t)field <
(uintptr_t)(table->fields + table->field_count));
upb_MiniTable_Sub* table_sub = (void*)&table->subs[field->submsg_index];
upb_MiniTableSub* table_sub = (void*)&table->subs[field->submsg_index];
table_sub->subenum = sub;
}

@ -59,23 +59,23 @@ upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
// as unknown. However there is no synchronization for this operation, which
// means parallel mutation requires external synchronization.
void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
upb_MiniTable_Field* field,
upb_MiniTableField* field,
const upb_MiniTable* sub);
// Links an enum field to a MiniTable for that enum. All enum fields must
// be linked prior to parsing.
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field,
const upb_MiniTable_Enum* sub);
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
const upb_MiniTableEnum* sub);
const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
upb_MiniTable_Extension* ext,
upb_MiniTableExtension* ext,
const upb_MiniTable* extendee,
upb_MiniTable_Sub sub,
upb_MiniTableSub sub,
upb_Status* status);
upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status);
upb_MiniTableEnum* upb_MiniTable_BuildEnum(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status);
// Like upb_MiniTable_Build(), but the user provides a buffer of layout data so
// it can be reused from call to call, avoiding repeated realloc()/free().

@ -70,7 +70,7 @@ TEST_P(MiniTableTest, AllScalarTypes) {
EXPECT_EQ(count, table->field_count);
absl::flat_hash_set<size_t> offsets;
for (int i = 0; i < 16; i++) {
const upb_MiniTable_Field* f = &table->fields[i];
const upb_MiniTableField* f = &table->fields[i];
EXPECT_EQ(i + 1, f->number);
EXPECT_EQ(kUpb_FieldMode_Scalar, f->mode & kUpb_FieldMode_Mask);
EXPECT_TRUE(offsets.insert(f->offset).second);
@ -96,7 +96,7 @@ TEST_P(MiniTableTest, AllRepeatedTypes) {
EXPECT_EQ(count, table->field_count);
absl::flat_hash_set<size_t> offsets;
for (int i = 0; i < 16; i++) {
const upb_MiniTable_Field* f = &table->fields[i];
const upb_MiniTableField* f = &table->fields[i];
EXPECT_EQ(i + 1, f->number);
EXPECT_EQ(kUpb_FieldMode_Array, f->mode & kUpb_FieldMode_Mask);
EXPECT_TRUE(offsets.insert(f->offset).second);
@ -124,7 +124,7 @@ TEST_P(MiniTableTest, Skips) {
EXPECT_EQ(count, table->field_count);
absl::flat_hash_set<size_t> offsets;
for (size_t i = 0; i < field_numbers.size(); i++) {
const upb_MiniTable_Field* f = &table->fields[i];
const upb_MiniTableField* f = &table->fields[i];
EXPECT_EQ(field_numbers[i], f->number);
EXPECT_EQ(kUpb_FieldType_Float, f->descriptortype);
EXPECT_EQ(kUpb_FieldMode_Scalar, f->mode & kUpb_FieldMode_Mask);
@ -154,7 +154,7 @@ TEST_P(MiniTableTest, AllScalarTypesOneof) {
EXPECT_EQ(count, table->field_count);
absl::flat_hash_set<size_t> offsets;
for (int i = 0; i < 16; i++) {
const upb_MiniTable_Field* f = &table->fields[i];
const upb_MiniTableField* f = &table->fields[i];
EXPECT_EQ(i + 1, f->number);
EXPECT_EQ(kUpb_FieldMode_Scalar, f->mode & kUpb_FieldMode_Mask);
// For a oneof all fields have the same offset.
@ -226,12 +226,12 @@ TEST(MiniTableEnumTest, Enum) {
e.EndEnum();
upb::Status status;
upb_MiniTable_Enum* table = upb_MiniTable_BuildEnum(
upb_MiniTableEnum* table = upb_MiniTable_BuildEnum(
e.data().data(), e.data().size(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table) << status.error_message();
for (int i = 0; i < UINT16_MAX; i++) {
EXPECT_EQ(values.contains(i), upb_MiniTable_Enum_CheckValue(table, i)) << i;
EXPECT_EQ(values.contains(i), upb_MiniTableEnum_CheckValue(table, i)) << i;
}
}
@ -268,12 +268,12 @@ TEST(MiniTableEnumTest, PositiveAndNegative) {
e.EndEnum();
upb::Status status;
upb_MiniTable_Enum* table = upb_MiniTable_BuildEnum(
upb_MiniTableEnum* table = upb_MiniTable_BuildEnum(
e.data().data(), e.data().size(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table) << status.error_message();
for (int i = -UINT16_MAX; i < UINT16_MAX; i++) {
EXPECT_EQ(values.contains(i), upb_MiniTable_Enum_CheckValue(table, i)) << i;
EXPECT_EQ(values.contains(i), upb_MiniTableEnum_CheckValue(table, i)) << i;
}
}

@ -146,7 +146,7 @@ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg,
}
const upb_Message_Extension* _upb_Message_Getext(
const upb_Message* msg, const upb_MiniTable_Extension* e) {
const upb_Message* msg, const upb_MiniTableExtension* e) {
size_t n;
const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n);
@ -163,7 +163,7 @@ const upb_Message_Extension* _upb_Message_Getext(
}
void _upb_Message_Clearext(upb_Message* msg,
const upb_MiniTable_Extension* ext_l) {
const upb_MiniTableExtension* ext_l) {
upb_Message_Internal* in = upb_Message_Getinternal(msg);
if (!in->internal) return;
const upb_Message_Extension* base =
@ -177,7 +177,7 @@ void _upb_Message_Clearext(upb_Message* msg,
}
upb_Message_Extension* _upb_Message_GetOrCreateExtension(
upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) {
upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) {
upb_Message_Extension* ext =
(upb_Message_Extension*)_upb_Message_Getext(msg, e);
if (ext) return ext;

@ -68,7 +68,7 @@ typedef struct {
uint8_t descriptortype;
uint8_t mode; /* upb_FieldMode | upb_LabelFlags |
(upb_FieldRep << kUpb_FieldRep_Shift) */
} upb_MiniTable_Field;
} upb_MiniTableField;
#define kUpb_NoSub ((uint16_t)-1)
@ -100,20 +100,20 @@ typedef enum {
kUpb_FieldRep_StringView = 2,
kUpb_FieldRep_8Byte = 3,
kUpb_FieldRep_Shift = 6, // Bit offset of the rep in upb_MiniTable_Field.mode
kUpb_FieldRep_Shift = 6, // Bit offset of the rep in upb_MiniTableField.mode
kUpb_FieldRep_Max = kUpb_FieldRep_8Byte,
} upb_FieldRep;
UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTable_Field* field) {
UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTableField* field) {
return (upb_FieldMode)(field->mode & 3);
}
UPB_INLINE bool upb_IsRepeatedOrMap(const upb_MiniTable_Field* field) {
UPB_INLINE bool upb_IsRepeatedOrMap(const upb_MiniTableField* field) {
/* This works because upb_FieldMode has no value 3. */
return !(field->mode & kUpb_FieldMode_Scalar);
}
UPB_INLINE bool upb_IsSubMessage(const upb_MiniTable_Field* field) {
UPB_INLINE bool upb_IsSubMessage(const upb_MiniTableField* field) {
return field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group;
}
@ -134,7 +134,7 @@ typedef struct {
uint32_t mask_limit; // Limit enum value that can be tested with mask.
uint32_t value_count; // Number of values after the bitfield.
uint32_t data[]; // Bitmask + enumerated values follow.
} upb_MiniTable_Enum;
} upb_MiniTableEnum;
typedef enum {
_kUpb_FastEnumCheck_ValueIsInEnum = 0,
@ -143,14 +143,14 @@ typedef enum {
} _kUpb_FastEnumCheck_Status;
UPB_INLINE _kUpb_FastEnumCheck_Status
_upb_MiniTable_CheckEnumValueFast(const upb_MiniTable_Enum* e, uint32_t val) {
_upb_MiniTable_CheckEnumValueFast(const upb_MiniTableEnum* e, uint32_t val) {
if (UPB_UNLIKELY(val >= 64)) return _kUpb_FastEnumCheck_CannotCheckFast;
uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32);
return (mask & (1ULL << val)) ? _kUpb_FastEnumCheck_ValueIsInEnum
: _kUpb_FastEnumCheck_ValueIsNotInEnum;
}
UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTable_Enum* e,
UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTableEnum* e,
uint32_t val) {
if (val < e->mask_limit) return e->data[val / 32] & (1ULL << (val % 32));
// OPT: binary search long lists?
@ -163,8 +163,8 @@ UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTable_Enum* e,
}
// Validates enum value against range defined by enum mini table.
UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e,
uint32_t val) {
UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e,
uint32_t val) {
_kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, val);
if (UPB_UNLIKELY(status == _kUpb_FastEnumCheck_CannotCheckFast)) {
return _upb_MiniTable_CheckEnumValueSlow(e, val);
@ -174,8 +174,8 @@ UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e,
typedef union {
const struct upb_MiniTable* submsg;
const upb_MiniTable_Enum* subenum;
} upb_MiniTable_Sub;
const upb_MiniTableEnum* subenum;
} upb_MiniTableSub;
typedef enum {
kUpb_ExtMode_NonExtendable = 0, // Non-extendable message.
@ -190,8 +190,8 @@ typedef enum {
} upb_ExtMode;
struct upb_MiniTable {
const upb_MiniTable_Sub* subs;
const upb_MiniTable_Field* fields;
const upb_MiniTableSub* subs;
const upb_MiniTableField* fields;
/* Must be aligned to sizeof(void*). Doesn't include internal members like
* unknown fields, extension dict, pointer to msglayout, etc. */
uint16_t size;
@ -206,20 +206,20 @@ struct upb_MiniTable {
_upb_FastTable_Entry fasttable[];
};
struct upb_MiniTable_Extension {
upb_MiniTable_Field field;
struct upb_MiniTableExtension {
upb_MiniTableField field;
const upb_MiniTable* extendee;
upb_MiniTable_Sub sub; /* NULL unless submessage or proto2 enum */
upb_MiniTableSub sub; /* NULL unless submessage or proto2 enum */
};
typedef struct {
const upb_MiniTable** msgs;
const upb_MiniTable_Enum** enums;
const upb_MiniTable_Extension** exts;
const upb_MiniTableEnum** enums;
const upb_MiniTableExtension** exts;
int msg_count;
int enum_count;
int ext_count;
} upb_MiniTable_File;
} upb_MiniTableFile;
// Computes a bitmask in which the |l->required_count| lowest bits are set,
// except that we skip the lowest bit (because upb never uses hasbit 0).
@ -314,7 +314,7 @@ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
* bytes). We accept this because we expect messages to be the most common
* extension type. */
typedef struct {
const upb_MiniTable_Extension* ext;
const upb_MiniTableExtension* ext;
union {
upb_StringView str;
void* ptr;
@ -326,7 +326,7 @@ typedef struct {
* message instance. This logically replaces any previously-added extension with
* this number */
upb_Message_Extension* _upb_Message_GetOrCreateExtension(
upb_Message* msg, const upb_MiniTable_Extension* ext, upb_Arena* arena);
upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena);
/* Returns an array of extensions for this message. Note: the array is
* ordered in reverse relative to the order of creation. */
@ -336,10 +336,9 @@ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg,
/* Returns an extension for the given field number, or NULL if no extension
* exists for this field number. */
const upb_Message_Extension* _upb_Message_Getext(
const upb_Message* msg, const upb_MiniTable_Extension* ext);
const upb_Message* msg, const upb_MiniTableExtension* ext);
void _upb_Message_Clearext(upb_Message* msg,
const upb_MiniTable_Extension* ext);
void _upb_Message_Clearext(upb_Message* msg, const upb_MiniTableExtension* ext);
/** Hasbit access *************************************************************/
@ -355,23 +354,23 @@ UPB_INLINE void _upb_clearhas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8)));
}
UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTable_Field* f) {
UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence > 0);
return f->presence;
}
UPB_INLINE bool _upb_hasbit_field(const upb_Message* msg,
const upb_MiniTable_Field* f) {
const upb_MiniTableField* f) {
return _upb_hasbit(msg, _upb_Message_Hasidx(f));
}
UPB_INLINE void _upb_sethas_field(const upb_Message* msg,
const upb_MiniTable_Field* f) {
const upb_MiniTableField* f) {
_upb_sethas(msg, _upb_Message_Hasidx(f));
}
UPB_INLINE void _upb_clearhas_field(const upb_Message* msg,
const upb_MiniTable_Field* f) {
const upb_MiniTableField* f) {
_upb_clearhas(msg, _upb_Message_Hasidx(f));
}
@ -385,18 +384,18 @@ UPB_INLINE uint32_t _upb_getoneofcase(const void* msg, size_t case_ofs) {
return *UPB_PTR_AT(msg, case_ofs, uint32_t);
}
UPB_INLINE size_t _upb_oneofcase_ofs(const upb_MiniTable_Field* f) {
UPB_INLINE size_t _upb_oneofcase_ofs(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence < 0);
return ~(ptrdiff_t)f->presence;
}
UPB_INLINE uint32_t* _upb_oneofcase_field(upb_Message* msg,
const upb_MiniTable_Field* f) {
const upb_MiniTableField* f) {
return _upb_oneofcase(msg, _upb_oneofcase_ofs(f));
}
UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_Message* msg,
const upb_MiniTable_Field* f) {
const upb_MiniTableField* f) {
return _upb_getoneofcase(msg, _upb_oneofcase_ofs(f));
}

@ -60,7 +60,7 @@ struct upb_DefBuilder {
upb_Arena* arena; // Allocate defs here.
upb_Arena* tmp_arena; // For temporary allocations.
upb_Status* status; // Record errors here.
const upb_MiniTable_File* layout; // NULL if we should build layouts.
const upb_MiniTableFile* layout; // NULL if we should build layouts.
int enum_count; // Count of enums built so far.
int msg_count; // Count of messages built so far.
int ext_count; // Count of extensions built so far.

@ -42,7 +42,7 @@ struct upb_DefPool {
upb_Arena* arena;
upb_strtable syms; // full_name -> packed def ptr
upb_strtable files; // file_name -> (upb_FileDef*)
upb_inttable exts; // (upb_MiniTable_Extension*) -> (upb_FieldDef*)
upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*)
upb_ExtensionRegistry* extreg;
void* scratch_data;
size_t scratch_size;
@ -80,7 +80,7 @@ err:
return NULL;
}
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext,
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext,
upb_FieldDef* f) {
return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f),
s->arena);
@ -280,7 +280,7 @@ static void remove_filedef(upb_DefPool* s, upb_FileDef* file) {
static const upb_FileDef* _upb_DefPool_AddFile(
upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto,
const upb_MiniTable_File* layout, upb_Status* status) {
const upb_MiniTableFile* layout, upb_Status* status) {
const upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto);
if (name.size == 0) {
@ -374,7 +374,7 @@ bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
goto err;
}
const upb_MiniTable_File* mt = rebuild_minitable ? NULL : init->layout;
const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout;
if (!_upb_DefPool_AddFile(s, file, mt, &status)) {
goto err;
}
@ -398,7 +398,7 @@ size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) {
upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; }
const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext) {
const upb_DefPool* s, const upb_MiniTableExtension* ext) {
upb_value v;
bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v);
UPB_ASSERT(ok);
@ -409,7 +409,7 @@ const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s,
const upb_MessageDef* m,
int32_t fieldnum) {
const upb_MiniTable* t = upb_MessageDef_MiniTable(m);
const upb_MiniTable_Extension* ext =
const upb_MiniTableExtension* ext =
upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum);
return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL;
}

@ -65,7 +65,7 @@ const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s,
size_t len);
const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext);
const upb_DefPool* s, const upb_MiniTableExtension* ext);
const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s,
const char* sym);

@ -41,7 +41,7 @@ upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s);
size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s);
upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s);
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext,
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext,
upb_FieldDef* f);
bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v,
upb_Status* status);
@ -54,7 +54,7 @@ size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s);
// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init** deps; // Dependencies of this file.
const upb_MiniTable_File* layout;
const upb_MiniTableFile* layout;
const char* filename;
upb_StringView descriptor; // Serialized descriptor.
} _upb_DefPool_Init;

@ -39,7 +39,7 @@
struct upb_EnumDef {
const google_protobuf_EnumOptions* opts;
const upb_MiniTable_Enum* layout; // Only for proto2.
const upb_MiniTableEnum* layout; // Only for proto2.
const upb_FileDef* file;
const upb_MessageDef* containing_type; // Could be merged with "file".
const char* full_name;
@ -64,7 +64,7 @@ void _upb_EnumDef_Debug(const upb_EnumDef* e) {
fprintf(stderr, "}\n");
}
const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) {
const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) {
return e->layout;
}
@ -132,7 +132,7 @@ const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e,
bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) {
// We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect
// this to be faster (especially for small numbers).
return upb_MiniTable_Enum_CheckValue(e->layout, num);
return upb_MiniTableEnum_CheckValue(e->layout, num);
}
const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) {
@ -185,14 +185,14 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a,
return true;
}
static upb_MiniTable_Enum* create_enumlayout(upb_DefBuilder* ctx,
const upb_EnumDef* e) {
static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx,
const upb_EnumDef* e) {
upb_StringView sv;
bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv);
if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor");
upb_Status status;
upb_MiniTable_Enum* layout =
upb_MiniTableEnum* layout =
upb_MiniTable_BuildEnum(sv.data, sv.size, ctx->arena, &status);
if (!layout)
_upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg);

@ -39,7 +39,7 @@ extern "C" {
upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i);
bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a);
const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e);
const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e);
// Allocate and initialize an array of |n| enum defs.
upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n,

@ -232,13 +232,13 @@ const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) {
return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL;
}
const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f) {
const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) {
UPB_ASSERT(!upb_FieldDef_IsExtension(f));
const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef);
return &layout->fields[f->layout_index];
}
const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable(
const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable(
const upb_FieldDef* f) {
UPB_ASSERT(upb_FieldDef_IsExtension(f));
const upb_FileDef* file = upb_FieldDef_File(f);
@ -696,7 +696,7 @@ static void _upb_FieldDef_CreateNotExt(
if (!ctx->layout) return;
const upb_MiniTable* mt = upb_MessageDef_MiniTable(m);
const upb_MiniTable_Field* fields = mt->fields;
const upb_MiniTableField* fields = mt->fields;
for (int i = 0; i < mt->field_count; i++) {
if (fields[i].number == f->number_) {
f->layout_index = i;
@ -851,7 +851,7 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix,
(unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m));
}
const upb_MiniTable_Extension* ext = _upb_FieldDef_ExtensionMiniTable(f);
const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f);
if (ctx->layout) {
UPB_ASSERT(upb_FieldDef_Number(f) == ext->field.number);
@ -861,8 +861,8 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix,
_upb_DefBuilder_OomErr(ctx);
}
upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext;
upb_MiniTable_Sub sub = {NULL};
upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext;
upb_MiniTableSub sub = {NULL};
if (upb_FieldDef_IsSubMessage(f)) {
sub.submsg = upb_MessageDef_MiniTable(f->sub.msgdef);
} else if (_upb_FieldDef_IsClosedEnum(f)) {

@ -74,7 +74,7 @@ const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f);
bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a,
upb_StringView* out);
const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f);
const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f);
const char* upb_FieldDef_Name(const upb_FieldDef* f);
uint32_t upb_FieldDef_Number(const upb_FieldDef* f);
const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f);

@ -39,7 +39,7 @@ extern "C" {
upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i);
const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable(
const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable(
const upb_FieldDef* f);
bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f);
bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f);

@ -48,7 +48,7 @@ struct upb_FileDef {
const upb_EnumDef* top_lvl_enums;
const upb_FieldDef* top_lvl_exts;
const upb_ServiceDef* services;
const upb_MiniTable_Extension** ext_layouts;
const upb_MiniTableExtension** ext_layouts;
const upb_DefPool* symtab;
int dep_count;
@ -149,7 +149,7 @@ const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) {
const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; }
const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable(
const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable(
const upb_FileDef* f, int i) {
return f->ext_layouts[i];
}
@ -216,7 +216,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx,
// We are building ext layouts from scratch.
file->ext_layouts = _upb_DefBuilder_Alloc(
ctx, sizeof(*file->ext_layouts) * file->ext_count);
upb_MiniTable_Extension* ext =
upb_MiniTableExtension* ext =
_upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count);
for (int i = 0; i < file->ext_count; i++) {
file->ext_layouts[i] = &ext[i];

@ -37,7 +37,7 @@
extern "C" {
#endif
const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable(
const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable(
const upb_FileDef* f, int i);
const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f);
const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f);

@ -41,7 +41,7 @@
// Must be last.
#include "upb/port/def.inc"
static size_t get_field_size(const upb_MiniTable_Field* f) {
static size_t get_field_size(const upb_MiniTableField* f) {
static unsigned char sizes[] = {
0, /* 0 */
8, /* kUpb_FieldType_Double */
@ -66,13 +66,13 @@ static size_t get_field_size(const upb_MiniTable_Field* f) {
return upb_IsRepeatedOrMap(f) ? sizeof(void*) : sizes[f->descriptortype];
}
static bool in_oneof(const upb_MiniTable_Field* field) {
static bool in_oneof(const upb_MiniTableField* field) {
return field->presence < 0;
}
static upb_MessageValue _upb_Message_Getraw(const upb_Message* msg,
const upb_FieldDef* f) {
const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
const char* mem = UPB_PTR_AT(msg, field->offset, char);
upb_MessageValue val = {0};
memcpy(&val, mem, get_field_size(field));
@ -82,10 +82,10 @@ static upb_MessageValue _upb_Message_Getraw(const upb_Message* msg,
bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) {
assert(upb_FieldDef_HasPresence(f));
if (upb_FieldDef_IsExtension(f)) {
const upb_MiniTable_Extension* ext = _upb_FieldDef_ExtensionMiniTable(f);
const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f);
return _upb_Message_Getext(msg, ext) != NULL;
} else {
const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
if (in_oneof(field)) {
return _upb_getoneofcase_field(msg, field) == field->number;
} else if (field->presence > 0) {
@ -105,7 +105,7 @@ const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1);
return upb_Message_Has(msg, f) ? f : NULL;
} else {
const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
uint32_t oneof_case = _upb_getoneofcase_field(msg, field);
f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL;
UPB_ASSERT((f != NULL) == (oneof_case != 0));
@ -178,7 +178,7 @@ bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
if (!ext) return false;
memcpy(&ext->data, &val, sizeof(val));
} else {
const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
// Building reflection should always cause all sub-message types to be
// linked, but double-check here just for extra assurance.
@ -202,7 +202,7 @@ void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f) {
if (upb_FieldDef_IsExtension(f)) {
_upb_Message_Clearext(msg, _upb_FieldDef_ExtensionMiniTable(f));
} else {
const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
char* mem = UPB_PTR_AT(msg, field->offset, char);
if (field->presence > 0) {

@ -343,7 +343,7 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) {
const upb_FieldDef* f = upb_MessageDef_Field(m, i);
const int layout_index = _upb_FieldDef_LayoutIndex(f);
UPB_ASSERT(layout_index < m->layout->field_count);
const upb_MiniTable_Field* mt_f = &m->layout->fields[layout_index];
const upb_MiniTableField* mt_f = &m->layout->fields[layout_index];
UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f));
}
#endif
@ -420,8 +420,8 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx,
upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m);
UPB_ASSERT(layout_index < m->field_count);
upb_MiniTable_Field* mt_f =
(upb_MiniTable_Field*)&m->layout->fields[layout_index];
upb_MiniTableField* mt_f =
(upb_MiniTableField*)&m->layout->fields[layout_index];
if (sub_m) {
if (!mt->subs) {
_upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name);

@ -205,8 +205,8 @@ static void _upb_Decoder_Munge(int type, wireval* val) {
}
static upb_Message* _upb_Decoder_NewSubMessage(
upb_Decoder* d, const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field) {
upb_Decoder* d, const upb_MiniTableSub* subs,
const upb_MiniTableField* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
upb_Message* msg = _upb_Message_New(subl, &d->arena);
@ -257,7 +257,7 @@ static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d,
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeSubMessage(
upb_Decoder* d, const char* ptr, upb_Message* submsg,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) {
const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) {
int saved_delta = _upb_Decoder_PushLimit(d, ptr, size);
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
@ -289,7 +289,7 @@ static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d,
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeKnownGroup(
upb_Decoder* d, const char* ptr, upb_Message* submsg,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) {
const upb_MiniTableSub* subs, const upb_MiniTableField* field) {
const upb_MiniTable* subl = subs[field->submsg_index].submsg;
UPB_ASSERT(subl);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number);
@ -320,8 +320,8 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
UPB_NOINLINE
static bool _upb_Decoder_CheckEnumSlow(upb_Decoder* d, const char* ptr,
upb_Message* msg,
const upb_MiniTable_Enum* e,
const upb_MiniTable_Field* field,
const upb_MiniTableEnum* e,
const upb_MiniTableField* field,
uint32_t v) {
if (_upb_MiniTable_CheckEnumValueSlow(e, v)) return true;
@ -337,9 +337,8 @@ static bool _upb_Decoder_CheckEnumSlow(upb_Decoder* d, const char* ptr,
UPB_FORCEINLINE
static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr,
upb_Message* msg,
const upb_MiniTable_Enum* e,
const upb_MiniTable_Field* field,
upb_Message* msg, const upb_MiniTableEnum* e,
const upb_MiniTableField* field,
wireval* val) {
uint32_t v = val->uint32_val;
@ -349,11 +348,13 @@ static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr,
}
UPB_NOINLINE
static const char* _upb_Decoder_DecodeEnumArray(
upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
wireval* val) {
const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr,
upb_Message* msg,
upb_Array* arr,
const upb_MiniTableSub* subs,
const upb_MiniTableField* field,
wireval* val) {
const upb_MiniTableEnum* e = subs[field->submsg_index].subenum;
if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr;
void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void);
arr->size++;
@ -364,7 +365,7 @@ static const char* _upb_Decoder_DecodeEnumArray(
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeFixedPacked(
upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
const upb_MiniTable_Field* field, int lg2) {
const upb_MiniTableField* field, int lg2) {
int mask = (1 << lg2) - 1;
size_t count = val->size >> lg2;
if ((val->size & mask) != 0) {
@ -406,7 +407,7 @@ static const char* _upb_Decoder_DecodeFixedPacked(
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeVarintPacked(
upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
const upb_MiniTable_Field* field, int lg2) {
const upb_MiniTableField* field, int lg2) {
int scale = 1 << lg2;
int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size);
char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void);
@ -428,9 +429,9 @@ static const char* _upb_Decoder_DecodeVarintPacked(
UPB_NOINLINE
static const char* _upb_Decoder_DecodeEnumPacked(
upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
const upb_MiniTableSub* subs, const upb_MiniTableField* field,
wireval* val) {
const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
const upb_MiniTableEnum* e = subs[field->submsg_index].subenum;
int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size);
char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void);
while (!_upb_Decoder_IsDone(d, &ptr)) {
@ -452,7 +453,7 @@ static const char* _upb_Decoder_DecodeEnumPacked(
}
upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
/* Maps descriptor type -> elem_size_lg2. */
static const uint8_t kElemSizeLg2[] = {
[0] = -1, // invalid descriptor type
@ -484,8 +485,8 @@ upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d,
static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr,
upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field,
const upb_MiniTableSub* subs,
const upb_MiniTableField* field,
wireval* val, int op) {
upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void);
upb_Array* arr = *arrp;
@ -571,8 +572,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) {
[kUpb_FieldType_SInt64] = 8,
};
const upb_MiniTable_Field* key_field = &entry->fields[0];
const upb_MiniTable_Field* val_field = &entry->fields[1];
const upb_MiniTableField* key_field = &entry->fields[0];
const upb_MiniTableField* val_field = &entry->fields[1];
char key_size = kSizeInMap[key_field->descriptortype];
char val_size = kSizeInMap[val_field->descriptortype];
UPB_ASSERT(key_field->offset == 0);
@ -584,8 +585,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) {
static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field,
const upb_MiniTableSub* subs,
const upb_MiniTableField* field,
wireval* val) {
upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*);
upb_Map* map = *map_p;
@ -629,8 +630,8 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
static const char* _upb_Decoder_DecodeToSubMessage(
upb_Decoder* d, const char* ptr, upb_Message* msg,
const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field,
wireval* val, int op) {
const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val,
int op) {
void* mem = UPB_PTR_AT(msg, field->offset, void);
int type = field->descriptortype;
@ -756,7 +757,7 @@ enum {
};
static void upb_Decoder_AddKnownMessageSetItem(
upb_Decoder* d, upb_Message* msg, const upb_MiniTable_Extension* item_mt,
upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt,
const char* data, uint32_t size) {
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena);
@ -799,7 +800,7 @@ static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg,
const upb_MiniTable* t,
uint32_t type_id, const char* data,
uint32_t size) {
const upb_MiniTable_Extension* item_mt =
const upb_MiniTableExtension* item_mt =
upb_ExtensionRegistry_Lookup(d->extreg, t, type_id);
if (item_mt) {
upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size);
@ -861,10 +862,11 @@ static const char* upb_Decoder_DecodeMessageSetItem(
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
}
static const upb_MiniTable_Field* _upb_Decoder_FindField(
upb_Decoder* d, const upb_MiniTable* t, uint32_t field_number,
int* last_field_index) {
static upb_MiniTable_Field none = {
static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d,
const upb_MiniTable* t,
uint32_t field_number,
int* last_field_index) {
static upb_MiniTableField none = {
0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0};
if (t == NULL) return &none;
@ -894,14 +896,14 @@ static const upb_MiniTable_Field* _upb_Decoder_FindField(
if (d->extreg) {
switch (t->ext) {
case kUpb_ExtMode_Extendable: {
const upb_MiniTable_Extension* ext =
const upb_MiniTableExtension* ext =
upb_ExtensionRegistry_Lookup(d->extreg, t, field_number);
if (ext) return &ext->field;
break;
}
case kUpb_ExtMode_IsMessageSet:
if (field_number == kUpb_MsgSet_Item) {
static upb_MiniTable_Field item = {
static upb_MiniTableField item = {
0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0};
return &item;
}
@ -917,7 +919,7 @@ found:
return &t->fields[idx];
}
int _upb_Decoder_GetVarintOp(const upb_MiniTable_Field* field) {
int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) {
static const int8_t kVarintOps[] = {
[kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField,
[kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField,
@ -945,7 +947,7 @@ int _upb_Decoder_GetVarintOp(const upb_MiniTable_Field* field) {
}
int _upb_Decoder_GetDelimitedOp(const upb_MiniTable* mt,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
enum { kRepeatedBase = 19 };
static const int8_t kDelimitedOps[] = {
@ -1001,7 +1003,7 @@ int _upb_Decoder_GetDelimitedOp(const upb_MiniTable* mt,
// If sub-message is not linked, treat as unknown.
if (op == kUpb_DecodeOp_SubMessage &&
!(field->mode & kUpb_LabelFlags_IsExtension)) {
const upb_MiniTable_Sub* sub = &mt->subs[field->submsg_index];
const upb_MiniTableSub* sub = &mt->subs[field->submsg_index];
if (!sub->submsg) {
op = kUpb_DecodeOp_UnknownField;
}
@ -1011,9 +1013,11 @@ int _upb_Decoder_GetDelimitedOp(const upb_MiniTable* mt,
}
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeWireValue(
upb_Decoder* d, const char* ptr, const upb_MiniTable* mt,
const upb_MiniTable_Field* field, int wire_type, wireval* val, int* op) {
static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
const upb_MiniTable* mt,
const upb_MiniTableField* field,
int wire_type, wireval* val,
int* op) {
static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) |
(1 << kUpb_FieldType_Fixed32) |
(1 << kUpb_FieldType_SFixed32);
@ -1067,14 +1071,14 @@ static const char* _upb_Decoder_DecodeWireValue(
UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeKnownField(
upb_Decoder* d, const char* ptr, upb_Message* msg,
const upb_MiniTable* layout, const upb_MiniTable_Field* field, int op,
const upb_MiniTable* layout, const upb_MiniTableField* field, int op,
wireval* val) {
const upb_MiniTable_Sub* subs = layout->subs;
const upb_MiniTableSub* subs = layout->subs;
uint8_t mode = field->mode;
if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) {
const upb_MiniTable_Extension* ext_layout =
(const upb_MiniTable_Extension*)field;
const upb_MiniTableExtension* ext_layout =
(const upb_MiniTableExtension*)field;
upb_Message_Extension* ext =
_upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena);
if (UPB_UNLIKELY(!ext)) {
@ -1174,7 +1178,7 @@ static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
while (!_upb_Decoder_IsDone(d, &ptr)) {
uint32_t tag;
const upb_MiniTable_Field* field;
const upb_MiniTableField* field;
int field_number;
int wire_type;
wireval val;

@ -206,8 +206,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
const upb_MiniTable* m, size_t* size);
static void encode_scalar(upb_encstate* e, const void* _field_mem,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* f) {
const upb_MiniTableSub* subs,
const upb_MiniTableField* f) {
const char* field_mem = _field_mem;
int wire_type;
@ -289,8 +289,8 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
}
static void encode_array(upb_encstate* e, const upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* f) {
const upb_MiniTableSub* subs,
const upb_MiniTableField* f) {
const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*);
bool packed = f->mode & kUpb_LabelFlags_IsPacked;
size_t pre_len = e->limit - e->ptr;
@ -397,8 +397,8 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
static void encode_mapentry(upb_encstate* e, uint32_t number,
const upb_MiniTable* layout,
const upb_MapEntry* ent) {
const upb_MiniTable_Field* key_field = &layout->fields[0];
const upb_MiniTable_Field* val_field = &layout->fields[1];
const upb_MiniTableField* key_field = &layout->fields[0];
const upb_MiniTableField* val_field = &layout->fields[1];
size_t pre_len = e->limit - e->ptr;
size_t size;
encode_scalar(e, &ent->v, layout->subs, val_field);
@ -409,8 +409,8 @@ static void encode_mapentry(upb_encstate* e, uint32_t number,
}
static void encode_map(upb_encstate* e, const upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* f) {
const upb_MiniTableSub* subs,
const upb_MiniTableField* f) {
const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*);
const upb_MiniTable* layout = subs[f->submsg_index].submsg;
UPB_ASSERT(layout->field_count == 2);
@ -441,8 +441,8 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
}
static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* f) {
const upb_MiniTableSub* subs,
const upb_MiniTableField* f) {
if (f->presence == 0) {
/* Proto3 presence or map/array. */
const void* mem = UPB_PTR_AT(msg, f->offset, void);
@ -479,8 +479,8 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
}
static void encode_field(upb_encstate* e, const upb_Message* msg,
const upb_MiniTable_Sub* subs,
const upb_MiniTable_Field* field) {
const upb_MiniTableSub* subs,
const upb_MiniTableField* field) {
switch (upb_FieldMode_Get(field)) {
case kUpb_FieldMode_Array:
encode_array(e, msg, subs, field);
@ -549,8 +549,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
}
if (m->field_count) {
const upb_MiniTable_Field* f = &m->fields[m->field_count];
const upb_MiniTable_Field* first = &m->fields[0];
const upb_MiniTableField* f = &m->fields[m->field_count];
const upb_MiniTableField* first = &m->fields[0];
while (f != first) {
f--;
if (encode_shouldencode(e, msg, m->subs, f)) {

@ -112,7 +112,7 @@ void AddExtensionsFromMessage(
// Ordering must match upb/def.c!
//
// The ordering is significant because each upb_FieldDef* will point at the
// corresponding upb_MiniTable_Extension and we just iterate through the list
// corresponding upb_MiniTableExtension and we just iterate through the list
// without any search or lookup.
std::vector<const protobuf::FieldDescriptor*> SortedExtensions(
const protobuf::FileDescriptor* file) {
@ -147,14 +147,14 @@ upb_MiniTable* FilePlatformLayout::GetMiniTable(
return it->second;
}
upb_MiniTable_Enum* FilePlatformLayout::GetEnumTable(
upb_MiniTableEnum* FilePlatformLayout::GetEnumTable(
const protobuf::EnumDescriptor* d) const {
auto it = enum_map_.find(d);
assert(it != enum_map_.end());
return it->second;
}
const upb_MiniTable_Extension* FilePlatformLayout::GetExtension(
const upb_MiniTableExtension* FilePlatformLayout::GetExtension(
const protobuf::FieldDescriptor* fd) const {
auto it = extension_map_.find(fd);
assert(it != extension_map_.end());
@ -171,7 +171,7 @@ void FilePlatformLayout::ResolveIntraFileReferences() {
if (f->message_type() && f->message_type()->file() == f->file()) {
// const_cast is safe because the mini-table is owned exclusively
// by us, and was allocated from an arena (known-writable memory).
upb_MiniTable_Field* mt_f = const_cast<upb_MiniTable_Field*>(
upb_MiniTableField* mt_f = const_cast<upb_MiniTableField*>(
upb_MiniTable_FindFieldByNumber(mt, f->number()));
upb_MiniTable* sub_mt = GetMiniTable(f->message_type());
upb_MiniTable_SetSubMessage(mt, mt_f, sub_mt);
@ -182,19 +182,19 @@ void FilePlatformLayout::ResolveIntraFileReferences() {
}
}
upb_MiniTable_Sub FilePlatformLayout::PackSub(const char* data, SubTag tag) {
upb_MiniTableSub FilePlatformLayout::PackSub(const char* data, SubTag tag) {
uintptr_t val = reinterpret_cast<uintptr_t>(data);
assert((val & kMask) == 0);
upb_MiniTable_Sub sub;
upb_MiniTableSub sub;
sub.submsg = reinterpret_cast<upb_MiniTable*>(val | tag);
return sub;
}
bool FilePlatformLayout::IsNull(upb_MiniTable_Sub sub) {
bool FilePlatformLayout::IsNull(upb_MiniTableSub sub) {
return reinterpret_cast<uintptr_t>(sub.subenum) == 0;
}
std::string FilePlatformLayout::GetSub(upb_MiniTable_Sub sub) {
std::string FilePlatformLayout::GetSub(upb_MiniTableSub sub) {
uintptr_t as_int = reinterpret_cast<uintptr_t>(sub.submsg);
const char* str = reinterpret_cast<const char*>(as_int & ~SubTag::kMask);
switch (as_int & SubTag::kMask) {
@ -212,20 +212,20 @@ void FilePlatformLayout::SetSubTableStrings() {
for (const auto& pair : table_map_) {
upb_MiniTable* mt = pair.second;
for (const auto* f : FieldNumberOrder(pair.first)) {
upb_MiniTable_Field* mt_f = const_cast<upb_MiniTable_Field*>(
upb_MiniTableField* mt_f = const_cast<upb_MiniTableField*>(
upb_MiniTable_FindFieldByNumber(mt, f->number()));
assert(mt_f);
upb_MiniTable_Sub sub = PackSubForField(f, mt_f);
upb_MiniTableSub sub = PackSubForField(f, mt_f);
if (IsNull(sub)) continue;
// const_cast is safe because the mini-table is owned exclusively
// by us, and was allocated from an arena (known-writable memory).
*const_cast<upb_MiniTable_Sub*>(&mt->subs[mt_f->submsg_index]) = sub;
*const_cast<upb_MiniTableSub*>(&mt->subs[mt_f->submsg_index]) = sub;
}
}
}
upb_MiniTable_Sub FilePlatformLayout::PackSubForField(
const protobuf::FieldDescriptor* f, const upb_MiniTable_Field* mt_f) {
upb_MiniTableSub FilePlatformLayout::PackSubForField(
const protobuf::FieldDescriptor* f, const upb_MiniTableField* mt_f) {
if (mt_f->submsg_index == kUpb_NoSub) {
return PackSub(nullptr, SubTag::kNull);
} else if (f->message_type()) {
@ -262,8 +262,8 @@ void FilePlatformLayout::BuildExtensions(const protobuf::FileDescriptor* fd) {
upb::MtDataEncoder e;
e.EncodeExtension(static_cast<upb_FieldType>(f->type()), f->number(),
GetFieldModifiers(f));
upb_MiniTable_Extension& ext = extension_map_[f];
upb_MiniTable_Sub sub;
upb_MiniTableExtension& ext = extension_map_[f];
upb_MiniTableSub sub;
// The extendee may be from another file, so we build a temporary MiniTable
// for it, just for the purpose of building the extension.
// Note, we are not caching so this could use more memory than is necessary.
@ -360,7 +360,7 @@ upb_MiniTable* FilePlatformLayout::MakeRegularMiniTable(
return ret;
}
upb_MiniTable_Enum* FilePlatformLayout::MakeMiniTableEnum(
upb_MiniTableEnum* FilePlatformLayout::MakeMiniTableEnum(
const protobuf::EnumDescriptor* d) {
upb::Arena arena;
upb::MtDataEncoder e;
@ -373,8 +373,8 @@ upb_MiniTable_Enum* FilePlatformLayout::MakeMiniTableEnum(
absl::string_view str = e.data();
upb::Status status;
upb_MiniTable_Enum* ret = upb_MiniTable_BuildEnum(str.data(), str.size(),
arena_.ptr(), status.ptr());
upb_MiniTableEnum* ret = upb_MiniTable_BuildEnum(str.data(), str.size(),
arena_.ptr(), status.ptr());
if (!ret) {
fprintf(stderr, "Error building mini-table: %s\n", status.error_message());
}

@ -53,7 +53,7 @@ std::vector<const protobuf::Descriptor*> SortedMessages(
// Ordering must match upb/def.c!
//
// The ordering is significant because each upb_FieldDef* will point at the
// corresponding upb_MiniTable_Extension and we just iterate through the list
// corresponding upb_MiniTableExtension and we just iterate through the list
// without any search or lookup.
std::vector<const protobuf::FieldDescriptor*> SortedExtensions(
const protobuf::FileDescriptor* file);
@ -79,12 +79,12 @@ class FilePlatformLayout {
// Retrieves a upb MiniTable or Extension given a protobuf descriptor. The
// descriptor must be from this layout's file.
upb_MiniTable* GetMiniTable(const protobuf::Descriptor* m) const;
upb_MiniTable_Enum* GetEnumTable(const protobuf::EnumDescriptor* d) const;
const upb_MiniTable_Extension* GetExtension(
upb_MiniTableEnum* GetEnumTable(const protobuf::EnumDescriptor* d) const;
const upb_MiniTableExtension* GetExtension(
const protobuf::FieldDescriptor* fd) const;
// Get the initializer for the given sub-message/sub-enum link.
static std::string GetSub(upb_MiniTable_Sub sub);
static std::string GetSub(upb_MiniTableSub sub);
private:
// Functions to build mini-tables for this file's messages and extensions.
@ -94,7 +94,7 @@ class FilePlatformLayout {
upb_MiniTable* MakeMapMiniTable(const protobuf::Descriptor* m);
upb_MiniTable* MakeMessageSetMiniTable(const protobuf::Descriptor* m);
upb_MiniTable* MakeRegularMiniTable(const protobuf::Descriptor* m);
upb_MiniTable_Enum* MakeMiniTableEnum(const protobuf::EnumDescriptor* d);
upb_MiniTableEnum* MakeMiniTableEnum(const protobuf::EnumDescriptor* d);
uint64_t GetMessageModifiers(const protobuf::Descriptor* m);
uint64_t GetFieldModifiers(const protobuf::FieldDescriptor* f);
void ResolveIntraFileReferences();
@ -117,20 +117,20 @@ class FilePlatformLayout {
kMask = 3,
};
static upb_MiniTable_Sub PackSub(const char* data, SubTag tag);
static bool IsNull(upb_MiniTable_Sub sub);
static upb_MiniTableSub PackSub(const char* data, SubTag tag);
static bool IsNull(upb_MiniTableSub sub);
void SetSubTableStrings();
upb_MiniTable_Sub PackSubForField(const protobuf::FieldDescriptor* f,
const upb_MiniTable_Field* mt_f);
upb_MiniTableSub PackSubForField(const protobuf::FieldDescriptor* f,
const upb_MiniTableField* mt_f);
const char* AllocStr(absl::string_view str);
private:
using TableMap =
absl::flat_hash_map<const protobuf::Descriptor*, upb_MiniTable*>;
using EnumMap =
absl::flat_hash_map<const protobuf::EnumDescriptor*, upb_MiniTable_Enum*>;
absl::flat_hash_map<const protobuf::EnumDescriptor*, upb_MiniTableEnum*>;
using ExtensionMap = absl::flat_hash_map<const protobuf::FieldDescriptor*,
upb_MiniTable_Extension>;
upb_MiniTableExtension>;
upb::Arena arena_;
TableMap table_map_;
EnumMap enum_map_;
@ -160,24 +160,24 @@ class FileLayout {
return layout64_.GetMiniTable(m);
}
const upb_MiniTable_Enum* GetEnumTable(
const upb_MiniTableEnum* GetEnumTable(
const protobuf::EnumDescriptor* d) const {
return layout64_.GetEnumTable(d);
}
std::string GetFieldOffset(const protobuf::FieldDescriptor* f) const {
const upb_MiniTable_Field* f_32 = upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* f_32 = upb_MiniTable_FindFieldByNumber(
GetMiniTable32(f->containing_type()), f->number());
const upb_MiniTable_Field* f_64 = upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* f_64 = upb_MiniTable_FindFieldByNumber(
GetMiniTable64(f->containing_type()), f->number());
return absl::Substitute("UPB_SIZE($0, $1)", f_32->offset, f_64->offset);
}
std::string GetOneofCaseOffset(const protobuf::OneofDescriptor* o) const {
const protobuf::FieldDescriptor* f = o->field(0);
const upb_MiniTable_Field* f_32 = upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* f_32 = upb_MiniTable_FindFieldByNumber(
GetMiniTable32(f->containing_type()), f->number());
const upb_MiniTable_Field* f_64 = upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* f_64 = upb_MiniTable_FindFieldByNumber(
GetMiniTable64(f->containing_type()), f->number());
return absl::Substitute("UPB_SIZE($0, $1)", ~f_32->presence,
~f_64->presence);
@ -189,7 +189,7 @@ class FileLayout {
}
int GetHasbitIndex(const protobuf::FieldDescriptor* f) const {
const upb_MiniTable_Field* f_64 = upb_MiniTable_FindFieldByNumber(
const upb_MiniTableField* f_64 = upb_MiniTable_FindFieldByNumber(
GetMiniTable64(f->containing_type()), f->number());
return f_64->presence;
}
@ -198,7 +198,7 @@ class FileLayout {
return GetHasbitIndex(f) > 0;
}
const upb_MiniTable_Extension* GetExtension(
const upb_MiniTableExtension* GetExtension(
const protobuf::FieldDescriptor* f) const {
return layout64_.GetExtension(f);
}

@ -918,7 +918,7 @@ void WriteHeader(const FileLayout& layout, Output& output) {
output("extern const upb_MiniTable $0;\n", MessageInit(message));
}
for (auto ext : this_file_exts) {
output("extern const upb_MiniTable_Extension $0;\n", ExtensionLayout(ext));
output("extern const upb_MiniTableExtension $0;\n", ExtensionLayout(ext));
}
// Forward-declare types not in this file, but used as submessages.
@ -970,7 +970,7 @@ void WriteHeader(const FileLayout& layout, Output& output) {
if (file->syntax() == protobuf::FileDescriptor::SYNTAX_PROTO2) {
for (const auto* enumdesc : this_file_enums) {
output("extern const upb_MiniTable_Enum $0;\n", EnumInit(enumdesc));
output("extern const upb_MiniTableEnum $0;\n", EnumInit(enumdesc));
}
}
@ -983,7 +983,7 @@ void WriteHeader(const FileLayout& layout, Output& output) {
GenerateExtensionInHeader(ext, output);
}
output("extern const upb_MiniTable_File $0;\n\n", FileLayoutName(file));
output("extern const upb_MiniTableFile $0;\n\n", FileLayoutName(file));
if (file->name() ==
protobuf::FileDescriptorProto::descriptor()->file()->name()) {
@ -1054,7 +1054,7 @@ bool TryFillTableEntry(const FileLayout& layout,
const protobuf::FieldDescriptor* field,
TableEntry& ent) {
const upb_MiniTable* mt = layout.GetMiniTable64(field->containing_type());
const upb_MiniTable_Field* mt_f =
const upb_MiniTableField* mt_f =
upb_MiniTable_FindFieldByNumber(mt, field->number());
std::string type = "";
std::string cardinality = "";
@ -1272,8 +1272,8 @@ std::string GetModeInit(uint8_t mode32, uint8_t mode64) {
return ret;
}
void WriteField(const upb_MiniTable_Field* field64,
const upb_MiniTable_Field* field32, Output& output) {
void WriteField(const upb_MiniTableField* field64,
const upb_MiniTableField* field32, Output& output) {
output("{$0, UPB_SIZE($1, $2), UPB_SIZE($3, $4), $5, $6, $7}",
field64->number, field32->offset, field64->offset, field32->presence,
field64->presence,
@ -1284,8 +1284,8 @@ void WriteField(const upb_MiniTable_Field* field64,
}
// Writes a single field into a .upb.c source file.
void WriteMessageField(const upb_MiniTable_Field* field64,
const upb_MiniTable_Field* field32, Output& output) {
void WriteMessageField(const upb_MiniTableField* field64,
const upb_MiniTableField* field32, Output& output) {
output(" ");
WriteField(field64, field32, output);
output(",\n");
@ -1303,7 +1303,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout,
std::vector<std::string> subs;
for (int i = 0; i < mt_64->field_count; i++) {
const upb_MiniTable_Field* f = &mt_64->fields[i];
const upb_MiniTableField* f = &mt_64->fields[i];
if (f->submsg_index != kUpb_NoSub) {
subs.push_back(FilePlatformLayout::GetSub(mt_64->subs[f->submsg_index]));
}
@ -1312,7 +1312,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout,
if (!subs.empty()) {
std::string submsgs_array_name = msg_name + "_submsgs";
submsgs_array_ref = "&" + submsgs_array_name + "[0]";
output("static const upb_MiniTable_Sub $0[$1] = {\n", submsgs_array_name,
output("static const upb_MiniTableSub $0[$1] = {\n", submsgs_array_name,
subs.size());
for (const auto& sub : subs) {
@ -1325,7 +1325,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout,
if (mt_64->field_count > 0) {
std::string fields_array_name = msg_name + "__fields";
fields_array_ref = "&" + fields_array_name + "[0]";
output("static const upb_MiniTable_Field $0[$1] = {\n", fields_array_name,
output("static const upb_MiniTableField $0[$1] = {\n", fields_array_name,
mt_64->field_count);
for (int i = 0; i < mt_64->field_count; i++) {
WriteMessageField(&mt_64->fields[i], &mt_32->fields[i], output);
@ -1372,7 +1372,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout,
output("};\n\n");
}
void WriteEnum(const upb_MiniTable_Enum* mt, const protobuf::EnumDescriptor* e,
void WriteEnum(const upb_MiniTableEnum* mt, const protobuf::EnumDescriptor* e,
Output& output) {
std::string values_init = "{\n";
uint32_t value_count = (mt->mask_limit / 32) + mt->value_count;
@ -1384,7 +1384,7 @@ void WriteEnum(const upb_MiniTable_Enum* mt, const protobuf::EnumDescriptor* e,
output(
R"cc(
const upb_MiniTable_Enum $0 = {
const upb_MiniTableEnum $0 = {
$1,
$2,
$3,
@ -1409,7 +1409,7 @@ int WriteEnums(const FileLayout& layout, Output& output) {
}
if (!this_file_enums.empty()) {
output("static const upb_MiniTable_Enum *$0[$1] = {\n", kEnumsInit,
output("static const upb_MiniTableEnum *$0[$1] = {\n", kEnumsInit,
this_file_enums.size());
for (const auto* e : this_file_enums) {
output(" &$0,\n", EnumInit(e));
@ -1442,7 +1442,7 @@ int WriteMessages(const FileLayout& layout, Output& output,
return file_messages.size();
}
void WriteExtension(const upb_MiniTable_Extension* ext, Output& output) {
void WriteExtension(const upb_MiniTableExtension* ext, Output& output) {
WriteField(&ext->field, &ext->field, output);
output(",\n");
output(" &$0,\n", reinterpret_cast<const char*>(ext->extendee));
@ -1471,14 +1471,14 @@ int WriteExtensions(const FileLayout& layout, Output& output) {
}
for (auto ext : exts) {
output("const upb_MiniTable_Extension $0 = {\n ", ExtensionLayout(ext));
output("const upb_MiniTableExtension $0 = {\n ", ExtensionLayout(ext));
WriteExtension(layout.GetExtension(ext), output);
output("\n};\n");
}
output(
"\n"
"static const upb_MiniTable_Extension *$0[$1] = {\n",
"static const upb_MiniTableExtension *$0[$1] = {\n",
kExtensionsInit, exts.size());
for (auto ext : exts) {
@ -1517,7 +1517,7 @@ void WriteSource(const FileLayout& layout, Output& output,
int ext_count = WriteExtensions(layout, output);
int enum_count = WriteEnums(layout, output);
output("const upb_MiniTable_File $0 = {\n", FileLayoutName(file));
output("const upb_MiniTableFile $0 = {\n", FileLayoutName(file));
output(" $0,\n", msg_count ? kMessagesInit : "NULL");
output(" $0,\n", enum_count ? kEnumsInit : "NULL");
output(" $0,\n", ext_count ? kExtensionsInit : "NULL");

Loading…
Cancel
Save