Class: Google::Protobuf::ServiceDescriptor

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter, Internal::PointerHelper, Internal::TypeSafety
Includes:
Enumerable, Internal::Convert
Defined in:
lib/google/protobuf/ffi/service_descriptor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Internal::PointerHelper

descriptor_from_file_def

Methods included from Internal::TypeSafety

to_native

Methods included from Internal::Convert

#convert_ruby_to_upb, #convert_upb_to_ruby, #map_create_hash, #message_value_deep_copy, #repeated_field_create_array, #scalar_create_hash, #to_h_internal

Instance Attribute Details

#service_defObject (readonly)

Returns the value of attribute service_def.



11
12
13
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 11

def service_def
  @service_def
end

Class Method Details

.from_native(service_def, _ = nil) ⇒ Object

Parameters:

  • service_def (::FFI::Pointer)

    ServiceDef pointer to be wrapped

  • _ (Object) (defaults to: nil)

    Unused



36
37
38
39
40
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 36

def from_native(service_def, _ = nil)
  return nil if service_def.nil? or service_def.null?
  file_def = Google::Protobuf::FFI.file_def_by_raw_service_def(service_def)
  descriptor_from_file_def(file_def, service_def)
end

.new(*arguments, &block) ⇒ Object



43
44
45
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 43

def self.new(*arguments, &block)
  raise "Descriptor objects may not be created from Ruby."
end

.to_native(value, _) ⇒ Object

Parameters:

  • value (ServiceDescriptor)

    ServiceDescriptor to convert to an FFI native type

  • _ (Object)

    Unused



26
27
28
29
30
31
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 26

def to_native(value, _)
  service_def_ptr = value.nil? ? nil : value.instance_variable_get(:@service_def)
  return ::FFI::Pointer::NULL if service_def_ptr.nil?
  raise "Underlying service_def was null!" if service_def_ptr.null?
  service_def_ptr
end

Instance Method Details

#each(&block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 63

def each &block
  n = Google::Protobuf::FFI.method_count(self)
  0.upto(n-1) do |i|
    yield(Google::Protobuf::FFI.get_method_by_index(self, i))
  end
  nil
end

#file_descriptorObject



59
60
61
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 59

def file_descriptor
  @descriptor_pool.send(:get_file_descriptor, Google::Protobuf::FFI.file_def_by_raw_service_def(@service_def))
end

#inspectObject



51
52
53
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 51

def inspect
  "#{self.class.name}: #{name}"
end

#nameObject



55
56
57
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 55

def name
  @name ||= Google::Protobuf::FFI.get_service_full_name(self)
end

#optionsObject



71
72
73
74
75
76
77
78
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 71

def options
  @options ||= begin
    size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
    temporary_arena = Google::Protobuf::FFI.create_arena
    buffer = Google::Protobuf::FFI.service_options(self, size_ptr, temporary_arena)
    Google::Protobuf::ServiceOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze
  end
end

#to_sObject



47
48
49
# File 'lib/google/protobuf/ffi/service_descriptor.rb', line 47

def to_s
  inspect
end