提交 f8d51bc9 编写于 作者: H Hongze Cheng

refact submit request

上级 98173cfb
......@@ -2576,6 +2576,28 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
}
#define TD_AUTO_CREATE_TABLE 0x1
typedef struct {
int64_t suid;
int64_t uid;
int32_t sver;
uint64_t nData;
const void* pData;
SVCreateTbReq cTbReq;
} SVSubmitBlk;
typedef struct {
int32_t flags;
int32_t nBlocks;
union {
SArray* pArray;
SVSubmitBlk* pBlocks;
};
} SVSubmitReq;
int32_t tEncodeSVSubmitReq(SCoder* pCoder, const SVSubmitReq* pReq);
int32_t tDecodeSVSubmitReq(SCoder* pCoder, SVSubmitReq* pReq);
#pragma pack(pop)
#ifdef __cplusplus
......
......@@ -3841,3 +3841,65 @@ int32_t tDecodeSVDropStbReq(SCoder *pCoder, SVDropStbReq *pReq) {
tEndDecode(pCoder);
return 0;
}
static int32_t tEncodeSVSubmitBlk(SCoder *pCoder, const SVSubmitBlk *pBlock, int32_t flags) {
if (tStartEncode(pCoder) < 0) return -1;
if (tEncodeI64(pCoder, pBlock->suid) < 0) return -1;
if (tEncodeI64(pCoder, pBlock->uid) < 0) return -1;
if (tEncodeI32v(pCoder, pBlock->sver) < 0) return -1;
if (tEncodeBinary(pCoder, pBlock->pData, pBlock->nData) < 0) return -1;
if (flags & TD_AUTO_CREATE_TABLE) {
if (tEncodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
}
tEndEncode(pCoder);
return 0;
}
static int32_t tDecodeSVSubmitBlk(SCoder *pCoder, SVSubmitBlk *pBlock, int32_t flags) {
if (tStartDecode(pCoder) < 0) return -1;
if (tDecodeI64(pCoder, &pBlock->suid) < 0) return -1;
if (tDecodeI64(pCoder, &pBlock->uid) < 0) return -1;
if (tDecodeI32v(pCoder, &pBlock->sver) < 0) return -1;
if (tDecodeBinary(pCoder, &pBlock->pData, &pBlock->nData) < 0) return -1;
if (flags & TD_AUTO_CREATE_TABLE) {
if (tDecodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
}
tEndDecode(pCoder);
return 0;
}
int32_t tEncodeSVSubmitReq(SCoder *pCoder, const SVSubmitReq *pReq) {
int32_t nBlocks = taosArrayGetSize(pReq->pArray);
if (tStartEncode(pCoder) < 0) return -1;
if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1;
if (tEncodeI32v(pCoder, nBlocks) < 0) return -1;
for (int32_t iBlock = 0; iBlock < nBlocks; iBlock++) {
if (tEncodeSVSubmitBlk(pCoder, (SVSubmitBlk *)taosArrayGet(pReq->pArray, iBlock), pReq->flags) < 0) return -1;
}
tEndEncode(pCoder);
return 0;
}
int32_t tDecodeSVSubmitReq(SCoder *pCoder, SVSubmitReq *pReq) {
if (tStartDecode(pCoder) < 0) return -1;
if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1;
if (tDecodeI32v(pCoder, &pReq->nBlocks) < 0) return -1;
pReq->pBlocks = tCoderMalloc(pCoder, sizeof(SVSubmitBlk) * pReq->nBlocks);
if (pReq->pBlocks == NULL) return -1;
for (int32_t iBlock = 0; iBlock < pReq->nBlocks; iBlock++) {
if (tDecodeSVSubmitBlk(pCoder, pReq->pBlocks + iBlock, pReq->flags) < 0) return -1;
}
tEndDecode(pCoder);
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册