1 /*
2 * Copyright (c) 2009-2021, Google LLC
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Google LLC nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
29 #define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
30
31 // Must be last.
32 #include "upb/port/def.inc"
33
34 // The types a field can have. Note that this list is not identical to the
35 // types defined in descriptor.proto, which gives INT32 and SINT32 separate
36 // types (we distinguish the two with the "integer encoding" enum below).
37 // This enum is an internal convenience only and has no meaning outside of upb.
38 typedef enum {
39 kUpb_CType_Bool = 1,
40 kUpb_CType_Float = 2,
41 kUpb_CType_Int32 = 3,
42 kUpb_CType_UInt32 = 4,
43 kUpb_CType_Enum = 5, // Enum values are int32. TODO(b/279178239): rename
44 kUpb_CType_Message = 6,
45 kUpb_CType_Double = 7,
46 kUpb_CType_Int64 = 8,
47 kUpb_CType_UInt64 = 9,
48 kUpb_CType_String = 10,
49 kUpb_CType_Bytes = 11
50 } upb_CType;
51
52 // The repeated-ness of each field; this matches descriptor.proto.
53 typedef enum {
54 kUpb_Label_Optional = 1,
55 kUpb_Label_Required = 2,
56 kUpb_Label_Repeated = 3
57 } upb_Label;
58
59 // Descriptor types, as defined in descriptor.proto.
60 typedef enum {
61 kUpb_FieldType_Double = 1,
62 kUpb_FieldType_Float = 2,
63 kUpb_FieldType_Int64 = 3,
64 kUpb_FieldType_UInt64 = 4,
65 kUpb_FieldType_Int32 = 5,
66 kUpb_FieldType_Fixed64 = 6,
67 kUpb_FieldType_Fixed32 = 7,
68 kUpb_FieldType_Bool = 8,
69 kUpb_FieldType_String = 9,
70 kUpb_FieldType_Group = 10,
71 kUpb_FieldType_Message = 11,
72 kUpb_FieldType_Bytes = 12,
73 kUpb_FieldType_UInt32 = 13,
74 kUpb_FieldType_Enum = 14,
75 kUpb_FieldType_SFixed32 = 15,
76 kUpb_FieldType_SFixed64 = 16,
77 kUpb_FieldType_SInt32 = 17,
78 kUpb_FieldType_SInt64 = 18,
79 } upb_FieldType;
80
81 #define kUpb_FieldType_SizeOf 19
82
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86
upb_FieldType_IsPackable(upb_FieldType type)87 UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType type) {
88 // clang-format off
89 const unsigned kUnpackableTypes =
90 (1 << kUpb_FieldType_String) |
91 (1 << kUpb_FieldType_Bytes) |
92 (1 << kUpb_FieldType_Message) |
93 (1 << kUpb_FieldType_Group);
94 // clang-format on
95 return (1 << type) & ~kUnpackableTypes;
96 }
97
98 #ifdef __cplusplus
99 } /* extern "C" */
100 #endif
101
102 #include "upb/port/undef.inc"
103
104 #endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
105