package org.ts.ddcs.itemdatatemplate.sw;


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

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

/**
 * 0x05
 * 小时.分钟 HH.mm
 * 时段长,降水、引排水、抽水历时
 */
public class DataItemTemplateDT 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)) {
            count += 1;
            ValueLen valueLen = Sw2014DatagramTemplateHelp.getValueLen(data, index + count);
            count += 1;
            this.varcharValue = BytesHelp.byte2HexStr(data, index + count, valueLen.getByteLen());
            count += valueLen.getByteLen();
            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);
    }
}
