AlienMessage.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MECF.Framework.RT.Core.IoProviders.Common.IMessage
  7. {
  8. /// <summary>
  9. /// 异形消息对象,用于异形客户端的注册包接收以及验证使用
  10. /// </summary>
  11. public class AlienMessage : INetMessage
  12. {
  13. /// <summary>
  14. /// 本协议的消息头长度
  15. /// </summary>
  16. public int ProtocolHeadBytesLength
  17. {
  18. get { return 5; }
  19. }
  20. /// <summary>
  21. /// 头子节信息
  22. /// </summary>
  23. public byte[] HeadBytes { get; set; }
  24. /// <summary>
  25. /// 内容字节信息
  26. /// </summary>
  27. public byte[] ContentBytes { get; set; }
  28. /// <summary>
  29. /// 检查接收的数据是否合法
  30. /// </summary>
  31. /// <param name="token">令牌</param>
  32. /// <returns>是否合法</returns>
  33. public bool CheckHeadBytesLegal(byte[] token)
  34. {
  35. if (HeadBytes == null) return false;
  36. if (HeadBytes[0] == 0x48 &&
  37. HeadBytes[1] == 0x73 &&
  38. HeadBytes[2] == 0x6E)
  39. {
  40. return true;
  41. }
  42. else
  43. {
  44. return false;
  45. }
  46. }
  47. /// <summary>
  48. /// 从头子节信息中解析出接下来需要接收的数据长度
  49. /// </summary>
  50. /// <returns>接下来的数据长度</returns>
  51. public int GetContentLengthByHeadBytes()
  52. {
  53. return HeadBytes[4];
  54. }
  55. /// <summary>
  56. /// 获取头子节里的特殊标识
  57. /// </summary>
  58. /// <returns>标识信息</returns>
  59. public int GetHeadBytesIdentity()
  60. {
  61. return 0;
  62. }
  63. /// <summary>
  64. /// 发送的字节信息
  65. /// </summary>
  66. public byte[] SendBytes { get; set; }
  67. }
  68. }