Int64Serializer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if !NO_RUNTIME
  2. using System;
  3. using ProtoBuf.Meta;
  4. #if FEAT_IKVM
  5. using Type = IKVM.Reflection.Type;
  6. using IKVM.Reflection;
  7. #else
  8. using System.Reflection;
  9. #endif
  10. namespace ProtoBuf.Serializers
  11. {
  12. sealed class Int64Serializer : IProtoSerializer
  13. {
  14. #if FEAT_IKVM
  15. readonly Type expectedType;
  16. #else
  17. static readonly Type expectedType = typeof(long);
  18. #endif
  19. public Int64Serializer(ProtoBuf.Meta.TypeModel model)
  20. {
  21. #if FEAT_IKVM
  22. expectedType = model.MapType(typeof(long));
  23. #endif
  24. }
  25. public Type ExpectedType { get { return expectedType; } }
  26. bool IProtoSerializer.RequiresOldValue { get { return false; } }
  27. bool IProtoSerializer.ReturnsValue { get { return true; } }
  28. #if !FEAT_IKVM
  29. public object Read(object value, ProtoReader source)
  30. {
  31. Helpers.DebugAssert(value == null); // since replaces
  32. return source.ReadInt64();
  33. }
  34. public void Write(object value, ProtoWriter dest)
  35. {
  36. ProtoWriter.WriteInt64((long)value, dest);
  37. }
  38. #endif
  39. #if FEAT_COMPILER
  40. void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  41. {
  42. ctx.EmitBasicWrite("WriteInt64", valueFrom);
  43. }
  44. void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  45. {
  46. ctx.EmitBasicRead("ReadInt64", ExpectedType);
  47. }
  48. #endif
  49. }
  50. }
  51. #endif