41 lines
910 B
C#
41 lines
910 B
C#
using System;
|
|
using ProtoBuf.Compiler;
|
|
using ProtoBuf.Meta;
|
|
|
|
namespace ProtoBuf.Serializers;
|
|
|
|
internal sealed class GuidSerializer : IProtoSerializer
|
|
{
|
|
private static readonly Type expectedType = typeof(Guid);
|
|
|
|
public Type ExpectedType => expectedType;
|
|
|
|
bool IProtoSerializer.RequiresOldValue => false;
|
|
|
|
bool IProtoSerializer.ReturnsValue => true;
|
|
|
|
public GuidSerializer(TypeModel model)
|
|
{
|
|
}
|
|
|
|
public void Write(object value, ProtoWriter dest)
|
|
{
|
|
BclHelpers.WriteGuid((Guid)value, dest);
|
|
}
|
|
|
|
public object Read(object value, ProtoReader source)
|
|
{
|
|
return BclHelpers.ReadGuid(source);
|
|
}
|
|
|
|
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
|
|
{
|
|
ctx.EmitWrite(ctx.MapType(typeof(BclHelpers)), "WriteGuid", valueFrom);
|
|
}
|
|
|
|
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
|
|
{
|
|
ctx.EmitBasicRead(ctx.MapType(typeof(BclHelpers)), "ReadGuid", ExpectedType);
|
|
}
|
|
}
|