//
// Created by Ht on 2019/8/8.
//

#ifndef JSONPROTOCOL_JRPARAMTABLE_H
#define JSONPROTOCOL_JRPARAMTABLE_H

#include "JRDpBaseObj.h"
#include "JRDpFieldTypes.h"
#include <qlibc/ByteUtils.h>

namespace jedp {

    class JE_API JRTransTableItem {
    public:
        explicit JRTransTableItem(unsigned char *buff, size_t bufflen, const Json::Value& value);
        ~JRTransTableItem();

        Json::Value   val;
        QByte * bytes = nullptr;
        size_t  bufflen = 0;
    };

    class JE_API JRParamTable :
            public JRDpBaseObj {

    public:
        ~JRParamTable() override ;
        explicit JRParamTable(const Json::Value &value, size_t bitCnt);

        bool isValid();
		JRDpFieldValueType getValueType();

        void transValueFromBuffer(const QByte *buff, size_t bufflen, Json::Value& value);
        size_t makeBufferFromValue(const Json::Value& val, QByte **buff);

    protected:
        /**
         *  转换表：
         *      二进制转换为字符串，  目标Value值
         */
        std::unordered_map<string,JRTransTableItem*>  mTransTable;
        JRDpFieldValueType mValueType = typeUnkown;
        size_t mBitLen = 0;
    };

}
#endif //JSONPROTOCOL_JRPARAMTABLE_H
