ulib/3party/rpc_core/test/test_plugin.cpp
tqcq c3b5a29da2
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m6s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m9s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m17s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m22s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m39s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m48s
linux-x64-gcc / linux-gcc (push) Successful in 2m3s
feat add rpc_core
2024-01-21 16:05:01 +08:00

87 lines
1.8 KiB
C++

#include "assert_def.h"
#include "plugin/JsonType.h"
#include "plugin/RawType.h"
#include "plugin/fb/FbMsg_generated.h"
#include "rpc_core/plugin/flatbuffers.hpp"
#include "rpc_core/plugin/json.hpp"
#include "test.h"
namespace rpc_core_test {
void test_plugin() {
using namespace rpc_core;
{
RPC_CORE_LOGI("RawType...");
RawType a;
a.id = 1;
a.name = "test";
a.age = 18;
auto payload = serialize(a);
// payload is not readable
RPC_CORE_LOGI("RawType: size: %zu", payload.size());
RawType b;
deserialize(payload, b);
ASSERT(a.id == b.id);
ASSERT(a.name == b.name);
ASSERT(a.age == b.age);
}
{
RPC_CORE_LOGI("json...");
nlohmann::json a;
a["id"] = 1;
a["name"] = "test";
a["age"] = 18;
auto payload = serialize(a);
RPC_CORE_LOGI("json: %s", payload.c_str());
RPC_CORE_LOGI("json: size: %zu", payload.size());
nlohmann::json b;
deserialize(payload, b);
ASSERT(b["id"] == a["id"]);
ASSERT(b["name"] == a["name"]);
ASSERT(b["age"] == a["age"]);
}
{
RPC_CORE_LOGI("JsonType...");
JsonType a;
a.id = 1;
a.name = "test";
a.age = 18;
auto payload = serialize(a);
RPC_CORE_LOGI("JsonType: %s", payload.c_str());
RPC_CORE_LOGI("JsonType: size: %zu", payload.size());
JsonType b;
deserialize(payload, b);
ASSERT(b.id == a.id);
ASSERT(b.name == a.name);
ASSERT(b.age == a.age);
}
{
RPC_CORE_LOGI("flatbuffers...");
msg::FbMsgT a;
a.id = 1;
a.name = "test";
a.age = 18;
auto payload = serialize(a);
// flatbuffers payload is not readable
RPC_CORE_LOGI("flatbuffers: size: %zu", payload.size());
msg::FbMsgT b;
deserialize(payload, b);
ASSERT(b.id == a.id);
ASSERT(b.name == a.name);
ASSERT(b.age == a.age);
}
}
} // namespace rpc_core_test