Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
12050c9a
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
12050c9a
编写于
3月 01, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync encode test
上级
48bed202
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
11 deletion
+58
-11
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+2
-0
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+6
-6
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+50
-5
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
12050c9a
...
...
@@ -129,6 +129,8 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing);
void
syncPing2RpcMsg
(
const
SyncPing
*
pSyncPing
,
SRpcMsg
*
pRpcMsg
);
void
syncPingFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncPing
*
pSyncPing
);
cJSON
*
syncPing2Json
(
const
SyncPing
*
pSyncPing
);
#ifdef __cplusplus
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
12050c9a
...
...
@@ -53,13 +53,13 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing) {
void
syncPing2RpcMsg
(
const
SyncPing
*
pSyncPing
,
SRpcMsg
*
pRpcMsg
)
{
pRpcMsg
->
msgType
=
pSyncPing
->
msgType
;
uint32_t
bufLen
=
pSyncPing
->
bytes
;
char
*
buf
=
malloc
(
bufLen
);
syncPingSerialize
(
pSyncPing
,
buf
,
bufLen
);
pRpcMsg
->
contLen
=
bufLen
;
pRpcMsg
->
contLen
=
pSyncPing
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
memcpy
(
pRpcMsg
->
pCont
,
buf
,
pRpcMsg
->
contLen
);
free
(
buf
);
syncPingSerialize
(
pSyncPing
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncPingFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncPing
*
pSyncPing
)
{
syncPingDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pSyncPing
);
}
cJSON
*
syncPing2Json
(
const
SyncPing
*
pSyncPing
)
{
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
12050c9a
...
...
@@ -15,10 +15,8 @@ void logTest() {
#define PING_MSG_LEN 20
int
main
()
{
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
void
test1
()
{
sTrace
(
"test1: ----"
);
char
msg
[
PING_MSG_LEN
];
snprintf
(
msg
,
sizeof
(
msg
),
"%s"
,
"test ping"
);
...
...
@@ -40,7 +38,7 @@ int main() {
uint32_t
bufLen
=
pSyncPing
->
bytes
;
char
*
buf
=
(
char
*
)
malloc
(
bufLen
);
syncPingSerialize
(
pSyncPing
,
buf
,
bufLen
);
SyncPing
*
pSyncPing2
=
(
SyncPing
*
)
malloc
(
pSyncPing
->
bytes
);
syncPingDeserialize
(
buf
,
bufLen
,
pSyncPing2
);
...
...
@@ -55,6 +53,53 @@ int main() {
syncPingDestroy
(
pSyncPing
);
syncPingDestroy
(
pSyncPing2
);
free
(
buf
);
}
void
test2
()
{
sTrace
(
"test2: ----"
);
char
msg
[
PING_MSG_LEN
];
snprintf
(
msg
,
sizeof
(
msg
),
"%s"
,
"hello raft"
);
SyncPing
*
pSyncPing
=
syncPingBuild
(
PING_MSG_LEN
);
pSyncPing
->
srcId
.
addr
=
100
;
pSyncPing
->
srcId
.
vgId
=
200
;
pSyncPing
->
destId
.
addr
=
300
;
pSyncPing
->
destId
.
vgId
=
400
;
memcpy
(
pSyncPing
->
data
,
msg
,
PING_MSG_LEN
);
{
cJSON
*
pJson
=
syncPing2Json
(
pSyncPing
);
char
*
serialized
=
cJSON_Print
(
pJson
);
printf
(
"SyncPing:
\n
%s
\n\n
"
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
SRpcMsg
rpcMsg
;
syncPing2RpcMsg
(
pSyncPing
,
&
rpcMsg
);
SyncPing
*
pSyncPing2
=
(
SyncPing
*
)
malloc
(
pSyncPing
->
bytes
);
syncPingFromRpcMsg
(
&
rpcMsg
,
pSyncPing2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
{
cJSON
*
pJson
=
syncPing2Json
(
pSyncPing2
);
char
*
serialized
=
cJSON_Print
(
pJson
);
printf
(
"SyncPing2:
\n
%s
\n\n
"
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
syncPingDestroy
(
pSyncPing
);
syncPingDestroy
(
pSyncPing2
);
}
int
main
()
{
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
test1
();
test2
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录