Initial Commit (broken due to version update)

This commit is contained in:
Reinier Vens 2020-09-25 07:12:38 +01:00
commit 3f7b3b7440
3132 changed files with 1103305 additions and 0 deletions

View file

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace MessagePack.Formatters
{
public sealed class NullableFormatter<T> : IMessagePackFormatter<T?>
where T : struct
{
public int Serialize(ref byte[] bytes, int offset, T? value, IFormatterResolver formatterResolver)
{
if (value == null)
{
return MessagePackBinary.WriteNil(ref bytes, offset);
}
else
{
return formatterResolver.GetFormatterWithVerify<T>().Serialize(ref bytes, offset, value.Value, formatterResolver);
}
}
public T? Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
{
if (MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return null;
}
else
{
return formatterResolver.GetFormatterWithVerify<T>().Deserialize(bytes, offset, formatterResolver, out readSize);
}
}
}
public sealed class StaticNullableFormatter<T> : IMessagePackFormatter<T?>
where T : struct
{
readonly IMessagePackFormatter<T> underlyingFormatter;
public StaticNullableFormatter(IMessagePackFormatter<T> underlyingFormatter)
{
this.underlyingFormatter = underlyingFormatter;
}
public int Serialize(ref byte[] bytes, int offset, T? value, IFormatterResolver formatterResolver)
{
if (value == null)
{
return MessagePackBinary.WriteNil(ref bytes, offset);
}
else
{
return underlyingFormatter.Serialize(ref bytes, offset, value.Value, formatterResolver);
}
}
public T? Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
{
if (MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return null;
}
else
{
return underlyingFormatter.Deserialize(bytes, offset, formatterResolver, out readSize);
}
}
}
}