using PlcSiemens.O;

namespace PlcSiemens.Protocol.Iso
{
    public class CoptParams
    {
        public byte PduSizeCode { get; set; }
        public byte PduSizeLen { get; set; }
        public byte PduSizeVal { get; set; }
        public byte[] Tsap { get; set; }
        public int TsapLenth { get; set; }

        public CoptParams()
        {
            Tsap = new byte[245]; // We don't know in advance these fields....
        }

        public void GetByteBuffer(ByteBuffer buffer)
        {
            buffer.Push(PduSizeCode);
            buffer.Push(PduSizeLen);
            buffer.Push(PduSizeVal);
            buffer.Push(Tsap, 0, TsapLenth);
        }

        public void InitByBuffer(ByteBuffer buffer)
        {
            PduSizeCode = buffer.PopByte();
            PduSizeLen = buffer.PopByte();
            PduSizeVal = buffer.PopByte();
            TsapLenth = buffer.WriteIndex - buffer.ReadIndex;
            Tsap = buffer.PopBytes(TsapLenth);
        }
    }

    // COTP Header for DATA EXCHANGE
}
