#pragma once #include #include #include #include namespace fc { namespace rpc { typedef std::vector params_type; typedef std::vector result_type; struct brequest { optional id; std::string method; params_type params; }; struct bresponse { bresponse(){} bresponse( int64_t i, result_type r ):id(i),result(r){} bresponse( int64_t i, error_object r ):id(i),error(r){} int64_t id = 0; optional result; optional error; }; /** binary RPC state */ class bstate { public: typedef std::function method; ~bstate(); void add_method( const fc::string& name, method m ); void remove_method( const fc::string& name ); result_type local_call( const string& method_name, const params_type& args ); void handle_reply( const bresponse& response ); brequest start_remote_call( const string& method_name, params_type args ); result_type wait_for_response( uint64_t request_id ); void close(); void on_unhandled( const std::function& unhandled ); private: uint64_t _next_id = 1; std::unordered_map::ptr> _awaiting; std::unordered_map _methods; std::function _unhandled; }; } } // namespace fc::rpc FC_REFLECT( fc::rpc::brequest, (id)(method)(params) ); FC_REFLECT( fc::rpc::bresponse, (id)(result)(error) )