Class: ProtoPlugin::MethodDescriptor

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/proto_plugin/method_descriptor.rb

Overview

A wrapper class around Google::Protobuf::MethodDescriptorProto which provides helpers and more idiomatic Ruby access patterns.

Any method not defined directly is delegated to the descriptor the wrapper was initialized with.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptor, service, context) ⇒ MethodDescriptor

Returns a new instance of MethodDescriptor.

Parameters:

  • descriptor (Google::Protobuf::MethodDescriptorProto)
  • service (ServiceDescriptor)

    The service this method was defined in.

  • context (Context)


24
25
26
27
28
29
# File 'lib/proto_plugin/method_descriptor.rb', line 24

def initialize(descriptor, service, context)
  super(descriptor)
  @descriptor = descriptor
  @service = service
  @context = context
end

Instance Attribute Details

#descriptorGoogle::Protobuf::MethodDescriptorProto (readonly)

Returns:

  • (Google::Protobuf::MethodDescriptorProto)


14
15
16
# File 'lib/proto_plugin/method_descriptor.rb', line 14

def descriptor
  @descriptor
end

#serviceServiceDescriptor (readonly)

The service this method was defined in.

Returns:



19
20
21
# File 'lib/proto_plugin/method_descriptor.rb', line 19

def service
  @service
end

Instance Method Details

#bidirectional_streaming?Boolean

Returns true if both the client and server may send multiple streamed messages.

Returns:

  • (Boolean)


69
70
71
# File 'lib/proto_plugin/method_descriptor.rb', line 69

def bidirectional_streaming?
  client_streaming? && server_streaming?
end

#client_streaming?Boolean

Returns true if the client may stream multiple client messages.

Returns:

  • (Boolean)


48
49
50
# File 'lib/proto_plugin/method_descriptor.rb', line 48

def client_streaming?
  descriptor.client_streaming
end

#inputMessageDescriptor

Returns the MessageDescriptor of the method’s input type.

Returns:



34
35
36
# File 'lib/proto_plugin/method_descriptor.rb', line 34

def input
  @context.type_by_proto_name(input_type)
end

#outputMessageDescriptor

Returns the MessageDescriptor of the method’s output type.

Returns:



41
42
43
# File 'lib/proto_plugin/method_descriptor.rb', line 41

def output
  @context.type_by_proto_name(output_type)
end

#server_streaming?Boolean

Returns true if the server may stream multiple server messages.

Returns:

  • (Boolean)


55
56
57
# File 'lib/proto_plugin/method_descriptor.rb', line 55

def server_streaming?
  descriptor.server_streaming
end

#unary?Boolean

Returns true if both the client and server only may send single messages.

Returns:

  • (Boolean)


62
63
64
# File 'lib/proto_plugin/method_descriptor.rb', line 62

def unary?
  !client_streaming? && !server_streaming?
end