ProtobufPacker.cs 870 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.IO;
  3. namespace ET
  4. {
  5. public class ProtobufPacker : IMessagePacker
  6. {
  7. public byte[] SerializeTo(object obj)
  8. {
  9. return ProtobufHelper.ToBytes(obj);
  10. }
  11. public void SerializeTo(object obj, MemoryStream stream)
  12. {
  13. ProtobufHelper.ToStream(obj, stream);
  14. }
  15. public object DeserializeFrom(Type type, byte[] bytes, int index, int count)
  16. {
  17. return ProtobufHelper.FromBytes(type, bytes, index, count);
  18. }
  19. public object DeserializeFrom(object instance, byte[] bytes, int index, int count)
  20. {
  21. return ProtobufHelper.FromBytes(instance, bytes, index, count);
  22. }
  23. public object DeserializeFrom(Type type, MemoryStream stream)
  24. {
  25. return ProtobufHelper.FromStream(type, stream);
  26. }
  27. public object DeserializeFrom(object instance, MemoryStream stream)
  28. {
  29. return ProtobufHelper.FromStream(instance, stream);
  30. }
  31. }
  32. }