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

#ifndef JSONPROTOCOL_JRBYTETRANSFER_H
#define JSONPROTOCOL_JRBYTETRANSFER_H

#include <cstring>
#include <qlibc/qlibc.h>
#include "JRDpBaseObj.h"
#include "JRDpAction.h"

using namespace qlibc;

namespace jedp {

    class JE_API JRByteTransfer :
            public JRDpBaseObj {

    public:
        explicit JRByteTransfer(const QData& data);
        ~JRByteTransfer() override;

        bool deTransferBytes(const QByte *buff, size_t bufflen, QRByte &newbuff, size_t &newlen);
        size_t doTransferBytes(const QByte *orgBuff, size_t bufflen, QRByte &newbuff, size_t &newlen);

    private:
        QByte* signChar = nullptr;
        QByte* transChar = nullptr;
        JRDpAction *mAction = nullptr;

        unordered_map<QByte, bool> mCharToTrans;

        bool isCharToTransfer(QByte orgChar) const;
        void appendTransChar(QByte byte);

        QByte mNoTransStart = 0;
        QByte mNoTransEnd = 0;
    };

}


#endif //JSONPROTOCOL_JRBYTETRANSFER_H
