提交 f40d838f 编写于 作者: X Xiaoyu Wang

enh: add binary serialization method to node structure

上级 f32a1758
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
typedef struct STlv { typedef struct STlv {
int16_t type; int16_t type;
int16_t len; int32_t len;
char value[0]; char value[0];
} STlv; } STlv;
...@@ -70,7 +70,7 @@ static void endTlvEncode(STlvEncoder* pEncoder, char** pMsg, int32_t* pLen) { ...@@ -70,7 +70,7 @@ static void endTlvEncode(STlvEncoder* pEncoder, char** pMsg, int32_t* pLen) {
// nodesWarn("encode tlv count = %d, tl size = %d", pEncoder->tlvCount, sizeof(STlv) * pEncoder->tlvCount); // nodesWarn("encode tlv count = %d, tl size = %d", pEncoder->tlvCount, sizeof(STlv) * pEncoder->tlvCount);
} }
static int32_t tlvEncodeImpl(STlvEncoder* pEncoder, int16_t type, const void* pValue, int16_t len) { static int32_t tlvEncodeImpl(STlvEncoder* pEncoder, int16_t type, const void* pValue, int32_t len) {
int32_t tlvLen = sizeof(STlv) + len; int32_t tlvLen = sizeof(STlv) + len;
if (pEncoder->offset + tlvLen > pEncoder->allocSize) { if (pEncoder->offset + tlvLen > pEncoder->allocSize) {
void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize * 2); void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize * 2);
...@@ -187,7 +187,7 @@ static int32_t tlvGetNextTlv(STlvDecoder* pDecoder, STlv** pTlv) { ...@@ -187,7 +187,7 @@ static int32_t tlvGetNextTlv(STlvDecoder* pDecoder, STlv** pTlv) {
static bool tlvDecodeEnd(STlvDecoder* pDecoder) { return pDecoder->offset == pDecoder->bufSize; } static bool tlvDecodeEnd(STlvDecoder* pDecoder) { return pDecoder->offset == pDecoder->bufSize; }
static int32_t tlvDecodeImpl(STlv* pTlv, void* pValue, int16_t len) { static int32_t tlvDecodeImpl(STlv* pTlv, void* pValue, int32_t len) {
if (pTlv->len != len) { if (pTlv->len != len) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -710,6 +710,7 @@ static int32_t msgToLogicConditionNode(STlvDecoder* pDecoder, void* pObj) { ...@@ -710,6 +710,7 @@ static int32_t msgToLogicConditionNode(STlvDecoder* pDecoder, void* pObj) {
enum { enum {
FUNCTION_CODE_EXPR_BASE = 1, FUNCTION_CODE_EXPR_BASE = 1,
FUNCTION_CODE_FUNCTION_NAME,
FUNCTION_CODE_FUNCTION_ID, FUNCTION_CODE_FUNCTION_ID,
FUNCTION_CODE_FUNCTION_TYPE, FUNCTION_CODE_FUNCTION_TYPE,
FUNCTION_CODE_PARAMETERS, FUNCTION_CODE_PARAMETERS,
...@@ -720,6 +721,9 @@ static int32_t functionNodeToMsg(const void* pObj, STlvEncoder* pEncoder) { ...@@ -720,6 +721,9 @@ static int32_t functionNodeToMsg(const void* pObj, STlvEncoder* pEncoder) {
const SFunctionNode* pNode = (const SFunctionNode*)pObj; const SFunctionNode* pNode = (const SFunctionNode*)pObj;
int32_t code = tlvEncodeObj(pEncoder, FUNCTION_CODE_EXPR_BASE, exprNodeToMsg, pNode); int32_t code = tlvEncodeObj(pEncoder, FUNCTION_CODE_EXPR_BASE, exprNodeToMsg, pNode);
if (TSDB_CODE_SUCCESS == code) {
code = tlvEncodeCStr(pEncoder, FUNCTION_CODE_FUNCTION_NAME, pNode->functionName);
}
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tlvEncodeI32(pEncoder, FUNCTION_CODE_FUNCTION_ID, pNode->funcId); code = tlvEncodeI32(pEncoder, FUNCTION_CODE_FUNCTION_ID, pNode->funcId);
} }
...@@ -746,6 +750,9 @@ static int32_t msgToFunctionNode(STlvDecoder* pDecoder, void* pObj) { ...@@ -746,6 +750,9 @@ static int32_t msgToFunctionNode(STlvDecoder* pDecoder, void* pObj) {
case FUNCTION_CODE_EXPR_BASE: case FUNCTION_CODE_EXPR_BASE:
code = tlvDecodeObjFromTlv(pTlv, msgToExprNode, &pNode->node); code = tlvDecodeObjFromTlv(pTlv, msgToExprNode, &pNode->node);
break; break;
case FUNCTION_CODE_FUNCTION_NAME:
code = tlvDecodeCStr(pTlv, pNode->functionName);
break;
case FUNCTION_CODE_FUNCTION_ID: case FUNCTION_CODE_FUNCTION_ID:
code = tlvDecodeI32(pTlv, &pNode->funcId); code = tlvDecodeI32(pTlv, &pNode->funcId);
break; break;
......
...@@ -480,8 +480,12 @@ class PlannerTestBaseImpl { ...@@ -480,8 +480,12 @@ class PlannerTestBaseImpl {
DO_WITH_THROW(nodesNodeToMsg, pNode, &pNewStr, &newlen) DO_WITH_THROW(nodesNodeToMsg, pNode, &pNewStr, &newlen)
if (newlen != len || 0 != memcmp(pStr, pNewStr, len)) { if (newlen != len || 0 != memcmp(pStr, pNewStr, len)) {
cout << "nodesNodeToMsg error!!!!!!!!!!!!!! len = " << len << ", newlen = " << newlen << endl; cout << "nodesNodeToMsg error!!!!!!!!!!!!!! len = " << len << ", newlen = " << newlen << endl;
taosMemoryFreeClear(pNewStr);
DO_WITH_THROW(nodesNodeToString, pRoot, false, &pNewStr, &newlen)
cout << "orac node: " << pNewStr << endl;
taosMemoryFreeClear(pNewStr);
DO_WITH_THROW(nodesNodeToString, pNode, false, &pNewStr, &newlen) DO_WITH_THROW(nodesNodeToString, pNode, false, &pNewStr, &newlen)
cout << "nodesNodeToString " << pNewStr << endl; cout << "new node: " << pNewStr << endl;
} }
taosMemoryFreeClear(pNewStr); taosMemoryFreeClear(pNewStr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册