|
@@ -17,1654 +17,1583 @@
|
|
|
#include <vector>
|
|
|
#include <string>
|
|
|
#include <memory>
|
|
|
+#include "baseEx.h"
|
|
|
|
|
|
#define DEFAULT_CAPACITY 20480
|
|
|
|
|
|
|
|
|
-namespace Chromium {
|
|
|
+namespace Chromium
|
|
|
+{
|
|
|
|
|
|
|
|
|
- static inline bool is_base64(CSimpleStringA str)
|
|
|
- {
|
|
|
- int num = str.GetLength() % 4;
|
|
|
- CSimpleStringA endStr = "";
|
|
|
- if (0 == num)
|
|
|
- return true;
|
|
|
- for (int i = 0; i < num; ++i)
|
|
|
- {
|
|
|
- endStr.Append("=");
|
|
|
- }
|
|
|
- return str.IsEndWith(endStr);
|
|
|
+static inline bool is_base64(CSimpleStringA str)
|
|
|
+{
|
|
|
+ int num = str.GetLength() % 4;
|
|
|
+ CSimpleStringA endStr = "";
|
|
|
+ if (0 == num)
|
|
|
+ return true;
|
|
|
+ for (int i = 0; i < num; ++i) {
|
|
|
+ endStr.Append("=");
|
|
|
}
|
|
|
-
|
|
|
- CWSCodec::CWSCodec() :m_DeserializeCache(MAX_TRANSFER_LEN), m_SerializeCache(MAX_TRANSFER_LEN)
|
|
|
- {
|
|
|
- DbgEx("CWSCodec Constuctor");
|
|
|
- m_AckCallbackList = new std::map<int, entity_def_struct>();
|
|
|
- m_EventCallbackList = new std::map<int, std::vector<CMedthodInterface>*>();
|
|
|
+ return str.IsEndWith(endStr);
|
|
|
+}
|
|
|
+
|
|
|
+CWSCodec::CWSCodec() :m_DeserializeCache(MAX_TRANSFER_LEN), m_SerializeCache(MAX_TRANSFER_LEN)
|
|
|
+{
|
|
|
+ DbgEx("CWSCodec Constuctor");
|
|
|
+ m_AckCallbackList = new std::map<int, entity_def_struct>();
|
|
|
+ m_EventCallbackList = new std::map<int, std::vector<CMedthodInterface>*>();
|
|
|
+}
|
|
|
+
|
|
|
+CWSCodec::~CWSCodec()
|
|
|
+{
|
|
|
+ if (mInterpreter) {
|
|
|
+ delete this->mInterpreter;
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+CWSCodec* CWSCodec::getInstance()
|
|
|
+{
|
|
|
+ //DbgEx("CWSCodec static method getInstance");
|
|
|
+ static CWSCodec obj;
|
|
|
+ return &obj;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::checkEntityHasService(std::string entityName)
|
|
|
+{
|
|
|
+ if (!mInterpreter)
|
|
|
+ return true;//默认有service
|
|
|
+
|
|
|
+ return mInterpreter->checkEntityInservice(entityName);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::setEntityHandler(CSmartPointer<IEntityFunction> p)
|
|
|
+{
|
|
|
+ this->m_pFunc = p;
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::init(const char* xmlPath)
|
|
|
+{
|
|
|
+ DbgEx("CWSCodec method -> init from %s", xmlPath);
|
|
|
+ mInterpreter = new CStructureInterpreter(xmlPath);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::DeserializeBase(CMessage& msg, CTransStruct& ts, int& rpos, cJSON* ret)
|
|
|
+{
|
|
|
+
|
|
|
+ std::list<CMethodParam>::iterator i = ts.mParamList.begin();
|
|
|
+ auto deleteCjson = [](cJSON* dst) {
|
|
|
+ if (NULL != dst)
|
|
|
+ cJSON_Delete(dst);
|
|
|
+ };
|
|
|
+ std::unique_ptr<cJSON, decltype(deleteCjson)> extendJs(cJSON_CreateObject(), deleteCjson);
|
|
|
+
|
|
|
+ std::string t_arr[] = { "messageType", "sessionID", "transID", "isEnd", "errorCode", "errorMsg" };
|
|
|
+ std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
|
|
|
- CWSCodec::~CWSCodec() {
|
|
|
- if (mInterpreter) {
|
|
|
- delete this->mInterpreter;
|
|
|
+#if (defined _WIN32 || defined _WIN64)
|
|
|
+ for each (auto paramInfo in ts.mParamList) {
|
|
|
+ for each (auto repeatName in c_repeatParamList) {
|
|
|
+#else
|
|
|
+ for (auto paramInfo : ts.mParamList) {
|
|
|
+ for (auto repeatName : c_repeatParamList) {
|
|
|
+#endif
|
|
|
+ if (paramInfo.mName == repeatName)
|
|
|
+ DbgEx("requestAck参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
}
|
|
|
}
|
|
|
+ //存在脏数据,不做另外处理
|
|
|
|
|
|
- CWSCodec* CWSCodec::getInstance() {
|
|
|
- DbgEx("CWSCodec static method getInstance");
|
|
|
- static CWSCodec obj;
|
|
|
- return &obj;
|
|
|
- }
|
|
|
-
|
|
|
- bool CWSCodec::checkEntityHasService(std::string entityName)
|
|
|
- {
|
|
|
- if (!mInterpreter)
|
|
|
- return true;//默认有service
|
|
|
-
|
|
|
- return mInterpreter->checkEntityInservice(entityName);
|
|
|
- }
|
|
|
-
|
|
|
- void CWSCodec::setEntityHandler(CSmartPointer<IEntityFunction> p) {
|
|
|
- this->m_pFunc = p;
|
|
|
- }
|
|
|
-
|
|
|
- void CWSCodec::init(const char* xmlPath) {
|
|
|
- DbgEx("CWSCodec method -> init from %s", xmlPath);
|
|
|
- mInterpreter = new CStructureInterpreter(xmlPath);
|
|
|
- }
|
|
|
-
|
|
|
- void CWSCodec::DeserializeBase(CMessage& msg, CTransStruct& ts, int& rpos, cJSON* ret) {
|
|
|
-
|
|
|
- std::list<CMethodParam>::iterator i = ts.mParamList.begin();
|
|
|
- auto deleteCjson = [](cJSON* dst) {
|
|
|
- if (NULL != dst) {
|
|
|
- cJSON_Delete(dst);
|
|
|
- //cJSON_free(dst);
|
|
|
- }
|
|
|
- };
|
|
|
- std::unique_ptr<cJSON, decltype(deleteCjson)> extendJs(cJSON_CreateObject(), deleteCjson);
|
|
|
-
|
|
|
- std::string t_arr[] = { "messageType", "sessionID", "transID", "isEnd", "errorCode", "errorMsg" };
|
|
|
- std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
-
|
|
|
+ try {
|
|
|
+ while (i != ts.mParamList.end()) {
|
|
|
+ bool t_isRepeat = false;
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto paramInfo in ts.mParamList)
|
|
|
- {
|
|
|
for each (auto repeatName in c_repeatParamList)
|
|
|
- {
|
|
|
#else
|
|
|
- for (auto paramInfo : ts.mParamList)
|
|
|
- {
|
|
|
for (auto repeatName : c_repeatParamList)
|
|
|
- {
|
|
|
#endif
|
|
|
- if (paramInfo.mName == repeatName)
|
|
|
- DbgEx("requestAck参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
- }
|
|
|
- }
|
|
|
- //存在脏数据,不做另外处理
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- while (i != ts.mParamList.end())
|
|
|
{
|
|
|
- bool t_isRepeat = false;
|
|
|
+ if (i->mName == repeatName) {
|
|
|
+ DbgEx("requestAck参数名字重复, error, %s", i->mName);
|
|
|
+ t_isRepeat = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (i->mType == "int") {
|
|
|
+ int d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "uint") {
|
|
|
+ unsigned int d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "short") {
|
|
|
+ short d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "ushort") {
|
|
|
+ unsigned short d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "char") {
|
|
|
+ char d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "uchar") {
|
|
|
+ unsigned char d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "int64") {
|
|
|
+ __int64 d = 0;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "uint64") {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto repeatName in c_repeatParamList)
|
|
|
+ unsigned __int64 d = 0;
|
|
|
#else
|
|
|
- for (auto repeatName : c_repeatParamList)
|
|
|
+ u_int64_t d = 0;
|
|
|
#endif
|
|
|
- {
|
|
|
- if (i->mName == repeatName)
|
|
|
- {
|
|
|
- DbgEx("requestAck参数名字重复, error, %s", i->mName);
|
|
|
- t_isRepeat = true;
|
|
|
- }
|
|
|
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "bool") {
|
|
|
+ bool d = false;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddBoolToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "double") {
|
|
|
+ double d = false;
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "string") {
|
|
|
+ CSimpleStringA d = "";
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), d);
|
|
|
+ cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ } else if (i->mType == "wstring") {
|
|
|
+ CSimpleStringW d = "";
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), CSimpleStringW2A(d));
|
|
|
+ cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), CSimpleStringW2A(d));
|
|
|
+ } else if (i->mType == "blob") {
|
|
|
+ int len = 0;
|
|
|
+ void* binData = NULL;
|
|
|
+ char* base64Data = NULL;
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
+ if (0 != len) {//协商好,H5对blob数据进行base64加密,chromium这里进行base64解密
|
|
|
+ binData = (char*)malloc(sizeof(char) * len);
|
|
|
+ ReadT(msg.getPayload(), binData, len, &rpos);
|
|
|
+ int base64Len = modp_b64_encode_len(len);
|
|
|
+ base64Data = (char*)malloc(sizeof(char) * base64Len);
|
|
|
+ modp_b64_encode(base64Data, (const char*)binData, len);
|
|
|
+ if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), base64Data);
|
|
|
+ cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), base64Data);
|
|
|
+ if (binData != NULL) {
|
|
|
+ free(binData);
|
|
|
+ binData = NULL;
|
|
|
+ }
|
|
|
+ if (base64Data != NULL) {
|
|
|
+ free(base64Data);
|
|
|
+ base64Data = NULL;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), "");
|
|
|
+ cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), "");
|
|
|
}
|
|
|
- if (i->mType == "int")
|
|
|
- {
|
|
|
- int d = 0;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "uint")
|
|
|
- {
|
|
|
- unsigned int d = 0;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "short") {
|
|
|
- short d = 0;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "ushort") {
|
|
|
- unsigned short d = 0;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "char") {
|
|
|
- char d = 0;
|
|
|
+ } else if (i->mType == "array_int") {
|
|
|
+ int len = 0;
|
|
|
+ int d = 0;
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
+
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; ++c) {
|
|
|
ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
}
|
|
|
- else if (i->mType == "uchar") {
|
|
|
- unsigned char d = 0;
|
|
|
+
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_bool") {
|
|
|
+ int len = 0;
|
|
|
+ bool d = 0;
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
+
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; ++c) {
|
|
|
ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateBool(d));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateBool(d));
|
|
|
}
|
|
|
- else if (i->mType == "int64") {
|
|
|
- __int64 d = 0;
|
|
|
+
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_uint") {
|
|
|
+ int len = 0;
|
|
|
+ unsigned int d = 0;
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
+
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; ++c) {
|
|
|
ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
}
|
|
|
- else if (i->mType == "uint64") {
|
|
|
+
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_uint64") {
|
|
|
+ int len = 0;
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- unsigned __int64 d = 0;
|
|
|
+ unsigned __int64 d = 0;
|
|
|
#else
|
|
|
- u_int64_t d = 0;
|
|
|
+ u_int64_t d = 0;
|
|
|
#endif
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; c++) {
|
|
|
ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
}
|
|
|
- else if (i->mType == "bool")
|
|
|
- {
|
|
|
- bool d = false;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddBoolToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "double")
|
|
|
- {
|
|
|
- double d = false;
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddNumberToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddNumberToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "string")
|
|
|
- {
|
|
|
- CSimpleStringA d = "";
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), d);
|
|
|
- cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), d);
|
|
|
- }
|
|
|
- else if (i->mType == "wstring")
|
|
|
- {
|
|
|
- CSimpleStringW d = "";
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), CSimpleStringW2A(d));
|
|
|
- cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), CSimpleStringW2A(d));
|
|
|
- }
|
|
|
- else if (i->mType == "blob")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- void* binData = NULL;
|
|
|
- char* base64Data = NULL;
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
- if (0 != len)
|
|
|
- {//协商好,H5对blob数据进行base64加密,chromium这里进行base64解密
|
|
|
- binData = (char*)malloc(sizeof(char) * len);
|
|
|
- ReadT(msg.getPayload(), binData, len, &rpos);
|
|
|
- int base64Len = modp_b64_encode_len(len);
|
|
|
- base64Data = (char*)malloc(sizeof(char) * base64Len);
|
|
|
- modp_b64_encode(base64Data, (const char*)binData, len);
|
|
|
- if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), base64Data);
|
|
|
- cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), base64Data);
|
|
|
- if (binData != NULL) {
|
|
|
- free(binData);
|
|
|
- binData = NULL;
|
|
|
- }
|
|
|
- if (base64Data != NULL) {
|
|
|
- free(base64Data);
|
|
|
- base64Data = NULL;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if (!t_isRepeat) cJSON_AddStringToObject(ret, i->mName.c_str(), "");
|
|
|
- cJSON_AddStringToObject(extendJs.get(), i->mName.c_str(), "");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (i->mType == "array_int")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- int d = 0;
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
-
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < len; ++c) {
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
- }
|
|
|
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
- }
|
|
|
- else if (i->mType == "array_uint")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- unsigned int d = 0;
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
-
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < len; ++c) {
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
- }
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_string") {
|
|
|
+ int len = 0;
|
|
|
+ CSimpleStringA d = "";
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; ++c) {
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateString(d));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(d));
|
|
|
}
|
|
|
- else if (i->mType == "array_uint64")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
-#if (defined _WIN32 || defined _WIN64)
|
|
|
- unsigned __int64 d = 0;
|
|
|
-#else
|
|
|
- u_int64_t d = 0;
|
|
|
-#endif
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
-
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < len; c++) {
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateNumber(d));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateNumber(d));
|
|
|
- }
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_wstring") {
|
|
|
+ int len = 0;
|
|
|
+ CSimpleStringW d = "";
|
|
|
+ ReadT(msg.getPayload(), len, &rpos);
|
|
|
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
- }
|
|
|
- else if (i->mType == "array_string")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- CSimpleStringA d = "";
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
-
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < len; ++c) {
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateString(d));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(d));
|
|
|
- }
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < len; ++c) {
|
|
|
+ ReadT(msg.getPayload(), d, &rpos);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateString(CSimpleStringW2A(d)));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(CSimpleStringW2A(d)));
|
|
|
}
|
|
|
- else if (i->mType == "array_wstring")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- CSimpleStringW d = "";
|
|
|
- ReadT(msg.getPayload(), len, &rpos);
|
|
|
-
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < len; ++c) {
|
|
|
- ReadT(msg.getPayload(), d, &rpos);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateString(CSimpleStringW2A(d)));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(CSimpleStringW2A(d)));
|
|
|
- }
|
|
|
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
- }
|
|
|
- else if (i->mType == "array_blob")
|
|
|
- {
|
|
|
- int array_size = 0;
|
|
|
- ReadT(msg.getPayload(), array_size, &rpos);//array size
|
|
|
- //DbgEx("array_blob 1:%d", msg.getBufferLength());
|
|
|
- //msg.hexToFile();
|
|
|
- cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
- for (int c = 0; c < array_size; ++c) {
|
|
|
- int tmpSize = 0;
|
|
|
- ReadT(msg.getPayload(), tmpSize, &rpos);
|
|
|
- if (0 != tmpSize)
|
|
|
- {
|
|
|
- void* binData = (char*)malloc(sizeof(char) * tmpSize);
|
|
|
- ReadT(msg.getPayload(), binData, tmpSize, &rpos);
|
|
|
- //DbgEx("array_blob 2:%d", tmpSize);
|
|
|
- int base64Len = modp_b64_encode_len(tmpSize);
|
|
|
- char* base64Data = (char*)malloc(sizeof(char) * base64Len);
|
|
|
- modp_b64_encode(base64Data, (const char*)binData, tmpSize);
|
|
|
- cJSON_AddItemToArray(tmpArray, cJSON_CreateString(base64Data));
|
|
|
- cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(base64Data));
|
|
|
- }
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else if (i->mType == "array_blob") {
|
|
|
+ int array_size = 0;
|
|
|
+ ReadT(msg.getPayload(), array_size, &rpos);//array size
|
|
|
+ //DbgEx("array_blob 1:%d", msg.getBufferLength());
|
|
|
+ //msg.hexToFile();
|
|
|
+ cJSON* tmpArray = cJSON_CreateArray(), * tmpArray2 = cJSON_CreateArray();
|
|
|
+ for (int c = 0; c < array_size; ++c) {
|
|
|
+ int tmpSize = 0;
|
|
|
+ ReadT(msg.getPayload(), tmpSize, &rpos);
|
|
|
+ if (0 != tmpSize) {
|
|
|
+ void* binData = (char*)malloc(sizeof(char) * tmpSize);
|
|
|
+ ReadT(msg.getPayload(), binData, tmpSize, &rpos);
|
|
|
+ //DbgEx("array_blob 2:%d", tmpSize);
|
|
|
+ int base64Len = modp_b64_encode_len(tmpSize);
|
|
|
+ char* base64Data = (char*)malloc(sizeof(char) * base64Len);
|
|
|
+ modp_b64_encode(base64Data, (const char*)binData, tmpSize);
|
|
|
+ cJSON_AddItemToArray(tmpArray, cJSON_CreateString(base64Data));
|
|
|
+ cJSON_AddItemToArray(tmpArray2, cJSON_CreateString(base64Data));
|
|
|
}
|
|
|
- if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
- cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
}
|
|
|
- else
|
|
|
- DbgEx("DeserializeBase error name -> type: %s -> %s", i->mName.c_str(), i->mType.c_str());
|
|
|
- ++i;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (...)
|
|
|
- {
|
|
|
- if (i != ts.mParamList.end())
|
|
|
- DbgEx("DeserializeBase error:%s, %s", i->mName.c_str(), i->mType.c_str());
|
|
|
+ if (!t_isRepeat) cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
|
|
|
+ cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
|
|
|
+ } else
|
|
|
+ DbgEx("DeserializeBase error name -> type: %s -> %s", i->mName.c_str(), i->mType.c_str());
|
|
|
+ ++i;
|
|
|
}
|
|
|
-
|
|
|
- char* unformateStr = cJSON_PrintUnformatted(extendJs.get());
|
|
|
- std::string dstPayLoad = unformateStr;
|
|
|
- delete[]unformateStr;
|
|
|
-
|
|
|
- cJSON_AddStringToObject(ret, PARAMLIST_HEAD, dstPayLoad.c_str());
|
|
|
+ } catch (...) {
|
|
|
+ if (i != ts.mParamList.end())
|
|
|
+ DbgEx("DeserializeBase error:%s, %s", i->mName.c_str(), i->mType.c_str());
|
|
|
}
|
|
|
|
|
|
- void CWSCodec::DeserializeRequestAck(CMessage & msg, std::map<int, entity_def_struct>::iterator & it, int& rpos, cJSON * ret) {
|
|
|
- entity_def_struct* p_struct = &it->second;
|
|
|
- CMedthodInterface* mi = mInterpreter->getFunctionInterface(p_struct->entity_name, p_struct->class_name, p_struct->methodID);
|
|
|
- CTransStruct ts = mi->mResponseInterpreter;
|
|
|
+ char* unformateStr = cJSON_PrintUnformatted(extendJs.get());
|
|
|
+ std::string dstPayLoad = unformateStr;
|
|
|
+ delete[]unformateStr;
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- DeserializeBase(msg, ts, rpos, ret);
|
|
|
+ cJSON_AddStringToObject(ret, PARAMLIST_HEAD, dstPayLoad.c_str());
|
|
|
}
|
|
|
- catch (...)
|
|
|
- {
|
|
|
- DbgEx("error DeserializeRequestAck: %s, %s, %s", p_struct->entity_name, p_struct->class_name, p_struct->methodID);
|
|
|
- std::string errorMsg;
|
|
|
+
|
|
|
+void CWSCodec::DeserializeRequestAck(CMessage & msg, std::map<int, entity_def_struct>::iterator & it, int& rpos, cJSON * ret)
|
|
|
+{
|
|
|
+ entity_def_struct* p_struct = &it->second;
|
|
|
+ CMedthodInterface* mi = mInterpreter->getFunctionInterface(p_struct->entity_name, p_struct->class_name, p_struct->methodID);
|
|
|
+ CTransStruct ts = mi->mResponseInterpreter;
|
|
|
+
|
|
|
+ try {
|
|
|
+ DeserializeBase(msg, ts, rpos, ret);
|
|
|
+ } catch (...) {
|
|
|
+ DbgEx("error DeserializeRequestAck: %s, %s, %s", p_struct->entity_name, p_struct->class_name, p_struct->methodID);
|
|
|
+ std::string errorMsg;
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto it in ts.mParamList)
|
|
|
+ for each (auto it in ts.mParamList)
|
|
|
#else
|
|
|
- for (auto it : ts.mParamList)
|
|
|
+ for (auto it : ts.mParamList)
|
|
|
#endif
|
|
|
- errorMsg += it.mName + "--" + it.mType + "_";
|
|
|
- DbgEx(errorMsg.c_str());
|
|
|
+ errorMsg += it.mName + "--" + it.mType + "_";
|
|
|
+ DbgEx(errorMsg.c_str());
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- throw std::exception("error DeserializeRequestAck");
|
|
|
+ throw std::exception("error DeserializeRequestAck");
|
|
|
#else
|
|
|
- throw std::exception(std::logic_error("error DeserializeRequestAck"));
|
|
|
+ throw std::exception(std::logic_error("error DeserializeRequestAck"));
|
|
|
#endif
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- void CWSCodec::DeserializeEvent(CMessage & msg,
|
|
|
- std::vector<CMedthodInterface>*list,
|
|
|
- int& rpos, cJSON * ret) {
|
|
|
- int eventID = msg.getEventID();
|
|
|
- if (NULL == list || eventID < 0 || eventID >= list->size())
|
|
|
- {
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
- CSimpleStringA errmsg = "";
|
|
|
- errmsg.Format("Cannot find the eventID = %d!", eventID);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", errmsg);
|
|
|
- return;
|
|
|
- }
|
|
|
- CMedthodInterface* mi = &(list->at(eventID));
|
|
|
- CTransStruct ts = mi->mResponseInterpreter;
|
|
|
- try
|
|
|
- {
|
|
|
- DeserializeBase(msg, ts, rpos, ret);
|
|
|
- }
|
|
|
- catch (...)
|
|
|
- {
|
|
|
- std::string errorMsg;
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::DeserializeEvent(CMessage & msg,
|
|
|
+ std::vector<CMedthodInterface>*list,
|
|
|
+ int& rpos, cJSON * ret)
|
|
|
+{
|
|
|
+ int eventID = msg.getEventID();
|
|
|
+ if (NULL == list || eventID < 0 || eventID >= list->size()) {
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
+ CSimpleStringA errmsg = "";
|
|
|
+ errmsg.Format("Cannot find the eventID = %d!", eventID);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", errmsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CMedthodInterface* mi = &(list->at(eventID));
|
|
|
+ CTransStruct ts = mi->mResponseInterpreter;
|
|
|
+ try {
|
|
|
+ DeserializeBase(msg, ts, rpos, ret);
|
|
|
+ } catch (...) {
|
|
|
+ std::string errorMsg;
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto it in ts.mParamList)
|
|
|
+ for each (auto it in ts.mParamList)
|
|
|
#else
|
|
|
- for (auto it : ts.mParamList)
|
|
|
+ for (auto it : ts.mParamList)
|
|
|
#endif
|
|
|
- errorMsg += it.mName + "--" + it.mType + "_";
|
|
|
+ errorMsg += it.mName + "--" + it.mType + "_";
|
|
|
|
|
|
- DbgEx(errorMsg.c_str());
|
|
|
+ DbgEx(errorMsg.c_str());
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- throw std::exception("error DeserializeRequestAck");
|
|
|
+ throw std::exception("error DeserializeRequestAck");
|
|
|
#else
|
|
|
- throw std::exception(std::logic_error("error DeserializeRequestAck"));
|
|
|
+ throw std::exception(std::logic_error("error DeserializeRequestAck"));
|
|
|
#endif
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- void receivehexdump(const char* buf, const int num) {
|
|
|
- char str[8192 * 2] = { 0 };
|
|
|
- int i = 0;
|
|
|
- char c[5] = { 0 };
|
|
|
- if (num > 1200)
|
|
|
- {
|
|
|
- for (i = 0; i < 50; i++)
|
|
|
- {
|
|
|
- sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
- strcat(str, c);
|
|
|
- }
|
|
|
- DbgEx("buffer too long to show!show pre 50 hex! receivehexdump hex buf len = %d : %s", num, str);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (i = 0; i < num; i++)
|
|
|
- {
|
|
|
+}
|
|
|
+
|
|
|
+void receivehexdump(const char* buf, const int num)
|
|
|
+{
|
|
|
+ char str[8192 * 2] = { 0 };
|
|
|
+ int i = 0;
|
|
|
+ char c[5] = { 0 };
|
|
|
+ if (num > 1200) {
|
|
|
+ for (i = 0; i < 50; i++) {
|
|
|
sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
strcat(str, c);
|
|
|
}
|
|
|
- DbgEx("receivehexdump hex buf len = %d : %s", num, str);
|
|
|
+ DbgEx("buffer too long to show!show pre 50 hex! receivehexdump hex buf len = %d : %s", num, str);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- std::string CWSCodec::BufferToJson(CMessage & msg, int replaceTransId) {
|
|
|
- //LOG_FUNCTION();
|
|
|
- int rpos = 16;
|
|
|
- cJSON* ret = cJSON_CreateObject();
|
|
|
- int errorCode = Error_Succeed;
|
|
|
- int userCode = 0;
|
|
|
- CSimpleStringA errorMsg = "";
|
|
|
-
|
|
|
- receivehexdump(msg.getPayload(), msg.getLength());
|
|
|
-
|
|
|
- if (msg.getLength() < 12) //End session len = 12
|
|
|
- return std::string(); // 丢弃消息
|
|
|
-
|
|
|
- // 通用反序列化
|
|
|
- cJSON_AddNumberToObject(ret, "messageType", msg.getMessageType());
|
|
|
- switch (msg.getMessageType()) {
|
|
|
- case RequestAck: //PKT_TYPE_REQACK
|
|
|
- cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
- cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
- cJSON_AddNumberToObject(ret, "isEnd", msg.getIsEnd());
|
|
|
- rpos += 1;
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
- ReadT(msg.getPayload(), userCode, &rpos);
|
|
|
- /** 业务端要求返回userCode,需要改动框架,依赖信创版本框架 1.0.7-dev15 [Gifur@2021119]*/
|
|
|
- cJSON_AddNumberToObject(ret, "userCode", userCode);
|
|
|
-#endif //RVC_OS_LINUX
|
|
|
- ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
- ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", errorMsg);
|
|
|
- break;
|
|
|
- case SessionAck:
|
|
|
- cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
- cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
- ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
- ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", errorMsg);
|
|
|
- break;
|
|
|
- case Event:
|
|
|
- cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
- cJSON_AddNumberToObject(ret, "eventID", msg.getEventID());
|
|
|
- cJSON_AddNumberToObject(ret, "signatureID", msg.getSignatureID());
|
|
|
- rpos += 8;
|
|
|
- break;
|
|
|
- case SetVarAck:
|
|
|
- cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
- cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
- ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
- ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", errorMsg);
|
|
|
- break;
|
|
|
- case GetVarAck:
|
|
|
- cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
- cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
- ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
- ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
- cJSON_AddStringToObject(ret, "value", errorMsg);
|
|
|
- break;
|
|
|
- default:
|
|
|
- errorCode = Error_Unexpect;
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", "未知消息类型");
|
|
|
- break;
|
|
|
- }
|
|
|
- DbgEx("BufferToJson -> messageType=%d, sessionID=%d, transID=%d, replaceTransID=%d", msg.getMessageType(), msg.getSessionID(), msg.getTransID(), replaceTransId);
|
|
|
-
|
|
|
+ for (i = 0; i < num; i++) {
|
|
|
+ sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
+ strcat(str, c);
|
|
|
+ }
|
|
|
+ DbgEx("receivehexdump hex buf len = %d : %s", num, str);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+std::string CWSCodec::BufferToJson(CMessage & msg, int replaceTransId)
|
|
|
+{
|
|
|
+ //replaceTransId==0,MessageType为8(Event),其他都应该有值
|
|
|
+ //LOG_FUNCTION();
|
|
|
+ int rpos = 16;
|
|
|
+ cJSON* ret = cJSON_CreateObject();
|
|
|
+ int errorCode = Error_Succeed;
|
|
|
+ int userCode = 0;
|
|
|
+ CSimpleStringA errorMsg = "";
|
|
|
+
|
|
|
+ receivehexdump(msg.getPayload(), msg.getLength());
|
|
|
+
|
|
|
+ if (msg.getLength() < 12) //End session len = 12
|
|
|
+ return std::string(); // 丢弃消息
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 通用反序列化
|
|
|
+ cJSON_AddNumberToObject(ret, "messageType", msg.getMessageType());
|
|
|
+ switch (msg.getMessageType()) {
|
|
|
+ case RequestAck: //PKT_TYPE_REQACK
|
|
|
+ cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
+ cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
+ cJSON_AddNumberToObject(ret, "isEnd", msg.getIsEnd());
|
|
|
+ rpos += 1;
|
|
|
+#if (defined _WIN32 || defined _WIN64)
|
|
|
+#else
|
|
|
+ ReadT(msg.getPayload(), userCode, &rpos);
|
|
|
+ /** 业务端要求返回userCode,需要改动框架,依赖信创版本框架 1.0.7-dev15 [Gifur@2021119]*/
|
|
|
+#endif
|
|
|
|
|
|
- // RequestAck 返回的有问题 要删除对应的回调list项
|
|
|
- if (Error_Succeed != errorCode && RequestAck == msg.getMessageType())
|
|
|
+ ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
+ ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
{
|
|
|
- std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
- if (m_AckCallbackList->end() != it)
|
|
|
- m_AckCallbackList->erase(it);
|
|
|
+ auto userCodeInfo = splitStrToUserCodeAndErrMsg(errorMsg.GetData());
|
|
|
+ if (userCodeInfo.first != 0)
|
|
|
+ cJSON_AddNumberToObject(ret, "userCode", userCodeInfo.first);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", userCodeInfo.second.c_str());
|
|
|
}
|
|
|
- // 有错误时直接返回 或者 不是RequestAck和Event时也可以返回
|
|
|
- if (Error_Succeed != errorCode ||
|
|
|
- (RequestAck != msg.getMessageType() && Event != msg.getMessageType()))
|
|
|
+ break;
|
|
|
+ case SessionAck:
|
|
|
+ cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
+ cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
+ ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
+ ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
{
|
|
|
- char* str = getJsonStr(ret);
|
|
|
- cJSON_Delete(ret);
|
|
|
- //cJSON_free(ret);
|
|
|
- std::string s(str);
|
|
|
- free(str);
|
|
|
- return s;
|
|
|
- }
|
|
|
-
|
|
|
- // 数据部分反序列化 RequestAck & Event有数据部分
|
|
|
- if (RequestAck == msg.getMessageType())
|
|
|
- { // Request用户自定义部分反序列化
|
|
|
- // 回调反序列化列表
|
|
|
- std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
-
|
|
|
- if (m_AckCallbackList->end() == it)
|
|
|
- {
|
|
|
- // 没有对应的request,无法反序列化
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", "Cannot find the request for the ack!");
|
|
|
- char* str = getJsonStr(ret);
|
|
|
- cJSON_Delete(ret);
|
|
|
- //cJSON_free(ret);
|
|
|
- std::string s(str);
|
|
|
- free(str);
|
|
|
- return s;
|
|
|
- }
|
|
|
- DeserializeRequestAck(msg, it, rpos, ret);
|
|
|
- m_AckCallbackList->erase(it);
|
|
|
+ auto userCodeInfo = splitStrToUserCodeAndErrMsg(errorMsg.GetData());
|
|
|
+ if (userCodeInfo.first != 0)
|
|
|
+ cJSON_AddNumberToObject(ret, "userCode", userCodeInfo.first);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", userCodeInfo.second.c_str());
|
|
|
}
|
|
|
- else if (Event == msg.getMessageType())
|
|
|
+ break;
|
|
|
+ case Event:
|
|
|
+ cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
+ cJSON_AddNumberToObject(ret, "eventID", msg.getEventID());
|
|
|
+ cJSON_AddNumberToObject(ret, "signatureID", msg.getSignatureID());
|
|
|
+ rpos += 8;
|
|
|
+ break;
|
|
|
+ case SetVarAck:
|
|
|
+ cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
+ cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
+ ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
+ ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
{
|
|
|
- // Event用户自定义部分反序列化
|
|
|
- std::map<int, std::vector<CMedthodInterface>*>::iterator iter = m_EventCallbackList->find(msg.getTransID());
|
|
|
- if (m_EventCallbackList->end() == iter)
|
|
|
- {
|
|
|
- // 没有对应的register, 无法反序列化
|
|
|
- cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
- cJSON_AddStringToObject(ret, "errorMsg", "Cannot find the register for the ack!");
|
|
|
- char* str = getJsonStr(ret);
|
|
|
- cJSON_Delete(ret);
|
|
|
- //cJSON_free(ret);
|
|
|
- std::string s(str);
|
|
|
- free(str);
|
|
|
- return s;
|
|
|
- }
|
|
|
- DeserializeEvent(msg, iter->second, rpos, ret);
|
|
|
+ auto userCodeInfo = splitStrToUserCodeAndErrMsg(errorMsg.GetData());
|
|
|
+ if (userCodeInfo.first != 0)
|
|
|
+ cJSON_AddNumberToObject(ret, "userCode", userCodeInfo.first);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", userCodeInfo.second.c_str());
|
|
|
}
|
|
|
+ break;
|
|
|
+ case GetVarAck:
|
|
|
+ cJSON_AddNumberToObject(ret, "sessionID", msg.getSessionID());
|
|
|
+ cJSON_AddNumberToObject(ret, "transID", replaceTransId != 0 ? replaceTransId : msg.getTransID());
|
|
|
+ ReadT(msg.getPayload(), errorCode, &rpos);
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
+ ReadT(msg.getPayload(), errorMsg, &rpos);
|
|
|
+ cJSON_AddStringToObject(ret, "value", errorMsg);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ errorCode = Error_Unexpect;
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", errorCode);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", "未知消息类型");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ DbgEx("BufferToJson -> messageType=%d(%s), sessionID=%d, transID=%d, replaceTransID=%d", msg.getMessageType(), GetMessageTypeString(msg.getMessageType()).c_str(),
|
|
|
+ msg.getSessionID(), msg.getTransID(), replaceTransId);
|
|
|
+
|
|
|
|
|
|
+ // RequestAck 返回的有问题 要删除对应的回调list项
|
|
|
+ if (Error_Succeed != errorCode && RequestAck == msg.getMessageType()) {
|
|
|
+ std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
+ if (m_AckCallbackList->end() != it)
|
|
|
+ m_AckCallbackList->erase(it);
|
|
|
+ }
|
|
|
+ // 有错误时直接返回 或者 不是RequestAck和Event时也可以返回
|
|
|
+ if (Error_Succeed != errorCode ||
|
|
|
+ (RequestAck != msg.getMessageType() && Event != msg.getMessageType())) {
|
|
|
char* str = getJsonStr(ret);
|
|
|
cJSON_Delete(ret);
|
|
|
- //cJSON_free(ret);
|
|
|
std::string s(str);
|
|
|
free(str);
|
|
|
- //delete []str;
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
- std::pair<int, CMessage*> CWSCodec::JsonToBuffer(std::string strJson) {
|
|
|
- cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
- char errmsg[1024] = { 0 };
|
|
|
+ // 数据部分反序列化 RequestAck & Event有数据部分
|
|
|
+ if (RequestAck == msg.getMessageType()) { // Request用户自定义部分反序列化
|
|
|
+ // 回调反序列化列表
|
|
|
+ std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
|
|
|
- unsigned int messageType = 0;
|
|
|
- GetCJsonIntergerValue(pJson, "messageType", messageType, errmsg);
|
|
|
-
|
|
|
- // 查找序列化结构 有用户定义数据部分的只有 Info 和 Request
|
|
|
- CMedthodInterface* mi = NULL;
|
|
|
- if (Request == messageType || Info == messageType)
|
|
|
- {
|
|
|
- entity_def_struct st = { 0 };
|
|
|
- GetCJsonObjectValue(pJson, "class", st.class_name, errmsg);
|
|
|
- GetCJsonObjectValue(pJson, "entity", st.entity_name, errmsg);
|
|
|
- GetCJsonIntergerValue(pJson, "methodID", st.methodID, errmsg);
|
|
|
- mi = mInterpreter->getFunctionInterface(st.entity_name, st.class_name, st.methodID); //get the mothod of the json
|
|
|
- if (NULL == mi) {
|
|
|
- DbgEx("JsonToBuffer : Entity or class not found in structure interpreter! entityName:%s, class_name:%s, methodId:%d", st.entity_name, st.class_name, st.methodID);
|
|
|
- return std::make_pair(messageType, nullptr);
|
|
|
- }
|
|
|
- else
|
|
|
- DbgEx("JsonToBuffer parse method success, entityName:%s, className:%s, methodID:%d, DstMethodName:%s, DstMethodParamNum:%d",
|
|
|
- st.entity_name, st.class_name, st.methodID, mi->mMethodName.c_str(), mi->mRequestInterpreter.mParamList.size()); //如出错,可对比方法名和变量数量
|
|
|
- if (Request == messageType) {
|
|
|
- // 维护回调列表 Request
|
|
|
- int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
- m_AckCallbackList->insert(std::pair<int, entity_def_struct>(transid, st));
|
|
|
- }
|
|
|
- }
|
|
|
- else if (Register == messageType)
|
|
|
- {
|
|
|
- std::vector<CMedthodInterface>* milist = NULL;
|
|
|
- entity_def_struct st = { 0 };
|
|
|
- unsigned int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
- GetCJsonObjectValue(pJson, "entity", st.entity_name, errmsg);
|
|
|
- milist = mInterpreter->getAllMessageInterface(st.entity_name);
|
|
|
- m_EventCallbackList->insert(std::pair<int, std::vector<CMedthodInterface>*>(transid, milist));
|
|
|
+ if (m_AckCallbackList->end() == it) {
|
|
|
+ // 没有对应的request,无法反序列化
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", "Cannot find the request for the ack!");
|
|
|
+ char* str = getJsonStr(ret);
|
|
|
+ cJSON_Delete(ret);
|
|
|
+ std::string s(str);
|
|
|
+ free(str);
|
|
|
+ return s;
|
|
|
}
|
|
|
- else if (Broadcast == messageType)
|
|
|
- {
|
|
|
- ChromiumBroadcast e = {};
|
|
|
- GetCJsonObjectValue(pJson, "data", e.broadcastJson, errmsg);
|
|
|
- if (e.broadcastJson.GetLength() < 20000)
|
|
|
- {
|
|
|
- auto rc = SpSendBroadcast(m_pFunc, eMsg_ChromiumBroadcast, eMsgSig_ChromiumBroadcast, e);
|
|
|
- if (Error_Succeed != rc)
|
|
|
- DbgEx("Broadcast Msg Error:%d", rc);
|
|
|
- }
|
|
|
- else
|
|
|
- DbgEx("json is too long, do not send out sp broadcast!");
|
|
|
- return std::make_pair(messageType, nullptr);
|
|
|
+ DeserializeRequestAck(msg, it, rpos, ret);
|
|
|
+ m_AckCallbackList->erase(it);
|
|
|
+ } else if (Event == msg.getMessageType()) {
|
|
|
+ // Event用户自定义部分反序列化
|
|
|
+ std::map<int, std::vector<CMedthodInterface>*>::iterator iter = m_EventCallbackList->find(msg.getTransID());
|
|
|
+ if (m_EventCallbackList->end() == iter) {
|
|
|
+ // 没有对应的register, 无法反序列化
|
|
|
+ cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
|
+ cJSON_AddStringToObject(ret, "errorMsg", "Cannot find the register for the ack!");
|
|
|
+ char* str = getJsonStr(ret);
|
|
|
+ cJSON_Delete(ret);
|
|
|
+ std::string s(str);
|
|
|
+ free(str);
|
|
|
+ return s;
|
|
|
}
|
|
|
- else if (Event == messageType)
|
|
|
- {// 维护回调列表 Event
|
|
|
- struct GeneralEventStruct
|
|
|
- {
|
|
|
- CSimpleStringA data;
|
|
|
- void Serialize(SpBuffer& Buf)
|
|
|
- {
|
|
|
- auto& buf = Buf & data;
|
|
|
- }
|
|
|
- };
|
|
|
- struct GeneralEventStruct e = {};
|
|
|
- unsigned int eventID = 0;
|
|
|
- unsigned int eventSign = 0;
|
|
|
- GetCJsonIntergerValue(pJson, "eventID", eventID, errmsg);
|
|
|
- GetCJsonIntergerValue(pJson, "eventSign", eventSign, errmsg);
|
|
|
- GetCJsonObjectValue(pJson, "data", e.data, errmsg);
|
|
|
- SpSendBroadcast(m_pFunc, eventID, eventSign, e);
|
|
|
- //if (0 < strlen(errmsg))
|
|
|
- // DbgEx("JsonToBuffer errmsg : %s", errmsg);
|
|
|
- cJSON_Delete(pJson);
|
|
|
- //cJSON_free(pJson);
|
|
|
+ DeserializeEvent(msg, iter->second, rpos, ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ char* str = getJsonStr(ret);
|
|
|
+ cJSON_Delete(ret);
|
|
|
+ std::string s(str);
|
|
|
+ free(str);
|
|
|
+ //delete []str;
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|
|
|
+std::pair<int, CMessage*> CWSCodec::JsonToBuffer(std::string strJson)
|
|
|
+{
|
|
|
+ cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
+ char errmsg[1024] = { 0 };
|
|
|
+
|
|
|
+ unsigned int messageType = 0;
|
|
|
+ GetCJsonIntergerValue(pJson, "messageType", messageType, errmsg);
|
|
|
+
|
|
|
+ // 查找序列化结构 有用户定义数据部分的只有 Info 和 Request
|
|
|
+ CMedthodInterface* mi = NULL;
|
|
|
+ if (Request == messageType || Info == messageType) {
|
|
|
+ entity_def_struct st = { 0 };
|
|
|
+ GetCJsonObjectValue(pJson, "class", st.class_name, errmsg);
|
|
|
+ GetCJsonObjectValue(pJson, "entity", st.entity_name, errmsg);
|
|
|
+ GetCJsonIntergerValue(pJson, "methodID", st.methodID, errmsg);
|
|
|
+ mi = mInterpreter->getFunctionInterface(st.entity_name, st.class_name, st.methodID); //get the mothod of the json
|
|
|
+ if (NULL == mi) {
|
|
|
+ DbgEx("JsonToBuffer : Entity or class not found in structure interpreter! entityName:%s, class_name:%s, methodId:%d", st.entity_name, st.class_name, st.methodID);
|
|
|
return std::make_pair(messageType, nullptr);
|
|
|
+ } else
|
|
|
+ DbgEx("JsonToBuffer parse method success, entityName:%s, className:%s, methodID:%d, DstMethodName:%s, DstMethodParamNum:%d",
|
|
|
+ st.entity_name, st.class_name, st.methodID, mi->mMethodName.c_str(), mi->mRequestInterpreter.mParamList.size()); //如出错,可对比方法名和变量数量
|
|
|
+ if (Request == messageType) {
|
|
|
+ // 维护回调列表 Request
|
|
|
+ int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
+ m_AckCallbackList->insert(std::pair<int, entity_def_struct>(transid, st));
|
|
|
}
|
|
|
-
|
|
|
- // 数据定义
|
|
|
- char* data = (char*)malloc(MAX_TRANSFER_LEN);
|
|
|
- assert(data != NULL);
|
|
|
- int capacity = MAX_TRANSFER_LEN;
|
|
|
- int wpos = 0;
|
|
|
- unsigned int len = 0;
|
|
|
- // 通用序列化
|
|
|
- // 预先写入长度0
|
|
|
- WriteT(data, len, &wpos, &capacity);
|
|
|
-
|
|
|
- //写入messageType,附带链路信息
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- int messageTypeWithControl = messageType | PKT_TYPE_CONTROL_LINKCONTEXT;
|
|
|
-#else
|
|
|
- int messageTypeWithControl = messageType;
|
|
|
-#endif
|
|
|
- WriteT(data, messageTypeWithControl, &wpos, &capacity);
|
|
|
-
|
|
|
- auto linkContexFun = [&]() {
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- //添加链路信息,放到原数据最后
|
|
|
- auto linkContextRet = GetLinkContex(pJson, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
- {
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), &wpos, &capacity);
|
|
|
- }
|
|
|
- else// 生成链路信息
|
|
|
+ } else if (Register == messageType) {
|
|
|
+ std::vector<CMedthodInterface>* milist = NULL;
|
|
|
+ entity_def_struct st = { 0 };
|
|
|
+ unsigned int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
+ GetCJsonObjectValue(pJson, "entity", st.entity_name, errmsg);
|
|
|
+ milist = mInterpreter->getAllMessageInterface(st.entity_name);
|
|
|
+ m_EventCallbackList->insert(std::pair<int, std::vector<CMedthodInterface>*>(transid, milist));
|
|
|
+ } else if (Broadcast == messageType) {
|
|
|
+ ChromiumBroadcast e = {};
|
|
|
+ GetCJsonObjectValue(pJson, "data", e.broadcastJson, errmsg);
|
|
|
+ if (e.broadcastJson.GetLength() < 20000) {
|
|
|
+ auto rc = SpSendBroadcast(m_pFunc, eMsg_ChromiumBroadcast, eMsgSig_ChromiumBroadcast, e);
|
|
|
+ if (Error_Succeed != rc)
|
|
|
+ DbgEx("Broadcast Msg Error:%d", rc);
|
|
|
+ } else
|
|
|
+ DbgEx("json is too long, do not send out sp broadcast!");
|
|
|
+ return std::make_pair(messageType, nullptr);
|
|
|
+ } else if (Event == messageType) {// 维护回调列表 Event
|
|
|
+ struct GeneralEventStruct
|
|
|
+ {
|
|
|
+ CSimpleStringA data;
|
|
|
+ void Serialize(SpBuffer& Buf)
|
|
|
{
|
|
|
- CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
- CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
- CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
- CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, &wpos, &capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, &wpos, &capacity);
|
|
|
- WriteT(data, spanId, &wpos, &capacity);
|
|
|
- WriteT(data, parentSpanId, &wpos, &capacity);
|
|
|
+ auto& buf = Buf & data;
|
|
|
}
|
|
|
-#endif
|
|
|
-
|
|
|
};
|
|
|
-
|
|
|
- // 根据不同的request进行序列化
|
|
|
- switch (messageType) {
|
|
|
- //info和request由于有其他信息,需要在数据中获得context
|
|
|
- case Info:
|
|
|
- SerializeInfo(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- break;
|
|
|
- case Request:
|
|
|
- SerializeRequest(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- break;
|
|
|
- case BeginSession:
|
|
|
- SerializeBeginSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case EndSession:
|
|
|
- SerializeEndSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case Register:
|
|
|
- SerializeRegister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case Unregister:
|
|
|
- SerializeUnregister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case LogEventMsgType:
|
|
|
- SerializeLogEvent(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case LogWarnMsgType:
|
|
|
- SerializeLogWarn(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case SetVarReq:
|
|
|
- SerializeSetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- case GetVarReq:
|
|
|
- SerializeGetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
- break;
|
|
|
- default:
|
|
|
- // warn
|
|
|
- break;
|
|
|
- };
|
|
|
-
|
|
|
- // 修改头部的消息长度
|
|
|
- int i = 0;
|
|
|
- len = wpos - 8;
|
|
|
- WriteT(data, len, &i, &capacity);
|
|
|
+ struct GeneralEventStruct e = {};
|
|
|
+ unsigned int eventID = 0;
|
|
|
+ unsigned int eventSign = 0;
|
|
|
+ GetCJsonIntergerValue(pJson, "eventID", eventID, errmsg);
|
|
|
+ GetCJsonIntergerValue(pJson, "eventSign", eventSign, errmsg);
|
|
|
+ GetCJsonObjectValue(pJson, "data", e.data, errmsg);
|
|
|
+ SpSendBroadcast(m_pFunc, eventID, eventSign, e);
|
|
|
//if (0 < strlen(errmsg))
|
|
|
- // DbgEx("JsonToBuffer errmsg : %s, len = %d", errmsg, len);
|
|
|
-
|
|
|
+ // DbgEx("JsonToBuffer errmsg : %s", errmsg);
|
|
|
cJSON_Delete(pJson);
|
|
|
- //cJSON_free(pJson);
|
|
|
-
|
|
|
- if (wpos < m_SerializeCache.getCMessageLength())
|
|
|
- {
|
|
|
- m_SerializeCache.clear();
|
|
|
- if (nullptr == memcpy(m_SerializeCache.getWriteableData(), data, wpos))
|
|
|
- DbgEx("memcpy err ");
|
|
|
- free(data);
|
|
|
- }
|
|
|
- else
|
|
|
- { //数据长度过长
|
|
|
- free(data);
|
|
|
- DbgEx("string too long, discard");
|
|
|
- return std::make_pair(messageType, nullptr);
|
|
|
- }
|
|
|
-
|
|
|
- return std::make_pair(messageType, &m_SerializeCache);
|
|
|
+ return std::make_pair(messageType, nullptr);
|
|
|
}
|
|
|
|
|
|
- char* CWSCodec::getJsonStr(cJSON * pJson) {
|
|
|
- char* pStr = cJSON_PrintUnformatted(pJson);
|
|
|
-
|
|
|
- if (NULL == pStr) {
|
|
|
- pStr = (char*)malloc(64);
|
|
|
- if (pStr) {
|
|
|
- strncpy(pStr, "{\"errorCode\":1540,\"errormsg\":\"Failed to encode json\"}", 64);
|
|
|
- }
|
|
|
- }
|
|
|
- return pStr;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- void CWSCodec::SerializeInfo(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
+ // 数据定义
|
|
|
+ char* data = (char*)malloc(MAX_TRANSFER_LEN);
|
|
|
+ assert(data != NULL);
|
|
|
+ int capacity = MAX_TRANSFER_LEN;
|
|
|
+ int wpos = 0;
|
|
|
+ unsigned int len = 0;
|
|
|
+ // 通用序列化
|
|
|
+ // 预先写入长度0
|
|
|
+ WriteT(data, len, &wpos, &capacity);
|
|
|
+
|
|
|
+ //写入messageType,附带链路信息
|
|
|
+#ifdef OPEN_LINKINFO
|
|
|
+ int messageTypeWithControl = messageType | PKT_TYPE_CONTROL_LINKCONTEXT;
|
|
|
+#else
|
|
|
+ int messageTypeWithControl = messageType;
|
|
|
+#endif
|
|
|
+ WriteT(data, messageTypeWithControl, &wpos, &capacity);
|
|
|
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "methodID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "signature")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
+ auto linkContexFun = [&]() {
|
|
|
#ifdef OPEN_LINKINFO
|
|
|
- auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
- {
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
- }
|
|
|
- else// 生成链路信息
|
|
|
+ //添加链路信息,放到原数据最后
|
|
|
+ auto linkContextRet = GetLinkContex(pJson, data, errmsg);
|
|
|
+ if (linkContextRet.first) {
|
|
|
+ WriteT(data, std::get<0>(linkContextRet.second), &wpos, &capacity);
|
|
|
+ WriteT(data, std::get<1>(linkContextRet.second), &wpos, &capacity);
|
|
|
+ WriteT(data, std::get<2>(linkContextRet.second), &wpos, &capacity);
|
|
|
+ WriteT(data, std::get<3>(linkContextRet.second), &wpos, &capacity);
|
|
|
+ } else// 生成链路信息
|
|
|
{
|
|
|
CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, wpos, capacity);
|
|
|
- WriteT(data, spanId, wpos, capacity);
|
|
|
- WriteT(data, parentSpanId, wpos, capacity);
|
|
|
+ WriteT(data, bussinessId, &wpos, &capacity);//为适配silverlight,默认写入就是unicode
|
|
|
+ WriteT(data, traceId, &wpos, &capacity);
|
|
|
+ WriteT(data, spanId, &wpos, &capacity);
|
|
|
+ WriteT(data, parentSpanId, &wpos, &capacity);
|
|
|
}
|
|
|
-#endif
|
|
|
-
|
|
|
- if (NULL == pI)
|
|
|
- {
|
|
|
- // 没有对应定义
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
- if (paramJs == NULL)
|
|
|
- {
|
|
|
- //detect the same name
|
|
|
- std::string t_arr[] = { "transID", "sessionID", "methodID", "signature", "timeout" ,"messageType","class","entity","methodID" };
|
|
|
- std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
-#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto paramInfo in pI->mRequestInterpreter.mParamList)
|
|
|
- {
|
|
|
- for each (auto repeatName in c_repeatParamList)
|
|
|
- {
|
|
|
#else
|
|
|
- for (auto paramInfo : pI->mRequestInterpreter.mParamList)
|
|
|
- {
|
|
|
- for (auto repeatName : c_repeatParamList)
|
|
|
- {
|
|
|
#endif
|
|
|
|
|
|
- if (paramInfo.mName == repeatName)
|
|
|
- DbgEx("request参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
- }
|
|
|
- }
|
|
|
- //如果存在重复,可能数据已经脏了,所以也不需要作删除参数处理
|
|
|
+ };
|
|
|
+
|
|
|
+ // 根据不同的request进行序列化
|
|
|
+ switch (messageType) {
|
|
|
+ //info和request由于有其他信息,需要在数据中获得context
|
|
|
+ case Info:
|
|
|
+ SerializeInfo(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ break;
|
|
|
+ case Request:
|
|
|
+ SerializeRequest(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ break;
|
|
|
+ case BeginSession:
|
|
|
+ SerializeBeginSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case EndSession:
|
|
|
+ SerializeEndSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case Register:
|
|
|
+ SerializeRegister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case Unregister:
|
|
|
+ SerializeUnregister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case LogEventMsgType:
|
|
|
+ SerializeLogEvent(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case LogWarnMsgType:
|
|
|
+ SerializeLogWarn(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case SetVarReq:
|
|
|
+ SerializeSetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ case GetVarReq:
|
|
|
+ SerializeGetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
+ linkContexFun();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // warn
|
|
|
+ break;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 修改头部的消息长度
|
|
|
+ int i = 0;
|
|
|
+ len = wpos - 8;
|
|
|
+ WriteT(data, len, &i, &capacity);
|
|
|
+ //if (0 < strlen(errmsg))
|
|
|
+ // DbgEx("JsonToBuffer errmsg : %s, len = %d", errmsg, len);
|
|
|
+
|
|
|
+ cJSON_Delete(pJson);
|
|
|
+
|
|
|
+
|
|
|
+ if (wpos < m_SerializeCache.getCMessageLength()) {
|
|
|
+ m_SerializeCache.clear();
|
|
|
+ if (nullptr == memcpy(m_SerializeCache.getWriteableData(), data, wpos))
|
|
|
+ DbgEx("memcpy err ");
|
|
|
+ free(data);
|
|
|
+ } else { //数据长度过长
|
|
|
+ free(data);
|
|
|
+ DbgEx("string too long, discard");
|
|
|
+ return std::make_pair(messageType, nullptr);
|
|
|
+ }
|
|
|
|
|
|
- paramJs = js;
|
|
|
- }
|
|
|
- GeneralSerialize(paramJs, data, wpos, capacity, pI, errmsg);
|
|
|
+ return std::make_pair(messageType, &m_SerializeCache);
|
|
|
+}
|
|
|
|
|
|
- return;
|
|
|
- }
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- std::pair<bool, std::tuple<CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, int>> CWSCodec::GetLinkContex(cJSON * js, char* data, char* errmsg)
|
|
|
- {
|
|
|
- /*
|
|
|
- typedef struct {
|
|
|
- char businessId[32]; //32
|
|
|
- char traceId[32]; //32
|
|
|
- char spanId[16]; //16
|
|
|
- char parentSpanId[16]; //16
|
|
|
- char timestamp[16]; //16
|
|
|
- int reservedControl;
|
|
|
- }link_context;
|
|
|
- */
|
|
|
-
|
|
|
- CSimpleStringA BussinessId, TraceId, SpanId, ParentSpanId, Timestamp;
|
|
|
- int ReservedControl;
|
|
|
- GetCJsonObjectValue(js, "BussinessId", BussinessId, errmsg);
|
|
|
- GetCJsonObjectValue(js, "TraceId", TraceId, errmsg);
|
|
|
- GetCJsonObjectValue(js, "SpanId", SpanId, errmsg);
|
|
|
- GetCJsonObjectValue(js, "ParentSpanId", ParentSpanId, errmsg);
|
|
|
- GetCJsonObjectValue(js, "Timestamp", Timestamp, errmsg);
|
|
|
- GetCJsonIntergerValue(js, "ReservedControl", ReservedControl, errmsg);
|
|
|
-
|
|
|
- if (BussinessId.GetLength() > 0 && BussinessId.GetLength() < 32 && TraceId.GetLength() == 32 && SpanId.GetLength() == 16 && ParentSpanId.GetLength() == 16)
|
|
|
- return std::make_pair(true, std::make_tuple(BussinessId, TraceId, SpanId, ParentSpanId, Timestamp, ReservedControl));
|
|
|
- else
|
|
|
- return std::make_pair(false, std::make_tuple("", "", "", "", "", 0));
|
|
|
+char* CWSCodec::getJsonStr(cJSON * pJson)
|
|
|
+{
|
|
|
+ char* pStr = cJSON_PrintUnformatted(pJson);
|
|
|
|
|
|
+ if (NULL == pStr) {
|
|
|
+ pStr = (char*)malloc(64);
|
|
|
+ if (pStr) {
|
|
|
+ strncpy(pStr, "{\"errorCode\":1540,\"errormsg\":\"Failed to encode json\"}", 64);
|
|
|
+ }
|
|
|
}
|
|
|
-#endif
|
|
|
+ return pStr;
|
|
|
+}
|
|
|
|
|
|
- void CWSCodec::SerializeBeginSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- GetCJsonObjectValue(js, "entity", s, errmsg);
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- GetCJsonObjectValue(js, "method", s, errmsg);
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- GetCJsonObjectValue(js, "class", s, errmsg);
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
|
|
|
- }
|
|
|
|
|
|
- void CWSCodec::SerializeEndSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- }
|
|
|
+void CWSCodec::SerializeInfo(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
|
|
|
- void CWSCodec::SerializeRequest(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- unsigned int i4 = 0;
|
|
|
- GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "sessionID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "methodID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "signature", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "timeout", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ i4 = cJSON_GetObjectItem(js, "methodID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ i4 = cJSON_GetObjectItem(js, "signature")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
#ifdef OPEN_LINKINFO
|
|
|
- auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
- {
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
- }
|
|
|
- else// 生成链路信息
|
|
|
- {
|
|
|
- CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
- CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
- CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
- CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, wpos, capacity);
|
|
|
- WriteT(data, spanId, wpos, capacity);
|
|
|
- WriteT(data, parentSpanId, wpos, capacity);
|
|
|
- }
|
|
|
+ auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
+ if (linkContextRet.first) {
|
|
|
+ WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
+ } else// 生成链路信息
|
|
|
+ {
|
|
|
+ CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
+ CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
+ CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
+ CSimpleStringA parentSpanId = "0";
|
|
|
+ WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
+ WriteT(data, traceId, wpos, capacity);
|
|
|
+ WriteT(data, spanId, wpos, capacity);
|
|
|
+ WriteT(data, parentSpanId, wpos, capacity);
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
- if (NULL == pI)
|
|
|
- {
|
|
|
- // 没有对应定义
|
|
|
- DbgEx("没有对应定义");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (NULL == pI) {
|
|
|
+ // 没有对应定义
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
- if (paramJs == NULL)
|
|
|
- {
|
|
|
- //detect the same name
|
|
|
- std::string t_arr[] = { "transID", "sessionID", "methodID", "signature", "timeout" ,"messageType","class","entity","methodID" };
|
|
|
- std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
+ auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
+ if (paramJs == NULL) {
|
|
|
+ //detect the same name
|
|
|
+ std::string t_arr[] = { "transID", "sessionID", "methodID", "signature", "timeout" ,"messageType","class","entity","methodID" };
|
|
|
+ std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- for each (auto paramInfo in pI->mRequestInterpreter.mParamList)
|
|
|
- {
|
|
|
- for each (auto repeatName in c_repeatParamList)
|
|
|
- {
|
|
|
+ for each (auto paramInfo in pI->mRequestInterpreter.mParamList) {
|
|
|
+ for each (auto repeatName in c_repeatParamList) {
|
|
|
#else
|
|
|
- for (auto paramInfo : pI->mRequestInterpreter.mParamList)
|
|
|
- {
|
|
|
- for (auto repeatName : c_repeatParamList)
|
|
|
- {
|
|
|
+ for (auto paramInfo : pI->mRequestInterpreter.mParamList) {
|
|
|
+ for (auto repeatName : c_repeatParamList) {
|
|
|
#endif
|
|
|
- if (paramInfo.mName == repeatName)
|
|
|
- DbgEx("request参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
- }
|
|
|
+
|
|
|
+ if (paramInfo.mName == repeatName)
|
|
|
+ DbgEx("request参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
}
|
|
|
- //如果存在重复,可能数据已经脏了,所以也不需要作删除参数处理
|
|
|
- paramJs = js;
|
|
|
}
|
|
|
- GeneralSerialize(paramJs, data, wpos, capacity, pI, errmsg);
|
|
|
- }
|
|
|
+ //如果存在重复,可能数据已经脏了,所以也不需要作删除参数处理
|
|
|
|
|
|
- void CWSCodec::SerializeRegister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- unsigned int i4 = 0;
|
|
|
- GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- GetCJsonObjectValue(js, "entity", s, errmsg);
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- s = "";
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- }
|
|
|
+ paramJs = js;
|
|
|
+ }
|
|
|
+ GeneralSerialize(paramJs, data, wpos, capacity, pI, errmsg);
|
|
|
|
|
|
- void CWSCodec::SerializeUnregister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#ifdef OPEN_LINKINFO
|
|
|
+std::pair<bool, std::tuple<CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, int>> CWSCodec::GetLinkContex(cJSON * js, char* data, char* errmsg)
|
|
|
+{
|
|
|
+ /*
|
|
|
+ typedef struct {
|
|
|
+ char businessId[32]; //32
|
|
|
+ char traceId[32]; //32
|
|
|
+ char spanId[16]; //16
|
|
|
+ char parentSpanId[16]; //16
|
|
|
+ char timestamp[16]; //16
|
|
|
+ int reservedControl;
|
|
|
+}link_context;
|
|
|
+ */
|
|
|
|
|
|
- void CWSCodec::SerializeLogEvent(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- }
|
|
|
+ CSimpleStringA BussinessId, TraceId, SpanId, ParentSpanId, Timestamp;
|
|
|
+ int ReservedControl;
|
|
|
+ GetCJsonObjectValue(js, "BussinessId", BussinessId, errmsg);
|
|
|
+ GetCJsonObjectValue(js, "TraceId", TraceId, errmsg);
|
|
|
+ GetCJsonObjectValue(js, "SpanId", SpanId, errmsg);
|
|
|
+ GetCJsonObjectValue(js, "ParentSpanId", ParentSpanId, errmsg);
|
|
|
+ GetCJsonObjectValue(js, "Timestamp", Timestamp, errmsg);
|
|
|
+ GetCJsonIntergerValue(js, "ReservedControl", ReservedControl, errmsg);
|
|
|
+
|
|
|
+ if (BussinessId.GetLength() > 0 && BussinessId.GetLength() < 32 && TraceId.GetLength() == 32 && SpanId.GetLength() == 16 && ParentSpanId.GetLength() == 16)
|
|
|
+ return std::make_pair(true, std::make_tuple(BussinessId, TraceId, SpanId, ParentSpanId, Timestamp, ReservedControl));
|
|
|
+ else
|
|
|
+ return std::make_pair(false, std::make_tuple("", "", "", "", "", 0));
|
|
|
+
|
|
|
+}
|
|
|
+#endif
|
|
|
|
|
|
- void CWSCodec::SerializeLogWarn(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+void CWSCodec::SerializeBeginSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ GetCJsonObjectValue(js, "entity", s, errmsg);
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+ GetCJsonObjectValue(js, "method", s, errmsg);
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+ GetCJsonObjectValue(js, "class", s, errmsg);
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeEndSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeRequest(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ unsigned int i4 = 0;
|
|
|
+ GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ GetCJsonIntergerValue(js, "sessionID", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ GetCJsonIntergerValue(js, "methodID", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ GetCJsonIntergerValue(js, "signature", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ GetCJsonIntergerValue(js, "timeout", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+#ifdef OPEN_LINKINFO
|
|
|
+ auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
+ if (linkContextRet.first) {
|
|
|
+ WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
+ WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
+ } else// 生成链路信息
|
|
|
+ {
|
|
|
+ CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
+ CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
+ CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
+ CSimpleStringA parentSpanId = "0";
|
|
|
+ WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
+ WriteT(data, traceId, wpos, capacity);
|
|
|
+ WriteT(data, spanId, wpos, capacity);
|
|
|
+ WriteT(data, parentSpanId, wpos, capacity);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
- void CWSCodec::SerializeSetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- s = cJSON_GetObjectItem(js, "value")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+ if (NULL == pI) {
|
|
|
+ // 没有对应定义
|
|
|
+ DbgEx("没有对应定义");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- using namespace std;
|
|
|
- vector<string> split(const string & s, const string & seperator) {
|
|
|
- vector<string> result;
|
|
|
- typedef string::size_type string_size;
|
|
|
- string_size i = 0;
|
|
|
-
|
|
|
- while (i != s.size()) {
|
|
|
- //找到字符串中首个不等于分隔符的字母;
|
|
|
- int flag = 0;
|
|
|
- while (i != s.size() && flag == 0) {
|
|
|
- flag = 1;
|
|
|
- for (string_size x = 0; x < seperator.size(); ++x)
|
|
|
- if (s[i] == seperator[x]) {
|
|
|
- ++i;
|
|
|
- flag = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //找到又一个分隔符,将两个分隔符之间的字符串取出;
|
|
|
- flag = 0;
|
|
|
- string_size j = i;
|
|
|
- while (j != s.size() && flag == 0) {
|
|
|
- for (string_size x = 0; x < seperator.size(); ++x)
|
|
|
- if (s[j] == seperator[x]) {
|
|
|
- flag = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (flag == 0)
|
|
|
- ++j;
|
|
|
+ auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
+ if (paramJs == NULL) {
|
|
|
+ //detect the same name
|
|
|
+ std::string t_arr[] = { "transID", "sessionID", "methodID", "signature", "timeout" ,"messageType","class","entity","methodID" };
|
|
|
+ std::vector<std::string> c_repeatParamList(t_arr, t_arr + sizeof(t_arr) / sizeof(t_arr[0]));
|
|
|
+#if (defined _WIN32 || defined _WIN64)
|
|
|
+ for each (auto paramInfo in pI->mRequestInterpreter.mParamList) {
|
|
|
+ for each (auto repeatName in c_repeatParamList) {
|
|
|
+#else
|
|
|
+ for (auto paramInfo : pI->mRequestInterpreter.mParamList) {
|
|
|
+ for (auto repeatName : c_repeatParamList) {
|
|
|
+#endif
|
|
|
+ if (paramInfo.mName == repeatName)
|
|
|
+ DbgEx("request参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
}
|
|
|
- if (i != j) {
|
|
|
- result.emplace_back(s.substr(i, j - i));
|
|
|
- i = j;
|
|
|
+ }
|
|
|
+ //如果存在重复,可能数据已经脏了,所以也不需要作删除参数处理
|
|
|
+ paramJs = js;
|
|
|
}
|
|
|
+ GeneralSerialize(paramJs, data, wpos, capacity, pI, errmsg);
|
|
|
}
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- void CWSCodec::SerializeGetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
+void CWSCodec::SerializeRegister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ unsigned int i4 = 0;
|
|
|
+ GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ GetCJsonObjectValue(js, "entity", s, errmsg);
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+ s = "";
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeUnregister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeLogEvent(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ i4 = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeLogWarn(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ i4 = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeSetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+ s = cJSON_GetObjectItem(js, "value")->valuestring;
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+using namespace std;
|
|
|
+vector<string> split(const string & s, const string & seperator)
|
|
|
+{
|
|
|
+ vector<string> result;
|
|
|
+ typedef string::size_type string_size;
|
|
|
+ string_size i = 0;
|
|
|
+
|
|
|
+ while (i != s.size()) {
|
|
|
+ //找到字符串中首个不等于分隔符的字母;
|
|
|
+ int flag = 0;
|
|
|
+ while (i != s.size() && flag == 0) {
|
|
|
+ flag = 1;
|
|
|
+ for (string_size x = 0; x < seperator.size(); ++x)
|
|
|
+ if (s[i] == seperator[x]) {
|
|
|
+ ++i;
|
|
|
+ flag = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- void CWSCodec::GeneralSerialize(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- std::list<CMethodParam>::iterator it = pI->mRequestInterpreter.mParamList.begin();
|
|
|
+ //找到又一个分隔符,将两个分隔符之间的字符串取出;
|
|
|
+ flag = 0;
|
|
|
+ string_size j = i;
|
|
|
+ while (j != s.size() && flag == 0) {
|
|
|
+ for (string_size x = 0; x < seperator.size(); ++x)
|
|
|
+ if (s[j] == seperator[x]) {
|
|
|
+ flag = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (flag == 0)
|
|
|
+ ++j;
|
|
|
+ }
|
|
|
+ if (i != j) {
|
|
|
+ result.emplace_back(s.substr(i, j - i));
|
|
|
+ i = j;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::SerializeGetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ int i4 = 0;
|
|
|
+ i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
+ WriteT(data, i4, wpos, capacity);
|
|
|
+ CSimpleStringA s = "";
|
|
|
+ s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
+ WriteT(data, s, wpos, capacity);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void CWSCodec::GeneralSerialize(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+{
|
|
|
+ std::list<CMethodParam>::iterator it = pI->mRequestInterpreter.mParamList.begin();
|
|
|
+
|
|
|
+ auto dealBlob = [](CSimpleString src, char* bin)->std::pair <int, std::string> {
|
|
|
+ if (!is_base64(src))
|
|
|
+ return std::make_pair(-1, "base64 decode failed!");
|
|
|
+
|
|
|
+ int binlen = modp_b64_decode_len(src.GetLength()) - 1;//二进制流,不需要结束
|
|
|
+
|
|
|
+ if (binlen > 0) {
|
|
|
+ bin = new char[binlen + 1];
|
|
|
+ ZeroMemory(bin, binlen + 1);
|
|
|
+ modp_b64_decode(bin, src.GetData(), src.GetLength());//binlen有可能比bin长
|
|
|
+ short objectNum = *((short*)bin);
|
|
|
+ int extendLen = 2 + objectNum * 2;
|
|
|
+ int dstLen = binlen - (binlen - extendLen) % 4;
|
|
|
+ return std::make_pair(dstLen, "");
|
|
|
+ } else
|
|
|
+ return std::make_pair(-1, "error binlen");
|
|
|
+ };
|
|
|
+
|
|
|
+ while (it != pI->mRequestInterpreter.mParamList.end()) {
|
|
|
+ if (it->mType == "int") {
|
|
|
+ unsigned int d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "bool") {
|
|
|
+ bool d = true;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "double") {
|
|
|
+ double d = 0;
|
|
|
+ GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "char") {
|
|
|
+ char d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "short") {
|
|
|
+ short d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "ushort") {
|
|
|
+ unsigned short d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "uint") {
|
|
|
+ unsigned int d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "int64") {
|
|
|
+ __int64 d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "uint64") {
|
|
|
+#if (defined _WIN32 || defined _WIN64)
|
|
|
+ unsigned __int64 d = 0;
|
|
|
+#else
|
|
|
+ u_int64_t d = 0;
|
|
|
+#endif
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "uchar") {
|
|
|
+ unsigned char d = 0;
|
|
|
+ GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "string") {
|
|
|
+ CSimpleStringA d = "";
|
|
|
+ GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ //DbgEx("GeneralSerialize string %s -> %s", it->mName.c_str(), d);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "wstring") {
|
|
|
+ CSimpleStringW d = "";
|
|
|
+ GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "blob") {
|
|
|
+ CSimpleStringA d = "";
|
|
|
+ GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
+
|
|
|
+ if (!is_base64(d)) {
|
|
|
+ strcat(errmsg, "base64 decode failed!");
|
|
|
+ ++it;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- auto dealBlob = [](CSimpleString src, char* bin)->std::pair <int, std::string> {
|
|
|
- if (!is_base64(src))
|
|
|
- return std::make_pair(-1, "base64 decode failed!");
|
|
|
+ int binlen = modp_b64_decode_len(d.GetLength()) - 1;//二进制流,不需要结束
|
|
|
|
|
|
- int binlen = modp_b64_decode_len(src.GetLength()) - 1;//二进制流,不需要结束
|
|
|
|
|
|
- if (binlen > 0)
|
|
|
- {
|
|
|
+ char* bin = NULL;
|
|
|
+ if (binlen > 0) {
|
|
|
bin = new char[binlen + 1];
|
|
|
ZeroMemory(bin, binlen + 1);
|
|
|
- modp_b64_decode(bin, src.GetData(), src.GetLength());//binlen有可能比bin长
|
|
|
+ modp_b64_decode(bin, d.GetData(), d.GetLength());//binlen有可能比bin长
|
|
|
short objectNum = *((short*)bin);
|
|
|
int extendLen = 2 + objectNum * 2;
|
|
|
int dstLen = binlen - (binlen - extendLen) % 4;
|
|
|
- return std::make_pair(dstLen, "");
|
|
|
- }
|
|
|
- else
|
|
|
- return std::make_pair(-1, "error binlen");
|
|
|
- };
|
|
|
-
|
|
|
- while (it != pI->mRequestInterpreter.mParamList.end()) {
|
|
|
- if (it->mType == "int")
|
|
|
- {
|
|
|
- unsigned int d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "bool")
|
|
|
- {
|
|
|
- bool d = true;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "double")
|
|
|
- {
|
|
|
- double d = 0;
|
|
|
- GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "char")
|
|
|
- {
|
|
|
- char d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "short")
|
|
|
- {
|
|
|
- short d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "ushort")
|
|
|
- {
|
|
|
- unsigned short d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "uint")
|
|
|
- {
|
|
|
- unsigned int d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "int64")
|
|
|
- {
|
|
|
- __int64 d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "uint64")
|
|
|
- {
|
|
|
-#if (defined _WIN32 || defined _WIN64)
|
|
|
- unsigned __int64 d = 0;
|
|
|
-#else
|
|
|
- u_int64_t d = 0;
|
|
|
-#endif
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "uchar")
|
|
|
- {
|
|
|
- unsigned char d = 0;
|
|
|
- GetCJsonIntergerValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "string")
|
|
|
- {
|
|
|
- CSimpleStringA d = "";
|
|
|
- GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- //DbgEx("GeneralSerialize string %s -> %s", it->mName.c_str(), d);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "wstring")
|
|
|
- {
|
|
|
- CSimpleStringW d = "";
|
|
|
- GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- else if (it->mType == "blob")
|
|
|
- {
|
|
|
- CSimpleStringA d = "";
|
|
|
- GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
|
|
|
|
|
|
- if (!is_base64(d)) {
|
|
|
- strcat(errmsg, "base64 decode failed!");
|
|
|
- ++it;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- int binlen = modp_b64_decode_len(d.GetLength()) - 1;//二进制流,不需要结束
|
|
|
-
|
|
|
-
|
|
|
- char* bin = NULL;
|
|
|
- if (binlen > 0)
|
|
|
- {
|
|
|
- bin = new char[binlen + 1];
|
|
|
- ZeroMemory(bin, binlen + 1);
|
|
|
- modp_b64_decode(bin, d.GetData(), d.GetLength());//binlen有可能比bin长
|
|
|
- short objectNum = *((short*)bin);
|
|
|
- int extendLen = 2 + objectNum * 2;
|
|
|
- int dstLen = binlen - (binlen - extendLen) % 4;
|
|
|
+ std::string tempBlob = "blob len , " + std::to_string((ULONGLONG)dstLen) + ":";
|
|
|
+ for (size_t i = 0; i < dstLen; i++)
|
|
|
+ tempBlob += std::to_string((ULONGLONG)(unsigned char)bin[i]) + ",";
|
|
|
|
|
|
- std::string tempBlob = "blob len , " + std::to_string((ULONGLONG)dstLen) + ":";
|
|
|
- for (size_t i = 0; i < dstLen; i++)
|
|
|
- tempBlob += std::to_string((ULONGLONG)(unsigned char)bin[i]) + ",";
|
|
|
+ DbgEx(tempBlob.c_str());
|
|
|
+ WriteT(data, dstLen, wpos, capacity);
|
|
|
+ WriteT(data, bin, wpos, capacity, dstLen);
|
|
|
|
|
|
- DbgEx(tempBlob.c_str());
|
|
|
- WriteT(data, dstLen, wpos, capacity);
|
|
|
- WriteT(data, bin, wpos, capacity, dstLen);
|
|
|
+ delete[]bin;
|
|
|
+ bin = NULL;
|
|
|
+ }
|
|
|
|
|
|
- delete[]bin;
|
|
|
- bin = NULL;
|
|
|
+ } else if (it->mType == "array_int") {
|
|
|
+ //DbgEx("array int -> ");
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ //DbgEx("array int -> true len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ unsigned int d = 0;
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg))
|
|
|
+ break;
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ DbgEx("array int -> false len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- else if (it->mType == "array_int")
|
|
|
- {
|
|
|
- //DbgEx("array int -> ");
|
|
|
- int len = 0;
|
|
|
- if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
- //DbgEx("array int -> true len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- unsigned int d = 0;
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
- if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
- DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
- break;
|
|
|
- }
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgEx("array int -> false len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
+ } else if (it->mType == "array_bool") {
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ unsigned int d = 0;
|
|
|
+ bool dst = false;
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg))
|
|
|
+ break;
|
|
|
+ dst = d;
|
|
|
+ WriteT(data, dst, wpos, capacity);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ DbgEx("array bool -> false len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- else if (it->mType == "array_uint")
|
|
|
- {
|
|
|
- //DbgEx("array uint -> ");
|
|
|
- int len = 0;
|
|
|
- if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
- //DbgEx("array int -> true len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- unsigned int d = 0;
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
- if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
- DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "array_uint") {
|
|
|
+ //DbgEx("array uint -> ");
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ //DbgEx("array int -> true len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ unsigned int d = 0;
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
+ DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
+ break;
|
|
|
}
|
|
|
+
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
}
|
|
|
- else {
|
|
|
- DbgEx("array int -> false len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ DbgEx("array int -> false len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- else if (it->mType == "array_string")
|
|
|
- {
|
|
|
- //DbgEx("array string -> ");
|
|
|
- int len = 0;
|
|
|
- if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
- //DbgEx("array string -> true len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- CSimpleStringA d = "";
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
- if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
- DbgEx("array string[%d] failed %s, break", i, errmsg);
|
|
|
- break;
|
|
|
- }
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "array_string") {
|
|
|
+ //DbgEx("array string -> ");
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ //DbgEx("array string -> true len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ CSimpleStringA d = "";
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
+ DbgEx("array string[%d] failed %s, break", i, errmsg);
|
|
|
+ break;
|
|
|
}
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
}
|
|
|
- else {
|
|
|
- DbgEx("array string -> false len = %d", len);
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ DbgEx("array string -> false len = %d", len);
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- else if (it->mType == "array_wstring")
|
|
|
- {
|
|
|
- int len = 0;
|
|
|
- if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- CSimpleStringW d = "";
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
- if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
- DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
- break;
|
|
|
- }
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "array_wstring") {
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ CSimpleStringW d = "";
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
+ DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
+ break;
|
|
|
}
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
}
|
|
|
- else {
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- else if (it->mType == "array_blob") {
|
|
|
- int len = 0;
|
|
|
- if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- CSimpleStringW d = "";
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
- if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
- DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
- break;
|
|
|
- }
|
|
|
- WriteT(data, d, wpos, capacity);
|
|
|
+ } else if (it->mType == "array_blob") {
|
|
|
+ int len = 0;
|
|
|
+ if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
+ CSimpleStringW d = "";
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ if (!GetCJsonObjectValue(cJSON_GetArrayItem(cJSON_GetObjectItem(js, it->mName.c_str()), i), d, errmsg)) {
|
|
|
+ DbgEx("[%d] failed %s, break", i, errmsg);
|
|
|
+ break;
|
|
|
}
|
|
|
+ WriteT(data, d, wpos, capacity);
|
|
|
}
|
|
|
- else {
|
|
|
- WriteT(data, len, wpos, capacity);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgEx("GeneralSerialize error name -> type: %s -> %s", it->mName, it->mType);
|
|
|
+ } else {
|
|
|
+ WriteT(data, len, wpos, capacity);
|
|
|
}
|
|
|
- ++it;
|
|
|
+ } else {
|
|
|
+ DbgEx("GeneralSerialize error name -> type: %s -> %s", it->mName.c_str(), it->mType.c_str());
|
|
|
}
|
|
|
+ ++it;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, char* dstValue, char* errmsg) {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, char* dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- strncpy(dstValue, pTmpNode->valuestring, strlen(pTmpNode->valuestring));
|
|
|
+ strncpy(dstValue, pTmpNode->valuestring, strlen(pTmpNode->valuestring));
|
|
|
#else
|
|
|
- strncpy(dstValue, pTmpNode->valuestring, strlen(pTmpNode->valuestring) + 1);
|
|
|
+ strncpy(dstValue, pTmpNode->valuestring, strlen(pTmpNode->valuestring) + 1);
|
|
|
#endif
|
|
|
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- strncpy(dstValue, "", strlen(""));
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ strncpy(dstValue, "", strlen(""));
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, CSimpleStringA & dstValue, char* errmsg) {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, CSimpleStringA & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- dstValue = pTmpNode->valuestring;
|
|
|
+ dstValue = pTmpNode->valuestring;
|
|
|
#else
|
|
|
- CSimpleStringW wStr = "";
|
|
|
- UTF8ToUnicode(pTmpNode->valuestring, wStr);
|
|
|
- dstValue = CSimpleStringW2A(wStr);
|
|
|
+ CSimpleStringW wStr = "";
|
|
|
+ UTF8ToUnicode(pTmpNode->valuestring, wStr);
|
|
|
+ dstValue = CSimpleStringW2A(wStr);
|
|
|
#endif
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = "";
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ dstValue = "";
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, std::string & dstValue, char* errmsg)
|
|
|
- {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, std::string & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- dstValue = pTmpNode->valuestring;
|
|
|
+ dstValue = pTmpNode->valuestring;
|
|
|
#else
|
|
|
- CSimpleStringW wStr = "";
|
|
|
- UTF8ToUnicode(pTmpNode->valuestring, wStr);
|
|
|
- dstValue = CSimpleStringW2A(wStr);
|
|
|
+ CSimpleStringW wStr = "";
|
|
|
+ UTF8ToUnicode(pTmpNode->valuestring, wStr);
|
|
|
+ dstValue = CSimpleStringW2A(wStr);
|
|
|
#endif
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = "";
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ dstValue = "";
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, CSimpleStringW & dstValue, char* errmsg) {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, CSimpleStringW & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- dstValue = CSimpleStringA2W(pTmpNode->valuestring);
|
|
|
+ dstValue = CSimpleStringA2W(pTmpNode->valuestring);
|
|
|
#else
|
|
|
- UTF8ToUnicode(pTmpNode->valuestring, dstValue);
|
|
|
+ UTF8ToUnicode(pTmpNode->valuestring, dstValue);
|
|
|
#endif
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = "";
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
- /*
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned int& dstValue, char* errmsg){
|
|
|
- cJSON *pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if(NULL != pTmpNode){
|
|
|
- dstValue = *(unsigned int*)&pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }else{
|
|
|
- if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned short& dstValue, char* errmsg){
|
|
|
- cJSON *pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if(NULL != pTmpNode){
|
|
|
- dstValue = pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }else{
|
|
|
- if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ dstValue = "";
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, short& dstValue, char* errmsg){
|
|
|
- cJSON *pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if(NULL != pTmpNode){
|
|
|
- dstValue = pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }else{
|
|
|
- if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+/*
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned int& dstValue, char* errmsg){
|
|
|
+ cJSON *pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if(NULL != pTmpNode){
|
|
|
+ dstValue = *(unsigned int*)&pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ }else{
|
|
|
+ if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, int& dstValue, char* errmsg){
|
|
|
- cJSON *pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if(NULL != pTmpNode){
|
|
|
- dstValue = pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }else{
|
|
|
- if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned short& dstValue, char* errmsg){
|
|
|
+ cJSON *pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if(NULL != pTmpNode){
|
|
|
+ dstValue = pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ }else{
|
|
|
+ if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
- */
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, double& dstValue, char* errmsg) {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
- dstValue = pTmpNode->valuedouble;
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, short& dstValue, char* errmsg){
|
|
|
+ cJSON *pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if(NULL != pTmpNode){
|
|
|
+ dstValue = pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ }else{
|
|
|
+ if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- template<typename T>
|
|
|
- bool CWSCodec::GetCJsonIntergerValue(cJSON * root, const char* strKey, T & dstValue, char* errmsg)
|
|
|
- {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
- dstValue = pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, int& dstValue, char* errmsg){
|
|
|
+ cJSON *pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if(NULL != pTmpNode){
|
|
|
+ dstValue = pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ }else{
|
|
|
+ if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, bool& dstValue, char* errmsg){
|
|
|
- cJSON *pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if(NULL != pTmpNode){
|
|
|
- dstValue = pTmpNode->valueint;
|
|
|
- ret = true;
|
|
|
- }else{
|
|
|
- if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+*/
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * root, const char* strKey, double& dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
+ dstValue = pTmpNode->valuedouble;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
- */
|
|
|
- bool CWSCodec::GetCJsonArraySize(cJSON * root, const char* strKey, int& dstValue, char* errmsg) {
|
|
|
- cJSON* pTmpNode = NULL;
|
|
|
- bool ret = false;
|
|
|
- pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
- if (NULL != pTmpNode) {
|
|
|
- dstValue = cJSON_GetArraySize(pTmpNode);
|
|
|
- ret = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
- dstValue = 0;
|
|
|
- ret = false;
|
|
|
- }
|
|
|
- return ret;
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+template<typename T>
|
|
|
+bool CWSCodec::GetCJsonIntergerValue(cJSON * root, const char* strKey, T & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
+ dstValue = pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
+ dstValue = 0;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * obj, int& dstValue, char* errmsg) {
|
|
|
- if (cJSON_Number == obj->type)
|
|
|
- {
|
|
|
- dstValue = obj->valueint;
|
|
|
- return true;
|
|
|
- }
|
|
|
- strcat(errmsg, "array member ");
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON *root, const char* strKey, bool& dstValue, char* errmsg){
|
|
|
+ cJSON *pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if(NULL != pTmpNode){
|
|
|
+ dstValue = pTmpNode->valueint;
|
|
|
+ ret = true;
|
|
|
+ }else{
|
|
|
+ if(nullptr != errmsg) strcat(errmsg, strKey);
|
|
|
dstValue = 0;
|
|
|
- return false;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * obj, unsigned int& dstValue, char* errmsg) {
|
|
|
- if (cJSON_Number == obj->type)
|
|
|
- {
|
|
|
- dstValue = obj->valueint;
|
|
|
- return true;
|
|
|
- }
|
|
|
- strcat(errmsg, "array member ");
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+*/
|
|
|
+bool CWSCodec::GetCJsonArraySize(cJSON * root, const char* strKey, int& dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ cJSON* pTmpNode = NULL;
|
|
|
+ bool ret = false;
|
|
|
+ pTmpNode = cJSON_GetObjectItem(root, strKey);
|
|
|
+ if (NULL != pTmpNode) {
|
|
|
+ dstValue = cJSON_GetArraySize(pTmpNode);
|
|
|
+ ret = true;
|
|
|
+ } else {
|
|
|
+ if (nullptr != errmsg) { strcat(errmsg, "-"); strcat(errmsg, strKey); }
|
|
|
dstValue = 0;
|
|
|
- return false;
|
|
|
+ ret = false;
|
|
|
}
|
|
|
-
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * obj, CSimpleStringA & dstValue, char* errmsg) {
|
|
|
- if (cJSON_String == obj->type) {
|
|
|
- DbgEx("GetCJsonObjectValue CSimpleStringA = %s", obj->valuestring);
|
|
|
- hexdump(obj->valuestring, strlen(obj->valuestring));
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * obj, int& dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ if (cJSON_Number == obj->type) {
|
|
|
+ dstValue = obj->valueint;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ strcat(errmsg, "array member ");
|
|
|
+ dstValue = 0;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * obj, unsigned int& dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ if (cJSON_Number == obj->type) {
|
|
|
+ dstValue = obj->valueint;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ strcat(errmsg, "array member ");
|
|
|
+ dstValue = 0;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * obj, CSimpleStringA & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ if (cJSON_String == obj->type) {
|
|
|
+ //DbgEx("GetCJsonObjectValue CSimpleStringA = %s", obj->valuestring);
|
|
|
+ //hexdump(obj->valuestring, strlen(obj->valuestring));
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- dstValue = obj->valuestring;
|
|
|
+ dstValue = obj->valuestring;
|
|
|
#else
|
|
|
- CSimpleStringW strw = "";
|
|
|
- UTF8ToUnicode(obj->valuestring, strw);
|
|
|
- dstValue = CSimpleStringW2A(strw);
|
|
|
+ CSimpleStringW strw = "";
|
|
|
+ UTF8ToUnicode(obj->valuestring, strw);
|
|
|
+ dstValue = CSimpleStringW2A(strw);
|
|
|
#endif
|
|
|
|
|
|
- return true;
|
|
|
- }
|
|
|
- strcat(errmsg, "array member ");
|
|
|
- DbgEx("GetCJsonObjectValue Type %d", obj->type);
|
|
|
- dstValue = "";
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
+ strcat(errmsg, "array member ");
|
|
|
+ dstValue = "";
|
|
|
+ return false;
|
|
|
+}
|
|
|
|
|
|
|
|
|
- bool CWSCodec::GetCJsonObjectValue(cJSON * obj, CSimpleStringW & dstValue, char* errmsg) {
|
|
|
- if (cJSON_String == obj->type) {
|
|
|
+bool CWSCodec::GetCJsonObjectValue(cJSON * obj, CSimpleStringW & dstValue, char* errmsg)
|
|
|
+{
|
|
|
+ if (cJSON_String == obj->type) {
|
|
|
#if (defined _WIN32 || defined _WIN64)
|
|
|
- dstValue = CSimpleStringA2W(obj->valuestring);
|
|
|
+ dstValue = CSimpleStringA2W(obj->valuestring);
|
|
|
#else
|
|
|
- UTF8ToUnicode(obj->valuestring, dstValue);
|
|
|
+ UTF8ToUnicode(obj->valuestring, dstValue);
|
|
|
#endif
|
|
|
- return true;
|
|
|
- }
|
|
|
- strcat(errmsg, "array member ");
|
|
|
- dstValue = "";
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
- int CWSCodec::UTF8ToUnicode(char* input, CSimpleStringW & output) {
|
|
|
- if (nullptr == input)
|
|
|
- return -1;
|
|
|
+ strcat(errmsg, "array member ");
|
|
|
+ dstValue = "";
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+int CWSCodec::UTF8ToUnicode(char* input, CSimpleStringW & output)
|
|
|
+{
|
|
|
+ if (nullptr == input)
|
|
|
+ return -1;
|
|
|
#if (defined(_WIN32) || defined(_WIN64))
|
|
|
- //UTF8 to Unicode
|
|
|
- //预转换,得到所需空间的大小
|
|
|
- int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, input, strlen(input), NULL, 0);
|
|
|
- //分配空间要给'\0'留个空间,MultiByteToWideChar不会给'\0'空间
|
|
|
- wchar_t* wszString = new wchar_t[wcsLen + 1];
|
|
|
- //转换
|
|
|
- ::MultiByteToWideChar(CP_UTF8, NULL, input, strlen(input), wszString, wcsLen);
|
|
|
- //最后加上'\0'
|
|
|
- wszString[wcsLen] = '\0';
|
|
|
- output = wszString;
|
|
|
- delete[] wszString;
|
|
|
- wszString = NULL;
|
|
|
- return 0;
|
|
|
+ //UTF8 to Unicode
|
|
|
+ //预转换,得到所需空间的大小
|
|
|
+ int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, input, strlen(input), NULL, 0);
|
|
|
+ //分配空间要给'\0'留个空间,MultiByteToWideChar不会给'\0'空间
|
|
|
+ wchar_t* wszString = new wchar_t[wcsLen + 1];
|
|
|
+ //转换
|
|
|
+ ::MultiByteToWideChar(CP_UTF8, NULL, input, strlen(input), wszString, wcsLen);
|
|
|
+ //最后加上'\0'
|
|
|
+ wszString[wcsLen] = '\0';
|
|
|
+ output = wszString;
|
|
|
+ delete[] wszString;
|
|
|
+ wszString = NULL;
|
|
|
+ return 0;
|
|
|
#else
|
|
|
- std::wstring ret = SP::Utility::S2W(input);
|
|
|
- output = ret.c_str();
|
|
|
- return 0;
|
|
|
+ std::wstring ret = SP::Utility::S2W(input);
|
|
|
+ output = ret.c_str();
|
|
|
+ return 0;
|
|
|
#endif
|
|
|
- }
|
|
|
-
|
|
|
- void CWSCodec::hexdump(const char* buf, const int num) {
|
|
|
- char str[8192] = { 0 };
|
|
|
- int i = 0;
|
|
|
- char c[5] = { 0 };
|
|
|
- if (num > 1200)
|
|
|
- {
|
|
|
- for (i = 0; i < 50; i++)
|
|
|
- {
|
|
|
- sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
- strcat(str, c);
|
|
|
- }
|
|
|
- DbgEx("buffer too long to show!show pre 50 hex! CWSCodec hex buf : %d : %s", num, str);
|
|
|
- return;
|
|
|
- }
|
|
|
- for (i = 0; i < num; i++)
|
|
|
- {
|
|
|
+}
|
|
|
+
|
|
|
+void CWSCodec::hexdump(const char* buf, const int num)
|
|
|
+{
|
|
|
+ char str[8192] = { 0 };
|
|
|
+ int i = 0;
|
|
|
+ char c[5] = { 0 };
|
|
|
+ if (num > 1200) {
|
|
|
+ for (i = 0; i < 50; i++) {
|
|
|
sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
strcat(str, c);
|
|
|
}
|
|
|
- DbgEx("CWSCodec hex buf : %s", str);
|
|
|
+ DbgEx("buffer too long to show!show pre 50 hex! CWSCodec hex buf : %d : %s", num, str);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- std::string CWSCodec::GetEntityName(std::string strJson) {
|
|
|
- cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
- char entity_name[64] = { 0 };
|
|
|
- char errmsg[1024] = { 0 };
|
|
|
-
|
|
|
- GetCJsonObjectValue(pJson, "entity", entity_name, errmsg);
|
|
|
- std::string s(entity_name);
|
|
|
- cJSON_Delete(pJson);
|
|
|
- //cJSON_free(pJson);
|
|
|
- return s;
|
|
|
+ for (i = 0; i < num; i++) {
|
|
|
+ sprintf(c, "%02X ", (unsigned char)buf[i]);
|
|
|
+ strcat(str, c);
|
|
|
}
|
|
|
+ DbgEx("CWSCodec hex buf : %s", str);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+std::string CWSCodec::GetEntityName(std::string strJson)
|
|
|
+{
|
|
|
+ cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
+ char entity_name[64] = { 0 };
|
|
|
+ char errmsg[1024] = { 0 };
|
|
|
+
|
|
|
+ GetCJsonObjectValue(pJson, "entity", entity_name, errmsg);
|
|
|
+ std::string s(entity_name);
|
|
|
+ cJSON_Delete(pJson);
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|
|
|
+std::string CWSCodec::GetClassName(std::string strJson)
|
|
|
+{
|
|
|
+ cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
+ char class_name[64] = { 0 };
|
|
|
+ char errmsg[1024] = { 0 };
|
|
|
+
|
|
|
+ GetCJsonObjectValue(pJson, "class", class_name, errmsg);
|
|
|
+ std::string s(class_name);
|
|
|
+ cJSON_Delete(pJson);
|
|
|
+ return s;
|
|
|
+}
|
|
|
|
|
|
- std::string CWSCodec::GetClassName(std::string strJson) {
|
|
|
- cJSON* pJson = cJSON_Parse(strJson.c_str());
|
|
|
- char class_name[64] = { 0 };
|
|
|
- char errmsg[1024] = { 0 };
|
|
|
-
|
|
|
- GetCJsonObjectValue(pJson, "class", class_name, errmsg);
|
|
|
- std::string s(class_name);
|
|
|
- cJSON_Delete(pJson);
|
|
|
- //cJSON_free(pJson);
|
|
|
- return s;
|
|
|
}
|
|
|
-
|
|
|
- }
|