Compare commits
No commits in common. 'f81ac5842c8fe0f7ab829341357274b402a447a2' and '40170d553d8bd96f7e1d867a2895aaa1ac28603c' have entirely different histories.
f81ac5842c
...
40170d553d
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class RpcSerializer {
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
static void write(std::ostringstream& out, const T& v) {
|
||||||
|
out << v << ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static T read(std::istringstream& in) {
|
||||||
|
T v;
|
||||||
|
in >> v;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// Простейшее type-erased значение для RPC.
|
|
||||||
// PoC: поддерживаем только int, но интерфейс позволяет в будущем
|
|
||||||
// добавить другие типы (string, bool, и т.д.).
|
|
||||||
|
|
||||||
enum class RpcType {
|
|
||||||
Int,
|
|
||||||
};
|
|
||||||
|
|
||||||
class RpcValue {
|
|
||||||
public:
|
|
||||||
RpcValue() : type_(RpcType::Int), i_(0) {}
|
|
||||||
|
|
||||||
static RpcValue fromInt(int v) {
|
|
||||||
RpcValue r;
|
|
||||||
r.type_ = RpcType::Int;
|
|
||||||
r.i_ = v;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
RpcType type() const { return type_; }
|
|
||||||
|
|
||||||
int asInt() const {
|
|
||||||
// PoC: единственный поддерживаемый тип.
|
|
||||||
return i_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
RpcType type_;
|
|
||||||
int i_;
|
|
||||||
};
|
|
||||||
|
|
||||||
using RpcArgs = std::vector<RpcValue>;
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue