fix compile error
This commit is contained in:
parent
141ef5afd0
commit
20854de43b
|
@ -1824,7 +1824,7 @@ int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchR
|
||||||
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
|
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
|
||||||
if (tEncodeI32(pEncoder, pKv->key) < 0) return -1;
|
if (tEncodeI32(pEncoder, pKv->key) < 0) return -1;
|
||||||
if (tEncodeI32(pEncoder, pKv->valueLen) < 0) return -1;
|
if (tEncodeI32(pEncoder, pKv->valueLen) < 0) return -1;
|
||||||
if (tEncodeBinary(pEncoder, (const char*)pKv->value, pKv->valueLen) < 0) return -1;
|
if (tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen) < 0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ static FORCE_INLINE int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val,
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len) {
|
static FORCE_INLINE int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len) {
|
||||||
return tEncodeBinary(pCoder, (void*)val, len + 1);
|
return tEncodeBinary(pCoder, (uint8_t*)val, len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeCStr(SEncoder* pCoder, const char* val) {
|
static FORCE_INLINE int32_t tEncodeCStr(SEncoder* pCoder, const char* val) {
|
||||||
|
@ -383,7 +383,7 @@ static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val,
|
||||||
|
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
||||||
if (val) {
|
if (val) {
|
||||||
*val = (void*)TD_CODER_CURRENT(pCoder);
|
*val = (uint8_t*)TD_CODER_CURRENT(pCoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pCoder, *len);
|
TD_CODER_MOVE_POS(pCoder, *len);
|
||||||
|
|
|
@ -41,9 +41,9 @@ target_sources(freelistTest
|
||||||
)
|
)
|
||||||
target_link_libraries(freelistTest os util gtest gtest_main)
|
target_link_libraries(freelistTest os util gtest gtest_main)
|
||||||
|
|
||||||
# encodeTest
|
# # encodeTest
|
||||||
add_executable(encodeTest "encodeTest.cpp")
|
# add_executable(encodeTest "encodeTest.cpp")
|
||||||
target_link_libraries(encodeTest os util gtest gtest_main)
|
# target_link_libraries(encodeTest os util gtest gtest_main)
|
||||||
|
|
||||||
# queueTest
|
# queueTest
|
||||||
add_executable(procTest "procTest.cpp")
|
add_executable(procTest "procTest.cpp")
|
||||||
|
|
|
@ -12,48 +12,49 @@
|
||||||
#define BUF_SIZE 64
|
#define BUF_SIZE 64
|
||||||
td_endian_t endian_arr[2] = {TD_LITTLE_ENDIAN, TD_BIG_ENDIAN};
|
td_endian_t endian_arr[2] = {TD_LITTLE_ENDIAN, TD_BIG_ENDIAN};
|
||||||
|
|
||||||
static int32_t encode(SCoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, int16_t val) { return tEncodeI16(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, int16_t val) { return tEncodeI16(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, uint16_t val) { return tEncodeU16(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, uint16_t val) { return tEncodeU16(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, int32_t val) { return tEncodeI32(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, int32_t val) { return tEncodeI32(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, uint32_t val) { return tEncodeU32(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, uint32_t val) { return tEncodeU32(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, int64_t val) { return tEncodeI64(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, int64_t val) { return tEncodeI64(pCoder, val); }
|
||||||
static int32_t encode(SCoder *pCoder, uint64_t val) { return tEncodeU64(pCoder, val); }
|
static int32_t encode(SEncoder *pCoder, uint64_t val) { return tEncodeU64(pCoder, val); }
|
||||||
|
|
||||||
static int32_t decode(SCoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, int16_t *val) { return tDecodeI16(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, int16_t *val) { return tDecodeI16(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, uint16_t *val) { return tDecodeU16(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, uint16_t *val) { return tDecodeU16(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, int32_t *val) { return tDecodeI32(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, int32_t *val) { return tDecodeI32(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, uint32_t *val) { return tDecodeU32(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, uint32_t *val) { return tDecodeU32(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, int64_t *val) { return tDecodeI64(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, int64_t *val) { return tDecodeI64(pCoder, val); }
|
||||||
static int32_t decode(SCoder *pCoder, uint64_t *val) { return tDecodeU64(pCoder, val); }
|
static int32_t decode(SDecoder *pCoder, uint64_t *val) { return tDecodeU64(pCoder, val); }
|
||||||
|
|
||||||
static int32_t encodev(SCoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, int16_t val) { return tEncodeI16v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, int16_t val) { return tEncodeI16v(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, uint16_t val) { return tEncodeU16v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, uint16_t val) { return tEncodeU16v(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, int32_t val) { return tEncodeI32v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, int32_t val) { return tEncodeI32v(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, uint32_t val) { return tEncodeU32v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, uint32_t val) { return tEncodeU32v(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, int64_t val) { return tEncodeI64v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, int64_t val) { return tEncodeI64v(pCoder, val); }
|
||||||
static int32_t encodev(SCoder *pCoder, uint64_t val) { return tEncodeU64v(pCoder, val); }
|
static int32_t encodev(SEncoder *pCoder, uint64_t val) { return tEncodeU64v(pCoder, val); }
|
||||||
|
|
||||||
static int32_t decodev(SCoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, int16_t *val) { return tDecodeI16v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, int16_t *val) { return tDecodeI16v(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, uint16_t *val) { return tDecodeU16v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, uint16_t *val) { return tDecodeU16v(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, int32_t *val) { return tDecodeI32v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, int32_t *val) { return tDecodeI32v(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, uint32_t *val) { return tDecodeU32v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, uint32_t *val) { return tDecodeU32v(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, int64_t *val) { return tDecodeI64v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, int64_t *val) { return tDecodeI64v(pCoder, val); }
|
||||||
static int32_t decodev(SCoder *pCoder, uint64_t *val) { return tDecodeU64v(pCoder, val); }
|
static int32_t decodev(SDecoder *pCoder, uint64_t *val) { return tDecodeU64v(pCoder, val); }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void simple_encode_decode_func(bool var_len) {
|
static void simple_encode_decode_func(bool var_len) {
|
||||||
uint8_t buf[BUF_SIZE];
|
uint8_t buf[BUF_SIZE];
|
||||||
SCoder coder;
|
SEncoder encoder = {0};
|
||||||
T min_val, max_val;
|
SDecoder decoder = {0};
|
||||||
T step = 1;
|
T min_val, max_val;
|
||||||
|
T step = 1;
|
||||||
|
|
||||||
if (typeid(T) == typeid(int8_t)) {
|
if (typeid(T) == typeid(int8_t)) {
|
||||||
min_val = INT8_MIN;
|
min_val = INT8_MIN;
|
||||||
|
@ -95,51 +96,51 @@ static void simple_encode_decode_func(bool var_len) {
|
||||||
|
|
||||||
// Encode NULL
|
// Encode NULL
|
||||||
for (td_endian_t endian : endian_arr) {
|
for (td_endian_t endian : endian_arr) {
|
||||||
tCoderInit(&coder, endian, NULL, 0, TD_ENCODER);
|
tEncoderInit(&encoder, endian, NULL, 0, TD_ENCODER);
|
||||||
|
|
||||||
if (var_len) {
|
if (var_len) {
|
||||||
GTEST_ASSERT_EQ(encodev(&coder, i), 0);
|
GTEST_ASSERT_EQ(encodev(&encoder, i), 0);
|
||||||
} else {
|
} else {
|
||||||
GTEST_ASSERT_EQ(encode(&coder, i), 0);
|
GTEST_ASSERT_EQ(encode(&encoder, i), 0);
|
||||||
GTEST_ASSERT_EQ(coder.pos, sizeof(T));
|
GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
tCoderClear(&coder);
|
tCoderClear(&encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode and decode
|
// Encode and decode
|
||||||
for (td_endian_t e_endian : endian_arr) {
|
for (td_endian_t e_endian : endian_arr) {
|
||||||
for (td_endian_t d_endian : endian_arr) {
|
for (td_endian_t d_endian : endian_arr) {
|
||||||
// Encode
|
// Encode
|
||||||
tCoderInit(&coder, e_endian, buf, BUF_SIZE, TD_ENCODER);
|
tCoderInit(&encoder, e_endian, buf, BUF_SIZE, TD_ENCODER);
|
||||||
|
|
||||||
if (var_len) {
|
if (var_len) {
|
||||||
GTEST_ASSERT_EQ(encodev(&coder, i), 0);
|
GTEST_ASSERT_EQ(encodev(&encoder, i), 0);
|
||||||
} else {
|
} else {
|
||||||
GTEST_ASSERT_EQ(encode(&coder, i), 0);
|
GTEST_ASSERT_EQ(encode(&encoder, i), 0);
|
||||||
GTEST_ASSERT_EQ(coder.pos, sizeof(T));
|
GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t epos = coder.pos;
|
int32_t epos = encoder.pos;
|
||||||
|
|
||||||
tCoderClear(&coder);
|
tCoderClear(&encoder);
|
||||||
// Decode
|
// Decode
|
||||||
tCoderInit(&coder, d_endian, buf, BUF_SIZE, TD_DECODER);
|
tCoderInit(&encoder, d_endian, buf, BUF_SIZE, TD_DECODER);
|
||||||
|
|
||||||
if (var_len) {
|
if (var_len) {
|
||||||
GTEST_ASSERT_EQ(decodev(&coder, &dval), 0);
|
GTEST_ASSERT_EQ(decodev(&encoder, &dval), 0);
|
||||||
} else {
|
} else {
|
||||||
GTEST_ASSERT_EQ(decode(&coder, &dval), 0);
|
GTEST_ASSERT_EQ(decode(&encoder, &dval), 0);
|
||||||
GTEST_ASSERT_EQ(coder.pos, sizeof(T));
|
GTEST_ASSERT_EQ(encoder.pos, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
GTEST_ASSERT_EQ(coder.pos, epos);
|
GTEST_ASSERT_EQ(encoder.pos, epos);
|
||||||
|
|
||||||
if (typeid(T) == typeid(int8_t) || typeid(T) == typeid(uint8_t) || e_endian == d_endian) {
|
if (typeid(T) == typeid(int8_t) || typeid(T) == typeid(uint8_t) || e_endian == d_endian) {
|
||||||
GTEST_ASSERT_EQ(i, dval);
|
GTEST_ASSERT_EQ(i, dval);
|
||||||
}
|
}
|
||||||
|
|
||||||
tCoderClear(&coder);
|
tCoderClear(&encoder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue