From f6790e43aef5a57e0a57a0d66404008c18c26c01 Mon Sep 17 00:00:00 2001 From: dsavvinov Date: Fri, 15 Jul 2016 17:03:52 +0300 Subject: [PATCH] Fixed order of fields serialization according to Google Protobuf's requirements --- .../compiler/kotlin/src/kotlin_class_generator.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc index 2bdb6d2e1eb..1d42b10e873 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc @@ -6,6 +6,7 @@ #include #include "kotlin_enum_generator.h" #include "kotlin_field_generator.h" +#include namespace google { namespace protobuf { @@ -95,7 +96,15 @@ ClassGenerator::ClassGenerator(Descriptor const *descriptor) enumsDeclaraions.push_back(new EnumGenerator(nestedEnumDescriptor)); } - + /** + * Sort properties in ascending order on their tag numbers. This order + * affects order of serialization and deserialization, thus fields will be + * serialized in order of their tags, as demanded by Google + */ + std::sort(properties.begin(), properties.end(), + [](FieldGenerator const * first, FieldGenerator const * second) { + return first->fieldNumber < second->fieldNumber; + }); } ClassGenerator::~ClassGenerator() {