提交 6c0c1b22 编写于 作者: H Hongze Cheng

more

上级 c5b42e57
......@@ -14,6 +14,10 @@
#define tPutB(buf, val) \
({ \
((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \
((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \
((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \
((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \
......@@ -27,7 +31,17 @@
POINTER_SHIFT(buf, sizeof(val)); \
})
typedef enum { A, B, C } T;
#define tPutD(buf, val) \
({ \
uint64_t tmp = val; \
for (size_t i = 0; i < sizeof(val); i++) { \
((uint8_t *)buf)[i] = tmp & 0xff; \
tmp >>= 8; \
} \
POINTER_SHIFT(buf, sizeof(val)); \
})
typedef enum { A, B, C, D } T;
static void func(T t) {
uint64_t val = 198;
......@@ -59,6 +73,14 @@ static void func(T t) {
}
}
break;
case D:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutD(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf;
}
}
break;
default:
break;
......@@ -83,5 +105,8 @@ int main(int argc, char const *argv[]) {
func(C);
uint64_t t4 = now();
printf("C: %ld\n", t4 - t3);
func(D);
uint64_t t5 = now();
printf("D: %ld\n", t5 - t4);
return 0;
}
......@@ -20,8 +20,11 @@
extern "C" {
#endif
typedef enum { TD_LITTLE_ENDIAN = 0, TD_BIG_ENDIAN } td_endian_t;
static const int32_t endian_test_var = 1;
#define IS_LITTLE_ENDIAN() (*(uint8_t *)(&endian_test_var) != 0)
#define TD_RT_ENDIAN() (IS_LITTLE_ENDIAN() ? TD_LITTLE_ENDIAN : TD_BIG_ENDIAN)
#ifdef __cplusplus
}
......
......@@ -25,6 +25,162 @@ extern "C" {
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
/* ------------------------ FIXED-LENGTH ENCODING ------------------------ */
#define tPut(T, b, v) \
({ \
*(T *)(b) = (v); \
sizeof(T); \
})
#define tGet(T, b, v) \
({ \
(v) = (*(T *)(b)); \
sizeof(T); \
})
// 16
#define tPut16b(b, v) \
({ \
((uint8_t *)(b))[1] = (v)&0xff; \
((uint8_t *)(b))[0] = ((v) >> 8) & 0xff; \
2; \
})
#define tGet16b(b, v) \
({ \
(v) = ((uint8_t *)(b))[0]; \
(v) = (v) << 8; \
(v) |= ((uint8_t *)(b))[1]; \
2; \
})
#define tPut16l(b, v) \
({ \
((uint8_t *)(b))[0] = (v)&0xff; \
((uint8_t *)(b))[1] = ((v) >> 8) & 0xff; \
2; \
})
#define tGet16l(b, v) \
({ \
(v) = ((uint8_t *)(b))[1]; \
(v) <<= 8; \
(v) |= ((uint8_t *)(b))[0]; \
2; \
})
// 32
#define tPut32b(b, v) \
({ \
((uint8_t *)(b))[3] = (v)&0xff; \
((uint8_t *)(b))[2] = ((v) >> 8) & 0xff; \
((uint8_t *)(b))[1] = ((v) >> 16) & 0xff; \
((uint8_t *)(b))[0] = ((v) >> 24) & 0xff; \
4; \
})
#define tGet32b(b, v) \
({ \
(v) = ((uint8_t *)(b))[0]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[1]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[2]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[3]; \
4; \
})
#define tPut32l(b, v) \
({ \
((uint8_t *)(b))[0] = (v)&0xff; \
((uint8_t *)(b))[1] = ((v) >> 8) & 0xff; \
((uint8_t *)(b))[2] = ((v) >> 16) & 0xff; \
((uint8_t *)(b))[3] = ((v) >> 24) & 0xff; \
4; \
})
#define tGet32l(b, v) \
({ \
(v) = ((uint8_t *)(b))[3]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[2]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[1]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[0]; \
4; \
})
// 64
#define tPut64b(b, v) \
({ \
((uint8_t *)(b))[7] = (v)&0xff; \
((uint8_t *)(b))[6] = ((v) >> 8) & 0xff; \
((uint8_t *)(b))[5] = ((v) >> 16) & 0xff; \
((uint8_t *)(b))[4] = ((v) >> 24) & 0xff; \
((uint8_t *)(b))[3] = ((v) >> 32) & 0xff; \
((uint8_t *)(b))[2] = ((v) >> 40) & 0xff; \
((uint8_t *)(b))[1] = ((v) >> 48) & 0xff; \
((uint8_t *)(b))[0] = ((v) >> 56) & 0xff; \
8; \
})
#define tGet64b(b, v) \
({ \
(v) = ((uint8_t *)(b))[0]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[1]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[2]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[3]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[4]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[5]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[6]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[7]; \
8; \
})
#define tPut64l(b, v) \
({ \
((uint8_t *)(b))[0] = (v)&0xff; \
((uint8_t *)(b))[1] = ((v) >> 8) & 0xff; \
((uint8_t *)(b))[2] = ((v) >> 16) & 0xff; \
((uint8_t *)(b))[3] = ((v) >> 24) & 0xff; \
((uint8_t *)(b))[4] = ((v) >> 32) & 0xff; \
((uint8_t *)(b))[5] = ((v) >> 40) & 0xff; \
((uint8_t *)(b))[6] = ((v) >> 48) & 0xff; \
((uint8_t *)(b))[7] = ((v) >> 56) & 0xff; \
8; \
})
#define tGet64l(b, v) \
({ \
(v) = ((uint8_t *)(b))[7]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[6]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[5]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[4]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[3]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[2]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[1]; \
(v) <<= 8; \
(v) = ((uint8_t *)(b))[0]; \
8; \
})
/* ------------------------ LEGACY CODES ------------------------ */
#if 1
// ---- Fixed U8
static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) {
if (buf != NULL) {
......@@ -368,6 +524,8 @@ static FORCE_INLINE void *taosDecodeStringTo(void *buf, char *value) {
return POINTER_SHIFT(buf, size);
}
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -403,10 +403,10 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
buf = taosDecodeFixedU8(buf, &(pTbCfg->type));
if (pTbCfg->type == META_SUPER_TABLE) {
buf = taosDecodeVariantU32(buf, pTbCfg->stbCfg.nTagCols);
buf = taosDecodeVariantU32(buf, &(pTbCfg->stbCfg.nTagCols));
pTbCfg->stbCfg.pTagSchema = (SSchema *)malloc(sizeof(SSchema) * pTbCfg->stbCfg.nTagCols);
for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) {
buf = taosDecodeFixedI8(buf, &pTbCfg->stbCfg.pSchema[i].type);
buf = taosDecodeFixedI8(buf, &(pTbCfg->stbCfg.pSchema[i].type));
buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].colId);
buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].bytes);
buf = taosDecodeStringTo(buf, pTbCfg->stbCfg.pSchema[i].name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册