/// <summary> /// Compares the DateRange based to the bytes representation. /// </summary> public int CompareTo(DateRange other) { var buffer1 = Serializer.Serialize((ushort)ProtocolVersion.MaxSupported, this); var buffer2 = Serializer.Serialize((ushort)ProtocolVersion.MaxSupported, other); if (buffer1.Length == buffer2.Length) { // Use Array IStructuralComparable implementation return(((IStructuralComparable)buffer1).CompareTo(buffer2, Comparer <byte> .Default)); } var length = Math.Max(buffer1.Length, buffer2.Length); // Different length comparison should return as soon as we find a difference starting from msb for (var i = 0; i < length; i++) { byte b1 = 0; byte b2 = 0; if (buffer1.Length > i) { b1 = buffer1[i]; } if (buffer2.Length > i) { b2 = buffer2[i]; } if (b1 != b2) { return(b1 - b2); } } return(0); }
public void Serialize_Deserialize_Test() { var serializer = new DateRangeSerializer(); foreach (var value in DateRangeTests.Values.Select(e => e.Item3)) { var serialized = serializer.Serialize(4, value); // Use a buffer at a different index than 0 var buffer = DateRangeSerializerTests.JoinBuffers(new[] { new byte[10], serialized }, serialized.Length + 10); var deserialized = serializer.Deserialize(4, buffer, 10, serialized.Length, serializer.TypeInfo); Assert.AreEqual(value, deserialized); } }