Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: third_party/protobuf/src/google/protobuf/any.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/src/README.md ('k') | third_party/protobuf/src/google/protobuf/any.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 12 matching lines...) Expand all
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #include <google/protobuf/any.h> 31 #include <google/protobuf/any.h>
32 32
33 #include <google/protobuf/generated_message_util.h>
34
33 namespace google { 35 namespace google {
34 namespace protobuf { 36 namespace protobuf {
35 namespace internal { 37 namespace internal {
36 38
37 namespace { 39 namespace {
38 string GetTypeUrl(const Descriptor* message, 40 string GetTypeUrl(const Descriptor* message,
39 const string& type_url_prefix) { 41 const string& type_url_prefix) {
40 if (!type_url_prefix.empty() && 42 if (!type_url_prefix.empty() &&
41 type_url_prefix[type_url_prefix.size() - 1] == '/') { 43 type_url_prefix[type_url_prefix.size() - 1] == '/') {
42 return type_url_prefix + message->full_name(); 44 return type_url_prefix + message->full_name();
(...skipping 20 matching lines...) Expand all
63 type_url_->SetNoArena(&::google::protobuf::internal::GetEmptyString(), 65 type_url_->SetNoArena(&::google::protobuf::internal::GetEmptyString(),
64 GetTypeUrl(message.GetDescriptor(), type_url_prefix)); 66 GetTypeUrl(message.GetDescriptor(), type_url_prefix));
65 message.SerializeToString(value_->MutableNoArena( 67 message.SerializeToString(value_->MutableNoArena(
66 &::google::protobuf::internal::GetEmptyStringAlreadyInited())); 68 &::google::protobuf::internal::GetEmptyStringAlreadyInited()));
67 } 69 }
68 70
69 bool AnyMetadata::UnpackTo(Message* message) const { 71 bool AnyMetadata::UnpackTo(Message* message) const {
70 if (!InternalIs(message->GetDescriptor())) { 72 if (!InternalIs(message->GetDescriptor())) {
71 return false; 73 return false;
72 } 74 }
73 return message->ParseFromString( 75 return message->ParseFromString(value_->GetNoArena());
74 value_->GetNoArena(&::google::protobuf::internal::GetEmptyString()));
75 } 76 }
76 77
77 bool AnyMetadata::InternalIs(const Descriptor* descriptor) const { 78 bool AnyMetadata::InternalIs(const Descriptor* descriptor) const {
78 const string type_url = type_url_->GetNoArena( 79 const string type_url = type_url_->GetNoArena();
79 &::google::protobuf::internal::GetEmptyString());
80 string full_name; 80 string full_name;
81 if (!ParseAnyTypeUrl(type_url, &full_name)) { 81 if (!ParseAnyTypeUrl(type_url, &full_name)) {
82 return false; 82 return false;
83 } 83 }
84 return full_name == descriptor->full_name(); 84 return full_name == descriptor->full_name();
85 } 85 }
86 86
87 bool ParseAnyTypeUrl(const string& type_url, string* full_type_name) { 87 bool ParseAnyTypeUrl(const string& type_url, string* full_type_name) {
88 size_t pos = type_url.find_last_of("/"); 88 size_t pos = type_url.find_last_of("/");
89 if (pos == string::npos || pos + 1 == type_url.size()) { 89 if (pos == string::npos || pos + 1 == type_url.size()) {
(...skipping 15 matching lines...) Expand all
105 *value_field = descriptor->FindFieldByNumber(2); 105 *value_field = descriptor->FindFieldByNumber(2);
106 return (*type_url_field != NULL && 106 return (*type_url_field != NULL &&
107 (*type_url_field)->type() == FieldDescriptor::TYPE_STRING && 107 (*type_url_field)->type() == FieldDescriptor::TYPE_STRING &&
108 *value_field != NULL && 108 *value_field != NULL &&
109 (*value_field)->type() == FieldDescriptor::TYPE_BYTES); 109 (*value_field)->type() == FieldDescriptor::TYPE_BYTES);
110 } 110 }
111 111
112 } // namespace internal 112 } // namespace internal
113 } // namespace protobuf 113 } // namespace protobuf
114 } // namespace google 114 } // namespace google
OLDNEW
« no previous file with comments | « third_party/protobuf/src/README.md ('k') | third_party/protobuf/src/google/protobuf/any.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698