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

Side by Side Diff: third_party/protobuf/src/google/protobuf/unknown_field_set.h

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update defines Created 4 years, 8 months 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 // http://code.google.com/p/protobuf/ 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.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
(...skipping 21 matching lines...) Expand all
35 // Contains classes used to keep track of unrecognized fields seen while 35 // Contains classes used to keep track of unrecognized fields seen while
36 // parsing a protocol message. 36 // parsing a protocol message.
37 37
38 #ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ 38 #ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__
39 #define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ 39 #define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__
40 40
41 #include <assert.h> 41 #include <assert.h>
42 #include <string> 42 #include <string>
43 #include <vector> 43 #include <vector>
44 #include <google/protobuf/stubs/common.h> 44 #include <google/protobuf/stubs/common.h>
45 // TODO(jasonh): some people seem to rely on protobufs to include this for them! 45 #include <google/protobuf/stubs/logging.h>
46 46
47 namespace google { 47 namespace google {
48 namespace protobuf { 48 namespace protobuf {
49 namespace io { 49 namespace io {
50 class CodedInputStream; // coded_stream.h 50 class CodedInputStream; // coded_stream.h
51 class CodedOutputStream; // coded_stream.h 51 class CodedOutputStream; // coded_stream.h
52 class ZeroCopyInputStream; // zero_copy_stream.h 52 class ZeroCopyInputStream; // zero_copy_stream.h
53 } 53 }
54 namespace internal { 54 namespace internal {
55 class WireFormat; // wire_format.h 55 class WireFormat; // wire_format.h
56 class UnknownFieldSetFieldSkipperUsingCord; 56 class MessageSetFieldSkipperUsingCord;
57 // extension_set_heavy.cc 57 // extension_set_heavy.cc
58 } 58 }
59 59
60 class Message; // message.h 60 class Message; // message.h
61 class UnknownField; // below 61 class UnknownField; // below
62 62
63 // An UnknownFieldSet contains fields that were encountered while parsing a 63 // An UnknownFieldSet contains fields that were encountered while parsing a
64 // message but were not defined by its type. Keeping track of these can be 64 // message but were not defined by its type. Keeping track of these can be
65 // useful, especially in that they may be written if the message is serialized 65 // useful, especially in that they may be written if the message is serialized
66 // again without being cleared in between. This means that software which 66 // again without being cleared in between. This means that software which
(...skipping 15 matching lines...) Expand all
82 82
83 // Remove all fields and deallocate internal data objects 83 // Remove all fields and deallocate internal data objects
84 void ClearAndFreeMemory(); 84 void ClearAndFreeMemory();
85 85
86 // Is this set empty? 86 // Is this set empty?
87 inline bool empty() const; 87 inline bool empty() const;
88 88
89 // Merge the contents of some other UnknownFieldSet with this one. 89 // Merge the contents of some other UnknownFieldSet with this one.
90 void MergeFrom(const UnknownFieldSet& other); 90 void MergeFrom(const UnknownFieldSet& other);
91 91
92 // Similar to above, but this function will destroy the contents of other.
93 void MergeFromAndDestroy(UnknownFieldSet* other);
94
92 // Swaps the contents of some other UnknownFieldSet with this one. 95 // Swaps the contents of some other UnknownFieldSet with this one.
93 inline void Swap(UnknownFieldSet* x); 96 inline void Swap(UnknownFieldSet* x);
94 97
95 // Computes (an estimate of) the total number of bytes currently used for 98 // Computes (an estimate of) the total number of bytes currently used for
96 // storing the unknown fields in memory. Does NOT include 99 // storing the unknown fields in memory. Does NOT include
97 // sizeof(*this) in the calculation. 100 // sizeof(*this) in the calculation.
98 int SpaceUsedExcludingSelf() const; 101 int SpaceUsedExcludingSelf() const;
99 102
100 // Version of SpaceUsed() including sizeof(*this). 103 // Version of SpaceUsed() including sizeof(*this).
101 int SpaceUsed() const; 104 int SpaceUsed() const;
(...skipping 30 matching lines...) Expand all
132 void DeleteByNumber(int number); 135 void DeleteByNumber(int number);
133 136
134 // Parsing helpers ------------------------------------------------- 137 // Parsing helpers -------------------------------------------------
135 // These work exactly like the similarly-named methods of Message. 138 // These work exactly like the similarly-named methods of Message.
136 139
137 bool MergeFromCodedStream(io::CodedInputStream* input); 140 bool MergeFromCodedStream(io::CodedInputStream* input);
138 bool ParseFromCodedStream(io::CodedInputStream* input); 141 bool ParseFromCodedStream(io::CodedInputStream* input);
139 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); 142 bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input);
140 bool ParseFromArray(const void* data, int size); 143 bool ParseFromArray(const void* data, int size);
141 inline bool ParseFromString(const string& data) { 144 inline bool ParseFromString(const string& data) {
142 return ParseFromArray(data.data(), data.size()); 145 return ParseFromArray(data.data(), static_cast<int>(data.size()));
143 } 146 }
144 147
148 static const UnknownFieldSet* default_instance();
145 private: 149 private:
146 150 // For InternalMergeFrom
151 friend class UnknownField;
152 // Merges from other UnknownFieldSet. This method assumes, that this object
153 // is newly created and has fields_ == NULL;
154 void InternalMergeFrom(const UnknownFieldSet& other);
147 void ClearFallback(); 155 void ClearFallback();
148 156
157 // fields_ is either NULL, or a pointer to a vector that is *non-empty*. We
158 // never hold the empty vector because we want the 'do we have any unknown
159 // fields' check to be fast, and avoid a cache miss: the UFS instance gets
160 // embedded in the message object, so 'fields_ != NULL' tests a member
161 // variable hot in the cache, without the need to go touch a vector somewhere
162 // else in memory.
149 std::vector<UnknownField>* fields_; 163 std::vector<UnknownField>* fields_;
150
151 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); 164 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet);
152 }; 165 };
153 166
154 // Represents one field in an UnknownFieldSet. 167 // Represents one field in an UnknownFieldSet.
155 class LIBPROTOBUF_EXPORT UnknownField { 168 class LIBPROTOBUF_EXPORT UnknownField {
156 public: 169 public:
157 enum Type { 170 enum Type {
158 TYPE_VARINT, 171 TYPE_VARINT,
159 TYPE_FIXED32, 172 TYPE_FIXED32,
160 TYPE_FIXED64, 173 TYPE_FIXED64,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const; 205 uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const;
193 206
194 inline int GetLengthDelimitedSize() const; 207 inline int GetLengthDelimitedSize() const;
195 208
196 private: 209 private:
197 friend class UnknownFieldSet; 210 friend class UnknownFieldSet;
198 211
199 // If this UnknownField contains a pointer, delete it. 212 // If this UnknownField contains a pointer, delete it.
200 void Delete(); 213 void Delete();
201 214
215 // Reset all the underlying pointers to NULL. A special function to be only
216 // used while merging from a temporary UFS.
217 void Reset();
218
202 // Make a deep copy of any pointers in this UnknownField. 219 // Make a deep copy of any pointers in this UnknownField.
203 void DeepCopy(); 220 void DeepCopy(const UnknownField& other);
204 221
222 // Set the wire type of this UnknownField. Should only be used when this
223 // UnknownField is being created.
224 inline void SetType(Type type);
205 225
206 unsigned int number_ : 29; 226 union LengthDelimited {
207 unsigned int type_ : 3; 227 string* string_value_;
228 };
229
230 uint32 number_;
231 uint32 type_;
208 union { 232 union {
209 uint64 varint_; 233 uint64 varint_;
210 uint32 fixed32_; 234 uint32 fixed32_;
211 uint64 fixed64_; 235 uint64 fixed64_;
212 mutable union { 236 mutable union LengthDelimited length_delimited_;
213 string* string_value_;
214 } length_delimited_;
215 UnknownFieldSet* group_; 237 UnknownFieldSet* group_;
216 }; 238 };
217 }; 239 };
218 240
219 // =================================================================== 241 // ===================================================================
220 // inline implementations 242 // inline implementations
221 243
222 inline void UnknownFieldSet::Clear() { 244 inline void UnknownFieldSet::Clear() {
223 if (fields_ != NULL) { 245 if (fields_) {
224 ClearFallback(); 246 ClearFallback();
225 } 247 }
226 } 248 }
227 249
228 inline bool UnknownFieldSet::empty() const { 250 inline bool UnknownFieldSet::empty() const {
229 return fields_ == NULL || fields_->empty(); 251 // Invariant: fields_ is never empty if present.
252 return !fields_;
230 } 253 }
231 254
232 inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { 255 inline void UnknownFieldSet::Swap(UnknownFieldSet* x) {
233 std::swap(fields_, x->fields_); 256 std::swap(fields_, x->fields_);
234 } 257 }
235 258
236 inline int UnknownFieldSet::field_count() const { 259 inline int UnknownFieldSet::field_count() const {
237 return (fields_ == NULL) ? 0 : fields_->size(); 260 return fields_ ? static_cast<int>(fields_->size()) : 0;
238 } 261 }
239 inline const UnknownField& UnknownFieldSet::field(int index) const { 262 inline const UnknownField& UnknownFieldSet::field(int index) const {
263 GOOGLE_DCHECK(fields_ != NULL);
240 return (*fields_)[index]; 264 return (*fields_)[index];
241 } 265 }
242 inline UnknownField* UnknownFieldSet::mutable_field(int index) { 266 inline UnknownField* UnknownFieldSet::mutable_field(int index) {
243 return &(*fields_)[index]; 267 return &(*fields_)[index];
244 } 268 }
245 269
246 inline void UnknownFieldSet::AddLengthDelimited( 270 inline void UnknownFieldSet::AddLengthDelimited(
247 int number, const string& value) { 271 int number, const string& value) {
248 AddLengthDelimited(number)->assign(value); 272 AddLengthDelimited(number)->assign(value);
249 } 273 }
250 274
251 275
252 inline int UnknownField::number() const { return number_; } 276 inline int UnknownField::number() const { return number_; }
253 inline UnknownField::Type UnknownField::type() const { 277 inline UnknownField::Type UnknownField::type() const {
254 return static_cast<Type>(type_); 278 return static_cast<Type>(type_);
255 } 279 }
256 280
257 inline uint64 UnknownField::varint () const { 281 inline uint64 UnknownField::varint() const {
258 assert(type_ == TYPE_VARINT); 282 assert(type() == TYPE_VARINT);
259 return varint_; 283 return varint_;
260 } 284 }
261 inline uint32 UnknownField::fixed32() const { 285 inline uint32 UnknownField::fixed32() const {
262 assert(type_ == TYPE_FIXED32); 286 assert(type() == TYPE_FIXED32);
263 return fixed32_; 287 return fixed32_;
264 } 288 }
265 inline uint64 UnknownField::fixed64() const { 289 inline uint64 UnknownField::fixed64() const {
266 assert(type_ == TYPE_FIXED64); 290 assert(type() == TYPE_FIXED64);
267 return fixed64_; 291 return fixed64_;
268 } 292 }
269 inline const string& UnknownField::length_delimited() const { 293 inline const string& UnknownField::length_delimited() const {
270 assert(type_ == TYPE_LENGTH_DELIMITED); 294 assert(type() == TYPE_LENGTH_DELIMITED);
271 return *length_delimited_.string_value_; 295 return *length_delimited_.string_value_;
272 } 296 }
273 inline const UnknownFieldSet& UnknownField::group() const { 297 inline const UnknownFieldSet& UnknownField::group() const {
274 assert(type_ == TYPE_GROUP); 298 assert(type() == TYPE_GROUP);
275 return *group_; 299 return *group_;
276 } 300 }
277 301
278 inline void UnknownField::set_varint(uint64 value) { 302 inline void UnknownField::set_varint(uint64 value) {
279 assert(type_ == TYPE_VARINT); 303 assert(type() == TYPE_VARINT);
280 varint_ = value; 304 varint_ = value;
281 } 305 }
282 inline void UnknownField::set_fixed32(uint32 value) { 306 inline void UnknownField::set_fixed32(uint32 value) {
283 assert(type_ == TYPE_FIXED32); 307 assert(type() == TYPE_FIXED32);
284 fixed32_ = value; 308 fixed32_ = value;
285 } 309 }
286 inline void UnknownField::set_fixed64(uint64 value) { 310 inline void UnknownField::set_fixed64(uint64 value) {
287 assert(type_ == TYPE_FIXED64); 311 assert(type() == TYPE_FIXED64);
288 fixed64_ = value; 312 fixed64_ = value;
289 } 313 }
290 inline void UnknownField::set_length_delimited(const string& value) { 314 inline void UnknownField::set_length_delimited(const string& value) {
291 assert(type_ == TYPE_LENGTH_DELIMITED); 315 assert(type() == TYPE_LENGTH_DELIMITED);
292 length_delimited_.string_value_->assign(value); 316 length_delimited_.string_value_->assign(value);
293 } 317 }
294 inline string* UnknownField::mutable_length_delimited() { 318 inline string* UnknownField::mutable_length_delimited() {
295 assert(type_ == TYPE_LENGTH_DELIMITED); 319 assert(type() == TYPE_LENGTH_DELIMITED);
296 return length_delimited_.string_value_; 320 return length_delimited_.string_value_;
297 } 321 }
298 inline UnknownFieldSet* UnknownField::mutable_group() { 322 inline UnknownFieldSet* UnknownField::mutable_group() {
299 assert(type_ == TYPE_GROUP); 323 assert(type() == TYPE_GROUP);
300 return group_; 324 return group_;
301 } 325 }
302 326
303 inline int UnknownField::GetLengthDelimitedSize() const { 327 inline int UnknownField::GetLengthDelimitedSize() const {
304 GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type_); 328 GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
305 return length_delimited_.string_value_->size(); 329 return static_cast<int>(length_delimited_.string_value_->size());
306 } 330 }
307 331
332 inline void UnknownField::SetType(Type type) {
333 type_ = type;
334 }
335
336
308 } // namespace protobuf 337 } // namespace protobuf
309 338
310 } // namespace google 339 } // namespace google
311 #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ 340 #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698