Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:18

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 // https://developers.google.com/protocol-buffers/
0004 ///
0005 // Use of this source code is governed by a BSD-style
0006 // license that can be found in the LICENSE file or at
0007 // https://developers.google.com/open-source/licenses/bsd
0008 
0009 #ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
0010 #define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_
0011 
0012 #include <stddef.h>
0013 #include <stdint.h>
0014 
0015 #include "upb/base/descriptor_constants.h"
0016 
0017 // Must be last.
0018 #include "upb/port/def.inc"
0019 
0020 #ifdef __cplusplus
0021 extern "C" {
0022 #endif
0023 
0024 // Return the log2 of the storage size in bytes for a upb_CType
0025 UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) {
0026   static const int8_t size[] = {
0027       0,               // kUpb_CType_Bool
0028       2,               // kUpb_CType_Float
0029       2,               // kUpb_CType_Int32
0030       2,               // kUpb_CType_UInt32
0031       2,               // kUpb_CType_Enum
0032       UPB_SIZE(2, 3),  // kUpb_CType_Message
0033       3,               // kUpb_CType_Double
0034       3,               // kUpb_CType_Int64
0035       3,               // kUpb_CType_UInt64
0036       UPB_SIZE(3, 4),  // kUpb_CType_String
0037       UPB_SIZE(3, 4),  // kUpb_CType_Bytes
0038   };
0039 
0040   // -1 here because the enum is one-based but the table is zero-based.
0041   return size[c_type - 1];
0042 }
0043 
0044 // Return the log2 of the storage size in bytes for a upb_FieldType
0045 UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) {
0046   static const int8_t size[] = {
0047       3,               // kUpb_FieldType_Double
0048       2,               // kUpb_FieldType_Float
0049       3,               // kUpb_FieldType_Int64
0050       3,               // kUpb_FieldType_UInt64
0051       2,               // kUpb_FieldType_Int32
0052       3,               // kUpb_FieldType_Fixed64
0053       2,               // kUpb_FieldType_Fixed32
0054       0,               // kUpb_FieldType_Bool
0055       UPB_SIZE(3, 4),  // kUpb_FieldType_String
0056       UPB_SIZE(2, 3),  // kUpb_FieldType_Group
0057       UPB_SIZE(2, 3),  // kUpb_FieldType_Message
0058       UPB_SIZE(3, 4),  // kUpb_FieldType_Bytes
0059       2,               // kUpb_FieldType_UInt32
0060       2,               // kUpb_FieldType_Enum
0061       2,               // kUpb_FieldType_SFixed32
0062       3,               // kUpb_FieldType_SFixed64
0063       2,               // kUpb_FieldType_SInt32
0064       3,               // kUpb_FieldType_SInt64
0065   };
0066 
0067   // -1 here because the enum is one-based but the table is zero-based.
0068   return size[field_type - 1];
0069 }
0070 
0071 #ifdef __cplusplus
0072 } /* extern "C" */
0073 #endif
0074 
0075 #include "upb/port/undef.inc"
0076 
0077 #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */