Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
03f2ca28
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
03f2ca28
编写于
5月 07, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add encoding functions
上级
3133106b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
166 addition
and
9 deletion
+166
-9
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+1
-1
src/util/inc/tcoding.h
src/util/inc/tcoding.h
+49
-8
src/util/tests/codingTests.cpp
src/util/tests/codingTests.cpp
+116
-0
未找到文件。
src/common/inc/tdataformat.h
浏览文件 @
03f2ca28
...
...
@@ -97,7 +97,7 @@ typedef void *SDataRow;
#define TD_DATA_ROW_HEAD_SIZE sizeof(int32_t)
#define dataRowLen(r) (*(int32_t *)(r))
#define dataRowTuple(r) POINTER_
DR
IFT(r, TD_DATA_ROW_HEAD_SIZE)
#define dataRowTuple(r) POINTER_
SH
IFT(r, TD_DATA_ROW_HEAD_SIZE)
#define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r)))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
...
...
src/util/inc/tcoding.h
浏览文件 @
03f2ca28
...
...
@@ -24,8 +24,9 @@ extern "C" {
#include "tutil.h"
const
int32_t
TNUMBER
=
1
;
const
uint8_t
ENCODE_LIMIT
=
(
1
<<
7
);
// TODO: move this to a platform file
#define ENCODE_LIMIT (((uint8_t)1) << 7)
static
const
int32_t
TNUMBER
=
1
;
#define IS_LITTLE_ENDIAN() (*(uint8_t *)(&TNUMBER) != 0)
static
FORCE_INLINE
void
*
taosEncodeFixed16
(
void
*
buf
,
uint16_t
value
)
{
...
...
@@ -154,17 +155,57 @@ static FORCE_INLINE void *taosEncodeVariant64(void *buf, uint64_t value) {
static
FORCE_INLINE
void
*
taosDecodeVariant16
(
void
*
buf
,
uint16_t
*
value
)
{
int
i
=
0
;
uint16_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
3
&&
)
{
(
*
value
)
|=
(((
uint8_t
*
)
buf
)[
i
]
<<
(
7
*
i
));
i
++
;
while
(
i
<
3
)
{
tval
=
(
uint16_t
)(((
uint8_t
*
)
buf
)[
i
]);
if
(
tval
<
ENCODE_LIMIT
)
{
(
*
value
)
|=
(
tval
<<
(
7
*
i
));
return
POINTER_SHIFT
(
buf
,
i
+
1
);
}
else
{
(
*
value
)
|=
((
tval
&
(
ENCODE_LIMIT
-
1
))
<<
(
7
*
i
));
i
++
;
}
}
return
NULL
;
// error happened
}
static
FORCE_INLINE
void
*
taosDecodeVariant32
(
void
*
buf
,
uint32_t
*
value
)
{
int
i
=
0
;
uint32_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
5
)
{
tval
=
(
uint32_t
)(((
uint8_t
*
)
buf
)[
i
]);
if
(
tval
<
ENCODE_LIMIT
)
{
(
*
value
)
|=
(
tval
<<
(
7
*
i
));
return
POINTER_SHIFT
(
buf
,
i
+
1
);
}
else
{
(
*
value
)
|=
((
tval
&
(
ENCODE_LIMIT
-
1
))
<<
(
7
*
i
));
i
++
;
}
}
return
NULL
;
// error happened
return
NULL
;
// error happened
}
static
FORCE_INLINE
void
*
taosDecodeVariant32
(
void
*
buf
,
uint32_t
*
value
)
{}
static
FORCE_INLINE
void
*
taosDecodeVariant64
(
void
*
buf
,
uint64_t
*
value
)
{}
static
FORCE_INLINE
void
*
taosDecodeVariant64
(
void
*
buf
,
uint64_t
*
value
)
{
int
i
=
0
;
uint64_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
10
)
{
tval
=
(
uint64_t
)(((
uint8_t
*
)
buf
)[
i
]);
if
(
tval
<
ENCODE_LIMIT
)
{
(
*
value
)
|=
(
tval
<<
(
7
*
i
));
return
POINTER_SHIFT
(
buf
,
i
+
1
);
}
else
{
(
*
value
)
|=
((
tval
&
(
ENCODE_LIMIT
-
1
))
<<
(
7
*
i
));
i
++
;
}
}
return
NULL
;
// error happened
}
#ifdef __cplusplus
}
...
...
src/util/tests/codingTests.cpp
0 → 100644
浏览文件 @
03f2ca28
#include <gtest/gtest.h>
#include <stdlib.h>
#include <time.h>
#include <random>
#include "tcoding.h"
static
bool
test_fixed_uint16
(
uint16_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint16_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixed16
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixed16
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_uint32
(
uint32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint32_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixed32
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixed32
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_uint64
(
uint64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint64_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixed64
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixed64
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint16
(
uint16_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint16_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariant16
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariant16
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint32
(
uint32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint32_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariant32
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariant32
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint64
(
uint64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint64_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariant64
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariant64
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
TEST
(
codingTest
,
fixed_encode_decode
)
{
srand
(
time
(
0
));
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_fixed_uint16
(
value
));
if
(
value
==
UINT16_MAX
)
break
;
}
ASSERT_TRUE
(
test_fixed_uint32
(
0
));
ASSERT_TRUE
(
test_fixed_uint32
(
UINT32_MAX
));
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_uint32
(
rand
()));
}
std
::
mt19937_64
gen
(
std
::
random_device
{}());
ASSERT_TRUE
(
test_fixed_uint64
(
0
));
ASSERT_TRUE
(
test_fixed_uint64
(
UINT64_MAX
));
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_uint64
(
gen
()));
}
}
TEST
(
codingTest
,
variant_encode_decode
)
{
srand
(
time
(
0
));
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_variant_uint16
(
value
));
if
(
value
==
UINT16_MAX
)
break
;
}
ASSERT_TRUE
(
test_variant_uint32
(
0
));
ASSERT_TRUE
(
test_variant_uint32
(
UINT32_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
ASSERT_TRUE
(
test_variant_uint32
(
rand
()));
}
std
::
mt19937_64
gen
(
std
::
random_device
{}());
ASSERT_TRUE
(
test_variant_uint64
(
0
));
ASSERT_TRUE
(
test_variant_uint64
(
UINT64_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
uint64_t
value
=
gen
();
// printf("%ull\n", value);
ASSERT_TRUE
(
test_variant_uint64
(
value
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录