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 syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pSyncPing);
|
||||
|
||||
cJSON* syncPing2Json(const SyncPing* pSyncPing);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue