package org.ts.ddcs.itemdatatemplate.sw;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.ts.ddcs.common.util.BytesHelp;
import org.ts.ddcs.itemdatatemplate.DataItemTemplate;

import java.util.List;
import java.util.Map;

/**
 * 0xF1
 * 长度固定为5 ，长度用F1表示
 * 测站编码
 */
@Slf4j
public class DataItemTemplateST extends DataItemTemplate {

    @Override
    public int stream(byte[] data, int index) {
        log.info("template {}",this.getClass().getName());
        this.macth = false;
        int count = 0;
        String flag = BytesHelp.byte2HexStr(data, index + count, 1);
        if (flag.toUpperCase().equals(this.feture.toUpperCase())) {
            count += 1;
            //ValueLen valueLen = Sw2014DatagramTemplateHelp.getValueLen(data, index + count);
            int len = 5;
            count += 1;
            byte[] stcd = BytesHelp.subBytes(data, index + count, len);
            count += len;
            this.varcharValue = BytesHelp.byte2HexStr(stcd);
            this.macth = true;
        }
        return count;
    }

    @Override
    public int stream(byte[] data, int index, int batchSize) {
        return 0;
    }

    @Override
    public String getStringValue() {
        return this.varcharValue;
    }

    @Override
    public void saveValue(Map<String, List<Map<String,Object>>> keyStore) {
        this.saveVarcharValues(keyStore);
    }

}
