SByteSerializer.cs 1.4 KB

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