package org.ts.ddcs.DataItemTemplate;

import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Tool.StringUtil;

import java.math.BigDecimal;

/**
 * 0x01
 * 断面面积
 */
@SuppressWarnings("all")
public class DataItemTemplateAC extends DataItemTemplate {
    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if(this.macth){
            return remain;
        }
        String flag = BytesHelp.byte2HexStr(remain,0,1);
        if(flag.equals(this.feture)){
            byte[] len =  BytesHelp.subBytes(remain, 1, 1);
            int dataTotalLen = len[0]>>3;
            int decimalLen = len[0]&7;
            byte[] buff=BytesHelp.subBytes(remain, 2, dataTotalLen);
            String hexStr=BytesHelp.byte2HexStr(buff);
            StringBuffer dataStr =  new StringBuffer(hexStr);
            if(decimalLen !=0){
                dataStr.insert(dataStr.length() - decimalLen, ".");
            }
            String value =  StringUtil.getPrettyNumber(dataStr.toString());
            this.bigDecimalValue = new BigDecimal(value);
            remain =  BytesHelp.subBytes(remain, 2+dataTotalLen, remain.length-(2+dataTotalLen));
            this.macth=true;
        }
        return remain;
    }

}
