123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef __CWSCODEC_H
- #define __CWSCODEC_H
- #include "CStructureInterpreter.h"
- #include "CMessage.h"
- #include "cJSON.h"
- #include "baseEx.h"
- #include <tuple>
- #include <string>
- namespace Chromium {
- typedef struct entity_def_struct {
- char entity_name[64];
- char class_name[64];
- unsigned int methodID;
- }entity_def_struct;
- class CWSCodec {
- public:
- CWSCodec();
- ~CWSCodec();
- static CWSCodec* getInstance();
- void init(const char* xmlPath);
- void setEntityHandler(CSmartPointer<IEntityFunction> p);
- std::pair<int, CMessage*> JsonToBuffer(std::string strJson);
- std::string BufferToJson(CMessage& msg, int replaceTransId = 0);
- std::string GetEntityName(std::string strJson);
- std::string GetClassName(std::string strJson);
- private:
- void DeserializeRequestAck(CMessage& msg, std::map<int, entity_def_struct>::iterator& it, int& rpos, cJSON* ret);
- void DeserializeEvent(CMessage& msg, std::vector<CMedthodInterface>* list, int& rpos, cJSON* ret);
- void DeserializeBase(CMessage& msg, CTransStruct& ts, int& rpos, cJSON* ret); //解析json->buffer
- char* getJsonStr(cJSON* pJson);
- std::pair<bool, std::tuple<CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, int>> GetLinkContex(cJSON* js, char* data, char* errmsg);
- void SerializeInfo(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeBeginSession(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeEndSession(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeRequest(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeRegister(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeUnregister(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- /* void SerializeEvent(cJSON* js, char* data, int* wpos, int* capacity, unsigned int* len);*/
- void SerializeLogEvent(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeLogWarn(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeSetVarReq(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeGetVarReq(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, char* dstValue, char* errmsg);
- template<typename T>
- bool GetCJsonIntergerValue(cJSON* root, const char* strKey, T& dstValue, char* errmsg);
- /*
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, short& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned short& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, bool& dstValue, char* errmsg);
- */
- bool GetCJsonObjectValue(cJSON* obj, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* obj, unsigned int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, double& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, CSimpleStringA& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, CSimpleStringW& dstValue, char* errmsg);
- bool GetCJsonArraySize(cJSON* root, const char* strKey, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* root, const char* strKey, std::string& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* obj, CSimpleStringA& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON* obj, CSimpleStringW& dstValue, char* errmsg);
- int UTF8ToUnicode(char* input, CSimpleStringW& output);
- void hexdump(const char* buf, const int num);
- private:
- CStructureInterpreter* mInterpreter;
- std::map<int, entity_def_struct>* m_AckCallbackList;
- std::map<int, std::vector<CMedthodInterface>*>* m_EventCallbackList;
- CMessage m_DeserializeCache;
- CMessage m_SerializeCache; //存在脏数据可能
- CSmartPointer<IEntityFunction> m_pFunc;
- };
- }
- #endif
|