aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBWellKnownTypes.h
diff options
context:
space:
mode:
authorTeBoring <teboring@google.com>2015-07-15 16:16:08 -0700
committerTeBoring <teboring@google.com>2015-07-21 15:45:02 -0700
commit7366efd81e7f36108aa35e66fca61da8a65762c2 (patch)
treec3b05157928bf27405115aea5835055066cb7022 /objectivec/GPBWellKnownTypes.h
parentfde6e89f99eda04a4f1b8677bcea07e6c2040405 (diff)
downloadprotobuf-7366efd81e7f36108aa35e66fca61da8a65762c2.tar.gz
protobuf-7366efd81e7f36108aa35e66fca61da8a65762c2.tar.bz2
protobuf-7366efd81e7f36108aa35e66fca61da8a65762c2.zip
Add packFrom, unpackTo and is in google.protobuf.Any.
The previous two methods make it easy to transform between any and normal message. unPackeTo will throw error if the type url in any doesn't match the type of the message to be transformed to. is checks any's type url matches the give GPBMessage type.
Diffstat (limited to 'objectivec/GPBWellKnownTypes.h')
-rw-r--r--objectivec/GPBWellKnownTypes.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/objectivec/GPBWellKnownTypes.h b/objectivec/GPBWellKnownTypes.h
index c98594a2..050f85f6 100644
--- a/objectivec/GPBWellKnownTypes.h
+++ b/objectivec/GPBWellKnownTypes.h
@@ -30,8 +30,10 @@
#import <Foundation/Foundation.h>
-#import "google/protobuf/Timestamp.pbobjc.h"
+#import "google/protobuf/Any.pbobjc.h"
#import "google/protobuf/Duration.pbobjc.h"
+#import "google/protobuf/Timestamp.pbobjc.h"
+
NS_ASSUME_NONNULL_BEGIN
@@ -49,4 +51,22 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970;
@end
+// Extension to GPBAny to support packing and unpacking for arbitrary messages.
+@interface GPBAny (GPBWellKnownTypes)
+// Initialize GPBAny instance with the given message. e.g., for google.protobuf.foo, type
+// url will be "type.googleapis.com/google.protobuf.foo" and value will be serialized foo.
+- (instancetype)initWithMessage:(GPBMessage*)message;
+// Serialize the given message to the value in GPBAny. Type url will also be updated.
+- (void)setMessage:(GPBMessage*)message;
+// Parse the value in GPBAny to the given message. If messageClass message doesn't match the
+// type url in GPBAny, nil is returned.
+- (GPBMessage*)messageOfClass:(Class)messageClass;
+// True if the given type matches the type url in GPBAny.
+- (BOOL)wrapsMessageOfClass:(Class)messageClass;
+@end
+
+// Common prefix of type url in GPBAny, which is @"type.googleapis.com/". All valid
+// type urls in any should start with this prefix.
+extern NSString *const GPBTypeGoogleApisComPrefix;
+
NS_ASSUME_NONNULL_END