ProtobufPacker.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.IO;
  3. namespace KYFramework.Network
  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. }