Method: GRPC::GenericService::Dsl#rpc

Defined in:
src/ruby/lib/grpc/generic/service.rb

#rpc(name, input, output) ⇒ Object

Adds an RPC spec.

Takes the RPC name and the classes representing the types to be serialized, and adds them to the including classes rpc_desc hash.

input and output should both have the methods #marshal and #unmarshal that are responsible for writing and reading an object instance from a byte buffer respectively.

Parameters:

  • name (String)

    the name of the rpc

  • input (Object)

    the input parameter’s class

  • output (Object)

    the output parameter’s class



92
93
94
95
96
97
98
99
100
101
102
103
# File 'src/ruby/lib/grpc/generic/service.rb', line 92

def rpc(name, input, output)
  fail(DuplicateRpcName, name) if rpc_descs.key? name
  assert_can_marshal(input)
  assert_can_marshal(output)
  rpc_descs[name] = RpcDesc.new(name, input, output,
                                marshal_class_method,
                                unmarshal_class_method)
  define_method(GenericService.underscore(name.to_s).to_sym) do |*|
    fail GRPC::BadStatus.new_status_exception(
      GRPC::Core::StatusCodes::UNIMPLEMENTED)
  end
end