From 8f1a1b7bbc5b5d15ea49d9e8e5944c518e71984c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:26:32 +0000 Subject: [PATCH] refact --- include/common/tmsg.h | 42 ------------ source/common/src/tmsg.c | 141 +-------------------------------------- 2 files changed, 1 insertion(+), 182 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 5365a0ee36..6c2b4a1acc 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -57,48 +57,6 @@ extern int tMsgDict[]; typedef uint16_t tmsg_t; -/* ------------------------ ENCODE/DECODE FUNCTIONS AND MACROS ------------------------ */ -#if 0 -struct SMEListNode { - TD_SLIST_NODE(SMEListNode); - SEncoder coder; -}; - -typedef struct SMsgEncoder { - SEncoder coder; - TD_SLIST(SMEListNode) eStack; // encode stack -} SMsgEncoder; - -struct SMDFreeListNode { - TD_SLIST_NODE(SMDFreeListNode); - char payload[]; -}; - -struct SMDListNode { - TD_SLIST_NODE(SMDListNode); - SDecoder coder; -}; - -typedef struct SMsgDecoder { - SDecoder coder; - TD_SLIST(SMDListNode) dStack; - TD_SLIST(SMDFreeListNode) freeList; -} SMsgDecoder; - -#define TMSG_MALLOC(SIZE, DECODER) \ - ({ \ - void* ptr = malloc((SIZE) + sizeof(struct SMDFreeListNode)); \ - if (ptr) { \ - TD_SLIST_PUSH(&((DECODER)->freeList), (struct SMDFreeListNode*)ptr); \ - ptr = POINTER_SHIFT(ptr, sizeof(struct SMDFreeListNode*)); \ - } \ - ptr; \ - }) - -void tmsgInitMsgDecoder(SMsgDecoder* pMD, td_endian_t endian, uint8_t* data, int64_t size); -void tmsgClearMsgDecoder(SMsgDecoder* pMD); -#endif - /* ------------------------ OTHER DEFINITIONS ------------------------ */ // IE type #define TSDB_IE_TYPE_SEC 1 diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c0baa1e411..0874c471aa 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -27,83 +27,6 @@ #undef TD_MSG_SEG_CODE_ #include "tmsgdef.h" -#if 0 -static int tmsgStartEncode(SMsgEncoder *pME); -static void tmsgEndEncode(SMsgEncoder *pME); -static int tmsgStartDecode(SMsgDecoder *pMD); -static void tmsgEndDecode(SMsgDecoder *pMD); -#endif - -/* ------------------------ ENCODE/DECODE FUNCTIONS ------------------------ */ -#if 0 -void tmsgInitMsgEncoder(SMsgEncoder *pME, td_endian_t endian, uint8_t *data, int64_t size) { - tInitEncoder(&(pME->coder), endian, data, size); - TD_SLIST_INIT(&(pME->eStack)); -} - -void tmsgClearMsgEncoder(SMsgEncoder *pME) { - struct SMEListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pME->eStack)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pME->eStack)); - free(pNode); - } -} - -void tmsgInitMsgDecoder(SMsgDecoder *pMD, td_endian_t endian, uint8_t *data, int64_t size) { - tInitDecoder(&pMD->coder, endian, data, size); - TD_SLIST_INIT(&(pMD->dStack)); - TD_SLIST_INIT(&(pMD->freeList)); -} - -void tmsgClearMsgDecoder(SMsgDecoder *pMD) { - { - struct SMDFreeListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pMD->freeList)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pMD->freeList)); - free(pNode); - } - } - { - struct SMDListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pMD->dStack)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pMD->dStack)); - free(pNode); - } - } -} -#endif - -/* ------------------------ MESSAGE ENCODE/DECODE ------------------------ */ -#if 0 -int tmsgSVCreateTbReqEncode(SMsgEncoder *pCoder, SVCreateTbReq *pReq) { - tmsgStartEncode(pCoder); - // TODO - - tmsgEndEncode(pCoder); - return 0; -} - -int tmsgSVCreateTbReqDecode(SMsgDecoder *pCoder, SVCreateTbReq *pReq) { - tmsgStartDecode(pCoder); - - // TODO: decode - - // Decode is not end - if (pCoder->coder.pos != pCoder->coder.size) { - // Continue decode - } - - tmsgEndDecode(pCoder); - return 0; -} -#endif - int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int tlen = 0; @@ -224,66 +147,4 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { } return buf; -} - -/* ------------------------ STATIC METHODS ------------------------ */ -#if 0 -static int tmsgStartEncode(SMsgEncoder *pME) { - struct SMEListNode *pNode = (struct SMEListNode *)malloc(sizeof(*pNode)); - if (TD_IS_NULL(pNode)) return -1; - - pNode->coder = pME->coder; - TD_SLIST_PUSH(&(pME->eStack), pNode); - TD_CODER_MOVE_POS(&(pME->coder), sizeof(int32_t)); - - return 0; -} - -static void tmsgEndEncode(SMsgEncoder *pME) { - int32_t size; - struct SMEListNode *pNode; - - pNode = TD_SLIST_HEAD(&(pME->eStack)); - ASSERT(pNode); - TD_SLIST_POP(&(pME->eStack)); - - size = pME->coder.pos - pNode->coder.pos; - tEncodeI32(&(pNode->coder), size); - - free(pNode); -} - -static int tmsgStartDecode(SMsgDecoder *pMD) { - struct SMDListNode *pNode; - int32_t size; - - pNode = (struct SMDListNode *)malloc(sizeof(*pNode)); - if (pNode == NULL) return -1; - - tDecodeI32(&(pMD->coder), &size); - - pNode->coder = pMD->coder; - TD_SLIST_PUSH(&(pMD->dStack), pNode); - - pMD->coder.pos = 0; - pMD->coder.size = size - sizeof(int32_t); - pMD->coder.data = TD_CODER_CURRENT(&(pNode->coder)); - - return 0; -} - -static void tmsgEndDecode(SMsgDecoder *pMD) { - ASSERT(pMD->coder.pos == pMD->coder.size); - struct SMDListNode *pNode; - - pNode = TD_SLIST_HEAD(&(pMD->dStack)); - ASSERT(pNode); - TD_SLIST_POP(&(pMD->dStack)); - - pNode->coder.pos += pMD->coder.size; - - pMD->coder = pNode->coder; - - free(pNode); -} -#endif \ No newline at end of file +} \ No newline at end of file -- GitLab