diff options
author | Jie Luo <jieluo@google.com> | 2017-12-19 11:54:11 -0800 |
---|---|---|
committer | Jie Luo <jieluo@google.com> | 2017-12-19 15:38:02 -0800 |
commit | b308580bb1c3f87a062ac1448a3e0bdaab9d40cf (patch) | |
tree | ea211f27b3deb05a9ba5461079288020a11b5c8d /src/google/protobuf/compiler/csharp/csharp_primitive_field.cc | |
parent | 3a06fe1fc9590b534f403114a0668befba926947 (diff) | |
download | protobuf-b308580bb1c3f87a062ac1448a3e0bdaab9d40cf.tar.gz protobuf-b308580bb1c3f87a062ac1448a3e0bdaab9d40cf.tar.bz2 protobuf-b308580bb1c3f87a062ac1448a3e0bdaab9d40cf.zip |
Cherrypick for csharp, including:
Add preserve UnknownFields
Compare floating point values bitwise
Add auto-generated header to C# generated files
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_primitive_field.cc')
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_primitive_field.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index 931adb4a..c3003e3d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -137,14 +137,22 @@ void PrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { } void PrimitiveFieldGenerator::WriteHash(io::Printer* printer) { - printer->Print( - variables_, - "if ($has_property_check$) hash ^= $property_name$.GetHashCode();\n"); + const char *text = "if ($has_property_check$) hash ^= $property_name$.GetHashCode();\n"; + if (descriptor_->type() == FieldDescriptor::TYPE_FLOAT) { + text = "if ($has_property_check$) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode($property_name$);\n"; + } else if (descriptor_->type() == FieldDescriptor::TYPE_DOUBLE) { + text = "if ($has_property_check$) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode($property_name$);\n"; + } + printer->Print(variables_, text); } void PrimitiveFieldGenerator::WriteEquals(io::Printer* printer) { - printer->Print( - variables_, - "if ($property_name$ != other.$property_name$) return false;\n"); + const char *text = "if ($property_name$ != other.$property_name$) return false;\n"; + if (descriptor_->type() == FieldDescriptor::TYPE_FLOAT) { + text = "if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals($property_name$, other.$property_name$)) return false;\n"; + } else if (descriptor_->type() == FieldDescriptor::TYPE_DOUBLE) { + text = "if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals($property_name$, other.$property_name$)) return false;\n"; + } + printer->Print(variables_, text); } void PrimitiveFieldGenerator::WriteToString(io::Printer* printer) { printer->Print( |