提交 0c8b7bb0 编写于 作者: H Hongze Cheng

more refact

上级 5d150204
...@@ -2596,7 +2596,7 @@ typedef struct { ...@@ -2596,7 +2596,7 @@ typedef struct {
int64_t suid; int64_t suid;
int64_t uid; int64_t uid;
int32_t sver; int32_t sver;
uint64_t nData; uint32_t nData;
const uint8_t* pData; const uint8_t* pData;
SVCreateTbReq cTbReq; SVCreateTbReq cTbReq;
} SVSubmitBlk; } SVSubmitBlk;
......
...@@ -102,19 +102,12 @@ static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) { ...@@ -102,19 +102,12 @@ static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) {
} \ } \
tCoderClear(&coder); \ tCoderClear(&coder); \
} while (0) } while (0)
// #define tEncodeSize(E, S, SIZE) \
// ({ \ typedef struct SEncoder SEncoder;
// SCoder coder = {0}; \ typedef struct SDecoder SDecoder;
// int ret = 0; \
// tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \ void tEncoderInit(SEncoder* pEncoder, uint8_t* data, uint32_t size);
// if ((E)(&coder, S) == 0) { \ void tDecoderInit(SDecoder* pDecoder, const uint8_t* data, uint32_t size);
// SIZE = coder.pos; \
// } else { \
// ret = -1; \
// } \
// tCoderClear(&coder); \
// ret; \
// })
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type); void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
void tCoderClear(SCoder* pCoder); void tCoderClear(SCoder* pCoder);
...@@ -138,8 +131,8 @@ static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val); ...@@ -138,8 +131,8 @@ static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val);
static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val); static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val);
static int32_t tEncodeFloat(SCoder* pEncoder, float val); static int32_t tEncodeFloat(SCoder* pEncoder, float val);
static int32_t tEncodeDouble(SCoder* pEncoder, double val); static int32_t tEncodeDouble(SCoder* pEncoder, double val);
static int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val, uint64_t len); static int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val, uint32_t len);
static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint32_t len);
static int32_t tEncodeCStr(SCoder* pEncoder, const char* val); static int32_t tEncodeCStr(SCoder* pEncoder, const char* val);
/* ------------------------ DECODE ------------------------ */ /* ------------------------ DECODE ------------------------ */
...@@ -162,8 +155,8 @@ static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val); ...@@ -162,8 +155,8 @@ static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val);
static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val); static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val);
static int32_t tDecodeFloat(SCoder* pDecoder, float* val); static int32_t tDecodeFloat(SCoder* pDecoder, float* val);
static int32_t tDecodeDouble(SCoder* pDecoder, double* val); static int32_t tDecodeDouble(SCoder* pDecoder, double* val);
static int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val, uint64_t* len); static int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val, uint32_t* len);
static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint32_t* len);
static int32_t tDecodeCStr(SCoder* pDecoder, const char** val); static int32_t tDecodeCStr(SCoder* pDecoder, const char** val);
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val); static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
...@@ -292,8 +285,8 @@ static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) { ...@@ -292,8 +285,8 @@ static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
return tEncodeU64(pEncoder, v.ui); return tEncodeU64(pEncoder, v.ui);
} }
static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val, uint32_t len) {
if (tEncodeU64v(pEncoder, len) < 0) return -1; if (tEncodeU32v(pEncoder, len) < 0) return -1;
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
memcpy(TD_CODER_CURRENT(pEncoder), val, len); memcpy(TD_CODER_CURRENT(pEncoder), val, len);
...@@ -303,12 +296,12 @@ static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val, ...@@ -303,12 +296,12 @@ static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const uint8_t* val,
return 0; return 0;
} }
static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint32_t len) {
return tEncodeBinary(pEncoder, (void*)val, len + 1); return tEncodeBinary(pEncoder, (void*)val, len + 1);
} }
static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) { static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) {
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val)); return tEncodeCStrWithLen(pEncoder, val, (uint32_t)strlen(val));
} }
/* ------------------------ FOR DECODER ------------------------ */ /* ------------------------ FOR DECODER ------------------------ */
...@@ -413,8 +406,8 @@ static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) { ...@@ -413,8 +406,8 @@ static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
return 0; return 0;
} }
static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val, uint32_t* len) {
if (tDecodeU64v(pDecoder, len) < 0) return -1; if (tDecodeU32v(pDecoder, len) < 0) return -1;
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
if (val) { if (val) {
...@@ -425,20 +418,20 @@ static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val, ...@@ -425,20 +418,20 @@ static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const uint8_t** val,
return 0; return 0;
} }
static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint32_t* len) {
if (tDecodeBinary(pDecoder, (const uint8_t**)val, len) < 0) return -1; if (tDecodeBinary(pDecoder, (const uint8_t**)val, len) < 0) return -1;
(*len) -= 1; (*len) -= 1;
return 0; return 0;
} }
static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) { static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) {
uint64_t len; uint32_t len;
return tDecodeCStrAndLen(pDecoder, val, &len); return tDecodeCStrAndLen(pDecoder, val, &len);
} }
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) { static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
const char* pStr; const char* pStr;
uint64_t len; uint32_t len;
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1; if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
memcpy(val, pStr, len + 1); memcpy(val, pStr, len + 1);
......
...@@ -3766,7 +3766,7 @@ int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) { ...@@ -3766,7 +3766,7 @@ int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) {
} }
int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) { int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) {
uint64_t len; uint32_t len;
if (tStartDecode(pCoder) < 0) return -1; if (tStartDecode(pCoder) < 0) return -1;
......
...@@ -44,7 +44,7 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) { ...@@ -44,7 +44,7 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
} }
int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) { int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
uint64_t len; uint32_t len;
if (tStartDecode(pCoder) < 0) return -1; if (tStartDecode(pCoder) < 0) return -1;
if (tDecodeI64(pCoder, &pME->version) < 0) return -1; if (tDecodeI64(pCoder, &pME->version) < 0) return -1;
......
...@@ -177,15 +177,20 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p ...@@ -177,15 +177,20 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
// do insert data to SMemData // do insert data to SMemData
SMemSkipListCurosr slc = {0}; SMemSkipListCurosr slc = {0};
const uint8_t *p = pSubmitBlk->pData; const uint8_t *p = pSubmitBlk->pData;
const uint8_t *pt;
const STSRow *pRow;
uint64_t szRow;
SCoder coder = {0};
// tsdbMemSkipListCursorOpen(&slc, &pMemData->sl); // tCoderInit(&coder, TD_LITTLE_ENDIAN, pSubmitBlk->pData, pSubmitBlk->nData, TD_DECODER);
for (; p - pSubmitBlk->pData < pSubmitBlk->nData;) { for (;;) {
// if (p - (uint8_t *)pSubmitBlk->pData >= pSubmitBlk->nData) break; // if (tDecodeIsEnd(&coder)) break;
// const uint8_t *pt = p; // if (tDecodeBinary(&coder, (const uint8_t **)&pRow, &szRow) < 0) {
// p = tGetBinary(p, &pTSRow, &rlen); // terrno = TSDB_CODE_INVALID_MSG;
// return -1;
// // check the row (todo) // }
// check the row (todo)
// // move the cursor to position to write (todo) // // move the cursor to position to write (todo)
// int32_t c; // int32_t c;
...@@ -206,10 +211,11 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p ...@@ -206,10 +211,11 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
// // insert row // // insert row
// tsdbMemSkipListCursorPut(&slc, pSlNode); // tsdbMemSkipListCursorPut(&slc, pSlNode);
// // update status // update status
// if (pTSRow->ts < pMemData->minKey) pMemData->minKey = pTSRow->ts; if (pRow->ts < pMemData->minKey) pMemData->minKey = pRow->ts;
// if (pTSRow->ts > pMemData->maxKey) pMemData->maxKey = pTSRow->ts; if (pRow->ts > pMemData->maxKey) pMemData->maxKey = pRow->ts;
} }
// tCoderClear(&coder);
// tsdbMemSkipListCursorClose(&slc); // tsdbMemSkipListCursorClose(&slc);
// update status // update status
......
...@@ -409,7 +409,7 @@ SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen) { ...@@ -409,7 +409,7 @@ SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen) {
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) { if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
return NULL; return NULL;
} }
uint64_t len; uint32_t len;
char* data = NULL; char* data = NULL;
if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) { if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) {
return NULL; return NULL;
...@@ -668,7 +668,7 @@ SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen) { ...@@ -668,7 +668,7 @@ SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen) {
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) { if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
return NULL; return NULL;
} }
uint64_t len; uint32_t len;
char* data = NULL; char* data = NULL;
if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) { if (tDecodeBinary(&decoder, (const uint8_t**)(&data), &len) < 0) {
return NULL; return NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册