ProtobufHelper.cs 575 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.IO;
  3. namespace ET
  4. {
  5. public static class ProtobufHelper
  6. {
  7. public static void ToStream(object message, MemoryStream stream)
  8. {
  9. ProtoBuf.Serializer.Serialize(stream, message);
  10. }
  11. public static object FromBytes(Type type, byte[] bytes, int index, int count)
  12. {
  13. using (MemoryStream ms = new MemoryStream(bytes, index, count))
  14. {
  15. return ProtoBuf.Serializer.Deserialize(type, ms);
  16. }
  17. }
  18. public static object FromStream(Type type, MemoryStream stream)
  19. {
  20. return ProtoBuf.Serializer.Deserialize(type, stream);
  21. }
  22. }
  23. }