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

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

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: 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
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 28 matching lines...) Expand all
39 #include <google/protobuf/message.h> 39 #include <google/protobuf/message.h>
40 40
41 #include <google/protobuf/stubs/logging.h> 41 #include <google/protobuf/stubs/logging.h>
42 #include <google/protobuf/stubs/common.h> 42 #include <google/protobuf/stubs/common.h>
43 #include <google/protobuf/stubs/mutex.h> 43 #include <google/protobuf/stubs/mutex.h>
44 #include <google/protobuf/stubs/once.h> 44 #include <google/protobuf/stubs/once.h>
45 #include <google/protobuf/reflection_internal.h> 45 #include <google/protobuf/reflection_internal.h>
46 #include <google/protobuf/io/coded_stream.h> 46 #include <google/protobuf/io/coded_stream.h>
47 #include <google/protobuf/io/zero_copy_stream_impl.h> 47 #include <google/protobuf/io/zero_copy_stream_impl.h>
48 #include <google/protobuf/descriptor.pb.h> 48 #include <google/protobuf/descriptor.pb.h>
49 #include <google/protobuf/map_field.h>
49 #include <google/protobuf/descriptor.h> 50 #include <google/protobuf/descriptor.h>
50 #include <google/protobuf/generated_message_util.h> 51 #include <google/protobuf/generated_message_util.h>
51 #include <google/protobuf/map_field.h>
52 #include <google/protobuf/reflection_ops.h> 52 #include <google/protobuf/reflection_ops.h>
53 #include <google/protobuf/wire_format.h> 53 #include <google/protobuf/wire_format.h>
54 #include <google/protobuf/stubs/strutil.h> 54 #include <google/protobuf/stubs/strutil.h>
55 #include <google/protobuf/stubs/map_util.h> 55 #include <google/protobuf/stubs/map_util.h>
56 #include <google/protobuf/stubs/singleton.h> 56 #include <google/protobuf/stubs/singleton.h>
57 #include <google/protobuf/stubs/stl_util.h> 57 #include <google/protobuf/stubs/stl_util.h>
58 58
59 namespace google { 59 namespace google {
60 namespace protobuf { 60 namespace protobuf {
61 61
62 using internal::WireFormat; 62 using internal::WireFormat;
63 using internal::ReflectionOps; 63 using internal::ReflectionOps;
64 64
65 Message::~Message() {}
66
65 void Message::MergeFrom(const Message& from) { 67 void Message::MergeFrom(const Message& from) {
66 const Descriptor* descriptor = GetDescriptor(); 68 const Descriptor* descriptor = GetDescriptor();
67 GOOGLE_CHECK_EQ(from.GetDescriptor(), descriptor) 69 GOOGLE_CHECK_EQ(from.GetDescriptor(), descriptor)
68 << ": Tried to merge from a message with a different type. " 70 << ": Tried to merge from a message with a different type. "
69 "to: " << descriptor->full_name() << ", " 71 "to: " << descriptor->full_name() << ", "
70 "from: " << from.GetDescriptor()->full_name(); 72 "from: " << from.GetDescriptor()->full_name();
71 ReflectionOps::Merge(from, this); 73 ReflectionOps::Merge(from, this);
72 } 74 }
73 75
74 void Message::CheckTypeAndMergeFrom(const MessageLite& other) { 76 void Message::CheckTypeAndMergeFrom(const MessageLite& other) {
(...skipping 14 matching lines...) Expand all
89 } 91 }
90 92
91 void Message::Clear() { 93 void Message::Clear() {
92 ReflectionOps::Clear(this); 94 ReflectionOps::Clear(this);
93 } 95 }
94 96
95 bool Message::IsInitialized() const { 97 bool Message::IsInitialized() const {
96 return ReflectionOps::IsInitialized(*this); 98 return ReflectionOps::IsInitialized(*this);
97 } 99 }
98 100
99 void Message::FindInitializationErrors(std::vector<string>* errors) const { 101 void Message::FindInitializationErrors(vector<string>* errors) const {
100 return ReflectionOps::FindInitializationErrors(*this, "", errors); 102 return ReflectionOps::FindInitializationErrors(*this, "", errors);
101 } 103 }
102 104
103 string Message::InitializationErrorString() const { 105 string Message::InitializationErrorString() const {
104 std::vector<string> errors; 106 vector<string> errors;
105 FindInitializationErrors(&errors); 107 FindInitializationErrors(&errors);
106 return Join(errors, ", "); 108 return Join(errors, ", ");
107 } 109 }
108 110
109 void Message::CheckInitialized() const { 111 void Message::CheckInitialized() const {
110 GOOGLE_CHECK(IsInitialized()) 112 GOOGLE_CHECK(IsInitialized())
111 << "Message of type \"" << GetDescriptor()->full_name() 113 << "Message of type \"" << GetDescriptor()->full_name()
112 << "\" is missing required fields: " << InitializationErrorString(); 114 << "\" is missing required fields: " << InitializationErrorString();
113 } 115 }
114 116
(...skipping 24 matching lines...) Expand all
139 io::IstreamInputStream zero_copy_input(input); 141 io::IstreamInputStream zero_copy_input(input);
140 return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof(); 142 return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();
141 } 143 }
142 144
143 145
144 void Message::SerializeWithCachedSizes( 146 void Message::SerializeWithCachedSizes(
145 io::CodedOutputStream* output) const { 147 io::CodedOutputStream* output) const {
146 WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output); 148 WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output);
147 } 149 }
148 150
149 size_t Message::ByteSizeLong() const { 151 int Message::ByteSize() const {
150 size_t size = WireFormat::ByteSize(*this); 152 int size = WireFormat::ByteSize(*this);
151 SetCachedSize(internal::ToCachedSize(size)); 153 SetCachedSize(size);
152 return size; 154 return size;
153 } 155 }
154 156
155 void Message::SetCachedSize(int /* size */) const { 157 void Message::SetCachedSize(int /* size */) const {
156 GOOGLE_LOG(FATAL) << "Message class \"" << GetDescriptor()->full_name() 158 GOOGLE_LOG(FATAL) << "Message class \"" << GetDescriptor()->full_name()
157 << "\" implements neither SetCachedSize() nor ByteSize(). " 159 << "\" implements neither SetCachedSize() nor ByteSize(). "
158 "Must implement one or the other."; 160 "Must implement one or the other.";
159 } 161 }
160 162
161 int Message::SpaceUsed() const { 163 int Message::SpaceUsed() const {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 220
219 #undef HANDLE_TYPE 221 #undef HANDLE_TYPE
220 222
221 void* Reflection::MutableRawRepeatedString( 223 void* Reflection::MutableRawRepeatedString(
222 Message* message, const FieldDescriptor* field, bool is_string) const { 224 Message* message, const FieldDescriptor* field, bool is_string) const {
223 return MutableRawRepeatedField(message, field, 225 return MutableRawRepeatedField(message, field,
224 FieldDescriptor::CPPTYPE_STRING, FieldOptions::STRING, NULL); 226 FieldDescriptor::CPPTYPE_STRING, FieldOptions::STRING, NULL);
225 } 227 }
226 228
227 229
230 // Default EnumValue API implementations. Real reflection implementations should
231 // override these. However, there are several legacy implementations that do
232 // not, and cannot easily be changed at the same time as the Reflection API, so
233 // we provide these for now.
234 // TODO: Remove these once all Reflection implementations are updated.
235 int Reflection::GetEnumValue(const Message& message,
236 const FieldDescriptor* field) const {
237 GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
238 return 0;
239 }
240 void Reflection::SetEnumValue(Message* message,
241 const FieldDescriptor* field,
242 int value) const {
243 GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
244 }
245 int Reflection::GetRepeatedEnumValue(
246 const Message& message,
247 const FieldDescriptor* field, int index) const {
248 GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
249 return 0;
250 }
251 void Reflection::SetRepeatedEnumValue(Message* message,
252 const FieldDescriptor* field, int index,
253 int value) const {
254 GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
255 }
256 void Reflection::AddEnumValue(Message* message,
257 const FieldDescriptor* field,
258 int value) const {
259 GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
260 }
261
228 MapIterator Reflection::MapBegin( 262 MapIterator Reflection::MapBegin(
229 Message* message, 263 Message* message,
230 const FieldDescriptor* field) const { 264 const FieldDescriptor* field) const {
231 GOOGLE_LOG(FATAL) << "Unimplemented Map Reflection API."; 265 GOOGLE_LOG(FATAL) << "Unimplemented Map Reflection API.";
232 MapIterator iter(message, field); 266 MapIterator iter(message, field);
233 return iter; 267 return iter;
234 } 268 }
235 269
236 MapIterator Reflection::MapEnd( 270 MapIterator Reflection::MapEnd(
237 Message* message, 271 Message* message,
(...skipping 22 matching lines...) Expand all
260 void RegisterType(const Descriptor* descriptor, const Message* prototype); 294 void RegisterType(const Descriptor* descriptor, const Message* prototype);
261 295
262 // implements MessageFactory --------------------------------------- 296 // implements MessageFactory ---------------------------------------
263 const Message* GetPrototype(const Descriptor* type); 297 const Message* GetPrototype(const Descriptor* type);
264 298
265 private: 299 private:
266 // Only written at static init time, so does not require locking. 300 // Only written at static init time, so does not require locking.
267 hash_map<const char*, RegistrationFunc*, 301 hash_map<const char*, RegistrationFunc*,
268 hash<const char*>, streq> file_map_; 302 hash<const char*>, streq> file_map_;
269 303
304 // Initialized lazily, so requires locking.
270 Mutex mutex_; 305 Mutex mutex_;
271 // Initialized lazily, so requires locking.
272 hash_map<const Descriptor*, const Message*> type_map_; 306 hash_map<const Descriptor*, const Message*> type_map_;
273 }; 307 };
274 308
275 GeneratedMessageFactory* generated_message_factory_ = NULL; 309 GeneratedMessageFactory* generated_message_factory_ = NULL;
276 GOOGLE_PROTOBUF_DECLARE_ONCE(generated_message_factory_once_init_); 310 GOOGLE_PROTOBUF_DECLARE_ONCE(generated_message_factory_once_init_);
277 311
278 void ShutdownGeneratedMessageFactory() { 312 void ShutdownGeneratedMessageFactory() {
279 delete generated_message_factory_; 313 delete generated_message_factory_;
280 } 314 }
281 315
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 GOOGLE_ATTRIBUTE_NOINLINE 508 GOOGLE_ATTRIBUTE_NOINLINE
475 #endif 509 #endif
476 void* GenericTypeHandler<Message>::GetMaybeArenaPointer( 510 void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
477 Message* value) { 511 Message* value) {
478 return value->GetMaybeArenaPointer(); 512 return value->GetMaybeArenaPointer();
479 } 513 }
480 } // namespace internal 514 } // namespace internal
481 515
482 } // namespace protobuf 516 } // namespace protobuf
483 } // namespace google 517 } // namespace google
OLDNEW
« no previous file with comments | « third_party/protobuf/src/google/protobuf/message.h ('k') | third_party/protobuf/src/google/protobuf/message_lite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698