From 779f61c6a3ce02a119e28e802f229e61b69b9046 Mon Sep 17 00:00:00 2001 From: temporal Date: Wed, 13 Aug 2008 03:15:00 +0000 Subject: Integrate recent changes from google3. protoc - New flags --encode and --decode can be used to convert between protobuf text format and binary format from the command-line. - New flag --descriptor_set_out can be used to write FileDescriptorProtos for all parsed files directly into a single output file. This is particularly useful if you wish to parse .proto files from programs written in languages other than C++: just run protoc as a background process and have it output a FileDescriptorList, then parse that natively. C++ - Reflection objects are now per-class rather than per-instance. To make this possible, the Reflection interface had to be changed such that all methods take the Message instance as a parameter. This change improves performance significantly in memory-bandwidth-limited use cases, since it makes the message objects smaller. Note that source-incompatible interface changes like this will not be made again after the library leaves beta. Python - MergeFrom(message) and CopyFrom(message) are now implemented. - SerializeToString() raises an exception if the message is missing required fields. - Code organization improvements. - Fixed doc comments for RpcController and RpcChannel, which had somehow been swapped. --- src/google/protobuf/extension_set.cc | 68 ++++++++++-------------------------- 1 file changed, 18 insertions(+), 50 deletions(-) (limited to 'src/google/protobuf/extension_set.cc') diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 154f06f8..f679d7ae 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -34,42 +34,10 @@ namespace internal { // ------------------------------------------------------------------- // Lookup functions -const FieldDescriptor* -ExtensionSet::FindKnownExtensionByName(const string& name) const { - const FieldDescriptor* result = descriptor_pool_->FindExtensionByName(name); - if (result != NULL && result->containing_type() == extendee_) { - return result; - } - - if (extendee_->options().message_set_wire_format()) { - // MessageSet extensions may be identified by type name. - const Descriptor* type = descriptor_pool_->FindMessageTypeByName(name); - if (type != NULL) { - // Look for a matching extension in the foreign type's scope. - for (int i = 0; i < type->extension_count(); i++) { - const FieldDescriptor* extension = type->extension(i); - if (extension->containing_type() == extendee_ && - extension->type() == FieldDescriptor::TYPE_MESSAGE && - extension->is_optional() && - extension->message_type() == type) { - // Found it. - return extension; - } - } - } - } - - return NULL; -} - -const FieldDescriptor* -ExtensionSet::FindKnownExtensionByNumber(int number) const { - return descriptor_pool_->FindExtensionByNumber(extendee_, number); -} - const FieldDescriptor* ExtensionSet::FindKnownExtensionOrDie(int number) const { - const FieldDescriptor* descriptor = FindKnownExtensionByNumber(number); + const FieldDescriptor* descriptor = + descriptor_pool_->FindExtensionByNumber(*extendee_, number); if (descriptor == NULL) { // This extension doesn't exist, so we have to crash. However, let's // try to provide an informative error message. @@ -77,7 +45,7 @@ ExtensionSet::FindKnownExtensionOrDie(int number) const { message_factory_ == MessageFactory::generated_factory()) { // This is probably the ExtensionSet for a generated class. GOOGLE_LOG(FATAL) << ": No extension is registered for \"" - << extendee_->full_name() << "\" with number " + << (*extendee_)->full_name() << "\" with number " << number << ". Perhaps you were trying to access it via " "the Reflection interface, but you provided a " "FieldDescriptor which did not come from a linked-in " @@ -87,7 +55,7 @@ ExtensionSet::FindKnownExtensionOrDie(int number) const { } else { // This is probably a DynamicMessage. GOOGLE_LOG(FATAL) << ": No extension is registered for \"" - << extendee_->full_name() << "\" with number " + << (*extendee_)->full_name() << "\" with number " << number << ". If you were using a DynamicMessage, " "remember that you are only allowed to access extensions " "which are defined in the DescriptorPool which you passed " @@ -105,7 +73,7 @@ ExtensionSet::GetPrototype(const Descriptor* message_type) const { // =================================================================== // Constructors and basic methods. -ExtensionSet::ExtensionSet(const Descriptor* extendee, +ExtensionSet::ExtensionSet(const Descriptor* const* extendee, const DescriptorPool* pool, MessageFactory* factory) : extendee_(extendee), @@ -461,7 +429,7 @@ void MergeRepeatedFields(const RepeatedPtrField& source, } // namespace void ExtensionSet::MergeFrom(const ExtensionSet& other) { - GOOGLE_DCHECK_EQ(extendee_, other.extendee_); + GOOGLE_DCHECK_EQ(*extendee_, *other.extendee_); for (map::const_iterator iter = other.extensions_.begin(); iter != other.extensions_.end(); ++iter) { @@ -558,22 +526,23 @@ bool ExtensionSet::IsInitialized() const { } bool ExtensionSet::ParseField(uint32 tag, io::CodedInputStream* input, - Message::Reflection* reflection) { + Message* message) { const FieldDescriptor* field = - FindKnownExtensionByNumber(WireFormat::GetTagFieldNumber(tag)); + message->GetReflection() + ->FindKnownExtensionByNumber(WireFormat::GetTagFieldNumber(tag)); - return WireFormat::ParseAndMergeField(tag, field, reflection, input); + return WireFormat::ParseAndMergeField(tag, field, message, input); } bool ExtensionSet::SerializeWithCachedSizes( int start_field_number, int end_field_number, - const Message::Reflection* reflection, + const Message& message, io::CodedOutputStream* output) const { map::const_iterator iter; for (iter = extensions_.lower_bound(start_field_number); iter != extensions_.end() && iter->first < end_field_number; ++iter) { - if (!iter->second.SerializeFieldWithCachedSizes(reflection, output)) { + if (!iter->second.SerializeFieldWithCachedSizes(message, output)) { return false; } } @@ -581,12 +550,12 @@ bool ExtensionSet::SerializeWithCachedSizes( return true; } -int ExtensionSet::ByteSize(const Message::Reflection* reflection) const { +int ExtensionSet::ByteSize(const Message& message) const { int total_size = 0; for (map::const_iterator iter = extensions_.begin(); iter != extensions_.end(); ++iter) { - total_size += iter->second.ByteSize(reflection); + total_size += iter->second.ByteSize(message); } return total_size; @@ -652,20 +621,19 @@ void ExtensionSet::Extension::Clear() { } bool ExtensionSet::Extension::SerializeFieldWithCachedSizes( - const Message::Reflection* reflection, + const Message& message, io::CodedOutputStream* output) const { if (descriptor->is_repeated() || !is_cleared) { return WireFormat::SerializeFieldWithCachedSizes( - descriptor, reflection, output); + descriptor, message, output); } else { return true; } } -int64 ExtensionSet::Extension::ByteSize( - const Message::Reflection* reflection) const { +int64 ExtensionSet::Extension::ByteSize(const Message& message) const { if (descriptor->is_repeated() || !is_cleared) { - return WireFormat::FieldByteSize(descriptor, reflection); + return WireFormat::FieldByteSize(descriptor, message); } else { // Cleared, non-repeated field. return 0; -- cgit v1.2.3