aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/any.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/any.h')
-rw-r--r--src/google/protobuf/any.h33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/google/protobuf/any.h b/src/google/protobuf/any.h
index c8dbef13..a34e5f8e 100644
--- a/src/google/protobuf/any.h
+++ b/src/google/protobuf/any.h
@@ -50,10 +50,26 @@ class LIBPROTOBUF_EXPORT AnyMetadata {
// AnyMetadata does not take ownership of "type_url" and "value".
AnyMetadata(UrlType* type_url, ValueType* value);
+ // Packs a message using the default type URL prefix: "type.googleapis.com".
+ // The resulted type URL will be "type.googleapis.com/<message_full_name>".
void PackFrom(const Message& message);
-
+ // Packs a message using the given type URL prefix. The type URL will be
+ // constructed by concatenating the message type's full name to the prefix
+ // with an optional "/" separator if the prefix doesn't already end up "/".
+ // For example, both PackFrom(message, "type.googleapis.com") and
+ // PackFrom(message, "type.googleapis.com/") yield the same result type
+ // URL: "type.googleapis.com/<message_full_name>".
+ void PackFrom(const Message& message, const string& type_url_prefix);
+
+ // Unpacks the payload into the given message. Returns false if the message's
+ // type doesn't match the type specified in the type URL (i.e., the full
+ // name after the last "/" of the type URL doesn't match the message's actual
+ // full name) or parsing the payload has failed.
bool UnpackTo(Message* message) const;
+ // Checks whether the type specified in the type URL matches the given type.
+ // A type is consdiered matching if its full name matches the full name after
+ // the last "/" in the type URL.
template<typename T>
bool Is() const {
return InternalIs(T::default_instance().GetDescriptor());
@@ -74,10 +90,21 @@ extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/".
// Get the proto type name from Any::type_url value. For example, passing
// "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in
-// *full_type_name. Returns false if type_url does not start with
-// "type.googleapis.com" or "type.googleprod.com".
+// *full_type_name. Returns false if the type_url does not have a "/"
+// in the type url separating the full type name.
+//
+// NOTE: this function is available publicly as:
+// google::protobuf::Any() // static method on the generated message type.
bool ParseAnyTypeUrl(const string& type_url, string* full_type_name);
+// Get the proto type name and prefix from Any::type_url value. For example,
+// passing "type.googleapis.com/rpc.QueryOrigin" will return
+// "type.googleapis.com/" in *url_prefix and "rpc.QueryOrigin" in
+// *full_type_name. Returns false if the type_url does not have a "/" in the
+// type url separating the full type name.
+bool ParseAnyTypeUrl(const string& type_url, string* url_prefix,
+ string* full_type_name);
+
// See if message is of type google.protobuf.Any, if so, return the descriptors
// for "type_url" and "value" fields.
bool GetAnyFieldDescriptors(const Message& message,