Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
| 3 | // https://developers.google.com/protocol-buffers/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | #import <Foundation/Foundation.h> |
| 32 | |
| 33 | #import "GPBUtilities.h" |
| 34 | |
| 35 | #import "GPBDescriptor_PackagePrivate.h" |
| 36 | |
| 37 | // Macros for stringifying library symbols. These are used in the generated |
Dave MacLachlan | aa1d7e7 | 2020-01-19 17:46:35 -0800 | [diff] [blame] | 38 | // GPB descriptor classes wherever a library symbol name is represented as a |
| 39 | // string. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 40 | #define GPBStringify(S) #S |
| 41 | #define GPBStringifySymbol(S) GPBStringify(S) |
| 42 | |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 43 | #define GPBNSStringify(S) @ #S |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 44 | #define GPBNSStringifySymbol(S) GPBNSStringify(S) |
| 45 | |
Dave MacLachlan | aa1d7e7 | 2020-01-19 17:46:35 -0800 | [diff] [blame] | 46 | // Macros for generating a Class from a class name. These are used in |
| 47 | // the generated GPB descriptor classes wherever an Objective C class |
| 48 | // reference is needed for a generated class. |
| 49 | #define GPBObjCClassSymbol(name) OBJC_CLASS_$_##name |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 50 | #define GPBObjCClass(name) ((__bridge Class) & (GPBObjCClassSymbol(name))) |
| 51 | #define GPBObjCClassDeclaration(name) extern const GPBObjcClass_t GPBObjCClassSymbol(name) |
Dave MacLachlan | aa1d7e7 | 2020-01-19 17:46:35 -0800 | [diff] [blame] | 52 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 53 | // Constant to internally mark when there is no has bit. |
| 54 | #define GPBNoHasBit INT32_MAX |
| 55 | |
| 56 | CF_EXTERN_C_BEGIN |
| 57 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 58 | // These two are used to inject a runtime check for version mismatch into the |
| 59 | // generated sources to make sure they are linked with a supporting runtime. |
Thomas Van Lenten | 1aa6500 | 2016-09-15 13:27:17 -0400 | [diff] [blame] | 60 | void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion); |
| 61 | GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS() { |
| 62 | // NOTE: By being inline here, this captures the value from the library's |
| 63 | // headers at the time the generated code was compiled. |
| 64 | #if defined(DEBUG) && DEBUG |
| 65 | GPBCheckRuntimeVersionSupport(GOOGLE_PROTOBUF_OBJC_VERSION); |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | // Legacy version of the checks, remove when GOOGLE_PROTOBUF_OBJC_GEN_VERSION |
| 70 | // goes away (see more info in GPBBootstrap.h). |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 71 | void GPBCheckRuntimeVersionInternal(int32_t version); |
| 72 | GPB_INLINE void GPBDebugCheckRuntimeVersion() { |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 73 | #if defined(DEBUG) && DEBUG |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 74 | GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION); |
| 75 | #endif |
| 76 | } |
| 77 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 78 | // Conversion functions for de/serializing floating point types. |
| 79 | |
| 80 | GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) { |
Thomas Van Lenten | 5846439 | 2019-09-20 10:52:34 -0400 | [diff] [blame] | 81 | GPBInternalCompileAssert(sizeof(double) == sizeof(int64_t), double_not_64_bits); |
| 82 | int64_t result; |
| 83 | memcpy(&result, &v, sizeof(result)); |
| 84 | return result; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | GPB_INLINE int32_t GPBConvertFloatToInt32(float v) { |
Thomas Van Lenten | 5846439 | 2019-09-20 10:52:34 -0400 | [diff] [blame] | 88 | GPBInternalCompileAssert(sizeof(float) == sizeof(int32_t), float_not_32_bits); |
| 89 | int32_t result; |
| 90 | memcpy(&result, &v, sizeof(result)); |
| 91 | return result; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | GPB_INLINE double GPBConvertInt64ToDouble(int64_t v) { |
Thomas Van Lenten | 5846439 | 2019-09-20 10:52:34 -0400 | [diff] [blame] | 95 | GPBInternalCompileAssert(sizeof(double) == sizeof(int64_t), double_not_64_bits); |
| 96 | double result; |
| 97 | memcpy(&result, &v, sizeof(result)); |
| 98 | return result; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | GPB_INLINE float GPBConvertInt32ToFloat(int32_t v) { |
Thomas Van Lenten | 5846439 | 2019-09-20 10:52:34 -0400 | [diff] [blame] | 102 | GPBInternalCompileAssert(sizeof(float) == sizeof(int32_t), float_not_32_bits); |
| 103 | float result; |
| 104 | memcpy(&result, &v, sizeof(result)); |
| 105 | return result; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | GPB_INLINE int32_t GPBLogicalRightShift32(int32_t value, int32_t spaces) { |
| 109 | return (int32_t)((uint32_t)(value) >> spaces); |
| 110 | } |
| 111 | |
| 112 | GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) { |
| 113 | return (int64_t)((uint64_t)(value) >> spaces); |
| 114 | } |
| 115 | |
| 116 | // Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers |
| 117 | // into values that can be efficiently encoded with varint. (Otherwise, |
| 118 | // negative values must be sign-extended to 64 bits to be varint encoded, |
| 119 | // thus always taking 10 bytes on the wire.) |
| 120 | GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) { |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 121 | return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(n)&1)); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | // Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers |
| 125 | // into values that can be efficiently encoded with varint. (Otherwise, |
| 126 | // negative values must be sign-extended to 64 bits to be varint encoded, |
| 127 | // thus always taking 10 bytes on the wire.) |
| 128 | GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) { |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 129 | return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n)&1)); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers |
| 133 | // into values that can be efficiently encoded with varint. (Otherwise, |
| 134 | // negative values must be sign-extended to 64 bits to be varint encoded, |
| 135 | // thus always taking 10 bytes on the wire.) |
| 136 | GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) { |
| 137 | // Note: the right-shift must be arithmetic |
Thomas Van Lenten | 953adb1 | 2018-01-31 11:59:57 -0500 | [diff] [blame] | 138 | return ((uint32_t)n << 1) ^ (uint32_t)(n >> 31); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | // Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers |
| 142 | // into values that can be efficiently encoded with varint. (Otherwise, |
| 143 | // negative values must be sign-extended to 64 bits to be varint encoded, |
| 144 | // thus always taking 10 bytes on the wire.) |
| 145 | GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) { |
| 146 | // Note: the right-shift must be arithmetic |
Thomas Van Lenten | 953adb1 | 2018-01-31 11:59:57 -0500 | [diff] [blame] | 147 | return ((uint64_t)n << 1) ^ (uint64_t)(n >> 63); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 150 | #pragma clang diagnostic push |
| 151 | #pragma clang diagnostic ignored "-Wswitch-enum" |
| 152 | #pragma clang diagnostic ignored "-Wdirect-ivar-access" |
| 153 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 154 | GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) { |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 155 | switch (type) { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 156 | case GPBDataTypeBytes: |
| 157 | case GPBDataTypeString: |
| 158 | case GPBDataTypeMessage: |
| 159 | case GPBDataTypeGroup: |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 160 | return YES; |
| 161 | default: |
| 162 | return NO; |
| 163 | } |
| 164 | } |
| 165 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 166 | GPB_INLINE BOOL GPBDataTypeIsMessage(GPBDataType type) { |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 167 | switch (type) { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 168 | case GPBDataTypeMessage: |
| 169 | case GPBDataTypeGroup: |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 170 | return YES; |
| 171 | default: |
| 172 | return NO; |
| 173 | } |
| 174 | } |
| 175 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 176 | GPB_INLINE BOOL GPBFieldDataTypeIsMessage(GPBFieldDescriptor *field) { |
| 177 | return GPBDataTypeIsMessage(field->description_->dataType); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 180 | GPB_INLINE BOOL GPBFieldDataTypeIsObject(GPBFieldDescriptor *field) { |
| 181 | return GPBDataTypeIsObject(field->description_->dataType); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | GPB_INLINE BOOL GPBExtensionIsMessage(GPBExtensionDescriptor *ext) { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 185 | return GPBDataTypeIsMessage(ext->description_->dataType); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | // The field is an array/map or it has an object value. |
| 189 | GPB_INLINE BOOL GPBFieldStoresObject(GPBFieldDescriptor *field) { |
| 190 | GPBMessageFieldDescription *desc = field->description_; |
| 191 | if ((desc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0) { |
| 192 | return YES; |
| 193 | } |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 194 | return GPBDataTypeIsObject(desc->dataType); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | BOOL GPBGetHasIvar(GPBMessage *self, int32_t index, uint32_t fieldNumber); |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 198 | void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, BOOL value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 199 | uint32_t GPBGetHasOneof(GPBMessage *self, int32_t index); |
| 200 | |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 201 | GPB_INLINE BOOL GPBGetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field) { |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 202 | GPBMessageFieldDescription *fieldDesc = field->description_; |
| 203 | return GPBGetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number); |
| 204 | } |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 205 | |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 206 | #pragma clang diagnostic pop |
| 207 | |
Thomas Van Lenten | 9e069b2 | 2022-09-19 13:34:01 -0400 | [diff] [blame] | 208 | // Disable clang-format for the macros. |
| 209 | // clang-format off |
| 210 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 211 | //%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE) |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 212 | //%void GPBSet##NAME##IvarWithFieldPrivate(GPBMessage *self, |
| 213 | //% NAME$S GPBFieldDescriptor *field, |
| 214 | //% NAME$S TYPE value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 215 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL) |
| 216 | // This block of code is generated, do not edit it directly. |
| 217 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 218 | void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self, |
| 219 | GPBFieldDescriptor *field, |
| 220 | BOOL value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 221 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(Int32, int32_t) |
| 222 | // This block of code is generated, do not edit it directly. |
| 223 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 224 | void GPBSetInt32IvarWithFieldPrivate(GPBMessage *self, |
| 225 | GPBFieldDescriptor *field, |
| 226 | int32_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 227 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt32, uint32_t) |
| 228 | // This block of code is generated, do not edit it directly. |
| 229 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 230 | void GPBSetUInt32IvarWithFieldPrivate(GPBMessage *self, |
| 231 | GPBFieldDescriptor *field, |
| 232 | uint32_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 233 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(Int64, int64_t) |
| 234 | // This block of code is generated, do not edit it directly. |
| 235 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 236 | void GPBSetInt64IvarWithFieldPrivate(GPBMessage *self, |
| 237 | GPBFieldDescriptor *field, |
| 238 | int64_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 239 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt64, uint64_t) |
| 240 | // This block of code is generated, do not edit it directly. |
| 241 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 242 | void GPBSetUInt64IvarWithFieldPrivate(GPBMessage *self, |
| 243 | GPBFieldDescriptor *field, |
| 244 | uint64_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 245 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(Float, float) |
| 246 | // This block of code is generated, do not edit it directly. |
| 247 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 248 | void GPBSetFloatIvarWithFieldPrivate(GPBMessage *self, |
| 249 | GPBFieldDescriptor *field, |
| 250 | float value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 251 | //%PDDM-EXPAND GPB_IVAR_SET_DECL(Double, double) |
| 252 | // This block of code is generated, do not edit it directly. |
| 253 | |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 254 | void GPBSetDoubleIvarWithFieldPrivate(GPBMessage *self, |
| 255 | GPBFieldDescriptor *field, |
| 256 | double value); |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 257 | //%PDDM-EXPAND-END (7 expansions) |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 258 | |
Thomas Van Lenten | 9e069b2 | 2022-09-19 13:34:01 -0400 | [diff] [blame] | 259 | // clang-format on |
| 260 | |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 261 | void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 262 | |
| 263 | id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); |
| 264 | |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 265 | void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, id value); |
| 266 | void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, |
| 267 | id __attribute__((ns_consumed)) value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 268 | |
| 269 | // GPBGetObjectIvarWithField will automatically create the field (message) if |
| 270 | // it doesn't exist. GPBGetObjectIvarWithFieldNoAutocreate will return nil. |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 271 | id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, GPBFieldDescriptor *field); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 272 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 273 | // Clears and releases the autocreated message ivar, if it's autocreated. If |
| 274 | // it's not set as autocreated, this method does nothing. |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 275 | void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 276 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 277 | // Returns an Objective C encoding for |selector|. |instanceSel| should be |
| 278 | // YES if it's an instance selector (as opposed to a class selector). |
| 279 | // |selector| must be a selector from MessageSignatureProtocol. |
| 280 | const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel); |
| 281 | |
| 282 | // Helper for text format name encoding. |
Peter Newman | e2cc2de | 2020-08-10 19:08:25 +0100 | [diff] [blame] | 283 | // decodeData is the data describing the special decodes. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 284 | // key and inputString are the input that needs decoding. |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 285 | NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, NSString *inputString); |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 286 | |
Thomas Van Lenten | 3c8e959 | 2020-04-13 10:49:16 -0400 | [diff] [blame] | 287 | // Shims from the older generated code into the runtime. |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 288 | void GPBSetInt32IvarWithFieldInternal(GPBMessage *self, GPBFieldDescriptor *field, int32_t value, |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 289 | GPBFileSyntax syntax); |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 290 | void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, int32_t oneofHasIndex, |
| 291 | uint32_t fieldNumberNotToClear); |
Thomas Van Lenten | e1e5b8a | 2020-04-10 15:55:32 -0400 | [diff] [blame] | 292 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 293 | // A series of selectors that are used solely to get @encoding values |
| 294 | // for them by the dynamic protobuf runtime code. See |
Dave MacLachlan | 37a6672 | 2017-11-14 15:16:04 -0800 | [diff] [blame] | 295 | // GPBMessageEncodingForSelector for details. GPBRootObject conforms to |
| 296 | // the protocol so that it is encoded in the Objective C runtime. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 297 | @protocol GPBMessageSignatureProtocol |
| 298 | @optional |
| 299 | |
| 300 | #define GPB_MESSAGE_SIGNATURE_ENTRY(TYPE, NAME) \ |
| 301 | -(TYPE)get##NAME; \ |
| 302 | -(void)set##NAME : (TYPE)value; \ |
| 303 | -(TYPE)get##NAME##AtIndex : (NSUInteger)index; |
| 304 | |
| 305 | GPB_MESSAGE_SIGNATURE_ENTRY(BOOL, Bool) |
| 306 | GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, Fixed32) |
| 307 | GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SFixed32) |
| 308 | GPB_MESSAGE_SIGNATURE_ENTRY(float, Float) |
| 309 | GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, Fixed64) |
| 310 | GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SFixed64) |
| 311 | GPB_MESSAGE_SIGNATURE_ENTRY(double, Double) |
| 312 | GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Int32) |
| 313 | GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, Int64) |
| 314 | GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SInt32) |
| 315 | GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SInt64) |
| 316 | GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, UInt32) |
| 317 | GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, UInt64) |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 318 | GPB_MESSAGE_SIGNATURE_ENTRY(NSData *, Bytes) |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 319 | GPB_MESSAGE_SIGNATURE_ENTRY(NSString *, String) |
| 320 | GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Message) |
| 321 | GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Group) |
| 322 | GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Enum) |
| 323 | |
| 324 | #undef GPB_MESSAGE_SIGNATURE_ENTRY |
| 325 | |
| 326 | - (id)getArray; |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 327 | - (NSUInteger)getArrayCount; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 328 | - (void)setArray:(NSArray *)array; |
| 329 | + (id)getClassValue; |
| 330 | @end |
| 331 | |
Thomas Van Lenten | 2d1c5e2 | 2017-03-02 14:50:10 -0500 | [diff] [blame] | 332 | BOOL GPBClassHasSel(Class aClass, SEL sel); |
| 333 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 334 | CF_EXTERN_C_END |