package  org.ts.ddcs.dataStream;
import org.ts.ddcs.datatemplate.Template;
import org.ts.ddcs.dataprocesser.DataProcesserInterface;
import org.ts.ddcs.datatemplate.DataTemplateInterface;
import lombok.Data;

import java.util.List;

/**
 * 数据流
 * @author dylan
 */
@Data
public class DataSteam implements DataStreamInterface {
    public byte[] dataBuff;
    public DataTemplateInterface takecareTemplates;
    public List<DataProcesserInterface> dataProcesser;
    public Template template;

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

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

    @Override
    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 null;
    }

    @Override
    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 null;
    }

    @Override
    public DataTemplateInterface getDataTemplate() {
        return this.takecareTemplates;
    }
}
