提交 3a759852 编写于 作者: H Hongze Cheng

TD-353

上级 63124ada
...@@ -83,7 +83,7 @@ typedef struct { ...@@ -83,7 +83,7 @@ typedef struct {
#define tdFreeSchema(s) tfree((s)) #define tdFreeSchema(s) tfree((s))
STSchema *tdDupSchema(STSchema *pSchema); STSchema *tdDupSchema(STSchema *pSchema);
void * tdEncodeSchema(void *buf, STSchema *pSchema); int tdEncodeSchema(void **buf, STSchema *pSchema);
void * tdDecodeSchema(void *buf, STSchema **pRSchema); void * tdDecodeSchema(void *buf, STSchema **pRSchema);
static FORCE_INLINE int comparColId(const void *key1, const void *key2) { static FORCE_INLINE int comparColId(const void *key1, const void *key2) {
...@@ -288,7 +288,7 @@ typedef struct { ...@@ -288,7 +288,7 @@ typedef struct {
SKVRow tdKVRowDup(SKVRow row); SKVRow tdKVRowDup(SKVRow row);
int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value); int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value);
void * tdEncodeKVRow(void *buf, SKVRow row); int tdEncodeKVRow(void **buf, SKVRow row);
void * tdDecodeKVRow(void *buf, SKVRow *row); void * tdDecodeKVRow(void *buf, SKVRow *row);
static FORCE_INLINE int comparTagId(const void *key1, const void *key2) { static FORCE_INLINE int comparTagId(const void *key1, const void *key2) {
......
...@@ -34,18 +34,19 @@ STSchema *tdDupSchema(STSchema *pSchema) { ...@@ -34,18 +34,19 @@ STSchema *tdDupSchema(STSchema *pSchema) {
/** /**
* Encode a schema to dst, and return the next pointer * Encode a schema to dst, and return the next pointer
*/ */
void *tdEncodeSchema(void *buf, STSchema *pSchema) { int tdEncodeSchema(void **buf, STSchema *pSchema) {
buf = taosEncodeFixedI32(buf, schemaVersion(pSchema)); int tlen = 0;
buf = taosEncodeFixedI32(buf, schemaNCols(pSchema)); tlen += taosEncodeFixedI32(buf, schemaVersion(pSchema));
tlen += taosEncodeFixedI32(buf, schemaNCols(pSchema));
for (int i = 0; i < schemaNCols(pSchema); i++) { for (int i = 0; i < schemaNCols(pSchema); i++) {
STColumn *pCol = schemaColAt(pSchema, i); STColumn *pCol = schemaColAt(pSchema, i);
buf = taosEncodeFixedI8(buf, colType(pCol)); tlen += taosEncodeFixedI8(buf, colType(pCol));
buf = taosEncodeFixedI16(buf, colColId(pCol)); tlen += taosEncodeFixedI16(buf, colColId(pCol));
buf = taosEncodeFixedI32(buf, colBytes(pCol)); tlen += taosEncodeFixedI32(buf, colBytes(pCol));
} }
return buf; return tlen;
} }
/** /**
...@@ -605,10 +606,14 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { ...@@ -605,10 +606,14 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
return 0; return 0;
} }
void *tdEncodeKVRow(void *buf, SKVRow row) { int tdEncodeKVRow(void **buf, SKVRow row) {
// May change the encode purpose // May change the encode purpose
kvRowCpy(buf, row); if (buf != NULL) {
return POINTER_SHIFT(buf, kvRowLen(row)); kvRowCpy(*buf, row);
*buf = POINTER_SHIFT(*buf, kvRowLen(row));
}
return kvRowLen(row);
} }
void *tdDecodeKVRow(void *buf, SKVRow *row) { void *tdDecodeKVRow(void *buf, SKVRow *row) {
......
...@@ -330,7 +330,7 @@ int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type); ...@@ -330,7 +330,7 @@ int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type);
SFileGroup* tsdbSearchFGroup(STsdbFileH* pFileH, int fid, int flags); SFileGroup* tsdbSearchFGroup(STsdbFileH* pFileH, int fid, int flags);
void tsdbFitRetention(STsdbRepo* pRepo); void tsdbFitRetention(STsdbRepo* pRepo);
int tsdbUpdateFileHeader(SFile* pFile, uint32_t version); int tsdbUpdateFileHeader(SFile* pFile, uint32_t version);
void* tsdbEncodeSFileInfo(void* buf, const STsdbFileInfo* pInfo); int tsdbEncodeSFileInfo(void** buf, const STsdbFileInfo* pInfo);
void* tsdbDecodeSFileInfo(void* buf, STsdbFileInfo* pInfo); void* tsdbDecodeSFileInfo(void* buf, STsdbFileInfo* pInfo);
int tsdbCpySFile(SFile* src, SFile* dst); int tsdbCpySFile(SFile* src, SFile* dst);
......
...@@ -302,8 +302,8 @@ int tsdbUpdateFileHeader(SFile *pFile, uint32_t version) { ...@@ -302,8 +302,8 @@ int tsdbUpdateFileHeader(SFile *pFile, uint32_t version) {
char buf[TSDB_FILE_HEAD_SIZE] = "\0"; char buf[TSDB_FILE_HEAD_SIZE] = "\0";
void *pBuf = (void *)buf; void *pBuf = (void *)buf;
pBuf = taosEncodeFixedU32(pBuf, version); taosEncodeFixedU32(pBuf, version);
pBuf = tsdbEncodeSFileInfo(pBuf, &(pFile->info)); tsdbEncodeSFileInfo(pBuf, &(pFile->info));
taosCalcChecksumAppend(0, (uint8_t *)buf, TSDB_FILE_HEAD_SIZE); taosCalcChecksumAppend(0, (uint8_t *)buf, TSDB_FILE_HEAD_SIZE);
...@@ -321,15 +321,16 @@ int tsdbUpdateFileHeader(SFile *pFile, uint32_t version) { ...@@ -321,15 +321,16 @@ int tsdbUpdateFileHeader(SFile *pFile, uint32_t version) {
return 0; return 0;
} }
void *tsdbEncodeSFileInfo(void *buf, const STsdbFileInfo *pInfo) { int tsdbEncodeSFileInfo(void **buf, const STsdbFileInfo *pInfo) {
buf = taosEncodeFixedU32(buf, pInfo->offset); int tlen = 0;
buf = taosEncodeFixedU32(buf, pInfo->len); tlen += taosEncodeFixedU32(buf, pInfo->offset);
buf = taosEncodeFixedU64(buf, pInfo->size); tlen += taosEncodeFixedU32(buf, pInfo->len);
buf = taosEncodeFixedU64(buf, pInfo->tombSize); tlen += taosEncodeFixedU64(buf, pInfo->size);
buf = taosEncodeFixedU32(buf, pInfo->totalBlocks); tlen += taosEncodeFixedU64(buf, pInfo->tombSize);
buf = taosEncodeFixedU32(buf, pInfo->totalSubBlocks); tlen += taosEncodeFixedU32(buf, pInfo->totalBlocks);
tlen += taosEncodeFixedU32(buf, pInfo->totalSubBlocks);
return buf; return tlen;
} }
void *tsdbDecodeSFileInfo(void *buf, STsdbFileInfo *pInfo) { void *tsdbDecodeSFileInfo(void *buf, STsdbFileInfo *pInfo) {
......
...@@ -42,9 +42,9 @@ static int tsdbTableSetSName(STableCfg *config, char *sname, bool dup); ...@@ -42,9 +42,9 @@ static int tsdbTableSetSName(STableCfg *config, char *sname, bool dup);
static int tsdbTableSetSuperUid(STableCfg *config, uint64_t uid); static int tsdbTableSetSuperUid(STableCfg *config, uint64_t uid);
static int tsdbTableSetTagValue(STableCfg *config, SKVRow row, bool dup); static int tsdbTableSetTagValue(STableCfg *config, SKVRow row, bool dup);
static int tsdbTableSetStreamSql(STableCfg *config, char *sql, bool dup); static int tsdbTableSetStreamSql(STableCfg *config, char *sql, bool dup);
static void * tsdbEncodeTableName(void *buf, tstr *name); static int tsdbEncodeTableName(void **buf, tstr *name);
static void * tsdbDecodeTableName(void *buf, tstr **name); static void * tsdbDecodeTableName(void *buf, tstr **name);
static void * tsdbEncodeTable(void *buf, STable *pTable); static int tsdbEncodeTable(void **buf, STable *pTable);
static void * tsdbDecodeTable(void *buf, STable **pRTable); static void * tsdbDecodeTable(void *buf, STable **pRTable);
// ------------------ OUTER FUNCTIONS ------------------ // ------------------ OUTER FUNCTIONS ------------------
...@@ -85,6 +85,9 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) { ...@@ -85,6 +85,9 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) {
} }
if (tsdbAddTableToMeta(pRepo, table, true) < 0) goto _err; if (tsdbAddTableToMeta(pRepo, table, true) < 0) goto _err;
int tlen = tsdbEncodeTable(NULL, pTable);
ASSERT(tlen > 0);
// // Write to meta file // // Write to meta file
// int bufLen = 0; // int bufLen = 0;
// char *buf = malloc(1024 * 1024); // char *buf = malloc(1024 * 1024);
...@@ -472,10 +475,11 @@ int tsdbUpdateTable(STsdbMeta *pMeta, STable *pTable, STableCfg *pCfg) { ...@@ -472,10 +475,11 @@ int tsdbUpdateTable(STsdbMeta *pMeta, STable *pTable, STableCfg *pCfg) {
} }
if (isChanged) { if (isChanged) {
char *buf = malloc(1024 * 1024); // TODO
tsdbEncodeTable(buf, pTable); // char *buf = malloc(1024 * 1024);
// tsdbInsertMetaRecord(pMeta->mfh, pTable->tableId.uid, buf, bufLen); // tsdbEncodeTable(buf, pTable);
free(buf); // // tsdbInsertMetaRecord(pMeta->mfh, pTable->tableId.uid, buf, bufLen);
// free(buf);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -999,14 +1003,17 @@ void tsdbClearTableCfg(STableCfg *config) { ...@@ -999,14 +1003,17 @@ void tsdbClearTableCfg(STableCfg *config) {
} }
} }
static void *tsdbEncodeTableName(void *buf, tstr *name) { static int tsdbEncodeTableName(void **buf, tstr *name) {
void *pBuf = buf; int tlen = 0;
pBuf = taosEncodeFixedI16(pBuf, name->len); tlen += taosEncodeFixedI16(buf, name->len);
memcpy(pBuf, name->data, name->len); if (buf != NULL) {
pBuf = POINTER_SHIFT(pBuf, name->len); memcpy(*buf, name->data, name->len);
*buf = POINTER_SHIFT(*buf, name->len);
}
tlen += name->len;
return pBuf; return tlen;
} }
static void *tsdbDecodeTableName(void *buf, tstr **name) { static void *tsdbDecodeTableName(void *buf, tstr **name) {
...@@ -1025,33 +1032,34 @@ static void *tsdbDecodeTableName(void *buf, tstr **name) { ...@@ -1025,33 +1032,34 @@ static void *tsdbDecodeTableName(void *buf, tstr **name) {
return buf; return buf;
} }
static void *tsdbEncodeTable(void *buf, STable *pTable) { static int tsdbEncodeTable(void **buf, STable *pTable) {
ASSERT(pTable != NULL); ASSERT(pTable != NULL);
int tlen = 0;
buf = taosEncodeFixedU8(buf, pTable->type); tlen = taosEncodeFixedU8(buf, pTable->type);
buf = tsdbEncodeTableName(buf, pTable->name); tlen = tsdbEncodeTableName(buf, pTable->name);
buf = taosEncodeFixedU64(buf, TABLE_UID(pTable)); tlen = taosEncodeFixedU64(buf, TABLE_UID(pTable));
buf = taosEncodeFixedI32(buf, TABLE_TID(pTable)); tlen = taosEncodeFixedI32(buf, TABLE_TID(pTable));
if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) { if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) {
buf = taosEncodeFixedU64(buf, TABLE_SUID(pTable)); tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable));
buf = tdEncodeKVRow(buf, pTable->tagVal); tlen += tdEncodeKVRow(buf, pTable->tagVal);
} else { } else {
buf = taosEncodeFixedU8(buf, pTable->numOfSchemas); tlen += taosEncodeFixedU8(buf, pTable->numOfSchemas);
for (int i = 0; i < pTable->numOfSchemas; i++) { for (int i = 0; i < pTable->numOfSchemas; i++) {
buf = tdEncodeSchema(buf, pTable->schema[i]); tlen += tdEncodeSchema(buf, pTable->schema[i]);
} }
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) { if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
buf = tdEncodeSchema(buf, pTable->tagSchema); tlen += tdEncodeSchema(buf, pTable->tagSchema);
} }
if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE) { if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE) {
buf = taosEncodeString(buf, pTable->sql); tlen += taosEncodeString(buf, pTable->sql);
} }
} }
return buf; return tlen;
} }
static void *tsdbDecodeTable(void *buf, STable **pRTable) { static void *tsdbDecodeTable(void *buf, STable **pRTable) {
......
...@@ -50,7 +50,7 @@ static int tsdbLoadSingleBlockDataCols(SRWHelper *pHelper, SCompBlock *pCompBl ...@@ -50,7 +50,7 @@ static int tsdbLoadSingleBlockDataCols(SRWHelper *pHelper, SCompBlock *pCompBl
static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, char *content, int32_t len, int8_t comp, int numOfRows, static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, char *content, int32_t len, int8_t comp, int numOfRows,
int maxPoints, char *buffer, int bufferSize); int maxPoints, char *buffer, int bufferSize);
static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols); static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols);
static void *tsdbEncodeSCompIdx(void *buf, SCompIdx *pIdx); static int tsdbEncodeSCompIdx(void **buf, SCompIdx *pIdx);
static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx); static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx);
static void tsdbDestroyHelperBlock(SRWHelper *pHelper); static void tsdbDestroyHelperBlock(SRWHelper *pHelper);
...@@ -371,8 +371,8 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { ...@@ -371,8 +371,8 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) {
pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer) * 2); pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer) * 2);
} }
buf = POINTER_SHIFT(pHelper->pBuffer, drift); buf = POINTER_SHIFT(pHelper->pBuffer, drift);
buf = taosEncodeVariantU32(buf, i); taosEncodeVariantU32(&buf, i);
buf = tsdbEncodeSCompIdx(buf, pCompIdx); tsdbEncodeSCompIdx(&buf, pCompIdx);
} }
} }
...@@ -1298,15 +1298,17 @@ _err: ...@@ -1298,15 +1298,17 @@ _err:
return -1; return -1;
} }
static void *tsdbEncodeSCompIdx(void *buf, SCompIdx *pIdx) { static int tsdbEncodeSCompIdx(void **buf, SCompIdx *pIdx) {
buf = taosEncodeVariantU32(buf, pIdx->len); int tlen = 0;
buf = taosEncodeVariantU32(buf, pIdx->offset);
buf = taosEncodeFixedU8(buf, pIdx->hasLast);
buf = taosEncodeVariantU32(buf, pIdx->numOfBlocks);
buf = taosEncodeFixedU64(buf, pIdx->uid);
buf = taosEncodeFixedU64(buf, pIdx->maxKey);
return buf; tlen += taosEncodeVariantU32(buf, pIdx->len);
tlen += taosEncodeVariantU32(buf, pIdx->offset);
tlen += taosEncodeFixedU8(buf, pIdx->hasLast);
tlen += taosEncodeVariantU32(buf, pIdx->numOfBlocks);
tlen += taosEncodeFixedU64(buf, pIdx->uid);
tlen += taosEncodeFixedU64(buf, pIdx->maxKey);
return tlen;
} }
static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx) { static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx) {
......
...@@ -33,9 +33,13 @@ static const int32_t TNUMBER = 1; ...@@ -33,9 +33,13 @@ static const int32_t TNUMBER = 1;
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode #define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
// ---- Fixed U8 // ---- Fixed U8
static FORCE_INLINE void *taosEncodeFixedU8(void *buf, uint8_t value) { static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) {
((uint8_t *)buf)[0] = value; if (buf != NULL) {
return POINTER_SHIFT(buf, sizeof(value)); ((uint8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value));
}
return (int)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU8(void *buf, uint8_t *value) { static FORCE_INLINE void *taosDecodeFixedU8(void *buf, uint8_t *value) {
...@@ -44,9 +48,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(void *buf, uint8_t *value) { ...@@ -44,9 +48,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(void *buf, uint8_t *value) {
} }
// ---- Fixed I8 // ---- Fixed I8
static FORCE_INLINE void *taosEncodeFixedI8(void *buf, int8_t value) { static FORCE_INLINE int taosEncodeFixedI8(void **buf, int8_t value) {
((int8_t *)buf)[0] = value; if (buf != NULL) {
return POINTER_SHIFT(buf, sizeof(value)); ((int8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value));
}
return (int)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedI8(void *buf, int8_t *value) { static FORCE_INLINE void *taosDecodeFixedI8(void *buf, int8_t *value) {
...@@ -55,15 +62,18 @@ static FORCE_INLINE void *taosDecodeFixedI8(void *buf, int8_t *value) { ...@@ -55,15 +62,18 @@ static FORCE_INLINE void *taosDecodeFixedI8(void *buf, int8_t *value) {
} }
// ---- Fixed U16 // ---- Fixed U16
static FORCE_INLINE void *taosEncodeFixedU16(void *buf, uint16_t value) { static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
} else { } else {
((uint8_t *)buf)[0] = value & 0xff; ((uint8_t *)(*buf))[0] = value & 0xff;
((uint8_t *)buf)[1] = (value >> 8) & 0xff; ((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
}
*buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return POINTER_SHIFT(buf, sizeof(value)); return (int)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU16(void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeFixedU16(void *buf, uint16_t *value) {
...@@ -78,7 +88,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(void *buf, uint16_t *value) { ...@@ -78,7 +88,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(void *buf, uint16_t *value) {
} }
// ---- Fixed I16 // ---- Fixed I16
static FORCE_INLINE void *taosEncodeFixedI16(void *buf, int16_t value) { static FORCE_INLINE int taosEncodeFixedI16(void **buf, int16_t value) {
return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -90,17 +100,20 @@ static FORCE_INLINE void *taosDecodeFixedI16(void *buf, int16_t *value) { ...@@ -90,17 +100,20 @@ static FORCE_INLINE void *taosDecodeFixedI16(void *buf, int16_t *value) {
} }
// ---- Fixed U32 // ---- Fixed U32
static FORCE_INLINE void *taosEncodeFixedU32(void *buf, uint32_t value) { static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
} else { } else {
((uint8_t *)buf)[0] = value & 0xff; ((uint8_t *)(*buf))[0] = value & 0xff;
((uint8_t *)buf)[1] = (value >> 8) & 0xff; ((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
((uint8_t *)buf)[2] = (value >> 16) & 0xff; ((uint8_t *)(*buf))[2] = (value >> 16) & 0xff;
((uint8_t *)buf)[3] = (value >> 24) & 0xff; ((uint8_t *)(*buf))[3] = (value >> 24) & 0xff;
}
*buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return POINTER_SHIFT(buf, sizeof(value)); return (int)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU32(void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeFixedU32(void *buf, uint32_t *value) {
...@@ -117,7 +130,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(void *buf, uint32_t *value) { ...@@ -117,7 +130,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(void *buf, uint32_t *value) {
} }
// ---- Fixed I32 // ---- Fixed I32
static FORCE_INLINE void *taosEncodeFixedI32(void *buf, int32_t value) { static FORCE_INLINE int taosEncodeFixedI32(void **buf, int32_t value) {
return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -129,21 +142,25 @@ static FORCE_INLINE void *taosDecodeFixedI32(void *buf, int32_t *value) { ...@@ -129,21 +142,25 @@ static FORCE_INLINE void *taosDecodeFixedI32(void *buf, int32_t *value) {
} }
// ---- Fixed U64 // ---- Fixed U64
static FORCE_INLINE void *taosEncodeFixedU64(void *buf, uint64_t value) { static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
} else { } else {
((uint8_t *)buf)[0] = value & 0xff; ((uint8_t *)(*buf))[0] = value & 0xff;
((uint8_t *)buf)[1] = (value >> 8) & 0xff; ((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
((uint8_t *)buf)[2] = (value >> 16) & 0xff; ((uint8_t *)(*buf))[2] = (value >> 16) & 0xff;
((uint8_t *)buf)[3] = (value >> 24) & 0xff; ((uint8_t *)(*buf))[3] = (value >> 24) & 0xff;
((uint8_t *)buf)[4] = (value >> 32) & 0xff; ((uint8_t *)(*buf))[4] = (value >> 32) & 0xff;
((uint8_t *)buf)[5] = (value >> 40) & 0xff; ((uint8_t *)(*buf))[5] = (value >> 40) & 0xff;
((uint8_t *)buf)[6] = (value >> 48) & 0xff; ((uint8_t *)(*buf))[6] = (value >> 48) & 0xff;
((uint8_t *)buf)[7] = (value >> 56) & 0xff; ((uint8_t *)(*buf))[7] = (value >> 56) & 0xff;
}
*buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return POINTER_SHIFT(buf, sizeof(value)); return (int)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU64(void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeFixedU64(void *buf, uint64_t *value) {
...@@ -164,7 +181,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(void *buf, uint64_t *value) { ...@@ -164,7 +181,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(void *buf, uint64_t *value) {
} }
// ---- Fixed I64 // ---- Fixed I64
static FORCE_INLINE void *taosEncodeFixedI64(void *buf, int64_t value) { static FORCE_INLINE int taosEncodeFixedI64(void **buf, int64_t value) {
return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -176,18 +193,21 @@ static FORCE_INLINE void *taosDecodeFixedI64(void *buf, int64_t *value) { ...@@ -176,18 +193,21 @@ static FORCE_INLINE void *taosDecodeFixedI64(void *buf, int64_t *value) {
} }
// ---- Variant U16 // ---- Variant U16
static FORCE_INLINE void *taosEncodeVariantU16(void *buf, uint16_t value) { static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
int i = 0; int i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
((uint8_t *)buf)[i] = (value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
i++; i++;
ASSERT(i < 3); ASSERT(i < 3);
} }
((uint8_t *)buf)[i] = value; if (buf != NULL) {
((uint8_t *)(*buf))[i] = value;
*buf = POINTER_SHIFT(*buf, i + 1);
}
return POINTER_SHIFT(buf, i + 1); return i + 1;
} }
static FORCE_INLINE void *taosDecodeVariantU16(void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeVariantU16(void *buf, uint16_t *value) {
...@@ -209,7 +229,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(void *buf, uint16_t *value) { ...@@ -209,7 +229,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(void *buf, uint16_t *value) {
} }
// ---- Variant I16 // ---- Variant I16
static FORCE_INLINE void *taosEncodeVariantI16(void *buf, int16_t value) { static FORCE_INLINE int taosEncodeVariantI16(void **buf, int16_t value) {
return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -221,18 +241,21 @@ static FORCE_INLINE void *taosDecodeVariantI16(void *buf, int16_t *value) { ...@@ -221,18 +241,21 @@ static FORCE_INLINE void *taosDecodeVariantI16(void *buf, int16_t *value) {
} }
// ---- Variant U32 // ---- Variant U32
static FORCE_INLINE void *taosEncodeVariantU32(void *buf, uint32_t value) { static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
int i = 0; int i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
((uint8_t *)buf)[i] = (value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
i++; i++;
ASSERT(i < 5); ASSERT(i < 5);
} }
((uint8_t *)buf)[i] = value; if (buf != NULL) {
((uint8_t *)(*buf))[i] = value;
*buf = POINTER_SHIFT(*buf, i + 1);
}
return POINTER_SHIFT(buf, i + 1); return i + 1;
} }
static FORCE_INLINE void *taosDecodeVariantU32(void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeVariantU32(void *buf, uint32_t *value) {
...@@ -254,7 +277,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(void *buf, uint32_t *value) { ...@@ -254,7 +277,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(void *buf, uint32_t *value) {
} }
// ---- Variant I32 // ---- Variant I32
static FORCE_INLINE void *taosEncodeVariantI32(void *buf, int32_t value) { static FORCE_INLINE int taosEncodeVariantI32(void **buf, int32_t value) {
return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -266,18 +289,21 @@ static FORCE_INLINE void *taosDecodeVariantI32(void *buf, int32_t *value) { ...@@ -266,18 +289,21 @@ static FORCE_INLINE void *taosDecodeVariantI32(void *buf, int32_t *value) {
} }
// ---- Variant U64 // ---- Variant U64
static FORCE_INLINE void *taosEncodeVariantU64(void *buf, uint64_t value) { static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
int i = 0; int i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
((uint8_t *)buf)[i] = (value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
i++; i++;
ASSERT(i < 10); ASSERT(i < 10);
} }
((uint8_t *)buf)[i] = value; if (buf != NULL) {
((uint8_t *)(*buf))[i] = value;
*buf = POINTER_SHIFT(*buf, i + 1);
}
return POINTER_SHIFT(buf, i + 1); return i + 1;
} }
static FORCE_INLINE void *taosDecodeVariantU64(void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeVariantU64(void *buf, uint64_t *value) {
...@@ -299,7 +325,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(void *buf, uint64_t *value) { ...@@ -299,7 +325,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(void *buf, uint64_t *value) {
} }
// ---- Variant I64 // ---- Variant I64
static FORCE_INLINE void *taosEncodeVariantI64(void *buf, int64_t value) { static FORCE_INLINE int taosEncodeVariantI64(void **buf, int64_t value) {
return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -311,13 +337,18 @@ static FORCE_INLINE void *taosDecodeVariantI64(void *buf, int64_t *value) { ...@@ -311,13 +337,18 @@ static FORCE_INLINE void *taosDecodeVariantI64(void *buf, int64_t *value) {
} }
// ---- string // ---- string
static FORCE_INLINE void *taosEncodeString(void *buf, char *value) { static FORCE_INLINE int taosEncodeString(void **buf, char *value) {
int tlen = 0;
size_t size = strlen(value); size_t size = strlen(value);
buf = taosEncodeVariantU64(buf, size); tlen += taosEncodeVariantU64(buf, size);
memcpy(buf, value, size); if (buf != NULL) {
memcpy(*buf, value, size);
*buf = POINTER_SHIFT(*buf, size);
}
tlen += size;
return POINTER_SHIFT(buf, size); return tlen;
} }
static FORCE_INLINE void *taosDecodeString(void *buf, char **value) { static FORCE_INLINE void *taosDecodeString(void *buf, char **value) {
......
...@@ -41,7 +41,7 @@ typedef struct { ...@@ -41,7 +41,7 @@ typedef struct {
} SKVRecord; } SKVRecord;
static int tdInitKVStoreHeader(int fd, char *fname); static int tdInitKVStoreHeader(int fd, char *fname);
static void * tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo); static int tdEncodeStoreInfo(void **buf, SStoreInfo *pInfo);
static void * tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo); static void * tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo);
static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH); static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH);
static char * tdGetKVStoreSnapshotFname(char *fdata); static char * tdGetKVStoreSnapshotFname(char *fdata);
...@@ -49,7 +49,7 @@ static char * tdGetKVStoreNewFname(char *fdata); ...@@ -49,7 +49,7 @@ static char * tdGetKVStoreNewFname(char *fdata);
static void tdFreeKVStore(SKVStore *pStore); static void tdFreeKVStore(SKVStore *pStore);
static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo); static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo);
static int tdLoadKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo); static int tdLoadKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo);
static void * tdEncodeKVRecord(void *buf, SKVRecord *pRecord); static int tdEncodeKVRecord(void **buf, SKVRecord *pRecord);
static void * tdDecodeKVRecord(void *buf, SKVRecord *pRecord); static void * tdDecodeKVRecord(void *buf, SKVRecord *pRecord);
static int tdRestoreKVStore(SKVStore *pStore); static int tdRestoreKVStore(SKVStore *pStore);
...@@ -269,7 +269,8 @@ int tdDropKVStoreRecord(SKVStore *pStore, uint64_t uid) { ...@@ -269,7 +269,8 @@ int tdDropKVStoreRecord(SKVStore *pStore, uint64_t uid) {
rInfo.uid = pRecord->uid; rInfo.uid = pRecord->uid;
rInfo.size = pRecord->size; rInfo.size = pRecord->size;
void *pBuf = tdEncodeKVRecord(buf, &rInfo); void *pBuf = buf;
tdEncodeKVRecord(&pBuf, &rInfo);
if (twrite(pStore->fd, buf, POINTER_DISTANCE(pBuf, buf)) < POINTER_DISTANCE(pBuf, buf)) { if (twrite(pStore->fd, buf, POINTER_DISTANCE(pBuf, buf)) < POINTER_DISTANCE(pBuf, buf)) {
uError("failed to write %d bytes to file %s since %s", POINTER_DISTANCE(pBuf, buf), pStore->fname, strerror(errno)); uError("failed to write %d bytes to file %s since %s", POINTER_DISTANCE(pBuf, buf), pStore->fname, strerror(errno));
...@@ -344,7 +345,8 @@ static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo) { ...@@ -344,7 +345,8 @@ static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo) {
return -1; return -1;
} }
void *pBuf = tdEncodeStoreInfo(buf, pInfo); void *pBuf = buf;
tdEncodeStoreInfo(&pBuf, pInfo);
ASSERT(POINTER_DISTANCE(pBuf, buf) + sizeof(TSCKSUM) <= TD_KVSTORE_HEADER_SIZE); ASSERT(POINTER_DISTANCE(pBuf, buf) + sizeof(TSCKSUM) <= TD_KVSTORE_HEADER_SIZE);
taosCalcChecksumAppend(0, (uint8_t *)buf, TD_KVSTORE_HEADER_SIZE); taosCalcChecksumAppend(0, (uint8_t *)buf, TD_KVSTORE_HEADER_SIZE);
...@@ -363,13 +365,14 @@ static int tdInitKVStoreHeader(int fd, char *fname) { ...@@ -363,13 +365,14 @@ static int tdInitKVStoreHeader(int fd, char *fname) {
return tdUpdateKVStoreHeader(fd, fname, &info); return tdUpdateKVStoreHeader(fd, fname, &info);
} }
static void *tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo) { static int tdEncodeStoreInfo(void **buf, SStoreInfo *pInfo) {
buf = taosEncodeVariantI64(buf, pInfo->size); int tlen = 0;
buf = taosEncodeVariantI64(buf, pInfo->tombSize); tlen += taosEncodeVariantI64(buf, pInfo->size);
buf = taosEncodeVariantI64(buf, pInfo->nRecords); tlen += taosEncodeVariantI64(buf, pInfo->tombSize);
buf = taosEncodeVariantI64(buf, pInfo->nDels); tlen += taosEncodeVariantI64(buf, pInfo->nRecords);
tlen += taosEncodeVariantI64(buf, pInfo->nDels);
return buf; return tlen;
} }
static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) { static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) {
...@@ -450,12 +453,13 @@ static char *tdGetKVStoreNewFname(char *fdata) { ...@@ -450,12 +453,13 @@ static char *tdGetKVStoreNewFname(char *fdata) {
return fname; return fname;
} }
static void *tdEncodeKVRecord(void *buf, SKVRecord *pRecord) { static int tdEncodeKVRecord(void **buf, SKVRecord *pRecord) {
buf = taosEncodeFixedU64(buf, pRecord->uid); int tlen = 0;
buf = taosEncodeFixedI64(buf, pRecord->offset); tlen += taosEncodeFixedU64(buf, pRecord->uid);
buf = taosEncodeFixedI64(buf, pRecord->size); tlen += taosEncodeFixedI64(buf, pRecord->offset);
tlen += taosEncodeFixedI64(buf, pRecord->size);
return buf; return tlen;
} }
static void *tdDecodeKVRecord(void *buf, SKVRecord *pRecord) { static void *tdDecodeKVRecord(void *buf, SKVRecord *pRecord) {
......
...@@ -9,120 +9,144 @@ static bool test_fixed_uint16(uint16_t value) { ...@@ -9,120 +9,144 @@ static bool test_fixed_uint16(uint16_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint16_t value_check = 0; uint16_t value_check = 0;
void *ptr1 = taosEncodeFixedU16(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedU16(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); int tlen = taosEncodeFixedU16(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedU16(static_cast<void *>(buf), &value_check);
return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_fixed_int16(int16_t value) { static bool test_fixed_int16(int16_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int16_t value_check = 0; int16_t value_check = 0;
void *ptr1 = taosEncodeFixedI16(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedI16(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeFixedI16(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedI16(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_fixed_uint32(uint32_t value) { static bool test_fixed_uint32(uint32_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint32_t value_check = 0; uint32_t value_check = 0;
void *ptr1 = taosEncodeFixedU32(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedU32(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeFixedU32(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedU32(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_fixed_int32(int32_t value) { static bool test_fixed_int32(int32_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int32_t value_check = 0; int32_t value_check = 0;
void *ptr1 = taosEncodeFixedI32(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedI32(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); int tlen = taosEncodeFixedI32(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedI32(static_cast<void *>(buf), &value_check);
return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_fixed_uint64(uint64_t value) { static bool test_fixed_uint64(uint64_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint64_t value_check = 0; uint64_t value_check = 0;
void *ptr1 = taosEncodeFixedU64(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedU64(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeFixedU64(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedU64(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_fixed_int64(int64_t value) { static bool test_fixed_int64(int64_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int64_t value_check = 0; int64_t value_check = 0;
void *ptr1 = taosEncodeFixedI64(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeFixedI64(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeFixedI64(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeFixedI64(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_uint16(uint16_t value) { static bool test_variant_uint16(uint16_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint16_t value_check = 0; uint16_t value_check = 0;
void *ptr1 = taosEncodeVariantU16(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantU16(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); int tlen = taosEncodeVariantU16(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantU16(static_cast<void *>(buf), &value_check);
return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_int16(int16_t value) { static bool test_variant_int16(int16_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int16_t value_check = 0; int16_t value_check = 0;
void *ptr1 = taosEncodeVariantI16(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantI16(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeVariantI16(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantI16(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_uint32(uint32_t value) { static bool test_variant_uint32(uint32_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint32_t value_check = 0; uint32_t value_check = 0;
void *ptr1 = taosEncodeVariantU32(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantU32(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeVariantU32(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantU32(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_int32(int32_t value) { static bool test_variant_int32(int32_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int32_t value_check = 0; int32_t value_check = 0;
void *ptr1 = taosEncodeVariantI32(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantI32(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); int tlen = taosEncodeVariantI32(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantI32(static_cast<void *>(buf), &value_check);
return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_uint64(uint64_t value) { static bool test_variant_uint64(uint64_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
uint64_t value_check = 0; uint64_t value_check = 0;
void *ptr1 = taosEncodeVariantU64(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantU64(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeVariantU64(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantU64(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
static bool test_variant_int64(int64_t value) { static bool test_variant_int64(int64_t value) {
char buf[20] = "\0"; char buf[20] = "\0";
int64_t value_check = 0; int64_t value_check = 0;
void *ptr1 = taosEncodeVariantI64(static_cast<void *>(buf), value); void *pBuf = (void *)buf;
void *ptr2 = taosDecodeVariantI64(static_cast<void *>(buf), &value_check);
int tlen = taosEncodeVariantI64(static_cast<void **>(&pBuf), value);
void *ptr = taosDecodeVariantI64(static_cast<void *>(buf), &value_check);
return ((ptr2 != NULL) && (value == value_check) && (ptr1 == ptr2)); return ((ptr != NULL) && (value == value_check) && (pBuf == ptr) && POINTER_DISTANCE(pBuf, buf) == tlen);
} }
TEST(codingTest, fixed_encode_decode) { TEST(codingTest, fixed_encode_decode) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册