1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2023 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef UPB_MINI_TABLE_MESSAGE_H_ 9 #define UPB_MINI_TABLE_MESSAGE_H_ 10 11 #include "upb/mini_table/enum.h" 12 #include "upb/mini_table/field.h" 13 #include "upb/mini_table/internal/message.h" 14 15 // Must be last. 16 #include "upb/port/def.inc" 17 18 typedef struct upb_MiniTable upb_MiniTable; 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( 25 const upb_MiniTable* m, uint32_t number); 26 27 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( 28 const upb_MiniTable* m, uint32_t index); 29 30 UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m); 31 32 // DEPRECATED: use upb_MiniTable_SubMessage() instead 33 // Returns the MiniTable for a message field, NULL if the field is unlinked. 34 UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( 35 const upb_MiniTable* m, const upb_MiniTableField* f); 36 37 // Returns the MiniTable for a message field if it is a submessage, otherwise 38 // returns NULL. 39 // 40 // WARNING: if dynamic tree shaking is in use, the return value may be the 41 // "empty", zero-field placeholder message instead of the real message type. 42 // If the message is later linked, this function will begin returning the real 43 // message type. 44 UPB_API_INLINE const upb_MiniTable* upb_MiniTable_SubMessage( 45 const upb_MiniTable* m, const upb_MiniTableField* f); 46 47 // Returns the MiniTable for a map field. The given field must refer to a map. 48 UPB_API_INLINE const upb_MiniTable* upb_MiniTable_MapEntrySubMessage( 49 const upb_MiniTable* m, const upb_MiniTableField* f); 50 51 // Returns the MiniTableEnum for a message field, NULL if the field is unlinked. 52 UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( 53 const upb_MiniTable* m, const upb_MiniTableField* f); 54 55 // Returns the MiniTableField for the key of a map. 56 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( 57 const upb_MiniTable* m); 58 59 // Returns the MiniTableField for the value of a map. 60 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( 61 const upb_MiniTable* m); 62 63 // Returns true if this MiniTable field is linked to a MiniTable for the 64 // sub-message. 65 UPB_API_INLINE bool upb_MiniTable_FieldIsLinked(const upb_MiniTable* m, 66 const upb_MiniTableField* f); 67 68 // If this field is in a oneof, returns the first field in the oneof. 69 // 70 // Otherwise returns NULL. 71 // 72 // Usage: 73 // const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); 74 // do { 75 // .. 76 // } while (upb_MiniTable_NextOneofField(m, &field); 77 // 78 const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, 79 const upb_MiniTableField* f); 80 81 // Iterates to the next field in the oneof. If this is the last field in the 82 // oneof, returns false. The ordering of fields in the oneof is not 83 // guaranteed. 84 // REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated 85 // by prior upb_MiniTable_NextOneofField calls. 86 bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, 87 const upb_MiniTableField** f); 88 89 #ifdef __cplusplus 90 } /* extern "C" */ 91 #endif 92 93 #include "upb/port/undef.inc" 94 95 #endif /* UPB_MINI_TABLE_MESSAGE_H_ */ 96