UInt16Serializer.cs 1.1 KB

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