Skip to content

Commit 1285469

Browse files
Merge branch 'bollhals-amqpVersion'
2 parents d9c6f47 + 20486e3 commit 1285469

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

projects/RabbitMQ.Client/client/impl/AmqpVersion.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32+
using System;
33+
3234
namespace RabbitMQ.Client.Framing.Impl
3335
{
3436
/// <summary>Represents a version of the AMQP specification.</summary>
@@ -45,7 +47,7 @@ namespace RabbitMQ.Client.Framing.Impl
4547
/// special-cases 8-0, rewriting it at construction time to be 0-8 instead.
4648
/// </para>
4749
/// </remarks>
48-
internal class AmqpVersion
50+
internal readonly struct AmqpVersion : IEquatable<AmqpVersion>
4951
{
5052
/// <summary>
5153
/// Construct an <see cref="AmqpVersion"/> from major and minor version numbers.
@@ -70,27 +72,36 @@ public AmqpVersion(int major, int minor)
7072
/// <summary>
7173
/// The AMQP specification major version number.
7274
/// </summary>
73-
public int Major { get; private set; }
75+
public int Major { get; }
7476

7577
/// <summary>
7678
/// The AMQP specification minor version number.
7779
/// </summary>
78-
public int Minor { get; private set; }
80+
public int Minor { get; }
7981

8082
/// <summary>
8183
/// Implement value-equality comparison.
8284
/// </summary>
8385
public override bool Equals(object other)
8486
{
85-
return (other is AmqpVersion version) && (version.Major == Major) && (version.Minor == Minor);
87+
return other is AmqpVersion version && Equals(version);
8688
}
8789

90+
public bool Equals(AmqpVersion other) => Major == other.Major && Minor == other.Minor;
91+
92+
public static bool operator ==(AmqpVersion left, AmqpVersion right) => left.Equals(right);
93+
94+
public static bool operator !=(AmqpVersion left, AmqpVersion right) => !left.Equals(right);
95+
8896
/// <summary>
8997
/// Implement hashing as for value-equality.
9098
/// </summary>
9199
public override int GetHashCode()
92100
{
93-
return 31*Major.GetHashCode() + Minor.GetHashCode();
101+
unchecked
102+
{
103+
return (Major * 397) ^ Minor;
104+
}
94105
}
95106

96107
/// <summary>

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,16 +1060,12 @@ private void StartAndTune()
10601060

10611061
ServerProperties = connectionStart.m_serverProperties;
10621062

1063-
var serverVersion = new AmqpVersion(connectionStart.m_versionMajor,
1064-
connectionStart.m_versionMinor);
1063+
var serverVersion = new AmqpVersion(connectionStart.m_versionMajor, connectionStart.m_versionMinor);
10651064
if (!serverVersion.Equals(Protocol.Version))
10661065
{
10671066
TerminateMainloop();
10681067
FinishClose();
1069-
throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
1070-
Protocol.MinorVersion,
1071-
serverVersion.Major,
1072-
serverVersion.Minor);
1068+
throw new ProtocolVersionMismatchException(Protocol.MajorVersion, Protocol.MinorVersion, serverVersion.Major, serverVersion.Minor);
10731069
}
10741070

10751071
ClientProperties = new Dictionary<string, object>(_factory.ClientProperties)

0 commit comments

Comments
 (0)