diff options
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_message.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 66b8c2d5..f7c8ddfb 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -378,7 +378,7 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) { "public override void WriteTo(pb::ICodedOutputStream output) {"); writer->Indent(); // Make sure we've computed the serialized length, so that packed fields are generated correctly. - writer->WriteLine("int size = SerializedSize;"); + writer->WriteLine("CalcSerializedSize();"); writer->WriteLine("string[] field_names = _$0$FieldNames;", UnderscoresToCamelCase(class_name(), false)); if (descriptor_->extension_range_count()) { @@ -421,6 +421,17 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) { writer->Indent(); writer->WriteLine("int size = memoizedSerializedSize;"); writer->WriteLine("if (size != -1) return size;"); + writer->WriteLine("return CalcSerializedSize();"); + writer->Outdent(); + writer->WriteLine("}"); + writer->Outdent(); + writer->WriteLine("}"); + writer->WriteLine(); + + writer->WriteLine("private int CalcSerializedSize() {"); + writer->Indent(); + writer->WriteLine("int size = memoizedSerializedSize;"); + writer->WriteLine("if (size != -1) return size;"); writer->WriteLine(); writer->WriteLine("size = 0;"); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -443,9 +454,6 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) { writer->WriteLine("return size;"); writer->Outdent(); writer->WriteLine("}"); - writer->Outdent(); - writer->WriteLine("}"); - writer->WriteLine(); } void MessageGenerator::GenerateSerializeOneField( |