Commit 333d200a authored by Jan Tattermusch's avatar Jan Tattermusch

integrate CalcSerializedSize() fix from protobuf-csharp-port issue 84

parent 7cc05ecb
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment