using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HslCommunication.Core.IMessage
{
///
/// 本组件系统使用的默认的消息规则,说明解析和反解析规则的
///
public class HslMessage : INetMessage
{
///
/// 本协议的消息头长度
///
public int ProtocolHeadBytesLength
{
get { return 32; }
}
///
/// 头子节信息
///
public byte[] HeadBytes { get ; set; }
///
/// 内容字节信息
///
public byte[] ContentBytes { get ; set ; }
///
/// 检查接收的数据是否合法
///
/// 令牌
/// 是否合法
public bool CheckHeadBytesLegal(byte[] token)
{
if(HeadBytes?.Length>=32)
{
return BasicFramework.SoftBasic.IsTwoBytesEquel(HeadBytes, 12, token, 0, 16);
}
else
{
return false;
}
}
///
/// 从头子节信息中解析出接下来需要接收的数据长度
///
/// 接下来的数据长度
public int GetContentLengthByHeadBytes()
{
if (HeadBytes?.Length >= 32)
{
return BitConverter.ToInt32(HeadBytes, 28);
}
else
{
return 0;
}
}
///
/// 获取头子节里的特殊标识
///
/// 标识信息
public int GetHeadBytesIdentity()
{
if (HeadBytes?.Length >= 32)
{
return BitConverter.ToInt32(HeadBytes, 4);
}
else
{
return 0;
}
}
///
/// 发送的字节信息
///
public byte[] SendBytes { get; set; }
}
}