mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 14:28:25 +08:00
Both Synchronous and Asynchronous need to build the same binary data package to write a bytes array. Move that package building out into a common function. Also use IEnumerable to pass in data instead of converting it to array and back multiple times. Not that happy with the whole ByteArray class, we could probably just use a MemoryStream instead.
64 lines
1.2 KiB
C#
64 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace S7.Net.Types
|
|
{
|
|
class ByteArray
|
|
{
|
|
List<byte> list = new List<byte>();
|
|
|
|
public byte this[int index]
|
|
{
|
|
get => list[index];
|
|
set => list[index] = value;
|
|
}
|
|
|
|
public byte[] Array
|
|
{
|
|
get { return list.ToArray(); }
|
|
}
|
|
|
|
public int Length => list.Count;
|
|
|
|
public ByteArray()
|
|
{
|
|
list = new List<byte>();
|
|
}
|
|
|
|
public ByteArray(int size)
|
|
{
|
|
list = new List<byte>(size);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
list = new List<byte>();
|
|
}
|
|
|
|
public void Add(byte item)
|
|
{
|
|
list.Add(item);
|
|
}
|
|
|
|
public void AddWord(ushort value)
|
|
{
|
|
list.Add((byte) (value >> 8));
|
|
list.Add((byte) value);
|
|
}
|
|
|
|
public void Add(byte[] items)
|
|
{
|
|
list.AddRange(items);
|
|
}
|
|
|
|
public void Add(IEnumerable<byte> items)
|
|
{
|
|
list.AddRange(items);
|
|
}
|
|
|
|
public void Add(ByteArray byteArray)
|
|
{
|
|
list.AddRange(byteArray.Array);
|
|
}
|
|
}
|
|
}
|