UInt32Serializer.cs 1.4 KB

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