Index: third_party/protobuf/src/google/protobuf/unknown_field_set.h |
=================================================================== |
--- third_party/protobuf/src/google/protobuf/unknown_field_set.h (revision 216642) |
+++ third_party/protobuf/src/google/protobuf/unknown_field_set.h (working copy) |
@@ -38,12 +38,24 @@ |
#ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |
#define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ |
+#include <assert.h> |
#include <string> |
#include <vector> |
-#include <google/protobuf/repeated_field.h> |
+#include <google/protobuf/stubs/common.h> |
+// TODO(jasonh): some people seem to rely on protobufs to include this for them! |
namespace google { |
namespace protobuf { |
+ namespace io { |
+ class CodedInputStream; // coded_stream.h |
+ class CodedOutputStream; // coded_stream.h |
+ class ZeroCopyInputStream; // zero_copy_stream.h |
+ } |
+ namespace internal { |
+ class WireFormat; // wire_format.h |
+ class UnknownFieldSetFieldSkipperUsingCord; |
+ // extension_set_heavy.cc |
+ } |
class Message; // message.h |
class UnknownField; // below |
@@ -68,6 +80,9 @@ |
// Remove all fields. |
inline void Clear(); |
+ // Remove all fields and deallocate internal data objects |
+ void ClearAndFreeMemory(); |
+ |
// Is this set empty? |
inline bool empty() const; |
@@ -107,6 +122,15 @@ |
// Adds an unknown field from another set. |
void AddField(const UnknownField& field); |
+ // Delete fields with indices in the range [start .. start+num-1]. |
+ // Caution: implementation moves all fields with indices [start+num .. ]. |
+ void DeleteSubrange(int start, int num); |
+ |
+ // Delete all fields with a specific field number. The order of left fields |
+ // is preserved. |
+ // Caution: implementation moves all fields after the first deleted field. |
+ void DeleteByNumber(int number); |
+ |
// Parsing helpers ------------------------------------------------- |
// These work exactly like the similarly-named methods of Message. |
@@ -119,6 +143,7 @@ |
} |
private: |
+ |
void ClearFallback(); |
vector<UnknownField>* fields_; |
@@ -159,6 +184,15 @@ |
inline string* mutable_length_delimited(); |
inline UnknownFieldSet* mutable_group(); |
+ // Serialization API. |
+ // These methods can take advantage of the underlying implementation and may |
+ // archieve a better performance than using getters to retrieve the data and |
+ // do the serialization yourself. |
+ void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const; |
+ uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const; |
+ |
+ inline int GetLengthDelimitedSize() const; |
+ |
private: |
friend class UnknownFieldSet; |
@@ -168,13 +202,16 @@ |
// Make a deep copy of any pointers in this UnknownField. |
void DeepCopy(); |
+ |
unsigned int number_ : 29; |
unsigned int type_ : 3; |
union { |
uint64 varint_; |
uint32 fixed32_; |
uint64 fixed64_; |
- string* length_delimited_; |
+ mutable union { |
+ string* string_value_; |
+ } length_delimited_; |
UnknownFieldSet* group_; |
}; |
}; |
@@ -211,57 +248,63 @@ |
AddLengthDelimited(number)->assign(value); |
} |
+ |
inline int UnknownField::number() const { return number_; } |
inline UnknownField::Type UnknownField::type() const { |
return static_cast<Type>(type_); |
} |
inline uint64 UnknownField::varint () const { |
- GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); |
+ assert(type_ == TYPE_VARINT); |
return varint_; |
} |
inline uint32 UnknownField::fixed32() const { |
- GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); |
+ assert(type_ == TYPE_FIXED32); |
return fixed32_; |
} |
inline uint64 UnknownField::fixed64() const { |
- GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); |
+ assert(type_ == TYPE_FIXED64); |
return fixed64_; |
} |
inline const string& UnknownField::length_delimited() const { |
- GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); |
- return *length_delimited_; |
+ assert(type_ == TYPE_LENGTH_DELIMITED); |
+ return *length_delimited_.string_value_; |
} |
inline const UnknownFieldSet& UnknownField::group() const { |
- GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); |
+ assert(type_ == TYPE_GROUP); |
return *group_; |
} |
inline void UnknownField::set_varint(uint64 value) { |
- GOOGLE_DCHECK_EQ(type_, TYPE_VARINT); |
+ assert(type_ == TYPE_VARINT); |
varint_ = value; |
} |
inline void UnknownField::set_fixed32(uint32 value) { |
- GOOGLE_DCHECK_EQ(type_, TYPE_FIXED32); |
+ assert(type_ == TYPE_FIXED32); |
fixed32_ = value; |
} |
inline void UnknownField::set_fixed64(uint64 value) { |
- GOOGLE_DCHECK_EQ(type_, TYPE_FIXED64); |
+ assert(type_ == TYPE_FIXED64); |
fixed64_ = value; |
} |
inline void UnknownField::set_length_delimited(const string& value) { |
- GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); |
- length_delimited_->assign(value); |
+ assert(type_ == TYPE_LENGTH_DELIMITED); |
+ length_delimited_.string_value_->assign(value); |
} |
inline string* UnknownField::mutable_length_delimited() { |
- GOOGLE_DCHECK_EQ(type_, TYPE_LENGTH_DELIMITED); |
- return length_delimited_; |
+ assert(type_ == TYPE_LENGTH_DELIMITED); |
+ return length_delimited_.string_value_; |
} |
inline UnknownFieldSet* UnknownField::mutable_group() { |
- GOOGLE_DCHECK_EQ(type_, TYPE_GROUP); |
+ assert(type_ == TYPE_GROUP); |
return group_; |
} |
+inline int UnknownField::GetLengthDelimitedSize() const { |
+ GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type_); |
+ return length_delimited_.string_value_->size(); |
+} |
+ |
} // namespace protobuf |
} // namespace google |