NetProtocolProvider.cs 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using IFramework.Packets;
  2. namespace IFramework.Net
  3. {
  4. internal class NetProtocolProvider : INetProtocolProvider
  5. {
  6. public static NetProtocolProvider CreateProvider()
  7. {
  8. return new NetProtocolProvider();
  9. }
  10. public NetProtocolProvider()
  11. { }
  12. /// <summary>
  13. /// 解码
  14. /// </summary>
  15. /// <param name="buffer"></param>
  16. /// <param name="offset"></param>
  17. /// <param name="size"></param>
  18. /// <returns></returns>
  19. public Packet Decode(byte[] buffer, int offset, int size)
  20. {
  21. return Packet.UnPackPacket(buffer, offset, size);
  22. }
  23. /// <summary>
  24. /// 编码
  25. /// </summary>
  26. /// <param name="pkg"></param>
  27. /// <returns></returns>
  28. public byte[] Encode(Packet pkg)
  29. {
  30. return pkg.Pack();
  31. }
  32. }
  33. }