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

Unified Diff: third_party/protobuf/src/google/protobuf/message.h

Issue 1322483002: Revert https://codereview.chromium.org/1291903002 (protobuf roll). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/message.h
diff --git a/third_party/protobuf/src/google/protobuf/message.h b/third_party/protobuf/src/google/protobuf/message.h
index 18c092d051e663d6bd34c014d23b7d0ebd4500aa..0f90bc1a15bd6d0001129796dd09de4f30641d2f 100644
--- a/third_party/protobuf/src/google/protobuf/message.h
+++ b/third_party/protobuf/src/google/protobuf/message.h
@@ -1,6 +1,6 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
+// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -98,11 +98,11 @@
//
// // Use the reflection interface to examine the contents.
// const Reflection* reflection = foo->GetReflection();
-// assert(reflection->GetString(*foo, text_field) == "Hello World!");
-// assert(reflection->FieldSize(*foo, numbers_field) == 3);
-// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 0) == 1);
-// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 1) == 5);
-// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 2) == 42);
+// assert(reflection->GetString(foo, text_field) == "Hello World!");
+// assert(reflection->FieldSize(foo, numbers_field) == 3);
+// assert(reflection->GetRepeatedInt32(foo, numbers_field, 0) == 1);
+// assert(reflection->GetRepeatedInt32(foo, numbers_field, 1) == 5);
+// assert(reflection->GetRepeatedInt32(foo, numbers_field, 2) == 42);
//
// delete foo;
// }
@@ -110,21 +110,22 @@
#ifndef GOOGLE_PROTOBUF_MESSAGE_H__
#define GOOGLE_PROTOBUF_MESSAGE_H__
-#include <iosfwd>
-#include <string>
-#include <google/protobuf/stubs/type_traits.h>
#include <vector>
+#include <string>
+
+#ifdef __DECCXX
+// HP C++'s iosfwd doesn't work.
+#include <iostream>
+#else
+#include <iosfwd>
+#endif
-#include <google/protobuf/arena.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h>
-#define GOOGLE_PROTOBUF_HAS_ONEOF
-#define GOOGLE_PROTOBUF_HAS_ARENAS
-
namespace google {
namespace protobuf {
@@ -177,27 +178,15 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// for return-type covariance.)
virtual Message* New() const = 0;
- // Construct a new instance on the arena. Ownership is passed to the caller
- // if arena is a NULL. Default implementation allows for API compatibility
- // during the Arena transition.
- virtual Message* New(::google::protobuf::Arena* arena) const {
- Message* message = New();
- if (arena != NULL) {
- arena->Own(message);
- }
- return message;
- }
-
// Make this message into a copy of the given message. The given message
// must have the same descriptor, but need not necessarily be the same class.
// By default this is just implemented as "Clear(); MergeFrom(from);".
virtual void CopyFrom(const Message& from);
// Merge the fields from the given message into this message. Singular
- // fields will be overwritten, if specified in from, except for embedded
- // messages which will be merged. Repeated fields will be concatenated.
- // The given message must be of the same type as this message (i.e. the
- // exact same class).
+ // fields will be overwritten, except for embedded messages which will
+ // be merged. Repeated fields will be concatenated. The given message
+ // must be of the same type as this message (i.e. the exact same class).
virtual void MergeFrom(const Message& from);
// Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with
@@ -208,7 +197,7 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// This is much, much slower than IsInitialized() as it is implemented
// purely via reflection. Generally, you should not call this unless you
// have already determined that an error exists by calling IsInitialized().
- void FindInitializationErrors(std::vector<string>* errors) const;
+ void FindInitializationErrors(vector<string>* errors) const;
// Like FindInitializationErrors, but joins all the strings, delimited by
// commas, and returns them.
@@ -229,11 +218,6 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// Computes (an estimate of) the total number of bytes currently used for
// storing the message in memory. The default implementation calls the
// Reflection object's SpaceUsed() method.
- //
- // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented
- // using reflection (rather than the generated code implementation for
- // ByteSize()). Like ByteSize(), its CPU time is linear in the number of
- // fields defined for the proto.
virtual int SpaceUsed() const;
// Debugging & Testing----------------------------------------------
@@ -332,20 +316,6 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message);
};
-namespace internal {
-// Forward-declare interfaces used to implement RepeatedFieldRef.
-// These are protobuf internals that users shouldn't care about.
-class RepeatedFieldAccessor;
-} // namespace internal
-
-// Forward-declare RepeatedFieldRef templates. The second type parameter is
-// used for SFINAE tricks. Users should ignore it.
-template<typename T, typename Enable = void>
-class RepeatedFieldRef;
-
-template<typename T, typename Enable = void>
-class MutableRepeatedFieldRef;
-
// This interface contains methods that can be used to dynamically access
// and modify the fields of a protocol message. Their semantics are
// similar to the accessors the protocol compiler generates.
@@ -394,15 +364,12 @@ class LIBPROTOBUF_EXPORT Reflection {
// Get the UnknownFieldSet for the message. This contains fields which
// were seen when the Message was parsed but were not recognized according
- // to the Message's definition. For proto3 protos, this method will always
- // return an empty UnknownFieldSet.
+ // to the Message's definition.
virtual const UnknownFieldSet& GetUnknownFields(
const Message& message) const = 0;
// Get a mutable pointer to the UnknownFieldSet for the message. This
// contains fields which were seen when the Message was parsed but were not
- // recognized according to the Message's definition. For proto3 protos, this
- // method will return a valid mutable UnknownFieldSet pointer but modifying
- // it won't affect the serialized bytes of the message.
+ // recognized according to the Message's definition.
virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0;
// Estimate the amount of memory used by the message object.
@@ -421,26 +388,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void ClearField(Message* message,
const FieldDescriptor* field) const = 0;
- // Check if the oneof is set. Returns true if any field in oneof
- // is set, false otherwise.
- // TODO(jieluo) - make it pure virtual after updating all
- // the subclasses.
- virtual bool HasOneof(const Message& /*message*/,
- const OneofDescriptor* /*oneof_descriptor*/) const {
- return false;
- }
-
- virtual void ClearOneof(Message* /*message*/,
- const OneofDescriptor* /*oneof_descriptor*/) const {}
-
- // Returns the field descriptor if the oneof is set. NULL otherwise.
- // TODO(jieluo) - make it pure virtual.
- virtual const FieldDescriptor* GetOneofFieldDescriptor(
- const Message& /*message*/,
- const OneofDescriptor* /*oneof_descriptor*/) const {
- return NULL;
- }
-
// Removes the last element of a repeated field.
// We don't provide a way to remove any element other than the last
// because it invites inefficient use, such as O(n^2) filtering loops
@@ -458,26 +405,19 @@ class LIBPROTOBUF_EXPORT Reflection {
// Swap the complete contents of two messages.
virtual void Swap(Message* message1, Message* message2) const = 0;
- // Swap fields listed in fields vector of two messages.
- virtual void SwapFields(Message* message1,
- Message* message2,
- const std::vector<const FieldDescriptor*>& fields)
- const = 0;
-
// Swap two elements of a repeated field.
virtual void SwapElements(Message* message,
- const FieldDescriptor* field,
- int index1,
- int index2) const = 0;
+ const FieldDescriptor* field,
+ int index1,
+ int index2) const = 0;
// List all fields of the message which are currently set. This includes
// extensions. Singular fields will only be listed if HasField(field) would
// return true and repeated fields will only be listed if FieldSize(field)
// would return non-zero. Fields (both normal fields and extension fields)
// will be listed ordered by field number.
- virtual void ListFields(
- const Message& message,
- std::vector<const FieldDescriptor*>* output) const = 0;
+ virtual void ListFields(const Message& message,
+ vector<const FieldDescriptor*>* output) const = 0;
// Singular field getters ------------------------------------------
// These get the value of a non-repeated field. They return the default
@@ -501,15 +441,6 @@ class LIBPROTOBUF_EXPORT Reflection {
const FieldDescriptor* field) const = 0;
virtual const EnumValueDescriptor* GetEnum(
const Message& message, const FieldDescriptor* field) const = 0;
-
- // GetEnumValue() returns an enum field's value as an integer rather than
- // an EnumValueDescriptor*. If the integer value does not correspond to a
- // known value descriptor, a new value descriptor is created. (Such a value
- // will only be present when the new unknown-enum-value semantics are enabled
- // for a message.)
- virtual int GetEnumValue(
- const Message& message, const FieldDescriptor* field) const;
-
// See MutableMessage() for the meaning of the "factory" parameter.
virtual const Message& GetMessage(const Message& message,
const FieldDescriptor* field,
@@ -529,7 +460,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// regardless of the field's underlying representation. When initializing
// a newly-constructed string, though, it's just as fast and more readable
// to use code like:
- // string str = reflection->GetString(message, field);
+ // string str = reflection->GetString(field);
virtual const string& GetStringReference(const Message& message,
const FieldDescriptor* field,
string* scratch) const = 0;
@@ -558,14 +489,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void SetEnum (Message* message,
const FieldDescriptor* field,
const EnumValueDescriptor* value) const = 0;
- // Set an enum field's value with an integer rather than EnumValueDescriptor.
- // If the value does not correspond to a known enum value, either behavior is
- // undefined (for proto2 messages), or the value is accepted silently for
- // messages with new unknown-enum-value semantics.
- virtual void SetEnumValue(Message* message,
- const FieldDescriptor* field,
- int value) const;
-
// Get a mutable pointer to a field with a message type. If a MessageFactory
// is provided, it will be used to construct instances of the sub-message;
// otherwise, the default factory is used. If the field is an extension that
@@ -579,13 +502,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual Message* MutableMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory = NULL) const = 0;
- // Replaces the message specified by 'field' with the already-allocated object
- // sub_message, passing ownership to the message. If the field contained a
- // message, that message is deleted. If sub_message is NULL, the field is
- // cleared.
- virtual void SetAllocatedMessage(Message* message,
- Message* sub_message,
- const FieldDescriptor* field) const = 0;
// Releases the message specified by 'field' and returns the pointer,
// ReleaseMessage() will return the message the message object if it exists.
// Otherwise, it may or may not return NULL. In any case, if the return value
@@ -628,14 +544,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual const EnumValueDescriptor* GetRepeatedEnum(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
- // GetRepeatedEnumValue() returns an enum field's value as an integer rather
- // than an EnumValueDescriptor*. If the integer value does not correspond to a
- // known value descriptor, a new value descriptor is created. (Such a value
- // will only be present when the new unknown-enum-value semantics are enabled
- // for a message.)
- virtual int GetRepeatedEnumValue(
- const Message& message,
- const FieldDescriptor* field, int index) const;
virtual const Message& GetRepeatedMessage(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
@@ -676,13 +584,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void SetRepeatedEnum(Message* message,
const FieldDescriptor* field, int index,
const EnumValueDescriptor* value) const = 0;
- // Set an enum field's value with an integer rather than EnumValueDescriptor.
- // If the value does not correspond to a known enum value, either behavior is
- // undefined (for proto2 messages), or the value is accepted silently for
- // messages with new unknown-enum-value semantics.
- virtual void SetRepeatedEnumValue(Message* message,
- const FieldDescriptor* field, int index,
- int value) const;
// Get a mutable pointer to an element of a repeated field with a message
// type.
virtual Message* MutableRepeatedMessage(
@@ -712,57 +613,12 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void AddEnum (Message* message,
const FieldDescriptor* field,
const EnumValueDescriptor* value) const = 0;
- // Set an enum field's value with an integer rather than EnumValueDescriptor.
- // If the value does not correspond to a known enum value, either behavior is
- // undefined (for proto2 messages), or the value is accepted silently for
- // messages with new unknown-enum-value semantics.
- virtual void AddEnumValue(Message* message,
- const FieldDescriptor* field,
- int value) const;
// See MutableMessage() for comments on the "factory" parameter.
virtual Message* AddMessage(Message* message,
const FieldDescriptor* field,
MessageFactory* factory = NULL) const = 0;
- // Get a RepeatedFieldRef object that can be used to read the underlying
- // repeated field. The type parameter T must be set according to the
- // field's cpp type. The following table shows the mapping from cpp type
- // to acceptable T.
- //
- // field->cpp_type() T
- // CPPTYPE_INT32 int32
- // CPPTYPE_UINT32 uint32
- // CPPTYPE_INT64 int64
- // CPPTYPE_UINT64 uint64
- // CPPTYPE_DOUBLE double
- // CPPTYPE_FLOAT float
- // CPPTYPE_BOOL bool
- // CPPTYPE_ENUM generated enum type or int32
- // CPPTYPE_STRING string
- // CPPTYPE_MESSAGE generated message type or google::protobuf::Message
- //
- // A RepeatedFieldRef object can be copied and the resulted object will point
- // to the same repeated field in the same message. The object can be used as
- // long as the message is not destroyed.
- //
- // Note that to use this method users need to include the header file
- // "google/protobuf/reflection.h" (which defines the RepeatedFieldRef
- // class templates).
- template<typename T>
- RepeatedFieldRef<T> GetRepeatedFieldRef(
- const Message& message, const FieldDescriptor* field) const;
-
- // Like GetRepeatedFieldRef() but return an object that can also be used
- // manipulate the underlying repeated field.
- template<typename T>
- MutableRepeatedFieldRef<T> GetMutableRepeatedFieldRef(
- Message* message, const FieldDescriptor* field) const;
-
- // DEPRECATED. Please use Get(Mutable)RepeatedFieldRef() for repeated field
- // access. The following repeated field accesors will be removed in the
- // future.
- //
// Repeated field accessors -------------------------------------------------
// The methods above, e.g. GetRepeatedInt32(msg, fd, index), provide singular
// access to the data in a RepeatedField. The methods below provide aggregate
@@ -773,30 +629,22 @@ class LIBPROTOBUF_EXPORT Reflection {
//
// Usage example: my_doubs = refl->GetRepeatedField<double>(msg, fd);
- // DEPRECATED. Please use GetRepeatedFieldRef().
- //
// for T = Cord and all protobuf scalar types except enums.
template<typename T>
const RepeatedField<T>& GetRepeatedField(
const Message&, const FieldDescriptor*) const;
- // DEPRECATED. Please use GetMutableRepeatedFieldRef().
- //
// for T = Cord and all protobuf scalar types except enums.
template<typename T>
RepeatedField<T>* MutableRepeatedField(
Message*, const FieldDescriptor*) const;
- // DEPRECATED. Please use GetRepeatedFieldRef().
- //
// for T = string, google::protobuf::internal::StringPieceField
// google::protobuf::Message & descendants.
template<typename T>
const RepeatedPtrField<T>& GetRepeatedPtrField(
const Message&, const FieldDescriptor*) const;
- // DEPRECATED. Please use GetMutableRepeatedFieldRef().
- //
// for T = string, google::protobuf::internal::StringPieceField
// google::protobuf::Message & descendants.
template<typename T>
@@ -815,52 +663,6 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual const FieldDescriptor* FindKnownExtensionByNumber(
int number) const = 0;
- // Feature Flags -------------------------------------------------------------
-
- // Does this message support storing arbitrary integer values in enum fields?
- // If |true|, GetEnumValue/SetEnumValue and associated repeated-field versions
- // take arbitrary integer values, and the legacy GetEnum() getter will
- // dynamically create an EnumValueDescriptor for any integer value without
- // one. If |false|, setting an unknown enum value via the integer-based
- // setters results in undefined behavior (in practice, GOOGLE_DCHECK-fails).
- //
- // Generic code that uses reflection to handle messages with enum fields
- // should check this flag before using the integer-based setter, and either
- // downgrade to a compatible value or use the UnknownFieldSet if not. For
- // example:
- //
- // int new_value = GetValueFromApplicationLogic();
- // if (reflection->SupportsUnknownEnumValues()) {
- // reflection->SetEnumValue(message, field, new_value);
- // } else {
- // if (field_descriptor->enum_type()->
- // FindValueByNumver(new_value) != NULL) {
- // reflection->SetEnumValue(message, field, new_value);
- // } else if (emit_unknown_enum_values) {
- // reflection->MutableUnknownFields(message)->AddVarint(
- // field->number(),
- // new_value);
- // } else {
- // // convert value to a compatible/default value.
- // new_value = CompatibleDowngrade(new_value);
- // reflection->SetEnumValue(message, field, new_value);
- // }
- // }
- virtual bool SupportsUnknownEnumValues() const { return false; }
-
- // Returns the MessageFactory associated with this message. This can be
- // useful for determining if a message is a generated message or not, for
- // example:
- //
- // if (message->GetReflection()->GetMessageFactory() ==
- // google::protobuf::MessageFactory::generated_factory()) {
- // // This is a generated message.
- // }
- //
- // It can also be used to create more messages of this type, though
- // Message::New() is an easier way to accomplish this.
- virtual MessageFactory* GetMessageFactory() const;
-
// ---------------------------------------------------------------------------
protected:
@@ -873,36 +675,7 @@ class LIBPROTOBUF_EXPORT Reflection {
Message* message, const FieldDescriptor* field, FieldDescriptor::CppType,
int ctype, const Descriptor* message_type) const = 0;
- // The following methods are used to implement (Mutable)RepeatedFieldRef.
- // A Ref object will store a raw pointer to the repeated field data (obtained
- // from RepeatedFieldData()) and a pointer to a Accessor (obtained from
- // RepeatedFieldAccessor) which will be used to access the raw data.
- //
- // TODO(xiaofeng): Make these methods pure-virtual.
-
- // Returns a raw pointer to the repeated field
- //
- // "cpp_type" and "message_type" are decuded from the type parameter T passed
- // to Get(Mutable)RepeatedFieldRef. If T is a generated message type,
- // "message_type" should be set to its descriptor. Otherwise "message_type"
- // should be set to NULL. Implementations of this method should check whether
- // "cpp_type"/"message_type" is consistent with the actual type of the field.
- virtual void* RepeatedFieldData(
- Message* message, const FieldDescriptor* field,
- FieldDescriptor::CppType cpp_type,
- const Descriptor* message_type) const;
-
- // The returned pointer should point to a singleton instance which implements
- // the RepeatedFieldAccessor interface.
- virtual const internal::RepeatedFieldAccessor* RepeatedFieldAccessor(
- const FieldDescriptor* field) const;
-
private:
- template<typename T, typename Enable>
- friend class RepeatedFieldRef;
- template<typename T, typename Enable>
- friend class MutableRepeatedFieldRef;
-
// Special version for specialized implementations of string. We can't call
// MutableRawRepeatedField directly here because we don't have access to
// FieldOptions::* which are defined in descriptor.pb.h. Including that
@@ -926,7 +699,7 @@ class LIBPROTOBUF_EXPORT MessageFactory {
// Calling this method twice with the same Descriptor returns the same
// object. The returned object remains property of the factory. Also, any
// objects created by calling the prototype's New() method share some data
- // with the prototype, so these must be destroyed before the MessageFactory
+ // with the prototype, so these must be destoyed before the MessageFactory
// is destroyed.
//
// The given descriptor must outlive the returned message, and hence must
@@ -1057,6 +830,7 @@ inline RepeatedPtrField<PB>* Reflection::MutableRepeatedPtrField(
FieldDescriptor::CPPTYPE_MESSAGE, -1,
PB::default_instance().GetDescriptor()));
}
+
} // namespace protobuf
} // namespace google

Powered by Google App Engine
This is Rietveld 408576698