package  org.ts.ddcs.datatemplate;


import org.ts.ddcs.dataStream.DataStreamAdapter;
import org.ts.ddcs.dataStream.DataStreamInterface;
import org.ts.ddcs.dataprocesser.DataProcesserInterface;
import org.ts.ddcs.filter.DataFilter;

/**
 * created by swp on 2017/8/23
 */
public class JtUnknownDataTemplate extends DataTemplate implements DataTemplateInterface {
    byte[] packet = null;

    @Override
    public void stream(DataStreamInterface s) {
        if (s.getDataTemplate().state() == TestState.UNKNOWN) {
            //所有模板都无法识别的情况下
            state = TestState.MATHCE;
            packet = new byte[1];
            packet[0] = s.getByte(0);
        } else {
            packet = new byte[0];
        }
    }


    @Override
    public void ready() {
        state = TestState.LOOK;
    }

    @Override
    public int length() {
        return 1;
    }

    @Override
    public TestState state() {
        return state;
    }

    @Override
    public int featureWeight() {
        return this.featureWeight;
    }

    @Override
    public void setFeatureWeight(int weight) {
        this.featureWeight = weight;
    }

    @Override
    public String getName() {
        return this.templateName;
    }

    @Override
    public void setName(String name) {
        this.templateName = name;
    }

    @Override
    public void bridgeDataProcessor(DataProcesserInterface processer, DataStreamAdapter dataStreamAdapter) {
        processer.packetReadly(packet, 0, packet.length, dataStreamAdapter, this);
    }

    @Override
    public boolean bridgeDataFilter(DataFilter filter, DataStreamAdapter dataStreamAdapter) {
        return filter.filter(packet, 0, packet.length, dataStreamAdapter, this);
    }

    @Override
    public byte[] funcCode() {
        return new byte[0];
    }

    @Override
    public byte[] rtuCode() {
        return new byte[0];
    }

    @Override
    public byte[] datagramContext() {
        return new byte[0];
    }

    @Override
    public String agreement() {
        return null;
    }

    @Override
    public boolean hasNext() {
        return false;
    }

    @Override
    public int packageTotal() {
        return 0;
    }

    @Override
    public int packageIndex() {
        return 0;
    }

    @Override
    public byte[] body() {
        return new byte[0];
    }

    @Override
    public boolean checkFeature(byte[] check, int pos, int length) {
        return true;
    }
}
