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. #endif
  8. namespace ProtoBuf.Serializers
  9. {
  10. sealed class UInt32Serializer : IProtoSerializer
  11. {
  12. #if FEAT_IKVM
  13. readonly Type expectedType;
  14. #else
  15. static readonly Type expectedType = typeof(uint);
  16. #endif
  17. public UInt32Serializer(ProtoBuf.Meta.TypeModel model)
  18. {
  19. #if FEAT_IKVM
  20. expectedType = model.MapType(typeof(uint));
  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.ReadUInt32();
  31. }
  32. public void Write(object value, ProtoWriter dest)
  33. {
  34. ProtoWriter.WriteUInt32((uint)value, dest);
  35. }
  36. #endif
  37. #if FEAT_COMPILER
  38. void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  39. {
  40. ctx.EmitBasicWrite("WriteUInt32", valueFrom);
  41. }
  42. void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  43. {
  44. ctx.EmitBasicRead("ReadUInt32", ctx.MapType(typeof(uint)));
  45. }
  46. #endif
  47. }
  48. }
  49. #endif