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