| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2015 Google Inc. All rights reserved. | 2 // Copyright 2015 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 #import <Foundation/Foundation.h> | 31 #import <Foundation/Foundation.h> |
| 32 | 32 |
| 33 // This CPP symbol can be defined to use imports that match up to the framework | 33 #import "google/protobuf/Duration.pbobjc.h" |
| 34 // imports needed when using CocoaPods. | 34 #import "google/protobuf/Timestamp.pbobjc.h" |
| 35 #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) | |
| 36 #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 | |
| 37 #endif | |
| 38 | |
| 39 #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS | |
| 40 #import <Protobuf/Any.pbobjc.h> | |
| 41 #import <Protobuf/Duration.pbobjc.h> | |
| 42 #import <Protobuf/Timestamp.pbobjc.h> | |
| 43 #else | |
| 44 #import "google/protobuf/Any.pbobjc.h" | |
| 45 #import "google/protobuf/Duration.pbobjc.h" | |
| 46 #import "google/protobuf/Timestamp.pbobjc.h" | |
| 47 #endif | |
| 48 | 35 |
| 49 NS_ASSUME_NONNULL_BEGIN | 36 NS_ASSUME_NONNULL_BEGIN |
| 50 | 37 |
| 51 #pragma mark - Errors | 38 // Extension to GPBTimestamp to work with standard Foundation time/date types. |
| 52 | |
| 53 /** NSError domain used for errors. */ | |
| 54 extern NSString *const GPBWellKnownTypesErrorDomain; | |
| 55 | |
| 56 /** Error code for NSError with GPBWellKnownTypesErrorDomain. */ | |
| 57 typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) { | |
| 58 /** The type_url could not be computed for the requested GPBMessage class. */ | |
| 59 GPBWellKnownTypesErrorCodeFailedToComputeTypeURL = -100, | |
| 60 /** type_url in a Any doesn’t match that of the requested GPBMessage class. */ | |
| 61 GPBWellKnownTypesErrorCodeTypeURLMismatch = -101, | |
| 62 }; | |
| 63 | |
| 64 #pragma mark - GPBTimestamp | |
| 65 | |
| 66 /** | |
| 67 * Category for GPBTimestamp to work with standard Foundation time/date types. | |
| 68 **/ | |
| 69 @interface GPBTimestamp (GBPWellKnownTypes) | 39 @interface GPBTimestamp (GBPWellKnownTypes) |
| 70 | |
| 71 /** The NSDate representation of this GPBTimestamp. */ | |
| 72 @property(nonatomic, readwrite, strong) NSDate *date; | 40 @property(nonatomic, readwrite, strong) NSDate *date; |
| 73 | |
| 74 /** | |
| 75 * The NSTimeInterval representation of this GPBTimestamp. | |
| 76 * | |
| 77 * @note: Not all second/nanos combinations can be represented in a | |
| 78 * NSTimeInterval, so getting this could be a lossy transform. | |
| 79 **/ | |
| 80 @property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970; | 41 @property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970; |
| 81 | |
| 82 /** | |
| 83 * Initializes a GPBTimestamp with the given NSDate. | |
| 84 * | |
| 85 * @param date The date to configure the GPBTimestamp with. | |
| 86 * | |
| 87 * @return A newly initialized GPBTimestamp. | |
| 88 **/ | |
| 89 - (instancetype)initWithDate:(NSDate *)date; | 42 - (instancetype)initWithDate:(NSDate *)date; |
| 90 | |
| 91 /** | |
| 92 * Initializes a GPBTimestamp with the given NSTimeInterval. | |
| 93 * | |
| 94 * @param timeIntervalSince1970 Time interval to configure the GPBTimestamp with
. | |
| 95 * | |
| 96 * @return A newly initialized GPBTimestamp. | |
| 97 **/ | |
| 98 - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1
970; | 43 - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1
970; |
| 99 | |
| 100 @end | 44 @end |
| 101 | 45 |
| 102 #pragma mark - GPBDuration | 46 // Extension to GPBDuration to work with standard Foundation time type. |
| 103 | |
| 104 /** | |
| 105 * Category for GPBDuration to work with standard Foundation time type. | |
| 106 **/ | |
| 107 @interface GPBDuration (GBPWellKnownTypes) | 47 @interface GPBDuration (GBPWellKnownTypes) |
| 108 | |
| 109 /** | |
| 110 * The NSTimeInterval representation of this GPBDuration. | |
| 111 * | |
| 112 * @note: Not all second/nanos combinations can be represented in a | |
| 113 * NSTimeInterval, so getting this could be a lossy transform. | |
| 114 **/ | |
| 115 @property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970; | 48 @property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970; |
| 116 | |
| 117 /** | |
| 118 * Initializes a GPBDuration with the given NSTimeInterval. | |
| 119 * | |
| 120 * @param timeIntervalSince1970 Time interval to configure the GPBDuration with. | |
| 121 * | |
| 122 * @return A newly initialized GPBDuration. | |
| 123 **/ | |
| 124 - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1
970; | 49 - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1
970; |
| 125 | |
| 126 @end | |
| 127 | |
| 128 #pragma mark - GPBAny | |
| 129 | |
| 130 /** | |
| 131 * Category for GPBAny to help work with the message within the object. | |
| 132 **/ | |
| 133 @interface GPBAny (GBPWellKnownTypes) | |
| 134 | |
| 135 /** | |
| 136 * Convenience method to create a GPBAny containing the serialized message. | |
| 137 * This uses type.googleapis.com/ as the type_url's prefix. | |
| 138 * | |
| 139 * @param message The message to be packed into the GPBAny. | |
| 140 * @param errorPtr Pointer to an error that will be populated if something goes | |
| 141 * wrong. | |
| 142 * | |
| 143 * @return A newly configured GPBAny with the given message, or nil on failure. | |
| 144 */ | |
| 145 + (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message | |
| 146 error:(NSError **)errorPtr; | |
| 147 | |
| 148 /** | |
| 149 * Convenience method to create a GPBAny containing the serialized message. | |
| 150 * | |
| 151 * @param message The message to be packed into the GPBAny. | |
| 152 * @param typeURLPrefix The URL prefix to apply for type_url. | |
| 153 * @param errorPtr Pointer to an error that will be populated if something | |
| 154 * goes wrong. | |
| 155 * | |
| 156 * @return A newly configured GPBAny with the given message, or nil on failure. | |
| 157 */ | |
| 158 + (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message | |
| 159 typeURLPrefix:(nonnull NSString *)typeURLPrefix | |
| 160 error:(NSError **)errorPtr; | |
| 161 | |
| 162 /** | |
| 163 * Initializes a GPBAny to contain the serialized message. This uses | |
| 164 * type.googleapis.com/ as the type_url's prefix. | |
| 165 * | |
| 166 * @param message The message to be packed into the GPBAny. | |
| 167 * @param errorPtr Pointer to an error that will be populated if something goes | |
| 168 * wrong. | |
| 169 * | |
| 170 * @return A newly configured GPBAny with the given message, or nil on failure. | |
| 171 */ | |
| 172 - (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message | |
| 173 error:(NSError **)errorPtr; | |
| 174 | |
| 175 /** | |
| 176 * Initializes a GPBAny to contain the serialized message. | |
| 177 * | |
| 178 * @param message The message to be packed into the GPBAny. | |
| 179 * @param typeURLPrefix The URL prefix to apply for type_url. | |
| 180 * @param errorPtr Pointer to an error that will be populated if something | |
| 181 * goes wrong. | |
| 182 * | |
| 183 * @return A newly configured GPBAny with the given message, or nil on failure. | |
| 184 */ | |
| 185 - (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message | |
| 186 typeURLPrefix:(nonnull NSString *)typeURLPrefix | |
| 187 error:(NSError **)errorPtr; | |
| 188 | |
| 189 /** | |
| 190 * Packs the serialized message into this GPBAny. This uses | |
| 191 * type.googleapis.com/ as the type_url's prefix. | |
| 192 * | |
| 193 * @param message The message to be packed into the GPBAny. | |
| 194 * @param errorPtr Pointer to an error that will be populated if something goes | |
| 195 * wrong. | |
| 196 * | |
| 197 * @return Whether the packing was successful or not. | |
| 198 */ | |
| 199 - (BOOL)packWithMessage:(nonnull GPBMessage *)message | |
| 200 error:(NSError **)errorPtr; | |
| 201 | |
| 202 /** | |
| 203 * Packs the serialized message into this GPBAny. | |
| 204 * | |
| 205 * @param message The message to be packed into the GPBAny. | |
| 206 * @param typeURLPrefix The URL prefix to apply for type_url. | |
| 207 * @param errorPtr Pointer to an error that will be populated if something | |
| 208 * goes wrong. | |
| 209 * | |
| 210 * @return Whether the packing was successful or not. | |
| 211 */ | |
| 212 - (BOOL)packWithMessage:(nonnull GPBMessage *)message | |
| 213 typeURLPrefix:(nonnull NSString *)typeURLPrefix | |
| 214 error:(NSError **)errorPtr; | |
| 215 | |
| 216 /** | |
| 217 * Unpacks the serialized message as if it was an instance of the given class. | |
| 218 * | |
| 219 * @note When checking type_url, the base URL is not checked, only the fully | |
| 220 * qualified name. | |
| 221 * | |
| 222 * @param messageClass The class to use to deserialize the contained message. | |
| 223 * @param errorPtr Pointer to an error that will be populated if something | |
| 224 * goes wrong. | |
| 225 * | |
| 226 * @return An instance of the given class populated with the contained data, or | |
| 227 * nil on failure. | |
| 228 */ | |
| 229 - (nullable GPBMessage *)unpackMessageClass:(Class)messageClass | |
| 230 error:(NSError **)errorPtr; | |
| 231 | |
| 232 @end | 50 @end |
| 233 | 51 |
| 234 NS_ASSUME_NONNULL_END | 52 NS_ASSUME_NONNULL_END |
| OLD | NEW |