From 0f23c3f0c6297f076b3964a0b64ac6fe5ff93586 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 21 Mar 2024 17:12:46 -0700 Subject: [PATCH] upb: add upb_FieldDef_LayoutIndex() PiperOrigin-RevId: 618007325 --- upb/reflection/def.hpp | 4 ++++ upb/reflection/field_def.c | 4 ++++ upb/reflection/field_def.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/upb/reflection/def.hpp b/upb/reflection/def.hpp index 870ab0fd46..b3f172a8d1 100644 --- a/upb/reflection/def.hpp +++ b/upb/reflection/def.hpp @@ -18,6 +18,7 @@ #include "upb/base/status.hpp" #include "upb/base/string_view.h" #include "upb/mem/arena.hpp" +#include "upb/message/value.h" #include "upb/mini_descriptor/decode.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/field.h" @@ -87,6 +88,9 @@ class FieldDefPtr { // been finalized. uint32_t index() const { return upb_FieldDef_Index(ptr_); } + // Index into msgdef->layout->fields or file->exts + uint32_t layout_index() const { return upb_FieldDef_LayoutIndex(ptr_); } + // The MessageDef to which this field belongs (for extensions, the extended // message). MessageDefPtr containing_type() const; diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 1a0a821451..38366566e6 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -122,6 +122,10 @@ upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } +uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { + return f->layout_index; +} + upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { // TODO: remove once we can deprecate kUpb_Label_Required. if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == diff --git a/upb/reflection/field_def.h b/upb/reflection/field_def.h index 5667141a0c..2923228ca8 100644 --- a/upb/reflection/field_def.h +++ b/upb/reflection/field_def.h @@ -14,6 +14,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" +#include "upb/message/value.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/reflection/common.h" @@ -55,6 +56,7 @@ bool upb_FieldDef_IsString(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); UPB_API const char* upb_FieldDef_JsonName(const upb_FieldDef* f); UPB_API upb_Label upb_FieldDef_Label(const upb_FieldDef* f); +uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f); UPB_API const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f);