

#ifndef _MEDIAINFOPROTOCOL_H_
#define _MEDIAINFOPROTOCOL_H_

#include "MFSPublic.h"
#include "3rd/uvw.hpp"
#include "3rd/cJSON.h"

#include "Rtp808Service.h"
#include "BaseService.h"

namespace mfs
{
    /*
    {
        "data":{
            "msgHead":{
                "msgID":65001
            },
            "msgBody":{

            }
        }
    }
    */
    class MediaInfoProtocol:public BaseProtocol
    {
        private:
        std::pair<std::vector<uint8_t>, int> _readParam;
        int parseCLBSCommand();
        // 处理一条指令
        int executeCLBSCommand(const char* strJson);
        int getMessageID(cJSON* dataNode, int& msgID);

        // 执行
        int commandSetLogLevel(cJSON* dataNode);
        int commandSaveStreamData(cJSON* dataNode);
        int commandSelectStream(cJSON* dataNode);

        void parseStreamInfoJson(const std::vector<StreamInfo>& vec, std::string& result);

        public:
        MediaInfoProtocol(std::shared_ptr<uvw::Loop> loop, std::shared_ptr<uvw::TCPHandle> client, const std::string& name):BaseProtocol(loop, client, name)
        {
            client->userAlloc(true);
        }
        virtual void OnData(char* data, int dataLen) override;
        virtual void OnAlloc(uv_buf_t *buf, int suggested) override; 

        void SendMessage(const std::string& msg);
    };
}
#endif