aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/unknown_field_set.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/unknown_field_set.h')
-rw-r--r--src/google/protobuf/unknown_field_set.h71
1 files changed, 47 insertions, 24 deletions
diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h
index 612a942a..619855ed 100644
--- a/src/google/protobuf/unknown_field_set.h
+++ b/src/google/protobuf/unknown_field_set.h
@@ -43,6 +43,7 @@
#include <vector>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/message_lite.h>
namespace google {
namespace protobuf {
@@ -52,6 +53,7 @@ namespace protobuf {
class ZeroCopyInputStream; // zero_copy_stream.h
}
namespace internal {
+ class InternalMetadataWithArena; // metadata.h
class WireFormat; // wire_format.h
class MessageSetFieldSkipperUsingCord;
// extension_set_heavy.cc
@@ -92,16 +94,31 @@ class LIBPROTOBUF_EXPORT UnknownFieldSet {
// Similar to above, but this function will destroy the contents of other.
void MergeFromAndDestroy(UnknownFieldSet* other);
+ // Merge the contents an UnknownFieldSet with the UnknownFieldSet in
+ // *metadata, if there is one. If *metadata doesn't have an UnknownFieldSet
+ // then add one to it and make it be a copy of the first arg.
+ static void MergeToInternalMetdata(
+ const UnknownFieldSet& other,
+ internal::InternalMetadataWithArena* metadata);
+
// Swaps the contents of some other UnknownFieldSet with this one.
inline void Swap(UnknownFieldSet* x);
// Computes (an estimate of) the total number of bytes currently used for
// storing the unknown fields in memory. Does NOT include
// sizeof(*this) in the calculation.
- int SpaceUsedExcludingSelf() const;
+ size_t SpaceUsedExcludingSelfLong() const;
+
+ int SpaceUsedExcludingSelf() const {
+ return internal::ToIntSize(SpaceUsedExcludingSelfLong());
+ }
// Version of SpaceUsed() including sizeof(*this).
- int SpaceUsed() const;
+ size_t SpaceUsedLong() const;
+
+ int SpaceUsed() const {
+ return internal::ToIntSize(SpaceUsedLong());
+ }
// Returns the number of fields present in the UnknownFieldSet.
inline int field_count() const;
@@ -175,7 +192,7 @@ class LIBPROTOBUF_EXPORT UnknownField {
TYPE_GROUP
};
- // The field's tag number, as seen on the wire.
+ // The field's field number, as seen on the wire.
inline int number() const;
// The field type.
@@ -204,10 +221,8 @@ class LIBPROTOBUF_EXPORT UnknownField {
void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const;
uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const;
- inline int GetLengthDelimitedSize() const;
+ inline size_t GetLengthDelimitedSize() const;
- private:
- friend class UnknownFieldSet;
// If this UnknownField contains a pointer, delete it.
void Delete();
@@ -235,14 +250,20 @@ class LIBPROTOBUF_EXPORT UnknownField {
uint64 fixed64_;
mutable union LengthDelimited length_delimited_;
UnknownFieldSet* group_;
- };
+ } data_;
};
// ===================================================================
// inline implementations
+inline UnknownFieldSet::UnknownFieldSet() : fields_(NULL) {}
+
+inline UnknownFieldSet::~UnknownFieldSet() { Clear(); }
+
+inline void UnknownFieldSet::ClearAndFreeMemory() { Clear(); }
+
inline void UnknownFieldSet::Clear() {
- if (fields_) {
+ if (fields_ != NULL) {
ClearFallback();
}
}
@@ -261,10 +282,10 @@ inline int UnknownFieldSet::field_count() const {
}
inline const UnknownField& UnknownFieldSet::field(int index) const {
GOOGLE_DCHECK(fields_ != NULL);
- return (*fields_)[index];
+ return (*fields_)[static_cast<size_t>(index)];
}
inline UnknownField* UnknownFieldSet::mutable_field(int index) {
- return &(*fields_)[index];
+ return &(*fields_)[static_cast<size_t>(index)];
}
inline void UnknownFieldSet::AddLengthDelimited(
@@ -273,60 +294,62 @@ inline void UnknownFieldSet::AddLengthDelimited(
}
-inline int UnknownField::number() const { return number_; }
+
+
+inline int UnknownField::number() const { return static_cast<int>(number_); }
inline UnknownField::Type UnknownField::type() const {
return static_cast<Type>(type_);
}
inline uint64 UnknownField::varint() const {
assert(type() == TYPE_VARINT);
- return varint_;
+ return data_.varint_;
}
inline uint32 UnknownField::fixed32() const {
assert(type() == TYPE_FIXED32);
- return fixed32_;
+ return data_.fixed32_;
}
inline uint64 UnknownField::fixed64() const {
assert(type() == TYPE_FIXED64);
- return fixed64_;
+ return data_.fixed64_;
}
inline const string& UnknownField::length_delimited() const {
assert(type() == TYPE_LENGTH_DELIMITED);
- return *length_delimited_.string_value_;
+ return *data_.length_delimited_.string_value_;
}
inline const UnknownFieldSet& UnknownField::group() const {
assert(type() == TYPE_GROUP);
- return *group_;
+ return *data_.group_;
}
inline void UnknownField::set_varint(uint64 value) {
assert(type() == TYPE_VARINT);
- varint_ = value;
+ data_.varint_ = value;
}
inline void UnknownField::set_fixed32(uint32 value) {
assert(type() == TYPE_FIXED32);
- fixed32_ = value;
+ data_.fixed32_ = value;
}
inline void UnknownField::set_fixed64(uint64 value) {
assert(type() == TYPE_FIXED64);
- fixed64_ = value;
+ data_.fixed64_ = value;
}
inline void UnknownField::set_length_delimited(const string& value) {
assert(type() == TYPE_LENGTH_DELIMITED);
- length_delimited_.string_value_->assign(value);
+ data_.length_delimited_.string_value_->assign(value);
}
inline string* UnknownField::mutable_length_delimited() {
assert(type() == TYPE_LENGTH_DELIMITED);
- return length_delimited_.string_value_;
+ return data_.length_delimited_.string_value_;
}
inline UnknownFieldSet* UnknownField::mutable_group() {
assert(type() == TYPE_GROUP);
- return group_;
+ return data_.group_;
}
-inline int UnknownField::GetLengthDelimitedSize() const {
+inline size_t UnknownField::GetLengthDelimitedSize() const {
GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
- return static_cast<int>(length_delimited_.string_value_->size());
+ return data_.length_delimited_.string_value_->size();
}
inline void UnknownField::SetType(Type type) {