| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include <google/protobuf/stubs/logging.h> | 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 InternalMetadataWithArena; // metadata.h |
| 55 class WireFormat; // wire_format.h | 56 class WireFormat; // wire_format.h |
| 56 class MessageSetFieldSkipperUsingCord; | 57 class MessageSetFieldSkipperUsingCord; |
| 57 // extension_set_heavy.cc | 58 // extension_set_heavy.cc |
| 58 } | 59 } |
| 59 | 60 |
| 60 class Message; // message.h | 61 class Message; // message.h |
| 61 class UnknownField; // below | 62 class UnknownField; // below |
| 62 | 63 |
| 63 // An UnknownFieldSet contains fields that were encountered while parsing a | 64 // 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 | 65 // message but were not defined by its type. Keeping track of these can be |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 // Is this set empty? | 87 // Is this set empty? |
| 87 inline bool empty() const; | 88 inline bool empty() const; |
| 88 | 89 |
| 89 // Merge the contents of some other UnknownFieldSet with this one. | 90 // Merge the contents of some other UnknownFieldSet with this one. |
| 90 void MergeFrom(const UnknownFieldSet& other); | 91 void MergeFrom(const UnknownFieldSet& other); |
| 91 | 92 |
| 92 // Similar to above, but this function will destroy the contents of other. | 93 // Similar to above, but this function will destroy the contents of other. |
| 93 void MergeFromAndDestroy(UnknownFieldSet* other); | 94 void MergeFromAndDestroy(UnknownFieldSet* other); |
| 94 | 95 |
| 96 // Merge the contents an UnknownFieldSet with the UnknownFieldSet in |
| 97 // *metadata, if there is one. If *metadata doesn't have an UnknownFieldSet |
| 98 // then add one to it and make it be a copy of the first arg. |
| 99 static void MergeToInternalMetdata( |
| 100 const UnknownFieldSet& other, |
| 101 internal::InternalMetadataWithArena* metadata); |
| 102 |
| 95 // Swaps the contents of some other UnknownFieldSet with this one. | 103 // Swaps the contents of some other UnknownFieldSet with this one. |
| 96 inline void Swap(UnknownFieldSet* x); | 104 inline void Swap(UnknownFieldSet* x); |
| 97 | 105 |
| 98 // Computes (an estimate of) the total number of bytes currently used for | 106 // Computes (an estimate of) the total number of bytes currently used for |
| 99 // storing the unknown fields in memory. Does NOT include | 107 // storing the unknown fields in memory. Does NOT include |
| 100 // sizeof(*this) in the calculation. | 108 // sizeof(*this) in the calculation. |
| 101 int SpaceUsedExcludingSelf() const; | 109 int SpaceUsedExcludingSelf() const; |
| 102 | 110 |
| 103 // Version of SpaceUsed() including sizeof(*this). | 111 // Version of SpaceUsed() including sizeof(*this). |
| 104 int SpaceUsed() const; | 112 int SpaceUsed() const; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 class LIBPROTOBUF_EXPORT UnknownField { | 176 class LIBPROTOBUF_EXPORT UnknownField { |
| 169 public: | 177 public: |
| 170 enum Type { | 178 enum Type { |
| 171 TYPE_VARINT, | 179 TYPE_VARINT, |
| 172 TYPE_FIXED32, | 180 TYPE_FIXED32, |
| 173 TYPE_FIXED64, | 181 TYPE_FIXED64, |
| 174 TYPE_LENGTH_DELIMITED, | 182 TYPE_LENGTH_DELIMITED, |
| 175 TYPE_GROUP | 183 TYPE_GROUP |
| 176 }; | 184 }; |
| 177 | 185 |
| 178 // The field's tag number, as seen on the wire. | 186 // The field's field number, as seen on the wire. |
| 179 inline int number() const; | 187 inline int number() const; |
| 180 | 188 |
| 181 // The field type. | 189 // The field type. |
| 182 inline Type type() const; | 190 inline Type type() const; |
| 183 | 191 |
| 184 // Accessors ------------------------------------------------------- | 192 // Accessors ------------------------------------------------------- |
| 185 // Each method works only for UnknownFields of the corresponding type. | 193 // Each method works only for UnknownFields of the corresponding type. |
| 186 | 194 |
| 187 inline uint64 varint() const; | 195 inline uint64 varint() const; |
| 188 inline uint32 fixed32() const; | 196 inline uint32 fixed32() const; |
| 189 inline uint64 fixed64() const; | 197 inline uint64 fixed64() const; |
| 190 inline const string& length_delimited() const; | 198 inline const string& length_delimited() const; |
| 191 inline const UnknownFieldSet& group() const; | 199 inline const UnknownFieldSet& group() const; |
| 192 | 200 |
| 193 inline void set_varint(uint64 value); | 201 inline void set_varint(uint64 value); |
| 194 inline void set_fixed32(uint32 value); | 202 inline void set_fixed32(uint32 value); |
| 195 inline void set_fixed64(uint64 value); | 203 inline void set_fixed64(uint64 value); |
| 196 inline void set_length_delimited(const string& value); | 204 inline void set_length_delimited(const string& value); |
| 197 inline string* mutable_length_delimited(); | 205 inline string* mutable_length_delimited(); |
| 198 inline UnknownFieldSet* mutable_group(); | 206 inline UnknownFieldSet* mutable_group(); |
| 199 | 207 |
| 200 // Serialization API. | 208 // Serialization API. |
| 201 // These methods can take advantage of the underlying implementation and may | 209 // These methods can take advantage of the underlying implementation and may |
| 202 // archieve a better performance than using getters to retrieve the data and | 210 // archieve a better performance than using getters to retrieve the data and |
| 203 // do the serialization yourself. | 211 // do the serialization yourself. |
| 204 void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const; | 212 void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const; |
| 205 uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const; | 213 uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const; |
| 206 | 214 |
| 207 inline int GetLengthDelimitedSize() const; | 215 inline size_t GetLengthDelimitedSize() const; |
| 208 | 216 |
| 209 private: | 217 private: |
| 210 friend class UnknownFieldSet; | 218 friend class UnknownFieldSet; |
| 211 | 219 |
| 212 // If this UnknownField contains a pointer, delete it. | 220 // If this UnknownField contains a pointer, delete it. |
| 213 void Delete(); | 221 void Delete(); |
| 214 | 222 |
| 215 // Reset all the underlying pointers to NULL. A special function to be only | 223 // Reset all the underlying pointers to NULL. A special function to be only |
| 216 // used while merging from a temporary UFS. | 224 // used while merging from a temporary UFS. |
| 217 void Reset(); | 225 void Reset(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 234 uint32 fixed32_; | 242 uint32 fixed32_; |
| 235 uint64 fixed64_; | 243 uint64 fixed64_; |
| 236 mutable union LengthDelimited length_delimited_; | 244 mutable union LengthDelimited length_delimited_; |
| 237 UnknownFieldSet* group_; | 245 UnknownFieldSet* group_; |
| 238 }; | 246 }; |
| 239 }; | 247 }; |
| 240 | 248 |
| 241 // =================================================================== | 249 // =================================================================== |
| 242 // inline implementations | 250 // inline implementations |
| 243 | 251 |
| 252 inline UnknownFieldSet::UnknownFieldSet() : fields_(NULL) {} |
| 253 |
| 254 inline UnknownFieldSet::~UnknownFieldSet() { Clear(); } |
| 255 |
| 256 inline void UnknownFieldSet::ClearAndFreeMemory() { Clear(); } |
| 257 |
| 244 inline void UnknownFieldSet::Clear() { | 258 inline void UnknownFieldSet::Clear() { |
| 245 if (fields_) { | 259 if (fields_ != NULL) { |
| 246 ClearFallback(); | 260 ClearFallback(); |
| 247 } | 261 } |
| 248 } | 262 } |
| 249 | 263 |
| 250 inline bool UnknownFieldSet::empty() const { | 264 inline bool UnknownFieldSet::empty() const { |
| 251 // Invariant: fields_ is never empty if present. | 265 // Invariant: fields_ is never empty if present. |
| 252 return !fields_; | 266 return !fields_; |
| 253 } | 267 } |
| 254 | 268 |
| 255 inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { | 269 inline void UnknownFieldSet::Swap(UnknownFieldSet* x) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 331 } |
| 318 inline string* UnknownField::mutable_length_delimited() { | 332 inline string* UnknownField::mutable_length_delimited() { |
| 319 assert(type() == TYPE_LENGTH_DELIMITED); | 333 assert(type() == TYPE_LENGTH_DELIMITED); |
| 320 return length_delimited_.string_value_; | 334 return length_delimited_.string_value_; |
| 321 } | 335 } |
| 322 inline UnknownFieldSet* UnknownField::mutable_group() { | 336 inline UnknownFieldSet* UnknownField::mutable_group() { |
| 323 assert(type() == TYPE_GROUP); | 337 assert(type() == TYPE_GROUP); |
| 324 return group_; | 338 return group_; |
| 325 } | 339 } |
| 326 | 340 |
| 327 inline int UnknownField::GetLengthDelimitedSize() const { | 341 inline size_t UnknownField::GetLengthDelimitedSize() const { |
| 328 GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); | 342 GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); |
| 329 return static_cast<int>(length_delimited_.string_value_->size()); | 343 return length_delimited_.string_value_->size(); |
| 330 } | 344 } |
| 331 | 345 |
| 332 inline void UnknownField::SetType(Type type) { | 346 inline void UnknownField::SetType(Type type) { |
| 333 type_ = type; | 347 type_ = type; |
| 334 } | 348 } |
| 335 | 349 |
| 336 | 350 |
| 337 } // namespace protobuf | 351 } // namespace protobuf |
| 338 | 352 |
| 339 } // namespace google | 353 } // namespace google |
| 340 #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ | 354 #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |
| OLD | NEW |