1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 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 7 8 // For int32_t in GPB_ENUM/GPB_ENUM_FWD_DECLARE below. 9 #import <stdint.h> 10 11 /** 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. 17 **/ 18 #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 19 #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0 20 #endif 21 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. 26 #endif 27 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) 35 #define GPB_ENUM(X) \ 36 enum X : int32_t X; \ 37 enum X : int32_t 38 #else 39 #define GPB_ENUM(X) NS_ENUM(int32_t, X) 40 #endif 41 42 /** 43 * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example: 44 * 45 * ``` 46 * GPB_ENUM_FWD_DECLARE(Foo_Enum) 47 * 48 * @interface BarClass : NSObject 49 * @property (nonatomic) enum Foo_Enum value; 50 * - (void)bazMethod:(enum Foo_Enum)value; 51 * @end 52 * ``` 53 **/ 54 #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t 55 56 /** 57 * Based upon CF_INLINE. Forces inlining in non DEBUG builds. 58 **/ 59 #if !defined(DEBUG) 60 #define GPB_INLINE static __inline__ __attribute__((always_inline)) 61 #else 62 #define GPB_INLINE static __inline__ 63 #endif 64 65 /** 66 * For use in public headers that might need to deal with ARC. 67 **/ 68 #ifndef GPB_UNSAFE_UNRETAINED 69 #if __has_feature(objc_arc) 70 #define GPB_UNSAFE_UNRETAINED __unsafe_unretained 71 #else 72 #define GPB_UNSAFE_UNRETAINED 73 #endif 74 #endif 75 76 /** 77 * Attribute used for Objective-C proto interface deprecations without messages. 78 **/ 79 #ifndef GPB_DEPRECATED 80 #define GPB_DEPRECATED __attribute__((deprecated)) 81 #endif 82 83 /** 84 * Attribute used for Objective-C proto interface deprecations with messages. 85 **/ 86 #ifndef GPB_DEPRECATED_MSG 87 #if __has_extension(attribute_deprecated_with_message) 88 #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) 89 #else 90 #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated)) 91 #endif 92 #endif 93 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 96 // 97 // Meant to be used internally by generated code. 98 #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) 99 100 // Prevent subclassing of generated proto classes. 101 #ifndef GPB_FINAL 102 #define GPB_FINAL __attribute__((objc_subclassing_restricted)) 103 #endif // GPB_FINAL 104 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 109 // against. 110 // 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. 113 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 118 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 30001 122 123 // This is a legacy constant now frozen in time for old generated code. If 124 // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then 125 // this should also change to break code compiled with an old runtime that 126 // can't be supported any more. 127 #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001 128