using B24SiemensPlugin.TCP;
using Buffer = System.Buffer;

namespace B24SiemensPlugin;

public class SiemensTCPSession : TcpSession
{
    public event Func<PLCPacket, PLCPacket>? OnPLCPacketReceived;
    public SiemensTCPSession(TcpServer server) : base(server)
    {
        

    }

    protected override void OnReceived(byte[] buffer, long offset, long size)
    {

        var data = new byte[size];
        Buffer.BlockCopy(buffer, (int)offset, data, 0, (int)size);
        PLCPacket packet = PLCPacket.Deserialize(data);
        if(OnPLCPacketReceived!=null)
            packet=OnPLCPacketReceived(packet);
        SendAsync(packet.Serialize());




    }
}