Skip to content

Commit

Permalink
upb: add upb_FieldDef_LayoutIndex()
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 618007325
  • Loading branch information
ericsalo authored and copybara-github committed Mar 22, 2024
1 parent 821e854 commit 0f23c3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions upb/reflection/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions upb/reflection/field_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==
Expand Down
2 changes: 2 additions & 0 deletions upb/reflection/field_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0f23c3f

Please sign in to comment.