From 61e21ebf2aa0cab6098305cd0e8fc4ae10258ded Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 27 May 2022 14:05:14 +0000 Subject: [PATCH] feat: tag refact --- include/common/tdataformat.h | 3 ++- source/common/src/tdataformat.c | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 350dc9367e..3f6ff863ba 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -18,6 +18,7 @@ #include "os.h" #include "talgo.h" +#include "tarray.h" #include "tencode.h" #include "ttypes.h" #include "tutil.h" @@ -64,7 +65,7 @@ void tTagFree(STag *pTag); void tTagGet(STag *pTag, STagVal *pTagVal); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag); -int32_t tTagToValArray(STag *pTag, STagVal **ppTagVals, int16_t *nTag); +int32_t tTagToValArray(STag *pTag, SArray **ppArray); // STRUCT ================= struct STColumn { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index b2316ce4e1..87b01623e8 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -671,19 +671,20 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) { int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) { return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL); } -int32_t tTagToValArray(STag *pTag, STagVal **ppTagVals, int16_t *nTag) { +int32_t tTagToValArray(STag *pTag, SArray **ppArray) { int32_t code = 0; uint8_t *p = (uint8_t *)&pTag->idx[pTag->nTag]; + STagVal tv; - *nTag = pTag->nTag; - (*ppTagVals) = (STagVal *)taosMemoryMalloc(sizeof(STagVal) * pTag->nTag); - if (*ppTagVals == NULL) { + (*ppArray) = taosArrayInit(pTag->nTag, sizeof(STagVal)); + if (*ppArray == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } for (int16_t iTag = 0; iTag < pTag->nTag; iTag++) { - tGetTagVal(p + pTag->idx[iTag], &(*ppTagVals)[iTag], pTag->isJson); + tGetTagVal(p + pTag->idx[iTag], &tv, pTag->isJson); + taosArrayPush(*ppArray, &tv); } return code; -- GitLab