Răsfoiți Sursa

Z991239-5462 #comment fea: chromium support param arrary_double

chenliangyu 1 an în urmă
părinte
comite
ab968fc420
2 a modificat fișierele cu 47 adăugiri și 0 ștergeri
  1. 46 0
      Module/mod_chromium/CWSCodec.cpp
  2. 1 0
      Module/mod_chromium/CWSCodec.h

+ 46 - 0
Module/mod_chromium/CWSCodec.cpp

@@ -257,6 +257,22 @@ namespace Chromium {
 					if (!t_isRepeat && writeToOldParam)	cJSON_AddItemToObject(ret, i->mName.c_str(), tmpArray);
 					cJSON_AddItemToObject(extendJs.get(), i->mName.c_str(), tmpArray2);
 				}
+				else if (i->mType == "array_double")
+				{
+					int len = 0;
+					double 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 && writeToOldParam)	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;
@@ -1380,6 +1396,25 @@ namespace Chromium {
 					WriteT(data, len, wpos, capacity);
 				}
 			}
+			else if (it->mType == "array_double")
+			{
+			//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);
+				double 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 {
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("array int -> false len = %d", len);
+				WriteT(data, len, wpos, capacity);
+			}
+			}
 			else if (it->mType == "array_bool")
 			{
 				int len = 0;
@@ -1719,6 +1754,17 @@ namespace Chromium {
 		return false;
 	}
 
+	bool CWSCodec::GetCJsonObjectValue(cJSON* obj, double& dstValue, char* errmsg) {
+		if (cJSON_Number == obj->type)
+		{
+			dstValue = obj->valuedouble;
+			return true;
+		}
+		strcat(errmsg, "array member ");
+		dstValue = 0.0;
+		return false;
+	}
+
 	bool CWSCodec::GetCJsonObjectValue(cJSON * obj, CSimpleStringA & dstValue, char* errmsg) {
 		if (cJSON_String == obj->type) {
 			//DbgEx("GetCJsonObjectValue CSimpleStringA = %s", obj->valuestring);

+ 1 - 0
Module/mod_chromium/CWSCodec.h

@@ -77,6 +77,7 @@ namespace Chromium {
 		*/
 		bool GetCJsonObjectValue(cJSON* obj, int& dstValue, char* errmsg);
 		bool GetCJsonObjectValue(cJSON* obj, unsigned int& dstValue, char* errmsg);
+		bool GetCJsonObjectValue(cJSON* obj, double& dstValue, char* errmsg);
 		bool GetCJsonObjectValue(cJSON* root, const char* strKey, double& dstValue, char* errmsg);
 
 		bool GetCJsonObjectValue(cJSON* root, const char* strKey, CSimpleStringA& dstValue, char* errmsg);