Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:25:22

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
0009 #define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
0010 
0011 // Must be last.
0012 #include "upb/port/def.inc"
0013 
0014 // The types a field can have. Note that this list is not identical to the
0015 // types defined in descriptor.proto, which gives INT32 and SINT32 separate
0016 // types (we distinguish the two with the "integer encoding" enum below).
0017 // This enum is an internal convenience only and has no meaning outside of upb.
0018 typedef enum {
0019   kUpb_CType_Bool = 1,
0020   kUpb_CType_Float = 2,
0021   kUpb_CType_Int32 = 3,
0022   kUpb_CType_UInt32 = 4,
0023   kUpb_CType_Enum = 5,  // Enum values are int32. TODO: rename
0024   kUpb_CType_Message = 6,
0025   kUpb_CType_Double = 7,
0026   kUpb_CType_Int64 = 8,
0027   kUpb_CType_UInt64 = 9,
0028   kUpb_CType_String = 10,
0029   kUpb_CType_Bytes = 11
0030 } upb_CType;
0031 
0032 // The repeated-ness of each field; this matches descriptor.proto.
0033 typedef enum {
0034   kUpb_Label_Optional = 1,
0035   kUpb_Label_Required = 2,
0036   kUpb_Label_Repeated = 3
0037 } upb_Label;
0038 
0039 // Descriptor types, as defined in descriptor.proto.
0040 typedef enum {
0041   kUpb_FieldType_Double = 1,
0042   kUpb_FieldType_Float = 2,
0043   kUpb_FieldType_Int64 = 3,
0044   kUpb_FieldType_UInt64 = 4,
0045   kUpb_FieldType_Int32 = 5,
0046   kUpb_FieldType_Fixed64 = 6,
0047   kUpb_FieldType_Fixed32 = 7,
0048   kUpb_FieldType_Bool = 8,
0049   kUpb_FieldType_String = 9,
0050   kUpb_FieldType_Group = 10,
0051   kUpb_FieldType_Message = 11,
0052   kUpb_FieldType_Bytes = 12,
0053   kUpb_FieldType_UInt32 = 13,
0054   kUpb_FieldType_Enum = 14,
0055   kUpb_FieldType_SFixed32 = 15,
0056   kUpb_FieldType_SFixed64 = 16,
0057   kUpb_FieldType_SInt32 = 17,
0058   kUpb_FieldType_SInt64 = 18,
0059 } upb_FieldType;
0060 
0061 #define kUpb_FieldType_SizeOf 19
0062 
0063 #ifdef __cplusplus
0064 extern "C" {
0065 #endif
0066 
0067 // Convert from upb_FieldType to upb_CType
0068 UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
0069   static const upb_CType c_type[] = {
0070       kUpb_CType_Double,   // kUpb_FieldType_Double
0071       kUpb_CType_Float,    // kUpb_FieldType_Float
0072       kUpb_CType_Int64,    // kUpb_FieldType_Int64
0073       kUpb_CType_UInt64,   // kUpb_FieldType_UInt64
0074       kUpb_CType_Int32,    // kUpb_FieldType_Int32
0075       kUpb_CType_UInt64,   // kUpb_FieldType_Fixed64
0076       kUpb_CType_UInt32,   // kUpb_FieldType_Fixed32
0077       kUpb_CType_Bool,     // kUpb_FieldType_Bool
0078       kUpb_CType_String,   // kUpb_FieldType_String
0079       kUpb_CType_Message,  // kUpb_FieldType_Group
0080       kUpb_CType_Message,  // kUpb_FieldType_Message
0081       kUpb_CType_Bytes,    // kUpb_FieldType_Bytes
0082       kUpb_CType_UInt32,   // kUpb_FieldType_UInt32
0083       kUpb_CType_Enum,     // kUpb_FieldType_Enum
0084       kUpb_CType_Int32,    // kUpb_FieldType_SFixed32
0085       kUpb_CType_Int64,    // kUpb_FieldType_SFixed64
0086       kUpb_CType_Int32,    // kUpb_FieldType_SInt32
0087       kUpb_CType_Int64,    // kUpb_FieldType_SInt64
0088   };
0089 
0090   // -1 here because the enum is one-based but the table is zero-based.
0091   return c_type[field_type - 1];
0092 }
0093 
0094 UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
0095   // clang-format off
0096   const unsigned kUnpackableTypes =
0097       (1 << kUpb_FieldType_String) |
0098       (1 << kUpb_FieldType_Bytes) |
0099       (1 << kUpb_FieldType_Message) |
0100       (1 << kUpb_FieldType_Group);
0101   // clang-format on
0102   return (1 << field_type) & ~kUnpackableTypes;
0103 }
0104 
0105 #ifdef __cplusplus
0106 } /* extern "C" */
0107 #endif
0108 
0109 #include "upb/port/undef.inc"
0110 
0111 #endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */