Copy Aetheria Code

Added a bunch of code from the old Aetheria project
This commit is contained in:
hyperion51 2020-02-27 18:51:07 +00:00
commit c58ba0b1da
1704 changed files with 175081 additions and 313 deletions

View file

@ -1,73 +0,0 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Buffers;
#pragma warning disable SA1649 // File name should match first type name
namespace MessagePack.Formatters
{
public sealed class NullableFormatter<T> : IMessagePackFormatter<T?>
where T : struct
{
public void Serialize(ref MessagePackWriter writer, T? value, MessagePackSerializerOptions options)
{
if (value == null)
{
writer.WriteNil();
}
else
{
options.Resolver.GetFormatterWithVerify<T>().Serialize(ref writer, value.Value, options);
}
}
public T? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.IsNil)
{
reader.ReadNil();
return null;
}
else
{
return options.Resolver.GetFormatterWithVerify<T>().Deserialize(ref reader, options);
}
}
}
public sealed class StaticNullableFormatter<T> : IMessagePackFormatter<T?>
where T : struct
{
private readonly IMessagePackFormatter<T> underlyingFormatter;
public StaticNullableFormatter(IMessagePackFormatter<T> underlyingFormatter)
{
this.underlyingFormatter = underlyingFormatter;
}
public void Serialize(ref MessagePackWriter writer, T? value, MessagePackSerializerOptions options)
{
if (value == null)
{
writer.WriteNil();
}
else
{
this.underlyingFormatter.Serialize(ref writer, value.Value, options);
}
}
public T? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
return null;
}
else
{
return this.underlyingFormatter.Deserialize(ref reader, options);
}
}
}
}