Files
2026-08-27 10:56:38 -06:00

41 lines
856 B
C#

using System;
using ProtoBuf.Compiler;
using ProtoBuf.Meta;
namespace ProtoBuf.Serializers;
internal sealed class DoubleSerializer : IProtoSerializer
{
private static readonly Type expectedType = typeof(double);
public Type ExpectedType => expectedType;
bool IProtoSerializer.RequiresOldValue => false;
bool IProtoSerializer.ReturnsValue => true;
public DoubleSerializer(TypeModel model)
{
}
public object Read(object value, ProtoReader source)
{
return source.ReadDouble();
}
public void Write(object value, ProtoWriter dest)
{
ProtoWriter.WriteDouble((double)value, dest);
}
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicWrite("WriteDouble", valueFrom);
}
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom)
{
ctx.EmitBasicRead("ReadDouble", ExpectedType);
}
}