Merge pull request #12857 from taosdata/fix/hzcheng_3.0
feat: discard const when decode
This commit is contained in:
commit
0122fd12d9
|
@ -1697,7 +1697,7 @@ int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
|
|||
|
||||
// TDMT_VND_CREATE_STB ==============
|
||||
typedef struct SVCreateStbReq {
|
||||
const char* name;
|
||||
char* name;
|
||||
tb_uid_t suid;
|
||||
int8_t rollup;
|
||||
SSchemaWrapper schema;
|
||||
|
@ -1710,7 +1710,7 @@ int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
|
|||
|
||||
// TDMT_VND_DROP_STB ==============
|
||||
typedef struct SVDropStbReq {
|
||||
const char* name;
|
||||
char* name;
|
||||
tb_uid_t suid;
|
||||
} SVDropStbReq;
|
||||
|
||||
|
@ -1723,13 +1723,13 @@ typedef struct SVCreateTbReq {
|
|||
int32_t flags;
|
||||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
const char* name;
|
||||
char* name;
|
||||
int32_t ttl;
|
||||
int8_t type;
|
||||
union {
|
||||
struct {
|
||||
tb_uid_t suid;
|
||||
const uint8_t* pTag;
|
||||
uint8_t* pTag;
|
||||
} ctb;
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
|
@ -1777,7 +1777,7 @@ int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatc
|
|||
|
||||
// TDMT_VND_DROP_TABLE =================
|
||||
typedef struct {
|
||||
const char* name;
|
||||
char* name;
|
||||
int8_t igNotExists;
|
||||
} SVDropTbReq;
|
||||
|
||||
|
@ -1809,9 +1809,9 @@ int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
|
|||
|
||||
// TDMT_VND_ALTER_TABLE =====================
|
||||
typedef struct {
|
||||
const char* tbName;
|
||||
char* tbName;
|
||||
int8_t action;
|
||||
const char* colName;
|
||||
char* colName;
|
||||
// TSDB_ALTER_TABLE_ADD_COLUMN
|
||||
int8_t type;
|
||||
int8_t flags;
|
||||
|
@ -1820,17 +1820,17 @@ typedef struct {
|
|||
// TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
|
||||
int32_t colModBytes;
|
||||
// TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
|
||||
const char* colNewName;
|
||||
char* colNewName;
|
||||
// TSDB_ALTER_TABLE_UPDATE_TAG_VAL
|
||||
const char* tagName;
|
||||
char* tagName;
|
||||
int8_t isNull;
|
||||
uint32_t nTagVal;
|
||||
const uint8_t* pTagVal;
|
||||
uint8_t* pTagVal;
|
||||
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
|
||||
int8_t updateTTL;
|
||||
int32_t newTTL;
|
||||
int8_t updateComment;
|
||||
const char* newComment;
|
||||
char* newComment;
|
||||
} SVAlterTbReq;
|
||||
|
||||
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
|
||||
|
@ -2267,8 +2267,8 @@ typedef struct {
|
|||
int64_t interval;
|
||||
int64_t offset; // use unit by precision of DB
|
||||
int64_t sliding;
|
||||
const char* expr; // sma expression
|
||||
const char* tagsFilter;
|
||||
char* expr; // sma expression
|
||||
char* tagsFilter;
|
||||
} STSma; // Time-range-wise SMA
|
||||
|
||||
typedef STSma SVCreateTSmaReq;
|
||||
|
@ -2600,7 +2600,7 @@ typedef struct {
|
|||
int64_t uid;
|
||||
int32_t sver;
|
||||
uint32_t nData;
|
||||
const uint8_t* pData;
|
||||
uint8_t* pData;
|
||||
SVCreateTbReq cTbReq;
|
||||
} SVSubmitBlk;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct {
|
|||
} SEncoder;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
uint8_t* data;
|
||||
uint32_t size;
|
||||
uint32_t pos;
|
||||
SCoderMem* mList;
|
||||
|
@ -120,7 +120,7 @@ static int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t le
|
|||
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
||||
|
||||
/* ------------------------ DECODE ------------------------ */
|
||||
void tDecoderInit(SDecoder* pCoder, const uint8_t* data, uint32_t size);
|
||||
void tDecoderInit(SDecoder* pCoder, uint8_t* data, uint32_t size);
|
||||
void tDecoderClear(SDecoder* SDecoder);
|
||||
int32_t tStartDecode(SDecoder* pCoder);
|
||||
void tEndDecode(SDecoder* pCoder);
|
||||
|
@ -141,9 +141,9 @@ static int32_t tDecodeU64v(SDecoder* pCoder, uint64_t* val);
|
|||
static int32_t tDecodeI64v(SDecoder* pCoder, int64_t* val);
|
||||
static int32_t tDecodeFloat(SDecoder* pCoder, float* val);
|
||||
static int32_t tDecodeDouble(SDecoder* pCoder, double* val);
|
||||
static int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len);
|
||||
static int32_t tDecodeCStr(SDecoder* pCoder, const char** val);
|
||||
static int32_t tDecodeBinary(SDecoder* pCoder, uint8_t** val, uint32_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SDecoder* pCoder, char** val, uint32_t* len);
|
||||
static int32_t tDecodeCStr(SDecoder* pCoder, char** val);
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val);
|
||||
|
||||
/* ------------------------ IMPL ------------------------ */
|
||||
|
@ -377,7 +377,7 @@ static FORCE_INLINE int32_t tDecodeDouble(SDecoder* pCoder, double* val) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len) {
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, uint8_t** val, uint32_t* len) {
|
||||
if (tDecodeU32v(pCoder, len) < 0) return -1;
|
||||
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
||||
|
@ -389,19 +389,19 @@ static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len) {
|
||||
if (tDecodeBinary(pCoder, (const uint8_t**)val, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, char** val, uint32_t* len) {
|
||||
if (tDecodeBinary(pCoder, (uint8_t**)val, len) < 0) return -1;
|
||||
(*len) -= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SDecoder* pCoder, const char** val) {
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SDecoder* pCoder, char** val) {
|
||||
uint32_t len;
|
||||
return tDecodeCStrAndLen(pCoder, val, &len);
|
||||
}
|
||||
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) {
|
||||
const char* pStr;
|
||||
char* pStr;
|
||||
uint32_t len;
|
||||
if (tDecodeCStrAndLen(pCoder, &pStr, &len) < 0) return -1;
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ struct SMetaEntry {
|
|||
int64_t version;
|
||||
int8_t type;
|
||||
tb_uid_t uid;
|
||||
const char *name;
|
||||
char *name;
|
||||
union {
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
|
@ -187,7 +187,7 @@ struct SMetaEntry {
|
|||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
tb_uid_t suid;
|
||||
const uint8_t *pTags;
|
||||
uint8_t *pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
|
|
|
@ -165,7 +165,9 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
oStbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
memcpy(oStbEntry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, oStbEntry.pBuf, nData);
|
||||
metaDecodeEntry(&dc, &oStbEntry);
|
||||
|
||||
nStbEntry.version = version;
|
||||
|
@ -193,6 +195,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
// update uid index
|
||||
tdbTbcUpsert(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &version, sizeof(version), 0);
|
||||
|
||||
if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
|
||||
metaULock(pMeta);
|
||||
tDecoderClear(&dc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
@ -420,7 +423,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
// get table entry
|
||||
SDecoder dc = {0};
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
entry.pBuf = taosMemoryMalloc(nData);
|
||||
memcpy(entry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, entry.pBuf, nData);
|
||||
ret = metaDecodeEntry(&dc, &entry);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
|
|||
if (tDecodeIsEnd(&dc)) break;
|
||||
|
||||
// decode row
|
||||
if (tDecodeBinary(&dc, (const uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
|
||||
if (tDecodeBinary(&dc, (uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pR
|
|||
|
||||
static FORCE_INLINE int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow) {
|
||||
if (tDecodeI64(pDecoder, &pRow->version) < 0) return -1;
|
||||
if (tDecodeBinary(pDecoder, (const uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
|
||||
if (tDecodeBinary(pDecoder, (uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
}
|
||||
};
|
||||
|
||||
auto setAlterTagFunc = [&](const char* pTbname, const char* pTagName, const uint8_t* pNewVal, uint32_t bytes) {
|
||||
auto setAlterTagFunc = [&](const char* pTbname, const char* pTagName, uint8_t* pNewVal, uint32_t bytes) {
|
||||
memset(&expect, 0, sizeof(SVAlterTbReq));
|
||||
expect.tbName = strdup(pTbname);
|
||||
expect.action = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
|
@ -215,7 +215,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
expect.pTagVal = pNewVal;
|
||||
};
|
||||
|
||||
auto setAlterOptionsFunc = [&](const char* pTbname, int32_t ttl, const char* pComment = nullptr) {
|
||||
auto setAlterOptionsFunc = [&](const char* pTbname, int32_t ttl, char* pComment = nullptr) {
|
||||
memset(&expect, 0, sizeof(SVAlterTbReq));
|
||||
expect.tbName = strdup(pTbname);
|
||||
expect.action = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
|
||||
|
@ -240,7 +240,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
void* pBuf = POINTER_SHIFT(pVgData->pData, sizeof(SMsgHead));
|
||||
SVAlterTbReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
tDecoderInit(&coder, (const uint8_t*)pBuf, pVgData->size);
|
||||
tDecoderInit(&coder, (uint8_t*)pBuf, pVgData->size);
|
||||
ASSERT_EQ(tDecodeSVAlterTbReq(&coder, &req), TSDB_CODE_SUCCESS);
|
||||
|
||||
ASSERT_EQ(std::string(req.tbName), std::string(expect.tbName));
|
||||
|
@ -274,7 +274,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
setAlterOptionsFunc("t1", 10, nullptr);
|
||||
run("ALTER TABLE t1 TTL 10");
|
||||
|
||||
setAlterOptionsFunc("t1", -1, "test");
|
||||
setAlterOptionsFunc("t1", -1, (char*)"test");
|
||||
run("ALTER TABLE t1 COMMENT 'test'");
|
||||
|
||||
setAlterColFunc("t1", TSDB_ALTER_TABLE_ADD_COLUMN, "cc1", TSDB_DATA_TYPE_BIGINT);
|
||||
|
@ -290,7 +290,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
run("ALTER TABLE t1 RENAME COLUMN c1 cc1");
|
||||
|
||||
int32_t val = 10;
|
||||
setAlterTagFunc("st1s1", "tag1", (const uint8_t*)&val, sizeof(val));
|
||||
setAlterTagFunc("st1s1", "tag1", (uint8_t*)&val, sizeof(val));
|
||||
run("ALTER TABLE st1s1 SET TAG tag1=10");
|
||||
|
||||
// todo
|
||||
|
|
|
@ -411,7 +411,7 @@ SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen) {
|
|||
}
|
||||
uint32_t len;
|
||||
char* data = NULL;
|
||||
if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) {
|
||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
assert(len = pMsg->dataLen);
|
||||
|
@ -670,7 +670,7 @@ SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen) {
|
|||
}
|
||||
uint32_t len;
|
||||
char* data = NULL;
|
||||
if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) {
|
||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
assert(len = pMsg->dataLen);
|
||||
|
|
|
@ -30,7 +30,7 @@ struct SEncoderNode {
|
|||
|
||||
struct SDecoderNode {
|
||||
SDecoderNode* pNext;
|
||||
const uint8_t* data;
|
||||
uint8_t* data;
|
||||
uint32_t size;
|
||||
uint32_t pos;
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ void tEncoderClear(SEncoder* pCoder) {
|
|||
memset(pCoder, 0, sizeof(*pCoder));
|
||||
}
|
||||
|
||||
void tDecoderInit(SDecoder* pDecoder, const uint8_t* data, uint32_t size) {
|
||||
void tDecoderInit(SDecoder* pDecoder, uint8_t* data, uint32_t size) {
|
||||
pDecoder->data = data;
|
||||
pDecoder->size = size;
|
||||
pDecoder->pos = 0;
|
||||
|
|
Loading…
Reference in New Issue