Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-27 09:40:20

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_REFLECTION_DEF_HPP_
0009 #define UPB_REFLECTION_DEF_HPP_
0010 
0011 #include <stdint.h>
0012 
0013 #include <cstring>
0014 #include <memory>
0015 #include <string>
0016 
0017 #include "upb/base/descriptor_constants.h"
0018 #include "upb/base/status.hpp"
0019 #include "upb/base/string_view.h"
0020 #include "upb/mem/arena.hpp"
0021 #include "upb/message/value.h"
0022 #include "upb/mini_descriptor/decode.h"
0023 #include "upb/mini_table/enum.h"
0024 #include "upb/mini_table/field.h"
0025 #include "upb/mini_table/message.h"
0026 #include "upb/reflection/def.h"
0027 #include "upb/reflection/internal/def_pool.h"
0028 #include "upb/reflection/internal/enum_def.h"
0029 #include "upb/reflection/message.h"
0030 
0031 // Must be last
0032 #include "upb/port/def.inc"
0033 
0034 namespace upb {
0035 
0036 typedef upb_MessageValue MessageValue;
0037 
0038 class EnumDefPtr;
0039 class FileDefPtr;
0040 class MessageDefPtr;
0041 class OneofDefPtr;
0042 
0043 // A upb::FieldDefPtr describes a single field in a message.  It is most often
0044 // found as a part of a upb_MessageDef, but can also stand alone to represent
0045 // an extension.
0046 class FieldDefPtr {
0047  public:
0048   FieldDefPtr() : ptr_(nullptr) {}
0049   explicit FieldDefPtr(const upb_FieldDef* ptr) : ptr_(ptr) {}
0050 
0051   const upb_FieldDef* ptr() const { return ptr_; }
0052 
0053   typedef upb_FieldType Type;
0054   typedef upb_CType CType;
0055   typedef upb_Label Label;
0056 
0057   FileDefPtr file() const;
0058   const char* full_name() const { return upb_FieldDef_FullName(ptr_); }
0059 
0060   const upb_MiniTableField* mini_table() const {
0061     return upb_FieldDef_MiniTable(ptr_);
0062   }
0063 
0064   std::string MiniDescriptorEncode() const {
0065     upb::Arena arena;
0066     upb_StringView md;
0067     upb_FieldDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md);
0068     return std::string(md.data, md.size);
0069   }
0070 
0071   const UPB_DESC(FieldOptions) * options() const {
0072     return upb_FieldDef_Options(ptr_);
0073   }
0074 
0075   Type type() const { return upb_FieldDef_Type(ptr_); }
0076   CType ctype() const { return upb_FieldDef_CType(ptr_); }
0077   Label label() const { return upb_FieldDef_Label(ptr_); }
0078   const char* name() const { return upb_FieldDef_Name(ptr_); }
0079   const char* json_name() const { return upb_FieldDef_JsonName(ptr_); }
0080   uint32_t number() const { return upb_FieldDef_Number(ptr_); }
0081   bool is_extension() const { return upb_FieldDef_IsExtension(ptr_); }
0082   bool is_required() const { return upb_FieldDef_IsRequired(ptr_); }
0083   bool has_presence() const { return upb_FieldDef_HasPresence(ptr_); }
0084 
0085   // For non-string, non-submessage fields, this indicates whether binary
0086   // protobufs are encoded in packed or non-packed format.
0087   //
0088   // Note: this accessor reflects the fact that "packed" has different defaults
0089   // depending on whether the proto is proto2 or proto3.
0090   bool packed() const { return upb_FieldDef_IsPacked(ptr_); }
0091 
0092   // An integer that can be used as an index into an array of fields for
0093   // whatever message this field belongs to.  Guaranteed to be less than
0094   // f->containing_type()->field_count().  May only be accessed once the def has
0095   // been finalized.
0096   // The index ordering here is *dependent* on the order of the fields in the
0097   // .proto file.
0098   uint32_t index() const { return upb_FieldDef_Index(ptr_); }
0099 
0100   // Index into msgdef->layout->fields or file->exts.
0101   // This is the index that the MiniTable uses, and is independent of the order
0102   // of the fields in the .proto file.
0103   uint32_t layout_index() const { return upb_FieldDef_LayoutIndex(ptr_); }
0104 
0105   // The MessageDef to which this field belongs (for extensions, the extended
0106   // message).
0107   MessageDefPtr containing_type() const;
0108 
0109   // For extensions, the message the extension is declared inside, or NULL if
0110   // none.
0111   MessageDefPtr extension_scope() const;
0112 
0113   // The OneofDef to which this field belongs, or NULL if this field is not part
0114   // of a oneof.
0115   OneofDefPtr containing_oneof() const;
0116   OneofDefPtr real_containing_oneof() const;
0117 
0118   // Convenient field type tests.
0119   bool IsEnum() const { return upb_FieldDef_IsEnum(ptr_); }
0120   bool IsSubMessage() const { return upb_FieldDef_IsSubMessage(ptr_); }
0121   bool IsString() const { return upb_FieldDef_IsString(ptr_); }
0122   bool IsSequence() const { return upb_FieldDef_IsRepeated(ptr_); }
0123   bool IsPrimitive() const { return upb_FieldDef_IsPrimitive(ptr_); }
0124   bool IsMap() const { return upb_FieldDef_IsMap(ptr_); }
0125 
0126   MessageValue default_value() const { return upb_FieldDef_Default(ptr_); }
0127 
0128   // Returns the enum or submessage def for this field, if any.  The field's
0129   // type must match (ie. you may only call enum_subdef() for fields where
0130   // type() == kUpb_CType_Enum).
0131   EnumDefPtr enum_subdef() const;
0132   MessageDefPtr message_type() const;
0133 
0134   explicit operator bool() const { return ptr_ != nullptr; }
0135 
0136   friend bool operator==(FieldDefPtr lhs, FieldDefPtr rhs) {
0137     return lhs.ptr_ == rhs.ptr_;
0138   }
0139 
0140   friend bool operator!=(FieldDefPtr lhs, FieldDefPtr rhs) {
0141     return !(lhs == rhs);
0142   }
0143 
0144  private:
0145   const upb_FieldDef* ptr_;
0146 };
0147 
0148 // Class that represents a oneof.
0149 class OneofDefPtr {
0150  public:
0151   OneofDefPtr() : ptr_(nullptr) {}
0152   explicit OneofDefPtr(const upb_OneofDef* ptr) : ptr_(ptr) {}
0153 
0154   const upb_OneofDef* ptr() const { return ptr_; }
0155   explicit operator bool() const { return ptr_ != nullptr; }
0156 
0157   const UPB_DESC(OneofOptions) * options() const {
0158     return upb_OneofDef_Options(ptr_);
0159   }
0160 
0161   // Returns the MessageDef that contains this OneofDef.
0162   MessageDefPtr containing_type() const;
0163 
0164   // Returns the name of this oneof.
0165   const char* name() const { return upb_OneofDef_Name(ptr_); }
0166   const char* full_name() const { return upb_OneofDef_FullName(ptr_); }
0167 
0168   // Returns the number of fields in the oneof.
0169   int field_count() const { return upb_OneofDef_FieldCount(ptr_); }
0170   FieldDefPtr field(int i) const {
0171     return FieldDefPtr(upb_OneofDef_Field(ptr_, i));
0172   }
0173 
0174   // Looks up by name.
0175   FieldDefPtr FindFieldByName(const char* name, size_t len) const {
0176     return FieldDefPtr(upb_OneofDef_LookupNameWithSize(ptr_, name, len));
0177   }
0178   FieldDefPtr FindFieldByName(const char* name) const {
0179     return FieldDefPtr(upb_OneofDef_LookupName(ptr_, name));
0180   }
0181 
0182   template <class T>
0183   FieldDefPtr FindFieldByName(const T& str) const {
0184     return FindFieldByName(str.c_str(), str.size());
0185   }
0186 
0187   // Looks up by tag number.
0188   FieldDefPtr FindFieldByNumber(uint32_t num) const {
0189     return FieldDefPtr(upb_OneofDef_LookupNumber(ptr_, num));
0190   }
0191 
0192  private:
0193   const upb_OneofDef* ptr_;
0194 };
0195 
0196 // Structure that describes a single .proto message type.
0197 class MessageDefPtr {
0198  public:
0199   MessageDefPtr() : ptr_(nullptr) {}
0200   explicit MessageDefPtr(const upb_MessageDef* ptr) : ptr_(ptr) {}
0201 
0202   const UPB_DESC(MessageOptions) * options() const {
0203     return upb_MessageDef_Options(ptr_);
0204   }
0205 
0206   std::string MiniDescriptorEncode() const {
0207     upb::Arena arena;
0208     upb_StringView md;
0209     upb_MessageDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md);
0210     return std::string(md.data, md.size);
0211   }
0212 
0213   const upb_MessageDef* ptr() const { return ptr_; }
0214 
0215   FileDefPtr file() const;
0216 
0217   const char* full_name() const { return upb_MessageDef_FullName(ptr_); }
0218   const char* name() const { return upb_MessageDef_Name(ptr_); }
0219 
0220   // Returns the MessageDef that contains this MessageDef (or null).
0221   MessageDefPtr containing_type() const;
0222 
0223   const upb_MiniTable* mini_table() const {
0224     return upb_MessageDef_MiniTable(ptr_);
0225   }
0226 
0227   // The number of fields that belong to the MessageDef.
0228   int field_count() const { return upb_MessageDef_FieldCount(ptr_); }
0229   FieldDefPtr field(int i) const {
0230     return FieldDefPtr(upb_MessageDef_Field(ptr_, i));
0231   }
0232 
0233   // The number of oneofs that belong to the MessageDef.
0234   int oneof_count() const { return upb_MessageDef_OneofCount(ptr_); }
0235   int real_oneof_count() const { return upb_MessageDef_RealOneofCount(ptr_); }
0236   OneofDefPtr oneof(int i) const {
0237     return OneofDefPtr(upb_MessageDef_Oneof(ptr_, i));
0238   }
0239 
0240   int enum_type_count() const { return upb_MessageDef_NestedEnumCount(ptr_); }
0241   EnumDefPtr enum_type(int i) const;
0242 
0243   int nested_message_count() const {
0244     return upb_MessageDef_NestedMessageCount(ptr_);
0245   }
0246   MessageDefPtr nested_message(int i) const {
0247     return MessageDefPtr(upb_MessageDef_NestedMessage(ptr_, i));
0248   }
0249 
0250   int nested_extension_count() const {
0251     return upb_MessageDef_NestedExtensionCount(ptr_);
0252   }
0253   FieldDefPtr nested_extension(int i) const {
0254     return FieldDefPtr(upb_MessageDef_NestedExtension(ptr_, i));
0255   }
0256 
0257   int extension_range_count() const {
0258     return upb_MessageDef_ExtensionRangeCount(ptr_);
0259   }
0260 
0261   upb_Syntax syntax() const { return upb_MessageDef_Syntax(ptr_); }
0262 
0263   // These return null pointers if the field is not found.
0264   FieldDefPtr FindFieldByNumber(uint32_t number) const {
0265     return FieldDefPtr(upb_MessageDef_FindFieldByNumber(ptr_, number));
0266   }
0267   FieldDefPtr FindFieldByName(const char* name, size_t len) const {
0268     return FieldDefPtr(upb_MessageDef_FindFieldByNameWithSize(ptr_, name, len));
0269   }
0270   FieldDefPtr FindFieldByName(const char* name) const {
0271     return FieldDefPtr(upb_MessageDef_FindFieldByName(ptr_, name));
0272   }
0273 
0274   template <class T>
0275   FieldDefPtr FindFieldByName(const T& str) const {
0276     return FindFieldByName(str.c_str(), str.size());
0277   }
0278 
0279   OneofDefPtr FindOneofByName(const char* name, size_t len) const {
0280     return OneofDefPtr(upb_MessageDef_FindOneofByNameWithSize(ptr_, name, len));
0281   }
0282 
0283   OneofDefPtr FindOneofByName(const char* name) const {
0284     return OneofDefPtr(upb_MessageDef_FindOneofByName(ptr_, name));
0285   }
0286 
0287   template <class T>
0288   OneofDefPtr FindOneofByName(const T& str) const {
0289     return FindOneofByName(str.c_str(), str.size());
0290   }
0291 
0292   // Is this message a map entry?
0293   bool mapentry() const { return upb_MessageDef_IsMapEntry(ptr_); }
0294 
0295   FieldDefPtr map_key() const {
0296     if (!mapentry()) return FieldDefPtr();
0297     return FieldDefPtr(upb_MessageDef_Field(ptr_, 0));
0298   }
0299 
0300   FieldDefPtr map_value() const {
0301     if (!mapentry()) return FieldDefPtr();
0302     return FieldDefPtr(upb_MessageDef_Field(ptr_, 1));
0303   }
0304 
0305   // Return the type of well known type message. kUpb_WellKnown_Unspecified for
0306   // non-well-known message.
0307   upb_WellKnown wellknowntype() const {
0308     return upb_MessageDef_WellKnownType(ptr_);
0309   }
0310 
0311   explicit operator bool() const { return ptr_ != nullptr; }
0312 
0313   friend bool operator==(MessageDefPtr lhs, MessageDefPtr rhs) {
0314     return lhs.ptr_ == rhs.ptr_;
0315   }
0316 
0317   friend bool operator!=(MessageDefPtr lhs, MessageDefPtr rhs) {
0318     return !(lhs == rhs);
0319   }
0320 
0321  private:
0322   class FieldIter {
0323    public:
0324     explicit FieldIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {}
0325     void operator++() { i_++; }
0326 
0327     FieldDefPtr operator*() {
0328       return FieldDefPtr(upb_MessageDef_Field(m_, i_));
0329     }
0330 
0331     friend bool operator==(FieldIter lhs, FieldIter rhs) {
0332       return lhs.i_ == rhs.i_;
0333     }
0334 
0335     friend bool operator!=(FieldIter lhs, FieldIter rhs) {
0336       return !(lhs == rhs);
0337     }
0338 
0339    private:
0340     const upb_MessageDef* m_;
0341     int i_;
0342   };
0343 
0344   class FieldAccessor {
0345    public:
0346     explicit FieldAccessor(const upb_MessageDef* md) : md_(md) {}
0347     FieldIter begin() { return FieldIter(md_, 0); }
0348     FieldIter end() { return FieldIter(md_, upb_MessageDef_FieldCount(md_)); }
0349 
0350    private:
0351     const upb_MessageDef* md_;
0352   };
0353 
0354   class OneofIter {
0355    public:
0356     explicit OneofIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {}
0357     void operator++() { i_++; }
0358 
0359     OneofDefPtr operator*() {
0360       return OneofDefPtr(upb_MessageDef_Oneof(m_, i_));
0361     }
0362 
0363     friend bool operator==(OneofIter lhs, OneofIter rhs) {
0364       return lhs.i_ == rhs.i_;
0365     }
0366 
0367     friend bool operator!=(OneofIter lhs, OneofIter rhs) {
0368       return !(lhs == rhs);
0369     }
0370 
0371    private:
0372     const upb_MessageDef* m_;
0373     int i_;
0374   };
0375 
0376   class OneofAccessor {
0377    public:
0378     explicit OneofAccessor(const upb_MessageDef* md) : md_(md) {}
0379     OneofIter begin() { return OneofIter(md_, 0); }
0380     OneofIter end() { return OneofIter(md_, upb_MessageDef_OneofCount(md_)); }
0381 
0382    private:
0383     const upb_MessageDef* md_;
0384   };
0385 
0386  public:
0387   FieldAccessor fields() const { return FieldAccessor(ptr()); }
0388   OneofAccessor oneofs() const { return OneofAccessor(ptr()); }
0389 
0390  private:
0391   const upb_MessageDef* ptr_;
0392 };
0393 
0394 class EnumValDefPtr {
0395  public:
0396   EnumValDefPtr() : ptr_(nullptr) {}
0397   explicit EnumValDefPtr(const upb_EnumValueDef* ptr) : ptr_(ptr) {}
0398 
0399   const UPB_DESC(EnumValueOptions) * options() const {
0400     return upb_EnumValueDef_Options(ptr_);
0401   }
0402 
0403   int32_t number() const { return upb_EnumValueDef_Number(ptr_); }
0404   const char* full_name() const { return upb_EnumValueDef_FullName(ptr_); }
0405   const char* name() const { return upb_EnumValueDef_Name(ptr_); }
0406 
0407  private:
0408   const upb_EnumValueDef* ptr_;
0409 };
0410 
0411 class EnumDefPtr {
0412  public:
0413   EnumDefPtr() : ptr_(nullptr) {}
0414   explicit EnumDefPtr(const upb_EnumDef* ptr) : ptr_(ptr) {}
0415 
0416   const UPB_DESC(EnumOptions) * options() const {
0417     return upb_EnumDef_Options(ptr_);
0418   }
0419 
0420   const upb_MiniTableEnum* mini_table() const {
0421     return _upb_EnumDef_MiniTable(ptr_);
0422   }
0423 
0424   std::string MiniDescriptorEncode() const {
0425     upb::Arena arena;
0426     upb_StringView md;
0427     upb_EnumDef_MiniDescriptorEncode(ptr_, arena.ptr(), &md);
0428     return std::string(md.data, md.size);
0429   }
0430 
0431   const upb_EnumDef* ptr() const { return ptr_; }
0432   explicit operator bool() const { return ptr_ != nullptr; }
0433 
0434   FileDefPtr file() const;
0435   const char* full_name() const { return upb_EnumDef_FullName(ptr_); }
0436   const char* name() const { return upb_EnumDef_Name(ptr_); }
0437   bool is_closed() const { return upb_EnumDef_IsClosed(ptr_); }
0438 
0439   // Returns the MessageDef that contains this EnumDef (or null).
0440   MessageDefPtr containing_type() const;
0441 
0442   // The value that is used as the default when no field default is specified.
0443   // If not set explicitly, the first value that was added will be used.
0444   // The default value must be a member of the enum.
0445   // Requires that value_count() > 0.
0446   int32_t default_value() const { return upb_EnumDef_Default(ptr_); }
0447 
0448   // Returns the number of values currently defined in the enum.  Note that
0449   // multiple names can refer to the same number, so this may be greater than
0450   // the total number of unique numbers.
0451   int value_count() const { return upb_EnumDef_ValueCount(ptr_); }
0452   EnumValDefPtr value(int i) const {
0453     return EnumValDefPtr(upb_EnumDef_Value(ptr_, i));
0454   }
0455 
0456   // Lookups from name to integer, returning true if found.
0457   EnumValDefPtr FindValueByName(const char* name) const {
0458     return EnumValDefPtr(upb_EnumDef_FindValueByName(ptr_, name));
0459   }
0460 
0461   // Finds the name corresponding to the given number, or NULL if none was
0462   // found.  If more than one name corresponds to this number, returns the
0463   // first one that was added.
0464   EnumValDefPtr FindValueByNumber(int32_t num) const {
0465     return EnumValDefPtr(upb_EnumDef_FindValueByNumber(ptr_, num));
0466   }
0467 
0468  private:
0469   const upb_EnumDef* ptr_;
0470 };
0471 
0472 // Class that represents a .proto file with some things defined in it.
0473 //
0474 // Many users won't care about FileDefs, but they are necessary if you want to
0475 // read the values of file-level options.
0476 class FileDefPtr {
0477  public:
0478   explicit FileDefPtr(const upb_FileDef* ptr) : ptr_(ptr) {}
0479 
0480   const UPB_DESC(FileOptions) * options() const {
0481     return upb_FileDef_Options(ptr_);
0482   }
0483 
0484   const upb_FileDef* ptr() const { return ptr_; }
0485 
0486   // Get/set name of the file (eg. "foo/bar.proto").
0487   const char* name() const { return upb_FileDef_Name(ptr_); }
0488 
0489   // Package name for definitions inside the file (eg. "foo.bar").
0490   const char* package() const { return upb_FileDef_Package(ptr_); }
0491 
0492   // Syntax for the file.  Defaults to proto2.
0493   upb_Syntax syntax() const { return upb_FileDef_Syntax(ptr_); }
0494 
0495   // Get the list of dependencies from the file.  These are returned in the
0496   // order that they were added to the FileDefPtr.
0497   int dependency_count() const { return upb_FileDef_DependencyCount(ptr_); }
0498   FileDefPtr dependency(int index) const {
0499     return FileDefPtr(upb_FileDef_Dependency(ptr_, index));
0500   }
0501 
0502   int public_dependency_count() const {
0503     return upb_FileDef_PublicDependencyCount(ptr_);
0504   }
0505   FileDefPtr public_dependency(int index) const {
0506     return FileDefPtr(upb_FileDef_PublicDependency(ptr_, index));
0507   }
0508 
0509   int toplevel_enum_count() const {
0510     return upb_FileDef_TopLevelEnumCount(ptr_);
0511   }
0512   EnumDefPtr toplevel_enum(int index) const {
0513     return EnumDefPtr(upb_FileDef_TopLevelEnum(ptr_, index));
0514   }
0515 
0516   int toplevel_message_count() const {
0517     return upb_FileDef_TopLevelMessageCount(ptr_);
0518   }
0519   MessageDefPtr toplevel_message(int index) const {
0520     return MessageDefPtr(upb_FileDef_TopLevelMessage(ptr_, index));
0521   }
0522 
0523   int toplevel_extension_count() const {
0524     return upb_FileDef_TopLevelExtensionCount(ptr_);
0525   }
0526   FieldDefPtr toplevel_extension(int index) const {
0527     return FieldDefPtr(upb_FileDef_TopLevelExtension(ptr_, index));
0528   }
0529 
0530   bool resolves(const char* path) const {
0531     return upb_FileDef_Resolves(ptr_, path);
0532   }
0533 
0534   explicit operator bool() const { return ptr_ != nullptr; }
0535 
0536   friend bool operator==(FileDefPtr lhs, FileDefPtr rhs) {
0537     return lhs.ptr_ == rhs.ptr_;
0538   }
0539 
0540   friend bool operator!=(FileDefPtr lhs, FileDefPtr rhs) {
0541     return !(lhs == rhs);
0542   }
0543 
0544  private:
0545   const upb_FileDef* ptr_;
0546 };
0547 
0548 // Non-const methods in upb::DefPool are NOT thread-safe.
0549 class DefPool {
0550  public:
0551   DefPool() : ptr_(upb_DefPool_New(), upb_DefPool_Free) {}
0552   explicit DefPool(upb_DefPool* s) : ptr_(s, upb_DefPool_Free) {}
0553 
0554   const upb_DefPool* ptr() const { return ptr_.get(); }
0555   upb_DefPool* ptr() { return ptr_.get(); }
0556 
0557   // Finds an entry in the symbol table with this exact name.  If not found,
0558   // returns NULL.
0559   MessageDefPtr FindMessageByName(const char* sym) const {
0560     return MessageDefPtr(upb_DefPool_FindMessageByName(ptr_.get(), sym));
0561   }
0562 
0563   EnumDefPtr FindEnumByName(const char* sym) const {
0564     return EnumDefPtr(upb_DefPool_FindEnumByName(ptr_.get(), sym));
0565   }
0566 
0567   FileDefPtr FindFileByName(const char* name) const {
0568     return FileDefPtr(upb_DefPool_FindFileByName(ptr_.get(), name));
0569   }
0570 
0571   FieldDefPtr FindExtensionByName(const char* name) const {
0572     return FieldDefPtr(upb_DefPool_FindExtensionByName(ptr_.get(), name));
0573   }
0574 
0575   void _SetPlatform(upb_MiniTablePlatform platform) {
0576     _upb_DefPool_SetPlatform(ptr_.get(), platform);
0577   }
0578 
0579   // TODO: iteration?
0580 
0581   // Adds the given serialized FileDescriptorProto to the pool.
0582   FileDefPtr AddFile(const UPB_DESC(FileDescriptorProto) * file_proto,
0583                      Status* status) {
0584     return FileDefPtr(
0585         upb_DefPool_AddFile(ptr_.get(), file_proto, status->ptr()));
0586   }
0587 
0588  private:
0589   std::unique_ptr<upb_DefPool, decltype(&upb_DefPool_Free)> ptr_;
0590 };
0591 
0592 inline FileDefPtr EnumDefPtr::file() const {
0593   return FileDefPtr(upb_EnumDef_File(ptr_));
0594 }
0595 
0596 inline FileDefPtr FieldDefPtr::file() const {
0597   return FileDefPtr(upb_FieldDef_File(ptr_));
0598 }
0599 
0600 inline FileDefPtr MessageDefPtr::file() const {
0601   return FileDefPtr(upb_MessageDef_File(ptr_));
0602 }
0603 
0604 inline MessageDefPtr MessageDefPtr::containing_type() const {
0605   return MessageDefPtr(upb_MessageDef_ContainingType(ptr_));
0606 }
0607 
0608 inline MessageDefPtr EnumDefPtr::containing_type() const {
0609   return MessageDefPtr(upb_EnumDef_ContainingType(ptr_));
0610 }
0611 
0612 inline EnumDefPtr MessageDefPtr::enum_type(int i) const {
0613   return EnumDefPtr(upb_MessageDef_NestedEnum(ptr_, i));
0614 }
0615 
0616 inline MessageDefPtr FieldDefPtr::message_type() const {
0617   return MessageDefPtr(upb_FieldDef_MessageSubDef(ptr_));
0618 }
0619 
0620 inline MessageDefPtr FieldDefPtr::containing_type() const {
0621   return MessageDefPtr(upb_FieldDef_ContainingType(ptr_));
0622 }
0623 
0624 inline MessageDefPtr FieldDefPtr::extension_scope() const {
0625   return MessageDefPtr(upb_FieldDef_ExtensionScope(ptr_));
0626 }
0627 
0628 inline MessageDefPtr OneofDefPtr::containing_type() const {
0629   return MessageDefPtr(upb_OneofDef_ContainingType(ptr_));
0630 }
0631 
0632 inline OneofDefPtr FieldDefPtr::containing_oneof() const {
0633   return OneofDefPtr(upb_FieldDef_ContainingOneof(ptr_));
0634 }
0635 
0636 inline OneofDefPtr FieldDefPtr::real_containing_oneof() const {
0637   return OneofDefPtr(upb_FieldDef_RealContainingOneof(ptr_));
0638 }
0639 
0640 inline EnumDefPtr FieldDefPtr::enum_subdef() const {
0641   return EnumDefPtr(upb_FieldDef_EnumSubDef(ptr_));
0642 }
0643 
0644 }  // namespace upb
0645 
0646 #include "upb/port/undef.inc"
0647 
0648 #endif  // UPB_REFLECTION_DEF_HPP_