ByteSerializer.cs 1.1 KB

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