package org.ts.ddcs.itemdatatemplate.sw;

import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.common.util.BytesHelp;
import org.ts.ddcs.itemdatatemplate.DataItemTemplate;

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

/**
 * 0xF0
 * 长度固定为5 ，长度字节用F0表示
 * 格式 YYMMDDHHmm
 * 观测时间
 */
public class DataItemTemplateTT extends DataItemTemplate {

    @Override
    public int stream(byte[] data, int index) {
        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[] tm = BytesHelp.subBytes(data, index + count, 5);
            count += len;
            this.varcharValue = "20" + BytesHelp.byte2HexStr(tm) + "00";
            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);
    }

}
