1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 // For int32_t in GPB_ENUM/GPB_ENUM_FWD_DECLARE below.
12 * The Objective C runtime has complete enough info that most protos don’t end
13 * up using this, so leaving it on is no cost or very little cost. If you
14 * happen to see it causing bloat, this is the way to disable it. If you do
15 * need to disable it, try only disabling it for Release builds as having
16 * full TextFormat can be useful for debugging.
18 #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
19 #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
22 // Used in the generated code to give sizes to enums. int32_t was chosen based
23 // on the fact that Protocol Buffers enums are limited to this range.
24 #if !__has_feature(objc_fixed_enum)
25 #error All supported Xcode versions should support objc_fixed_enum.
28 // If the headers are imported into Objective-C++, we can run into an issue
29 // where the definition of NS_ENUM (really CF_ENUM) changes based on the C++
30 // standard that is in effect. If it isn't C++11 or higher, the definition
31 // doesn't allow us to forward declare. We work around this one case by
32 // providing a local definition. The default case has to use NS_ENUM for the
33 // magic that is Swift bridging of enums.
34 #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
39 #define GPB_ENUM(X) NS_ENUM(int32_t, X)
43 * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
46 * GPB_ENUM_FWD_DECLARE(Foo_Enum)
48 * @interface BarClass : NSObject
49 * @property (nonatomic) enum Foo_Enum value;
50 * - (void)bazMethod:(enum Foo_Enum)value;
54 #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
57 * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
60 #define GPB_INLINE static __inline__ __attribute__((always_inline))
62 #define GPB_INLINE static __inline__
66 * For use in public headers that might need to deal with ARC.
68 #ifndef GPB_UNSAFE_UNRETAINED
69 #if __has_feature(objc_arc)
70 #define GPB_UNSAFE_UNRETAINED __unsafe_unretained
72 #define GPB_UNSAFE_UNRETAINED
77 * Attribute used for Objective-C proto interface deprecations without messages.
79 #ifndef GPB_DEPRECATED
80 #define GPB_DEPRECATED __attribute__((deprecated))
84 * Attribute used for Objective-C proto interface deprecations with messages.
86 #ifndef GPB_DEPRECATED_MSG
87 #if __has_extension(attribute_deprecated_with_message)
88 #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
90 #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated))
94 // If property name starts with init we need to annotate it to get past ARC.
95 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
97 // Meant to be used internally by generated code.
98 #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
100 // Prevent subclassing of generated proto classes.
102 #define GPB_FINAL __attribute__((objc_subclassing_restricted))
105 // ----------------------------------------------------------------------------
106 // These version numbers are all internal to the ObjC Protobuf runtime; they
107 // are used to ensure compatibility between the generated sources and the
108 // headers being compiled against and/or the version of sources being run
111 // They are all #defines so the values are captured into every .o file they
112 // are used in and to allow comparisons in the preprocessor.
114 // Current library runtime version.
115 // - Gets bumped when the runtime makes changes to the interfaces between the
116 // generated code and runtime (things added/removed, etc).
117 #define GOOGLE_PROTOBUF_OBJC_VERSION 30007
119 // Minimum runtime version supported for compiling/running against.
120 // - Gets changed when support for the older generated code is dropped.
121 #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30007