using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.HSL
{
///
/// ByteArray工具类,一半用来做报文拼接
///
public class ByteArray
{
#region 初始化
private List list = new List();
public byte[] array => list.ToArray();
#endregion
#region 属性
///
/// List集合
///
public List List
{
get { return list; }
}
///
/// Array数组
///
public byte[] Array
{
get { return list.ToArray(); }
}
///
/// 长度
///
public int Length
{
get { return list.Count; }
}
#endregion
#region 方法
///
/// 添加一个字节
///
///
public void Add(byte item)
{
list.Add(item);
}
///
/// 添加一个数组
///
///
public void Add(byte[] array)
{
list.AddRange(array);
}
///
/// 添加一个集合
///
///
public void Add(List list)
{
list.AddRange(list);
}
///
/// 连续添加两个字节
///
///
///
///
public void Add(byte item1, byte item2)
{
Add(new byte[] { item1, item2 });
}
///
/// 连续添加三个字节
///
///
///
///
public void Add(byte item1, byte item2, byte item3)
{
Add(new byte[] { item1, item2, item3 });
}
///
/// 连续添加四个字节
///
///
///
///
public void Add(byte item1, byte item2, byte item3, byte item4)
{
Add(new byte[] { item1, item2, item3, item4 });
}
///
/// 连续添加五个字节
///
///
///
///
public void Add(byte item1, byte item2, byte item3, byte item4, byte item5)
{
Add(new byte[] { item1, item2, item3, item4, item5 });
}
///
/// 添加一个ByteArray对象
///
///
public void Add(ByteArray byteArray)
{
Add(byteArray.Array);
}
///
/// 添加一个Short类型
///
///
public void Add(short value)
{
Add((byte)(value >> 8)); //后八位
Add((byte)value); //前八位
}
///
/// 添加一个UShort类型
///
///
public void Add(ushort value)
{
Add((byte)(value >> 8)); //后八位
Add((byte)value); //前八位
}
///
/// 清空
///
public void Clear()
{
list.Clear();
}
#endregion
}
}