package org.ts.ddcs.dataStream;
import lombok.Data;
import org.ts.ddcs.datatemplate.TestState;


/**
 * 数据流
 * @author dylan
 */
@Data
public class DataStream {
    private byte[] dataBuff;
    private TestState state;
    private Integer readSize;
    private String agreement;
    private DataStreamProcessor matchDataStreamProcessor;
    private Boolean crcOk;
    private byte[] respPacket;
    private String datagramCode;
    private Integer datagramSize;

    public int dataSize() {
        if (null != dataBuff) {
            return dataBuff.length;
        }
        return 0;
    }

    public byte getByte(int pos) {
        if (dataBuff != null && pos < dataBuff.length) {
            return dataBuff[pos];
        }
        return 0x00;
    }

    public byte[] getBytes(int length) {
        if (dataBuff != null && dataBuff.length >= length) {
            byte[] buf = new byte[length];
            System.arraycopy(dataBuff, 0, buf, 0, length);
            return buf;
        }
        return new byte[0];
    }

    public byte[] getBytes(int pos, int length) {
        if (dataBuff != null && dataBuff.length >= (pos + length)) {
            byte[] buf = new byte[length];
            System.arraycopy(dataBuff, pos, buf, 0, length);
            return buf;
        }
        return new byte[0];
    }

}
