Initial Commit (broken due to version update)
This commit is contained in:
parent
74003df84b
commit
3f7b3b7440
3132 changed files with 1103305 additions and 0 deletions
71
Assets/Scripts/MessagePack/Formatters/NullableFormatter.cs
Normal file
71
Assets/Scripts/MessagePack/Formatters/NullableFormatter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue