diff options
Diffstat (limited to 'src/google/protobuf/wire_format.cc')
-rw-r--r-- | src/google/protobuf/wire_format.cc | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index 88a1a234..bd5b2489 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc @@ -42,6 +42,8 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/descriptor.h> +#include <google/protobuf/dynamic_message.h> +#include <google/protobuf/map_field.h> #include <google/protobuf/wire_format_lite_inl.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/coded_stream.h> @@ -834,6 +836,13 @@ void WireFormat::SerializeFieldWithCachedSizes( count = 1; } + // map_entries is for maps that'll be deterministically serialized. + std::vector<const Message*> map_entries; + if (count > 1 && field->is_map() && output->IsSerializationDeterministic()) { + map_entries = + DynamicMapSorter::Sort(message, count, message_reflection, field); + } + const bool is_packed = field->is_packed(); if (is_packed && count > 0) { WireFormatLite::WriteTag(field->number(), @@ -877,15 +886,17 @@ void WireFormat::SerializeFieldWithCachedSizes( HANDLE_PRIMITIVE_TYPE(BOOL, bool, Bool, Bool) #undef HANDLE_PRIMITIVE_TYPE -#define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \ - case FieldDescriptor::TYPE_##TYPE: \ - WireFormatLite::Write##TYPE_METHOD( \ - field->number(), \ - field->is_repeated() ? \ - message_reflection->GetRepeated##CPPTYPE_METHOD( \ - message, field, j) : \ - message_reflection->Get##CPPTYPE_METHOD(message, field), \ - output); \ +#define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \ + case FieldDescriptor::TYPE_##TYPE: \ + WireFormatLite::Write##TYPE_METHOD( \ + field->number(), \ + field->is_repeated() ? \ + (map_entries.empty() ? \ + message_reflection->GetRepeated##CPPTYPE_METHOD( \ + message, field, j) : \ + *map_entries[j]) : \ + message_reflection->Get##CPPTYPE_METHOD(message, field), \ + output); \ break; HANDLE_TYPE(GROUP , Group , Message) |