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
upb_MiniTable_GetFieldByIndex(const upb_MiniTable * m,uint32_t index)27 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex(
28 const upb_MiniTable* m, uint32_t index) {
29 return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index);
30 }
31
upb_MiniTable_FieldCount(const upb_MiniTable * m)32 UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) {
33 return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m);
34 }
35
36 // Returns the MiniTable for a message field, NULL if the field is unlinked.
upb_MiniTable_GetSubMessageTable(const upb_MiniTable * m,const upb_MiniTableField * f)37 UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
38 const upb_MiniTable* m, const upb_MiniTableField* f) {
39 return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f);
40 }
41
42 // Returns the MiniTableEnum for a message field, NULL if the field is unlinked.
upb_MiniTable_GetSubEnumTable(const upb_MiniTable * m,const upb_MiniTableField * f)43 UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
44 const upb_MiniTable* m, const upb_MiniTableField* f) {
45 return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f);
46 }
47
48 // Returns the MiniTableField for the key of a map.
upb_MiniTable_MapKey(const upb_MiniTable * m)49 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey(
50 const upb_MiniTable* m) {
51 return UPB_PRIVATE(_upb_MiniTable_MapKey)(m);
52 }
53
54 // Returns the MiniTableField for the value of a map.
upb_MiniTable_MapValue(const upb_MiniTable * m)55 UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue(
56 const upb_MiniTable* m) {
57 return UPB_PRIVATE(_upb_MiniTable_MapValue)(m);
58 }
59
60 // Returns true if this MiniTable field is linked to a MiniTable for the
61 // sub-message.
upb_MiniTable_MessageFieldIsLinked(const upb_MiniTable * m,const upb_MiniTableField * f)62 UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked(
63 const upb_MiniTable* m, const upb_MiniTableField* f) {
64 return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f);
65 }
66
67 // If this field is in a oneof, returns the first field in the oneof.
68 //
69 // Otherwise returns NULL.
70 //
71 // Usage:
72 // const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f);
73 // do {
74 // ..
75 // } while (upb_MiniTable_NextOneofField(m, &field);
76 //
77 const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m,
78 const upb_MiniTableField* f);
79
80 // Iterates to the next field in the oneof. If this is the last field in the
81 // oneof, returns false. The ordering of fields in the oneof is not
82 // guaranteed.
83 // REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated
84 // by prior upb_MiniTable_NextOneofField calls.
85 bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
86 const upb_MiniTableField** f);
87
88 #ifdef __cplusplus
89 } /* extern "C" */
90 #endif
91
92 #include "upb/port/undef.inc"
93
94 #endif /* UPB_MINI_TABLE_MESSAGE_H_ */
95