Int64Serializer.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if !NO_RUNTIME
  2. using System;
  3. namespace ProtoBuf.Serializers
  4. {
  5. sealed class Int64Serializer : IProtoSerializer
  6. {
  7. static readonly Type expectedType = typeof(long);
  8. public Int64Serializer(ProtoBuf.Meta.TypeModel model) { }
  9. public Type ExpectedType => expectedType;
  10. bool IProtoSerializer.RequiresOldValue => false;
  11. bool IProtoSerializer.ReturnsValue => true;
  12. public object Read(object value, ProtoReader source)
  13. {
  14. Helpers.DebugAssert(value == null); // since replaces
  15. return source.ReadInt64();
  16. }
  17. public void Write(object value, ProtoWriter dest)
  18. {
  19. ProtoWriter.WriteInt64((long)value, dest);
  20. }
  21. #if FEAT_COMPILER
  22. void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  23. {
  24. ctx.EmitBasicWrite("WriteInt64", valueFrom);
  25. }
  26. void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  27. {
  28. ctx.EmitBasicRead("ReadInt64", ExpectedType);
  29. }
  30. #endif
  31. }
  32. }
  33. #endif