Index: third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc |
diff --git a/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc |
index 963939032a8c723065f05a99c96fb87b26f6f991..febaa41f75004aadbaa465cdab2b69c2e982634b 100644 |
--- a/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc |
+++ b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc |
@@ -54,17 +54,6 @@ using util::Status; |
using util::error::INVALID_ARGUMENT; |
using util::error::NOT_FOUND; |
-bool SplitTypeUrl(const string& type_url, string* url_prefix, |
- string* message_name) { |
- size_t pos = type_url.find_last_of("/"); |
- if (pos == string::npos) { |
- return false; |
- } |
- *url_prefix = type_url.substr(0, pos); |
- *message_name = type_url.substr(pos + 1); |
- return true; |
-} |
- |
class DescriptorPoolTypeResolver : public TypeResolver { |
public: |
DescriptorPoolTypeResolver(const string& url_prefix, |
@@ -72,38 +61,27 @@ class DescriptorPoolTypeResolver : public TypeResolver { |
: url_prefix_(url_prefix), pool_(pool) {} |
Status ResolveMessageType(const string& type_url, Type* type) { |
- string url_prefix, message_name; |
- if (!SplitTypeUrl(type_url, &url_prefix, &message_name) || |
- url_prefix != url_prefix_) { |
- return Status(INVALID_ARGUMENT, |
- StrCat("Invalid type URL, type URLs must be of the form '", |
- url_prefix_, "/<typename>', got: ", type_url)); |
+ string type_name; |
+ Status status = ParseTypeUrl(type_url, &type_name); |
+ if (!status.ok()) { |
+ return status; |
} |
- if (url_prefix != url_prefix_) { |
- return Status(INVALID_ARGUMENT, |
- "Cannot resolve types from URL: " + url_prefix); |
- } |
- const Descriptor* descriptor = pool_->FindMessageTypeByName(message_name); |
+ |
+ const Descriptor* descriptor = pool_->FindMessageTypeByName(type_name); |
if (descriptor == NULL) { |
- return Status(NOT_FOUND, |
- "Invalid type URL, unknown type: " + message_name); |
+ return Status(NOT_FOUND, "Invalid type URL, unknown type: " + type_name); |
} |
ConvertDescriptor(descriptor, type); |
return Status(); |
} |
Status ResolveEnumType(const string& type_url, Enum* enum_type) { |
- string url_prefix, type_name; |
- if (!SplitTypeUrl(type_url, &url_prefix, &type_name) || |
- url_prefix != url_prefix_) { |
- return Status(INVALID_ARGUMENT, |
- StrCat("Invalid type URL, type URLs must be of the form '", |
- url_prefix_, "/<typename>', got: ", type_url)); |
- } |
- if (url_prefix != url_prefix_) { |
- return Status(INVALID_ARGUMENT, |
- "Cannot resolve types from URL: " + url_prefix); |
+ string type_name; |
+ Status status = ParseTypeUrl(type_url, &type_name); |
+ if (!status.ok()) { |
+ return status; |
} |
+ |
const EnumDescriptor* descriptor = pool_->FindEnumTypeByName(type_name); |
if (descriptor == NULL) { |
return Status(NOT_FOUND, "Invalid type URL, unknown type: " + type_name); |
@@ -203,6 +181,16 @@ class DescriptorPoolTypeResolver : public TypeResolver { |
return url_prefix_ + "/" + descriptor->full_name(); |
} |
+ Status ParseTypeUrl(const string& type_url, string* type_name) { |
+ if (type_url.substr(0, url_prefix_.size() + 1) != url_prefix_ + "/") { |
+ return Status(INVALID_ARGUMENT, |
+ StrCat("Invalid type URL, type URLs must be of the form '", |
+ url_prefix_, "/<typename>', got: ", type_url)); |
+ } |
+ *type_name = type_url.substr(url_prefix_.size() + 1); |
+ return Status(); |
+ } |
+ |
string DefaultValueAsString(const FieldDescriptor* descriptor) { |
switch (descriptor->cpp_type()) { |
case FieldDescriptor::CPPTYPE_INT32: |