2015-05-01 12:57:16 +00:00
|
|
|
|
// Protocol Buffers - Google's data interchange format
|
|
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
|
// https://developers.google.com/protocol-buffers/
|
|
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
|
// met:
|
|
|
|
|
//
|
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
|
// distribution.
|
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
2016-05-09 17:53:20 +00:00
|
|
|
|
// This CPP symbol can be defined to use imports that match up to the framework
|
|
|
|
|
// imports needed when using CocoaPods.
|
|
|
|
|
#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
|
|
|
|
|
#define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
|
2020-01-22 20:50:52 +00:00
|
|
|
|
#import <Protobuf/GPBAny.pbobjc.h>
|
|
|
|
|
#import <Protobuf/GPBDuration.pbobjc.h>
|
|
|
|
|
#import <Protobuf/GPBTimestamp.pbobjc.h>
|
2016-05-09 17:53:20 +00:00
|
|
|
|
#else
|
2020-01-22 20:50:52 +00:00
|
|
|
|
#import "GPBAny.pbobjc.h"
|
|
|
|
|
#import "GPBDuration.pbobjc.h"
|
|
|
|
|
#import "GPBTimestamp.pbobjc.h"
|
2016-05-09 17:53:20 +00:00
|
|
|
|
#endif
|
2015-07-15 23:16:08 +00:00
|
|
|
|
|
2015-06-16 20:45:14 +00:00
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
2016-08-16 15:26:49 +00:00
|
|
|
|
#pragma mark - Errors
|
|
|
|
|
|
|
|
|
|
/** NSError domain used for errors. */
|
|
|
|
|
extern NSString *const GPBWellKnownTypesErrorDomain;
|
|
|
|
|
|
|
|
|
|
/** Error code for NSError with GPBWellKnownTypesErrorDomain. */
|
|
|
|
|
typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) {
|
|
|
|
|
/** The type_url could not be computed for the requested GPBMessage class. */
|
|
|
|
|
GPBWellKnownTypesErrorCodeFailedToComputeTypeURL = -100,
|
|
|
|
|
/** type_url in a Any doesn’t match that of the requested GPBMessage class. */
|
|
|
|
|
GPBWellKnownTypesErrorCodeTypeURLMismatch = -101,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma mark - GPBTimestamp
|
|
|
|
|
|
2016-08-08 14:15:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Category for GPBTimestamp to work with standard Foundation time/date types.
|
|
|
|
|
**/
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@interface GPBTimestamp (GBPWellKnownTypes)
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
|
|
|
|
/** The NSDate representation of this GPBTimestamp. */
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@property(nonatomic, readwrite, strong) NSDate *date;
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
2016-09-08 19:34:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* The NSTimeInterval representation of this GPBTimestamp.
|
|
|
|
|
*
|
|
|
|
|
* @note: Not all second/nanos combinations can be represented in a
|
|
|
|
|
* NSTimeInterval, so getting this could be a lossy transform.
|
|
|
|
|
**/
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970;
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a GPBTimestamp with the given NSDate.
|
|
|
|
|
*
|
|
|
|
|
* @param date The date to configure the GPBTimestamp with.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly initialized GPBTimestamp.
|
|
|
|
|
**/
|
2015-05-01 12:57:16 +00:00
|
|
|
|
- (instancetype)initWithDate:(NSDate *)date;
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a GPBTimestamp with the given NSTimeInterval.
|
|
|
|
|
*
|
|
|
|
|
* @param timeIntervalSince1970 Time interval to configure the GPBTimestamp with.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly initialized GPBTimestamp.
|
|
|
|
|
**/
|
2015-05-01 12:57:16 +00:00
|
|
|
|
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970;
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2016-08-16 15:26:49 +00:00
|
|
|
|
#pragma mark - GPBDuration
|
|
|
|
|
|
2016-08-08 14:15:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Category for GPBDuration to work with standard Foundation time type.
|
|
|
|
|
**/
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@interface GPBDuration (GBPWellKnownTypes)
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
2016-09-08 19:34:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* The NSTimeInterval representation of this GPBDuration.
|
|
|
|
|
*
|
|
|
|
|
* @note: Not all second/nanos combinations can be represented in a
|
|
|
|
|
* NSTimeInterval, so getting this could be a lossy transform.
|
|
|
|
|
**/
|
2017-01-12 22:13:10 +00:00
|
|
|
|
@property(nonatomic, readwrite) NSTimeInterval timeInterval;
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a GPBDuration with the given NSTimeInterval.
|
|
|
|
|
*
|
2017-01-12 22:13:10 +00:00
|
|
|
|
* @param timeInterval Time interval to configure the GPBDuration with.
|
2016-08-08 14:15:02 +00:00
|
|
|
|
*
|
2016-09-08 19:34:42 +00:00
|
|
|
|
* @return A newly initialized GPBDuration.
|
2016-08-08 14:15:02 +00:00
|
|
|
|
**/
|
2017-01-12 22:13:10 +00:00
|
|
|
|
- (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval;
|
|
|
|
|
|
|
|
|
|
// These next two methods are deprecated because GBPDuration has no need of a
|
|
|
|
|
// "base" time. The older methods were about symmetry with GBPTimestamp, but
|
|
|
|
|
// the unix epoch usage is too confusing.
|
|
|
|
|
|
|
|
|
|
/** Deprecated, use timeInterval instead. */
|
|
|
|
|
@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970
|
|
|
|
|
__attribute__((deprecated("Use timeInterval")));
|
|
|
|
|
/** Deprecated, use initWithTimeInterval: instead. */
|
|
|
|
|
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970
|
|
|
|
|
__attribute__((deprecated("Use initWithTimeInterval:")));
|
2016-08-08 14:15:02 +00:00
|
|
|
|
|
2015-05-01 12:57:16 +00:00
|
|
|
|
@end
|
2015-06-16 20:45:14 +00:00
|
|
|
|
|
2016-08-16 15:26:49 +00:00
|
|
|
|
#pragma mark - GPBAny
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Category for GPBAny to help work with the message within the object.
|
|
|
|
|
**/
|
|
|
|
|
@interface GPBAny (GBPWellKnownTypes)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convenience method to create a GPBAny containing the serialized message.
|
|
|
|
|
* This uses type.googleapis.com/ as the type_url's prefix.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something goes
|
|
|
|
|
* wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly configured GPBAny with the given message, or nil on failure.
|
|
|
|
|
*/
|
|
|
|
|
+ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convenience method to create a GPBAny containing the serialized message.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param typeURLPrefix The URL prefix to apply for type_url.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something
|
|
|
|
|
* goes wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly configured GPBAny with the given message, or nil on failure.
|
|
|
|
|
*/
|
|
|
|
|
+ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
typeURLPrefix:(nonnull NSString *)typeURLPrefix
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a GPBAny to contain the serialized message. This uses
|
|
|
|
|
* type.googleapis.com/ as the type_url's prefix.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something goes
|
|
|
|
|
* wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly configured GPBAny with the given message, or nil on failure.
|
|
|
|
|
*/
|
|
|
|
|
- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a GPBAny to contain the serialized message.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param typeURLPrefix The URL prefix to apply for type_url.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something
|
|
|
|
|
* goes wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return A newly configured GPBAny with the given message, or nil on failure.
|
|
|
|
|
*/
|
|
|
|
|
- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
typeURLPrefix:(nonnull NSString *)typeURLPrefix
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Packs the serialized message into this GPBAny. This uses
|
|
|
|
|
* type.googleapis.com/ as the type_url's prefix.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something goes
|
|
|
|
|
* wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the packing was successful or not.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL)packWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Packs the serialized message into this GPBAny.
|
|
|
|
|
*
|
|
|
|
|
* @param message The message to be packed into the GPBAny.
|
|
|
|
|
* @param typeURLPrefix The URL prefix to apply for type_url.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something
|
|
|
|
|
* goes wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the packing was successful or not.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL)packWithMessage:(nonnull GPBMessage *)message
|
|
|
|
|
typeURLPrefix:(nonnull NSString *)typeURLPrefix
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unpacks the serialized message as if it was an instance of the given class.
|
|
|
|
|
*
|
|
|
|
|
* @note When checking type_url, the base URL is not checked, only the fully
|
|
|
|
|
* qualified name.
|
|
|
|
|
*
|
|
|
|
|
* @param messageClass The class to use to deserialize the contained message.
|
|
|
|
|
* @param errorPtr Pointer to an error that will be populated if something
|
|
|
|
|
* goes wrong.
|
|
|
|
|
*
|
|
|
|
|
* @return An instance of the given class populated with the contained data, or
|
|
|
|
|
* nil on failure.
|
|
|
|
|
*/
|
|
|
|
|
- (nullable GPBMessage *)unpackMessageClass:(Class)messageClass
|
|
|
|
|
error:(NSError **)errorPtr;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2015-06-16 20:45:14 +00:00
|
|
|
|
NS_ASSUME_NONNULL_END
|