Skip to content

Commit

Permalink
#1479 Rework conditional packages in v6 branch including adding net 6 (
Browse files Browse the repository at this point in the history
…#1482)

* Have added net 6 as a TFM and implement conditional packages

Revert NetworkOrderDeserializer

Have ported some changes from V7 + Reviewed conditional compiles

* Bump Erlang and RabbitMQ versions for CI

---------

Co-authored-by: Luke Bakken <[email protected]>
  • Loading branch information
thompson-tomo and lukebakken authored Mar 15, 2024
1 parent 1b9a40d commit 08e1837
Show file tree
Hide file tree
Showing 24 changed files with 1,063 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .ci/versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"erlang": "26.0.2",
"rabbitmq": "3.12.4"
"erlang": "26.2.3",
"rabbitmq": "3.13.0"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;net6.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyTitle>RabbitMQ OAuth2 Client Library for .NET</AssemblyTitle>
Expand Down Expand Up @@ -59,6 +59,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions projects/RabbitMQ.Client/RabbitMQ.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;net6.0</TargetFrameworks>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -60,10 +60,10 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
<PackageReference Include="System.Threading.Channels" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="System.Threading.Channels" Version="7.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
/// <summary>Thrown when the application tries to make use of a
/// session or connection that has already been shut
/// down.</summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class AlreadyClosedException : OperationInterruptedException
{
///<summary>Construct an instance containing the given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace RabbitMQ.Client.Exceptions
{
/// <summary> Thrown when the cause is an
/// authentication failure. </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class AuthenticationFailureException : PossibleAuthenticationFailureException
{
public AuthenticationFailureException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
{
///<summary>Thrown when no connection could be opened during a
///ConnectionFactory.CreateConnection attempt.</summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class BrokerUnreachableException : IOException
{
///<summary>Construct a BrokerUnreachableException. The inner exception is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
/// <summary> Thrown when a SessionManager cannot allocate a new
/// channel number, or the requested channel number is already in
/// use. </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class ChannelAllocationException : ProtocolViolationException
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
namespace RabbitMQ.Client.Exceptions
{
/// <summary>Thrown when a connection to the broker fails</summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class ConnectFailureException : ProtocolViolationException
{
public ConnectFailureException(string msg, Exception inner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ namespace RabbitMQ.Client.Exceptions
/// operation, an OperationInterruptedException will be thrown to
/// the caller of IModel.QueueDeclare.
/// </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class OperationInterruptedException
// TODO: inherit from OperationCanceledException
: RabbitMQClientException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ namespace RabbitMQ.Client.Exceptions
///The peer's {'A','M','Q','P',txHi,txLo,major,minor} packet is
///decoded into instances of this class.
///</remarks>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class PacketNotRecognizedException : RabbitMQClientException
{
///<summary>Fills the new instance's properties with the values passed in.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace RabbitMQ.Client.Exceptions
{
/// <summary> Thrown when the likely cause is an
/// authentication failure. </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class PossibleAuthenticationFailureException : RabbitMQClientException
{
public PossibleAuthenticationFailureException(string msg, Exception inner) : base(msg, inner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
///<summary>Thrown to indicate that the peer does not support the
///wire protocol version we requested immediately after opening
///the TCP socket.</summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class ProtocolVersionMismatchException : ProtocolViolationException
{
///<summary>Fills the new instance's properties with the values passed in.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

namespace RabbitMQ.Client.Exceptions
{
#if !NETSTANDARD1_5
[Serializable]
#endif
public class ProtocolViolationException : RabbitMQClientException
{
public ProtocolViolationException(string message) : base(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

namespace RabbitMQ.Client.Exceptions
{
#if !NETSTANDARD1_5
[Serializable]
#endif
public abstract class RabbitMQClientException : Exception
{
/// <summary>Initializes a new instance of the <see cref="RabbitMQClientException" /> class.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
/// <summary>
/// Thrown when the model receives an RPC reply that it wasn't expecting.
/// </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class UnexpectedMethodException : ProtocolViolationException
{
public UnexpectedMethodException(IMethod method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace RabbitMQ.Client.Exceptions
/// <summary>
/// Thrown when the model receives an RPC request it cannot satisfy.
/// </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class UnsupportedMethodException : NotSupportedException
{
public UnsupportedMethodException(string methodName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ namespace RabbitMQ.Client.Exceptions
/// because the version of the protocol the model is implementing
/// does not contain a definition for the field in
/// question.</summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class UnsupportedMethodFieldException : NotSupportedException
{
public UnsupportedMethodFieldException(string methodName, string fieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace RabbitMQ.Client.Exceptions
{
/// <summary> Thrown when the wire-formatting code cannot encode a
/// particular .NET value to AMQP protocol format. </summary>
#if !NETSTANDARD1_5
[Serializable]
#endif
public class WireFormattingException : ProtocolViolationException
{
///<summary>Construct a WireFormattingException with no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace RabbitMQ.Client.Logging
[EventSource(Name = "rabbitmq-dotnet-client")]
public sealed class RabbitMqClientEventSource : EventSource
{
public static readonly RabbitMqClientEventSource Log = new RabbitMqClientEventSource();
public class Keywords
{
public const EventKeywords Log = (EventKeywords)1;
Expand All @@ -47,8 +48,6 @@ public RabbitMqClientEventSource() : base(EventSourceSettings.EtwSelfDescribingE
{
}

public static RabbitMqClientEventSource Log = new RabbitMqClientEventSource();

[Event(1, Message = "INFO", Keywords = Keywords.Log, Level = EventLevel.Informational)]
public void Info(string message)
{
Expand All @@ -67,20 +66,25 @@ public void Warn(string message)
public void Error(string message, RabbitMqExceptionDetail ex)
{
if (IsEnabled())
#if NET6_0_OR_GREATER
WriteExceptionEvent(message, ex);
#else
WriteEvent(3, message, ex);
#endif
}

[NonEvent]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
private void WriteExceptionEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string message, T ex)
public void Error(string message, Exception ex)
{
WriteEvent(3, message, ex);
Error(message, new RabbitMqExceptionDetail(ex));
}

[NonEvent]
public void Error(string message, Exception ex)
#if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
private void WriteExceptionEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string message, T ex)
{
Error(message, new RabbitMqExceptionDetail(ex));
WriteEvent(3, message, ex);
}
#endif
}
}
16 changes: 8 additions & 8 deletions projects/RabbitMQ.Client/util/NetworkOrderDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static double ReadDouble(ReadOnlySpan<byte> span)
throw new ArgumentOutOfRangeException(nameof(span), "Insufficient length to decode Double from memory.");
}
ulong val = ReadUInt64(span);
#elif NETSTANDARD
#else
ulong val = BinaryPrimitives.ReadUInt64BigEndian(span);
#endif
return Unsafe.As<ulong, double>(ref val);
Expand All @@ -31,7 +31,7 @@ internal static short ReadInt16(ReadOnlySpan<byte> span)
}

return (short)ReadUInt16(span);
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadInt16BigEndian(span);
#endif
}
Expand All @@ -46,7 +46,7 @@ internal static int ReadInt32(ReadOnlySpan<byte> span)
}

return (int)ReadUInt32(span);
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadInt32BigEndian(span);
#endif
}
Expand All @@ -61,7 +61,7 @@ internal static long ReadInt64(ReadOnlySpan<byte> span)
}

return (long)ReadUInt64(span);
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadInt64BigEndian(span);
#endif
}
Expand All @@ -76,7 +76,7 @@ internal static float ReadSingle(ReadOnlySpan<byte> span)
}

uint num = ReadUInt32(span);
#elif NETSTANDARD
#else
uint num = BinaryPrimitives.ReadUInt32BigEndian(span);
#endif
return Unsafe.As<uint, float>(ref num);
Expand All @@ -92,7 +92,7 @@ internal static ushort ReadUInt16(ReadOnlySpan<byte> span)
}

return (ushort)((span[0] << 8) | span[1]);
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadUInt16BigEndian(span);
#endif
}
Expand All @@ -107,7 +107,7 @@ internal static uint ReadUInt32(ReadOnlySpan<byte> span)
}

return (uint)((span[0] << 24) | (span[1] << 16) | (span[2] << 8) | span[3]);
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadUInt32BigEndian(span);
#endif
}
Expand All @@ -124,7 +124,7 @@ internal static ulong ReadUInt64(ReadOnlySpan<byte> span)
uint num1 = (uint)((span[0] << 24) | (span[1] << 16) | (span[2] << 8) | span[3]);
uint num2 = (uint)((span[4] << 24) | (span[5] << 16) | (span[6] << 8) | span[7]);
return ((ulong)num1 << 32) | num2;
#elif NETSTANDARD
#else
return BinaryPrimitives.ReadUInt64BigEndian(span);
#endif
}
Expand Down
16 changes: 8 additions & 8 deletions projects/RabbitMQ.Client/util/NetworkOrderSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static void WriteDouble(Span<byte> span, double val)
span[5] = (byte)((tempVal >> 16) & 0xFF);
span[6] = (byte)((tempVal >> 8) & 0xFF);
span[7] = (byte)(tempVal & 0xFF);
#elif NETSTANDARD
#else
long tempVal = BitConverter.DoubleToInt64Bits(val);
BinaryPrimitives.WriteInt64BigEndian(span, tempVal);
#endif
Expand All @@ -42,7 +42,7 @@ internal static void WriteInt16(Span<byte> span, short val)

span[0] = (byte)((val >> 8) & 0xFF);
span[1] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteInt16BigEndian(span, val);
#endif
}
Expand All @@ -60,7 +60,7 @@ internal static void WriteInt32(Span<byte> span, int val)
span[1] = (byte)((val >> 16) & 0xFF);
span[2] = (byte)((val >> 8) & 0xFF);
span[3] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteInt32BigEndian(span, val);
#endif
}
Expand All @@ -82,7 +82,7 @@ internal static void WriteInt64(Span<byte> span, long val)
span[5] = (byte)((val >> 16) & 0xFF);
span[6] = (byte)((val >> 8) & 0xFF);
span[7] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteInt64BigEndian(span, val);
#endif
}
Expand All @@ -101,7 +101,7 @@ internal static void WriteSingle(Span<byte> span, float val)
span[1] = (byte)((tempVal >> 16) & 0xFF);
span[2] = (byte)((tempVal >> 8) & 0xFF);
span[3] = (byte)(tempVal & 0xFF);
#elif NETSTANDARD
#else
int tempVal = Unsafe.As<float, int>(ref val);
BinaryPrimitives.WriteInt32BigEndian(span, tempVal);
#endif
Expand All @@ -118,7 +118,7 @@ internal static void WriteUInt16(Span<byte> span, ushort val)

span[0] = (byte)((val >> 8) & 0xFF);
span[1] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteUInt16BigEndian(span, val);
#endif
}
Expand All @@ -136,7 +136,7 @@ internal static void WriteUInt32(Span<byte> span, uint val)
span[1] = (byte)((val >> 16) & 0xFF);
span[2] = (byte)((val >> 8) & 0xFF);
span[3] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteUInt32BigEndian(span, val);
#endif
}
Expand All @@ -159,7 +159,7 @@ internal static void WriteUInt64(Span<byte> span, ulong val)
span[5] = (byte)((val >> 16) & 0xFF);
span[6] = (byte)((val >> 8) & 0xFF);
span[7] = (byte)(val & 0xFF);
#elif NETSTANDARD
#else
BinaryPrimitives.WriteUInt64BigEndian(span, val);
#endif
}
Expand Down
Loading

0 comments on commit 08e1837

Please sign in to comment.