sync encode test
This commit is contained in:
parent
48bed2020c
commit
12050c9a2a
|
@ -129,6 +129,8 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing);
|
||||||
|
|
||||||
void syncPing2RpcMsg(const SyncPing* pSyncPing, SRpcMsg* pRpcMsg);
|
void syncPing2RpcMsg(const SyncPing* pSyncPing, SRpcMsg* pRpcMsg);
|
||||||
|
|
||||||
|
void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pSyncPing);
|
||||||
|
|
||||||
cJSON* syncPing2Json(const SyncPing* pSyncPing);
|
cJSON* syncPing2Json(const SyncPing* pSyncPing);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -53,13 +53,13 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing) {
|
||||||
|
|
||||||
void syncPing2RpcMsg(const SyncPing* pSyncPing, SRpcMsg* pRpcMsg) {
|
void syncPing2RpcMsg(const SyncPing* pSyncPing, SRpcMsg* pRpcMsg) {
|
||||||
pRpcMsg->msgType = pSyncPing->msgType;
|
pRpcMsg->msgType = pSyncPing->msgType;
|
||||||
uint32_t bufLen = pSyncPing->bytes;
|
pRpcMsg->contLen = pSyncPing->bytes;
|
||||||
char* buf = malloc(bufLen);
|
|
||||||
syncPingSerialize(pSyncPing, buf, bufLen);
|
|
||||||
pRpcMsg->contLen = bufLen;
|
|
||||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||||
memcpy(pRpcMsg->pCont, buf, pRpcMsg->contLen);
|
syncPingSerialize(pSyncPing, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
free(buf);
|
}
|
||||||
|
|
||||||
|
void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pSyncPing) {
|
||||||
|
syncPingDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pSyncPing);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncPing2Json(const SyncPing* pSyncPing) {
|
cJSON* syncPing2Json(const SyncPing* pSyncPing) {
|
||||||
|
|
|
@ -15,10 +15,8 @@ void logTest() {
|
||||||
|
|
||||||
#define PING_MSG_LEN 20
|
#define PING_MSG_LEN 20
|
||||||
|
|
||||||
int main() {
|
void test1() {
|
||||||
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
|
sTrace("test1: ----");
|
||||||
tsAsyncLog = 0;
|
|
||||||
sDebugFlag = 143 + 64;
|
|
||||||
|
|
||||||
char msg[PING_MSG_LEN];
|
char msg[PING_MSG_LEN];
|
||||||
snprintf(msg, sizeof(msg), "%s", "test ping");
|
snprintf(msg, sizeof(msg), "%s", "test ping");
|
||||||
|
@ -55,6 +53,53 @@ int main() {
|
||||||
syncPingDestroy(pSyncPing);
|
syncPingDestroy(pSyncPing);
|
||||||
syncPingDestroy(pSyncPing2);
|
syncPingDestroy(pSyncPing2);
|
||||||
free(buf);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue