Class: GrpcReflection::FileDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_reflection/file_descriptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptor_data) ⇒ FileDescriptor

Returns a new instance of FileDescriptor.



10
11
12
13
14
15
16
17
18
# File 'lib/grpc_reflection/file_descriptor.rb', line 10

def initialize(descriptor_data)
  @file_descriptor_proto = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
  @descriptor_data = descriptor_data.b
  @filename = @file_descriptor_proto.name
  @dependency = @file_descriptor_proto.dependency || []
  @service_and_method_names = {}

  set_service_and_method_names
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



8
9
10
# File 'lib/grpc_reflection/file_descriptor.rb', line 8

def dependency
  @dependency
end

#descriptor_dataObject (readonly)

Returns the value of attribute descriptor_data.



8
9
10
# File 'lib/grpc_reflection/file_descriptor.rb', line 8

def descriptor_data
  @descriptor_data
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/grpc_reflection/file_descriptor.rb', line 8

def filename
  @filename
end

#service_and_method_namesObject (readonly)

Returns the value of attribute service_and_method_names.



8
9
10
# File 'lib/grpc_reflection/file_descriptor.rb', line 8

def service_and_method_names
  @service_and_method_names
end

Instance Method Details

#set_service_and_method_namesObject



20
21
22
23
24
25
26
27
28
# File 'lib/grpc_reflection/file_descriptor.rb', line 20

def set_service_and_method_names
  @file_descriptor_proto.service.each do |s|
    converted_service = JSON.parse(s.to_json)
    @service_and_method_names[@file_descriptor_proto.package + "." + converted_service["name"]] = true
    converted_service["method"].each do |m|
      @service_and_method_names[@file_descriptor_proto.package + "." + converted_service["name"] + "." + m["name"]] = true
    end
  end
end