@use itertools::Itertools; @use crate::data::RPC; @use crate::generators::cpp_s::*; @(rpc: &RPC) #pragma once #ifndef MRPC_GEN_H #define MRPC_GEN_H #include #include #include #include #include #include #include #define RAPIDJSON_HAS_STDSTRING 1 #include #include #include namespace restbed @{ class Resource; class Session; @} namespace mrpc @{ using MRPCJWriter = rapidjson::Writer; @for e in &rpc.enums { enum struct @e.name : std::uint64_t @{ @e.values.iter().map(|(k,v)| format!("{k} = {v}")).join(",\n ") @}; } @for s in &rpc.structs {struct @s.name; } @for s in &rpc.structs { struct @s.name @{ @for f in &s.fields { @ty_to_str(&f.ty) @f.name; } MRPCJWriter& operator >>(MRPCJWriter&) const; @(s.name)& operator <<(const rapidjson::Value&); @};} @if streams_required(rpc).len() > 0 { struct MRPCStreamImpl @{ void close() const noexcept; bool is_open() const noexcept; protected: explicit MRPCStreamImpl(const std::shared_ptr &conn); std::shared_ptr conn; @}; template struct MRPCStream final : MRPCStreamImpl @{ explicit MRPCStream(const std::shared_ptr &conn) : MRPCStreamImpl(conn) @{@} void send(const T &v) const noexcept; @}; @for s in streams_required(rpc) {template struct MRPCStream<@(s)>; }} struct MRPCServer @{ explicit MRPCServer(std::shared_ptr&); private: @for s in &rpc.services {@for m in &s.methods { virtual @method_ret(m) @(s.name)_@(m.name)(@method_args(m)) = 0; }} virtual void msg_handler(std::shared_ptr, const restbed::Bytes&) final; @}; @} #endif // MRPC_GEN_H