Class: GrpcKit::RpcDesc

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/rpc_desc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, marshal:, unmarshal:, marshal_method:, unmarshal_method:, service_name:) ⇒ RpcDesc

Returns a new instance of RpcDesc.

Parameters:

  • name (Symbol)

    path name

  • marshal (Class, GrpcKit::Grpc::Stream)

    marshaling object

  • unmarshal (Class, GrpcKit::Grpc::Stream)

    unmarshaling object

  • marshal_method (Symbol)

    method name of marshaling which marshal is called this method

  • unmarshal_method (Symbol)

    method name of unmarshaling which unmarshal is called this method

  • service_name (String)


32
33
34
35
36
37
38
39
# File 'lib/grpc_kit/rpc_desc.rb', line 32

def initialize(name:, marshal:, unmarshal:, marshal_method:, unmarshal_method:, service_name:)
  @name = name
  @marshal = marshal
  @unmarshal = unmarshal
  @marshal_method = marshal_method
  @unmarshal_method = unmarshal_method
  @service_name = service_name
end

Instance Attribute Details

#marshalClass, GrpcKit::Grpc::Stream (readonly)

Returns:



45
46
47
# File 'lib/grpc_kit/rpc_desc.rb', line 45

def marshal
  @marshal
end

#marshal_methodSymbol (readonly)

Returns:

  • (Symbol)


48
49
50
# File 'lib/grpc_kit/rpc_desc.rb', line 48

def marshal_method
  @marshal_method
end

#nameString (readonly)

Returns:

  • (String)


42
43
44
# File 'lib/grpc_kit/rpc_desc.rb', line 42

def name
  @name
end

#service_nameString (readonly)

Returns:

  • (String)


42
43
44
# File 'lib/grpc_kit/rpc_desc.rb', line 42

def service_name
  @service_name
end

#unmarshalClass, GrpcKit::Grpc::Stream (readonly)

Returns:



45
46
47
# File 'lib/grpc_kit/rpc_desc.rb', line 45

def unmarshal
  @unmarshal
end

#unmarshal_methodSymbol (readonly)

Returns:

  • (Symbol)


48
49
50
# File 'lib/grpc_kit/rpc_desc.rb', line 48

def unmarshal_method
  @unmarshal_method
end

Instance Method Details

#bidi_streamer?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/grpc_kit/rpc_desc.rb', line 117

def bidi_streamer?
  @marshal.is_a?(GrpcKit::Grpc::Stream) && @unmarshal.is_a?(GrpcKit::Grpc::Stream)
end

#build_client(interceptors: [], max_send_message_size: nil, max_receive_message_size: nil) ⇒ #invoke

Returns Client version of rpc class.

Parameters:

  • interceptors (Array<GrpcKit::Grpc::ClientInterceptor>) (defaults to: [])
  • max_receive_message_size (Integer, nil) (defaults to: nil)
  • max_send_message_size (Integer, nil) (defaults to: nil)

Returns:

  • (#invoke)

    Client version of rpc class



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/grpc_kit/rpc_desc.rb', line 75

def build_client(interceptors: [], max_send_message_size: nil, max_receive_message_size: nil)
  inter = interceptors.empty? ? nil : client_interceptor.new(interceptors)

  config = GrpcKit::MethodConfig.build_for_client(
    path: path,
    ruby_style_method_name: ruby_style_name,
    codec: client_codec,
    service_name: @service_name,
    method_name: @name,
    interceptor: inter,
    max_receive_message_size: max_receive_message_size || GrpcKit::MAX_CLIENT_RECEIVE_MESSAGE_SIZE,
    max_send_message_size: max_send_message_size || GrpcKit::MAX_CLIENT_SEND_MESSAGE_SIZE,
  )
  client.new(config)
end

#build_server(handler, interceptors: [], max_send_message_size: nil, max_receive_message_size: nil) ⇒ #invoke

Returns Server version of rpc class.

Parameters:

Returns:

  • (#invoke)

    Server version of rpc class



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/grpc_kit/rpc_desc.rb', line 55

def build_server(handler, interceptors: [], max_send_message_size: nil, max_receive_message_size: nil)
  inter = interceptors.empty? ? nil : server_interceptor.new(interceptors)

  config = GrpcKit::MethodConfig.build_for_server(
    path: path,
    ruby_style_method_name: ruby_style_name,
    codec: server_codec,
    service_name: @service_name,
    method_name: @name,
    interceptor: inter,
    max_receive_message_size: max_receive_message_size || GrpcKit::MAX_SERVER_RECEIVE_MESSAGE_SIZE,
    max_send_message_size: max_send_message_size || GrpcKit::MAX_SERVER_SEND_MESSAGE_SIZE,
  )
  server.new(handler, config)
end

#client_streamer?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/grpc_kit/rpc_desc.rb', line 107

def client_streamer?
  @marshal.is_a?(GrpcKit::Grpc::Stream) && !@unmarshal.is_a?(GrpcKit::Grpc::Stream)
end

#pathString

Returns Full name of path name.

Returns:

  • (String)

    Full name of path name



97
98
99
# File 'lib/grpc_kit/rpc_desc.rb', line 97

def path
  @path ||= "/#{@service_name}/#{@name}"
end

#request_response?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/grpc_kit/rpc_desc.rb', line 102

def request_response?
  !@marshal.is_a?(GrpcKit::Grpc::Stream) && !@unmarshal.is_a?(GrpcKit::Grpc::Stream)
end

#ruby_style_nameSymbol

Returns Snake case name.

Returns:

  • (Symbol)

    Snake case name



92
93
94
# File 'lib/grpc_kit/rpc_desc.rb', line 92

def ruby_style_name
  @ruby_style_name ||= to_underscore(@name).to_sym
end

#server_streamer?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/grpc_kit/rpc_desc.rb', line 112

def server_streamer?
  !@marshal.is_a?(GrpcKit::Grpc::Stream) && @unmarshal.is_a?(GrpcKit::Grpc::Stream)
end