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) { ...@@ -378,7 +378,7 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) {
"public override void WriteTo(pb::ICodedOutputStream output) {"); "public override void WriteTo(pb::ICodedOutputStream output) {");
writer->Indent(); writer->Indent();
// Make sure we've computed the serialized length, so that packed fields are generated correctly. // 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;", writer->WriteLine("string[] field_names = _$0$FieldNames;",
UnderscoresToCamelCase(class_name(), false)); UnderscoresToCamelCase(class_name(), false));
if (descriptor_->extension_range_count()) { if (descriptor_->extension_range_count()) {
...@@ -421,6 +421,17 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) { ...@@ -421,6 +421,17 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) {
writer->Indent(); writer->Indent();
writer->WriteLine("int size = memoizedSerializedSize;"); writer->WriteLine("int size = memoizedSerializedSize;");
writer->WriteLine("if (size != -1) return size;"); 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();
writer->WriteLine("size = 0;"); writer->WriteLine("size = 0;");
for (int i = 0; i < descriptor_->field_count(); i++) { for (int i = 0; i < descriptor_->field_count(); i++) {
...@@ -443,9 +454,6 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) { ...@@ -443,9 +454,6 @@ void MessageGenerator::GenerateMessageSerializationMethods(Writer* writer) {
writer->WriteLine("return size;"); writer->WriteLine("return size;");
writer->Outdent(); writer->Outdent();
writer->WriteLine("}"); writer->WriteLine("}");
writer->Outdent();
writer->WriteLine("}");
writer->WriteLine();
} }
void MessageGenerator::GenerateSerializeOneField( 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