Compare commits
No commits in common. '43f67275e28b3dbdb0dde85868707130904f3f50' and 'c93aea6501f89360f444f5e5b87cb48ca4e1368d' have entirely different histories.
43f67275e2
...
c93aea6501
@ -1,61 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ipc/IpcMessage.h>
|
|
||||||
#include <rpc/RpcValue.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// Кодек, который знает, как упаковать/распаковать RPC-запросы/ответы
|
|
||||||
// в/IpcMessage. Живёт в IPC-слое, но опирается на типы RPC-ядра
|
|
||||||
// (RpcValue/RpcArgs).
|
|
||||||
namespace IpcCodec {
|
|
||||||
|
|
||||||
// Запрос: имя метода + вектор аргументов.
|
|
||||||
inline IpcMessage encodeRequest(const std::string& method,
|
|
||||||
const RpcArgs& args) {
|
|
||||||
IpcMessage msg;
|
|
||||||
|
|
||||||
// имя метода
|
|
||||||
msg.add(method);
|
|
||||||
|
|
||||||
// аргументы (PoC: только int)
|
|
||||||
for (const auto& a : args) {
|
|
||||||
msg.add(a.asInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void decodeRequest(const IpcMessage& msg,
|
|
||||||
std::string& method,
|
|
||||||
RpcArgs& args) {
|
|
||||||
IpcMessage copy = msg;
|
|
||||||
|
|
||||||
// имя метода
|
|
||||||
method = copy.get<std::string>();
|
|
||||||
|
|
||||||
// аргументы (PoC: только int, читаем до конца сообщения)
|
|
||||||
args.clear();
|
|
||||||
while (!copy.empty()) {
|
|
||||||
int v = copy.get<int>();
|
|
||||||
args.emplace_back(RpcValue::fromInt(v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ответ: одно RpcValue (PoC: считаем, что это int).
|
|
||||||
inline IpcMessage encodeResponse(const RpcValue& result) {
|
|
||||||
IpcMessage msg;
|
|
||||||
msg.add(result.asInt()); // PoC: только int
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline RpcValue decodeResponse(const IpcMessage& msg) {
|
|
||||||
IpcMessage copy = msg;
|
|
||||||
int v = copy.get<int>();
|
|
||||||
return RpcValue::fromInt(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace IpcCodec
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue