|
|
@ -1001,9 +1001,77 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, |
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ |
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ |
|
|
|
#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ |
|
|
|
#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ |
|
|
|
|
|
|
|
#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
#include <stdint.h> |
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the log2 of the storage size in bytes for a upb_CType
|
|
|
|
|
|
|
|
UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { |
|
|
|
|
|
|
|
static const int8_t size[] = { |
|
|
|
|
|
|
|
0, // kUpb_CType_Bool
|
|
|
|
|
|
|
|
2, // kUpb_CType_Float
|
|
|
|
|
|
|
|
2, // kUpb_CType_Int32
|
|
|
|
|
|
|
|
2, // kUpb_CType_UInt32
|
|
|
|
|
|
|
|
2, // kUpb_CType_Enum
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_CType_Message
|
|
|
|
|
|
|
|
3, // kUpb_CType_Double
|
|
|
|
|
|
|
|
3, // kUpb_CType_Int64
|
|
|
|
|
|
|
|
3, // kUpb_CType_UInt64
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_CType_String
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_CType_Bytes
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -1 here because the enum is one-based but the table is zero-based.
|
|
|
|
|
|
|
|
return size[c_type - 1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the log2 of the storage size in bytes for a upb_FieldType
|
|
|
|
|
|
|
|
UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { |
|
|
|
|
|
|
|
static const int8_t size[] = { |
|
|
|
|
|
|
|
3, // kUpb_FieldType_Double
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Float
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_Int64
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_UInt64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Int32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_Fixed64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Fixed32
|
|
|
|
|
|
|
|
0, // kUpb_FieldType_Bool
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_FieldType_String
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_FieldType_Group
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_FieldType_Message
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_FieldType_Bytes
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_UInt32
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Enum
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_SFixed32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_SFixed64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_SInt32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_SInt64
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -1 here because the enum is one-based but the table is zero-based.
|
|
|
|
|
|
|
|
return size[field_type - 1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
} /* extern "C" */ |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ |
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
|
|
struct upb_MiniTableField { |
|
|
|
struct upb_MiniTableField { |
|
|
@ -1086,6 +1154,12 @@ UPB_INLINE void _upb_MiniTableField_CheckIsMap( |
|
|
|
UPB_ASSUME(field->presence == 0); |
|
|
|
UPB_ASSUME(field->presence == 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPB_INLINE size_t |
|
|
|
|
|
|
|
_upb_MiniTableField_ElemSizeLg2(const struct upb_MiniTableField* field) { |
|
|
|
|
|
|
|
return upb_FieldType_SizeLg2( |
|
|
|
|
|
|
|
(upb_FieldType)field->UPB_PRIVATE(descriptortype)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
#ifdef __cplusplus |
|
|
|
} /* extern "C" */ |
|
|
|
} /* extern "C" */ |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2153,73 +2227,6 @@ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, |
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MESSAGE_INTERNAL_H_ */ |
|
|
|
#endif /* UPB_MESSAGE_INTERNAL_H_ */ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_ |
|
|
|
|
|
|
|
#define UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the log2 of the storage size in bytes for a upb_CType
|
|
|
|
|
|
|
|
UPB_INLINE int upb_SizeLog2_CType(upb_CType c_type) { |
|
|
|
|
|
|
|
static const int8_t size[] = { |
|
|
|
|
|
|
|
0, // kUpb_CType_Bool
|
|
|
|
|
|
|
|
2, // kUpb_CType_Float
|
|
|
|
|
|
|
|
2, // kUpb_CType_Int32
|
|
|
|
|
|
|
|
2, // kUpb_CType_UInt32
|
|
|
|
|
|
|
|
2, // kUpb_CType_Enum
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_CType_Message
|
|
|
|
|
|
|
|
3, // kUpb_CType_Double
|
|
|
|
|
|
|
|
3, // kUpb_CType_Int64
|
|
|
|
|
|
|
|
3, // kUpb_CType_UInt64
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_CType_String
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_CType_Bytes
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -1 here because the enum is one-based but the table is zero-based.
|
|
|
|
|
|
|
|
return size[c_type - 1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the log2 of the storage size in bytes for a upb_FieldType
|
|
|
|
|
|
|
|
UPB_INLINE int upb_SizeLog2_FieldType(upb_FieldType field_type) { |
|
|
|
|
|
|
|
static const int8_t size[] = { |
|
|
|
|
|
|
|
3, // kUpb_FieldType_Double
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Float
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_Int64
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_UInt64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Int32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_Fixed64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Fixed32
|
|
|
|
|
|
|
|
0, // kUpb_FieldType_Bool
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_FieldType_String
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_FieldType_Group
|
|
|
|
|
|
|
|
UPB_SIZE(2, 3), // kUpb_FieldType_Message
|
|
|
|
|
|
|
|
UPB_SIZE(3, 4), // kUpb_FieldType_Bytes
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_UInt32
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_Enum
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_SFixed32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_SFixed64
|
|
|
|
|
|
|
|
2, // kUpb_FieldType_SInt32
|
|
|
|
|
|
|
|
3, // kUpb_FieldType_SInt64
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -1 here because the enum is one-based but the table is zero-based.
|
|
|
|
|
|
|
|
return size[field_type - 1]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
|
|
|
} /* extern "C" */ |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MESSAGE_INTERNAL_SIZE_LOG2_H_ */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) |
|
|
|
#if defined(__GNUC__) && !defined(__clang__) |
|
|
@ -2376,12 +2383,6 @@ UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, |
|
|
|
UPB_UNREACHABLE(); |
|
|
|
UPB_UNREACHABLE(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UPB_INLINE size_t |
|
|
|
|
|
|
|
_upb_MiniTable_ElementSizeLg2(const upb_MiniTableField* field) { |
|
|
|
|
|
|
|
return upb_SizeLog2_FieldType( |
|
|
|
|
|
|
|
(upb_FieldType)field->UPB_PRIVATE(descriptortype)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Here we define universal getter/setter functions for message fields.
|
|
|
|
// Here we define universal getter/setter functions for message fields.
|
|
|
|
// These look very branchy and inefficient, but as long as the MiniTableField
|
|
|
|
// These look very branchy and inefficient, but as long as the MiniTableField
|
|
|
|
// values are known at compile time, all the branches are optimized away and
|
|
|
|
// values are known at compile time, all the branches are optimized away and
|
|
|
@ -3032,7 +3033,7 @@ UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( |
|
|
|
_upb_MiniTableField_CheckIsArray(field); |
|
|
|
_upb_MiniTableField_CheckIsArray(field); |
|
|
|
upb_Array* array = upb_Message_GetMutableArray(msg, field); |
|
|
|
upb_Array* array = upb_Message_GetMutableArray(msg, field); |
|
|
|
if (!array) { |
|
|
|
if (!array) { |
|
|
|
array = _upb_Array_New(arena, 4, _upb_MiniTable_ElementSizeLg2(field)); |
|
|
|
array = _upb_Array_New(arena, 4, _upb_MiniTableField_ElemSizeLg2(field)); |
|
|
|
// Check again due to: https://godbolt.org/z/7WfaoKG1r
|
|
|
|
// Check again due to: https://godbolt.org/z/7WfaoKG1r
|
|
|
|
_upb_MiniTableField_CheckIsArray(field); |
|
|
|
_upb_MiniTableField_CheckIsArray(field); |
|
|
|
upb_MessageValue val; |
|
|
|
upb_MessageValue val; |
|
|
|