package com.mvc.netty;


import com.mvc.utils.NumberUtil;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Component;

/**
 * 报文上下行标识及长度解析
 */
@Component
public class BodyLengthParse {
    private Integer identifier;
    private Integer bodyLength ;

    public BodyLengthParse() {
        identifier = null;
        bodyLength = null;
    }

    public void parse(String hexStr) {
        if (StringUtil.isNullOrEmpty(hexStr)) {
            return;
        }

        String idenStr = NumberUtil.hexStringToBinaryString(hexStr);
        identifier = NumberUtil.binaryToDecimal(idenStr.substring(0, 4));
        bodyLength = NumberUtil.binaryToDecimal(idenStr.substring(4));
    }

    public Integer getIdentifier() {
        return identifier;
    }

    public Integer getBodyLength() {
        return bodyLength;
    }
}
