Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3136a23b
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3136a23b
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coding
上级
1f83138d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
35 deletion
+35
-35
include/util/tcoding.h
include/util/tcoding.h
+35
-35
未找到文件。
include/util/tcoding.h
浏览文件 @
3136a23b
...
...
@@ -15,26 +15,26 @@
#ifndef _TD_UTIL_CODING_H
#define _TD_UTIL_CODING_H
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
#define ENCODE_LIMIT (((uint8_t)1) << 7)
#define ENCODE_LIMIT (((uint8_t)1) << 7)
#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
/* ------------------------ LEGACY CODES ------------------------ */
#if 1
// ---- Fixed U8
static
FORCE_INLINE
int
taosEncodeFixedU8
(
void
**
buf
,
uint8_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedU8
(
void
**
buf
,
uint8_t
value
)
{
if
(
buf
!=
NULL
)
{
((
uint8_t
*
)(
*
buf
))[
0
]
=
value
;
*
buf
=
POINTER_SHIFT
(
*
buf
,
sizeof
(
value
));
}
return
(
int
)
sizeof
(
value
);
return
(
int
32_t
)
sizeof
(
value
);
}
static
FORCE_INLINE
void
*
taosDecodeFixedU8
(
const
void
*
buf
,
uint8_t
*
value
)
{
...
...
@@ -43,12 +43,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
}
// ---- Fixed I8
static
FORCE_INLINE
int
taosEncodeFixedI8
(
void
**
buf
,
int8_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedI8
(
void
**
buf
,
int8_t
value
)
{
if
(
buf
!=
NULL
)
{
((
int8_t
*
)(
*
buf
))[
0
]
=
value
;
*
buf
=
POINTER_SHIFT
(
*
buf
,
sizeof
(
value
));
}
return
(
int
)
sizeof
(
value
);
return
(
int
32_t
)
sizeof
(
value
);
}
static
FORCE_INLINE
void
*
taosDecodeFixedI8
(
const
void
*
buf
,
int8_t
*
value
)
{
...
...
@@ -57,7 +57,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
}
// ---- Fixed U16
static
FORCE_INLINE
int
taosEncodeFixedU16
(
void
**
buf
,
uint16_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedU16
(
void
**
buf
,
uint16_t
value
)
{
if
(
buf
!=
NULL
)
{
if
(
IS_LITTLE_ENDIAN
())
{
memcpy
(
*
buf
,
&
value
,
sizeof
(
value
));
...
...
@@ -68,7 +68,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
*
buf
=
POINTER_SHIFT
(
*
buf
,
sizeof
(
value
));
}
return
(
int
)
sizeof
(
value
);
return
(
int
32_t
)
sizeof
(
value
);
}
static
FORCE_INLINE
void
*
taosDecodeFixedU16
(
const
void
*
buf
,
uint16_t
*
value
)
{
...
...
@@ -83,7 +83,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
}
// ---- Fixed I16
static
FORCE_INLINE
int
taosEncodeFixedI16
(
void
**
buf
,
int16_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedI16
(
void
**
buf
,
int16_t
value
)
{
return
taosEncodeFixedU16
(
buf
,
ZIGZAGE
(
int16_t
,
value
));
}
...
...
@@ -95,7 +95,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) {
}
// ---- Fixed U32
static
FORCE_INLINE
int
taosEncodeFixedU32
(
void
**
buf
,
uint32_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedU32
(
void
**
buf
,
uint32_t
value
)
{
if
(
buf
!=
NULL
)
{
if
(
IS_LITTLE_ENDIAN
())
{
memcpy
(
*
buf
,
&
value
,
sizeof
(
value
));
...
...
@@ -108,7 +108,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
*
buf
=
POINTER_SHIFT
(
*
buf
,
sizeof
(
value
));
}
return
(
int
)
sizeof
(
value
);
return
(
int
32_t
)
sizeof
(
value
);
}
static
FORCE_INLINE
void
*
taosDecodeFixedU32
(
const
void
*
buf
,
uint32_t
*
value
)
{
...
...
@@ -125,7 +125,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
}
// ---- Fixed I32
static
FORCE_INLINE
int
taosEncodeFixedI32
(
void
**
buf
,
int32_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedI32
(
void
**
buf
,
int32_t
value
)
{
return
taosEncodeFixedU32
(
buf
,
ZIGZAGE
(
int32_t
,
value
));
}
...
...
@@ -137,7 +137,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) {
}
// ---- Fixed U64
static
FORCE_INLINE
int
taosEncodeFixedU64
(
void
**
buf
,
uint64_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedU64
(
void
**
buf
,
uint64_t
value
)
{
if
(
buf
!=
NULL
)
{
if
(
IS_LITTLE_ENDIAN
())
{
memcpy
(
*
buf
,
&
value
,
sizeof
(
value
));
...
...
@@ -155,7 +155,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
*
buf
=
POINTER_SHIFT
(
*
buf
,
sizeof
(
value
));
}
return
(
int
)
sizeof
(
value
);
return
(
int
32_t
)
sizeof
(
value
);
}
static
FORCE_INLINE
void
*
taosDecodeFixedU64
(
const
void
*
buf
,
uint64_t
*
value
)
{
...
...
@@ -176,7 +176,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
}
// ---- Fixed I64
static
FORCE_INLINE
int
taosEncodeFixedI64
(
void
**
buf
,
int64_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeFixedI64
(
void
**
buf
,
int64_t
value
)
{
return
taosEncodeFixedU64
(
buf
,
ZIGZAGE
(
int64_t
,
value
));
}
...
...
@@ -188,8 +188,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) {
}
// ---- Variant U16
static
FORCE_INLINE
int
taosEncodeVariantU16
(
void
**
buf
,
uint16_t
value
)
{
int
i
=
0
;
static
FORCE_INLINE
int
32_t
taosEncodeVariantU16
(
void
**
buf
,
uint16_t
value
)
{
int
32_t
i
=
0
;
while
(
value
>=
ENCODE_LIMIT
)
{
if
(
buf
!=
NULL
)
((
uint8_t
*
)(
*
buf
))[
i
]
=
(
uint8_t
)(
value
|
ENCODE_LIMIT
);
value
>>=
7
;
...
...
@@ -206,7 +206,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
}
static
FORCE_INLINE
void
*
taosDecodeVariantU16
(
const
void
*
buf
,
uint16_t
*
value
)
{
int
i
=
0
;
int
32_t
i
=
0
;
uint16_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
3
)
{
...
...
@@ -224,7 +224,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value)
}
// ---- Variant I16
static
FORCE_INLINE
int
taosEncodeVariantI16
(
void
**
buf
,
int16_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeVariantI16
(
void
**
buf
,
int16_t
value
)
{
return
taosEncodeVariantU16
(
buf
,
ZIGZAGE
(
int16_t
,
value
));
}
...
...
@@ -236,8 +236,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value)
}
// ---- Variant U32
static
FORCE_INLINE
int
taosEncodeVariantU32
(
void
**
buf
,
uint32_t
value
)
{
int
i
=
0
;
static
FORCE_INLINE
int
32_t
taosEncodeVariantU32
(
void
**
buf
,
uint32_t
value
)
{
int
32_t
i
=
0
;
while
(
value
>=
ENCODE_LIMIT
)
{
if
(
buf
!=
NULL
)
((
uint8_t
*
)(
*
buf
))[
i
]
=
(
value
|
ENCODE_LIMIT
);
value
>>=
7
;
...
...
@@ -254,7 +254,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
}
static
FORCE_INLINE
void
*
taosDecodeVariantU32
(
const
void
*
buf
,
uint32_t
*
value
)
{
int
i
=
0
;
int
32_t
i
=
0
;
uint32_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
5
)
{
...
...
@@ -272,7 +272,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value)
}
// ---- Variant I32
static
FORCE_INLINE
int
taosEncodeVariantI32
(
void
**
buf
,
int32_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeVariantI32
(
void
**
buf
,
int32_t
value
)
{
return
taosEncodeVariantU32
(
buf
,
ZIGZAGE
(
int32_t
,
value
));
}
...
...
@@ -284,8 +284,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value)
}
// ---- Variant U64
static
FORCE_INLINE
int
taosEncodeVariantU64
(
void
**
buf
,
uint64_t
value
)
{
int
i
=
0
;
static
FORCE_INLINE
int
32_t
taosEncodeVariantU64
(
void
**
buf
,
uint64_t
value
)
{
int
32_t
i
=
0
;
while
(
value
>=
ENCODE_LIMIT
)
{
if
(
buf
!=
NULL
)
((
uint8_t
*
)(
*
buf
))[
i
]
=
(
uint8_t
)(
value
|
ENCODE_LIMIT
);
value
>>=
7
;
...
...
@@ -302,7 +302,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
}
static
FORCE_INLINE
void
*
taosDecodeVariantU64
(
const
void
*
buf
,
uint64_t
*
value
)
{
int
i
=
0
;
int
32_t
i
=
0
;
uint64_t
tval
=
0
;
*
value
=
0
;
while
(
i
<
10
)
{
...
...
@@ -320,7 +320,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value)
}
// ---- Variant I64
static
FORCE_INLINE
int
taosEncodeVariantI64
(
void
**
buf
,
int64_t
value
)
{
static
FORCE_INLINE
int
32_t
taosEncodeVariantI64
(
void
**
buf
,
int64_t
value
)
{
return
taosEncodeVariantU64
(
buf
,
ZIGZAGE
(
int64_t
,
value
));
}
...
...
@@ -332,16 +332,16 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value)
}
// ---- string
static
FORCE_INLINE
int
taosEncodeString
(
void
**
buf
,
const
char
*
value
)
{
int
tlen
=
0
;
size_t
size
=
strlen
(
value
);
static
FORCE_INLINE
int
32_t
taosEncodeString
(
void
**
buf
,
const
char
*
value
)
{
int
32_t
tlen
=
0
;
size_t
size
=
strlen
(
value
);
tlen
+=
taosEncodeVariantU64
(
buf
,
size
);
if
(
buf
!=
NULL
)
{
memcpy
(
*
buf
,
value
,
size
);
*
buf
=
POINTER_SHIFT
(
*
buf
,
size
);
}
tlen
+=
(
int
)
size
;
tlen
+=
(
int
32_t
)
size
;
return
tlen
;
}
...
...
@@ -372,14 +372,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) {
}
// ---- binary
static
FORCE_INLINE
int
taosEncodeBinary
(
void
**
buf
,
const
void
*
value
,
int32_t
valueLen
)
{
int
tlen
=
0
;
static
FORCE_INLINE
int
32_t
taosEncodeBinary
(
void
**
buf
,
const
void
*
value
,
int32_t
valueLen
)
{
int
32_t
tlen
=
0
;
if
(
buf
!=
NULL
)
{
memcpy
(
*
buf
,
value
,
valueLen
);
*
buf
=
POINTER_SHIFT
(
*
buf
,
valueLen
);
}
tlen
+=
(
int
)
valueLen
;
tlen
+=
(
int
32_t
)
valueLen
;
return
tlen
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录