PacketReader.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*********************************************************************************
  2. *Author: OnClick
  3. *Version: 0.0.1
  4. *UnityVersion: 2017.2.3p3
  5. *Date: 2019-03-14
  6. *Description: IFramework
  7. *History: 2018.11--
  8. *********************************************************************************/
  9. using System.Collections.Generic;
  10. namespace IFramework.Packets
  11. {
  12. #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
  13. public class PacketReader
  14. {
  15. private PacketQueue packetQueue;
  16. private object _lock = new object();
  17. public int count { get { return packetQueue.count; } }
  18. public PacketReader(int capacity = 128)
  19. {
  20. if (capacity < 128) capacity = 128;
  21. capacity += 1;
  22. packetQueue = new PacketQueue(capacity);
  23. }
  24. public bool Set(byte[] buff, int offset, int size)
  25. {
  26. lock (_lock)
  27. {
  28. return packetQueue.Set(buff, offset, size);
  29. }
  30. }
  31. public List<Packet> Get()
  32. {
  33. lock (_lock)
  34. {
  35. return packetQueue.Get();
  36. }
  37. }
  38. public void Clear()
  39. {
  40. lock (_lock)
  41. {
  42. packetQueue.Clear();
  43. }
  44. }
  45. }
  46. #pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
  47. }