Index: third_party/protobuf/src/google/protobuf/any.cc |
diff --git a/third_party/protobuf/src/google/protobuf/any.cc b/third_party/protobuf/src/google/protobuf/any.cc |
index f3ca06bfc04bf2c1041d4acb32ee720e91cdb22c..f7b1d310614cb6b5f4f3943ad2454327323d3a9e 100644 |
--- a/third_party/protobuf/src/google/protobuf/any.cc |
+++ b/third_party/protobuf/src/google/protobuf/any.cc |
@@ -35,10 +35,15 @@ namespace protobuf { |
namespace internal { |
namespace { |
-string GetTypeUrl(const Descriptor* message) { |
- return string(kTypeGoogleApisComPrefix) + message->full_name(); |
+string GetTypeUrl(const Descriptor* message, |
+ const string& type_url_prefix) { |
+ if (!type_url_prefix.empty() && |
+ type_url_prefix[type_url_prefix.size() - 1] == '/') { |
+ return type_url_prefix + message->full_name(); |
+ } else { |
+ return type_url_prefix + "/" + message->full_name(); |
+ } |
} |
- |
} // namespace |
const char kAnyFullTypeName[] = "google.protobuf.Any"; |
@@ -50,8 +55,13 @@ AnyMetadata::AnyMetadata(UrlType* type_url, ValueType* value) |
} |
void AnyMetadata::PackFrom(const Message& message) { |
+ PackFrom(message, kTypeGoogleApisComPrefix); |
+} |
+ |
+void AnyMetadata::PackFrom(const Message& message, |
+ const string& type_url_prefix) { |
type_url_->SetNoArena(&::google::protobuf::internal::GetEmptyString(), |
- GetTypeUrl(message.GetDescriptor())); |
+ GetTypeUrl(message.GetDescriptor(), type_url_prefix)); |
message.SerializeToString(value_->MutableNoArena( |
&::google::protobuf::internal::GetEmptyStringAlreadyInited())); |
} |
@@ -67,30 +77,20 @@ bool AnyMetadata::UnpackTo(Message* message) const { |
bool AnyMetadata::InternalIs(const Descriptor* descriptor) const { |
const string type_url = type_url_->GetNoArena( |
&::google::protobuf::internal::GetEmptyString()); |
- const string full_name = descriptor->full_name(); |
- if (type_url.length() < full_name.length()) { |
- return false; |
+ string full_name; |
+ if (!ParseAnyTypeUrl(type_url, &full_name)) { |
+ return false; |
} |
- return (0 == type_url.compare( |
- type_url.length() - full_name.length(), |
- full_name.length(), |
- full_name)); |
+ return full_name == descriptor->full_name(); |
} |
bool ParseAnyTypeUrl(const string& type_url, string* full_type_name) { |
- static const char* prefix[] = { |
- kTypeGoogleApisComPrefix, |
- kTypeGoogleProdComPrefix |
- }; |
- for (int i = 0; i < 2; i++) { |
- const int prefix_len = strlen(prefix[i]); |
- if (strncmp(type_url.c_str(), prefix[i], prefix_len) == 0) { |
- full_type_name->assign(type_url.data() + prefix_len, |
- type_url.size() - prefix_len); |
- return true; |
- } |
+ size_t pos = type_url.find_last_of("/"); |
+ if (pos == string::npos || pos + 1 == type_url.size()) { |
+ return false; |
} |
- return false; |
+ *full_type_name = type_url.substr(pos + 1); |
+ return true; |
} |