1
0

Updated to C# 12

This commit is contained in:
2024-01-14 13:10:33 +01:00
parent 9cd1344266
commit 27cd54fb30
51 changed files with 637 additions and 379 deletions

View File

@@ -0,0 +1,34 @@
using System.Net;
namespace MessagePack.Formatters
{
/// <summary>
/// Serialization of an <see cref="IPAddress"/> to and from <see cref="MessagePack"/>.
/// </summary>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class IPAddressFormatter : IMessagePackFormatter<IPAddress>
{
/// <inheritdoc/>
public IPAddress Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.IsNil)
return null;
byte[] bytes = options.Resolver.GetFormatterWithVerify<byte[]>().Deserialize(ref reader, options);
return new IPAddress(bytes);
}
/// <inheritdoc/>
public void Serialize(ref MessagePackWriter writer, IPAddress value, MessagePackSerializerOptions options)
{
if (value == null)
{
writer.WriteNil();
return;
}
byte[] bytes = value.GetAddressBytes();
options.Resolver.GetFormatterWithVerify<byte[]>().Serialize(ref writer, bytes, options);
}
}
}