fix TDB encode and decode bug
This commit is contained in:
parent
e707047d6c
commit
f136211bad
|
@ -84,15 +84,18 @@ static inline int tdbPutVarInt(u8 *p, int v) {
|
||||||
static inline int tdbGetVarInt(const u8 *p, int *v) {
|
static inline int tdbGetVarInt(const u8 *p, int *v) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int tv = 0;
|
int tv = 0;
|
||||||
|
int t;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (p[n] <= 0x7f) {
|
if (p[n] <= 0x7f) {
|
||||||
tv = (tv << 7) | p[n];
|
t = p[n];
|
||||||
|
tv |= (t << (7 * n));
|
||||||
n++;
|
n++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tv = (tv << 7) | (p[n] & 0x7f);
|
t = p[n] & 0x7f;
|
||||||
|
tv |= (t << (7 * n));
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# tdbTest
|
# tdbTest
|
||||||
add_executable(tdbTest "tdbTest.cpp")
|
add_executable(tdbTest "tdbTest.cpp")
|
||||||
target_link_libraries(tdbTest tdb gtest gtest_main)
|
target_link_libraries(tdbTest tdb gtest gtest_main)
|
||||||
|
|
||||||
|
# tdbUtilTest
|
||||||
|
add_executable(tdbUtilTest "tdbUtilTest.cpp")
|
||||||
|
target_link_libraries(tdbUtilTest tdb gtest gtest_main)
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "tdbInt.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TEST(tdb_util_test, simple_test) {
|
||||||
|
int vEncode = 5000;
|
||||||
|
int vDecode;
|
||||||
|
int nEncode;
|
||||||
|
int nDecode;
|
||||||
|
u8 buffer[128];
|
||||||
|
|
||||||
|
nEncode = tdbPutVarInt(buffer, vEncode);
|
||||||
|
|
||||||
|
nDecode = tdbGetVarInt(buffer, &vDecode);
|
||||||
|
|
||||||
|
GTEST_ASSERT_EQ(nEncode, nDecode);
|
||||||
|
GTEST_ASSERT_EQ(vEncode, vDecode);
|
||||||
|
}
|
Loading…
Reference in New Issue