File indexing completed on 2025-01-30 10:25:23
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
0009 #define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
0010
0011 #include <stddef.h>
0012 #include <stdint.h>
0013
0014 #include "upb/base/descriptor_constants.h"
0015 #include "upb/mini_table/internal/field.h"
0016 #include "upb/mini_table/internal/sub.h"
0017
0018
0019 #include "upb/port/def.inc"
0020
0021 struct upb_Decoder;
0022 struct upb_Message;
0023 typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr,
0024 struct upb_Message* msg, intptr_t table,
0025 uint64_t hasbits, uint64_t data);
0026 typedef struct {
0027 uint64_t field_data;
0028 _upb_FieldParser* field_parser;
0029 } _upb_FastTable_Entry;
0030
0031 typedef enum {
0032 kUpb_ExtMode_NonExtendable = 0,
0033 kUpb_ExtMode_Extendable = 1,
0034 kUpb_ExtMode_IsMessageSet = 2,
0035 kUpb_ExtMode_IsMessageSet_ITEM =
0036 3,
0037
0038
0039
0040 kUpb_ExtMode_IsMapEntry = 4,
0041 } upb_ExtMode;
0042
0043
0044
0045
0046
0047
0048 struct upb_MiniTable {
0049 const upb_MiniTableSubInternal* UPB_PRIVATE(subs);
0050 const struct upb_MiniTableField* UPB_ONLYBITS(fields);
0051
0052
0053
0054 uint16_t UPB_PRIVATE(size);
0055
0056 uint16_t UPB_ONLYBITS(field_count);
0057
0058 uint8_t UPB_PRIVATE(ext);
0059 uint8_t UPB_PRIVATE(dense_below);
0060 uint8_t UPB_PRIVATE(table_mask);
0061 uint8_t UPB_PRIVATE(required_count);
0062
0063 #ifdef UPB_TRACING_ENABLED
0064 const char* UPB_PRIVATE(full_name);
0065 #endif
0066
0067 #ifdef UPB_FASTTABLE_ENABLED
0068
0069
0070
0071 _upb_FastTable_Entry UPB_PRIVATE(fasttable)[];
0072 #endif
0073 };
0074
0075
0076 #ifdef __cplusplus
0077 extern "C" {
0078 #endif
0079
0080 UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
0081 _upb_MiniTable_StrongReference)(const struct upb_MiniTable* mt) {
0082 #if defined(__GNUC__)
0083 __asm__("" : : "r"(mt));
0084 #else
0085 const struct upb_MiniTable* volatile unused = mt;
0086 (void)&unused;
0087 #endif
0088 return mt;
0089 }
0090
0091 UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) {
0092 extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
0093
0094 return &UPB_PRIVATE(_kUpb_MiniTable_Empty);
0095 }
0096
0097 UPB_API_INLINE int upb_MiniTable_FieldCount(const struct upb_MiniTable* m) {
0098 return m->UPB_ONLYBITS(field_count);
0099 }
0100
0101 UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(
0102 const struct upb_MiniTable* m) {
0103 extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
0104
0105 return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty);
0106 }
0107
0108 UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_GetFieldByIndex(
0109 const struct upb_MiniTable* m, uint32_t i) {
0110 return &m->UPB_ONLYBITS(fields)[i];
0111 }
0112
0113 UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
0114 _upb_MiniTable_GetSubTableByIndex)(const struct upb_MiniTable* m,
0115 uint32_t i) {
0116 return *m->UPB_PRIVATE(subs)[i].UPB_PRIVATE(submsg);
0117 }
0118
0119 UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_SubMessage(
0120 const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
0121 if (upb_MiniTableField_CType(f) != kUpb_CType_Message) {
0122 return NULL;
0123 }
0124 return UPB_PRIVATE(_upb_MiniTable_GetSubTableByIndex)(
0125 m, f->UPB_PRIVATE(submsg_index));
0126 }
0127
0128 UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_GetSubMessageTable(
0129 const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
0130 UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
0131 const struct upb_MiniTable* ret = upb_MiniTable_SubMessage(m, f);
0132 UPB_ASSUME(ret);
0133 return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret;
0134 }
0135
0136 UPB_API_INLINE bool upb_MiniTable_FieldIsLinked(
0137 const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
0138 return upb_MiniTable_GetSubMessageTable(m, f) != NULL;
0139 }
0140
0141 UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_MapEntrySubMessage(
0142 const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
0143 UPB_ASSERT(upb_MiniTable_FieldIsLinked(m, f));
0144 UPB_ASSERT(upb_MiniTableField_IsMap(f));
0145 return upb_MiniTable_SubMessage(m, f);
0146 }
0147
0148 UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
0149 const struct upb_MiniTable* m, const struct upb_MiniTableField* f) {
0150 UPB_ASSERT(upb_MiniTableField_CType(f) == kUpb_CType_Enum);
0151 return m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)].UPB_PRIVATE(
0152 subenum);
0153 }
0154
0155 UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_MapKey(
0156 const struct upb_MiniTable* m) {
0157 UPB_ASSERT(upb_MiniTable_FieldCount(m) == 2);
0158 const struct upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, 0);
0159 UPB_ASSERT(upb_MiniTableField_Number(f) == 1);
0160 return f;
0161 }
0162
0163 UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_MapValue(
0164 const struct upb_MiniTable* m) {
0165 UPB_ASSERT(upb_MiniTable_FieldCount(m) == 2);
0166 const struct upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, 1);
0167 UPB_ASSERT(upb_MiniTableField_Number(f) == 2);
0168 return f;
0169 }
0170
0171
0172
0173
0174
0175
0176 UPB_INLINE uint64_t
0177 UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) {
0178 int n = m->UPB_PRIVATE(required_count);
0179 UPB_ASSERT(0 < n && n <= 64);
0180 return (1ULL << n) - 1;
0181 }
0182
0183 #ifdef UPB_TRACING_ENABLED
0184 UPB_INLINE const char* upb_MiniTable_FullName(
0185 const struct upb_MiniTable* mini_table) {
0186 return mini_table->UPB_PRIVATE(full_name);
0187 }
0188
0189
0190
0191 UPB_INLINE void upb_MiniTable_SetFullName(struct upb_MiniTable* mini_table,
0192 const char* full_name) {
0193 mini_table->UPB_PRIVATE(full_name) = full_name;
0194 }
0195 #endif
0196
0197 #ifdef __cplusplus
0198 }
0199 #endif
0200
0201 #include "upb/port/undef.inc"
0202
0203 #endif