Initial Client/Server Communication
#1 Followed the MagicOnion quickstart guide, borrowing code from the chat sample app to get something working
This commit is contained in:
parent
52b0d4d8ff
commit
a0c8dbee72
493 changed files with 57790 additions and 3 deletions
73
Assets/Scripts/MessagePack/Formatters/NullableFormatter.cs
Normal file
73
Assets/Scripts/MessagePack/Formatters/NullableFormatter.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue