Class: Google::Protobuf::OneofDescriptor

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter, Internal::PointerHelper, Internal::TypeSafety
Includes:
Enumerable
Defined in:
lib/google/protobuf/ffi/oneof_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

Instance Attribute Details

#descriptor_poolObject (readonly)

Returns the value of attribute descriptor_pool.



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

def descriptor_pool
  @descriptor_pool
end

Class Method Details

.from_native(oneof_def, _ = nil) ⇒ Object

Parameters:

  • oneof_def (::FFI::Pointer)

    OneofDef pointer to be wrapped

  • _ (Object) (defaults to: nil)

    Unused



31
32
33
34
35
36
37
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 31

def from_native(oneof_def, _ = nil)
  return nil if oneof_def.nil? or oneof_def.null?
  message_descriptor = Google::Protobuf::FFI.get_oneof_containing_type oneof_def
  raise RuntimeError.new "Message Descriptor is nil" if message_descriptor.nil?
  file_def = Google::Protobuf::FFI.get_message_file_def message_descriptor.to_native
  descriptor_from_file_def(file_def, oneof_def)
end

.new(*arguments, &block) ⇒ Object



40
41
42
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 40

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

.to_native(value, _ = nil) ⇒ Object

Parameters:

  • value (OneofDescriptor)

    FieldDescriptor to convert to an FFI native type

  • _ (Object) (defaults to: nil)

    Unused



24
25
26
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 24

def to_native(value, _ = nil)
  value.instance_variable_get(:@oneof_def) || ::FFI::Pointer::NULL
end

Instance Method Details

#each(&block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 48

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

#nameObject



44
45
46
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 44

def name
  Google::Protobuf::FFI.get_oneof_name(self)
end

#optionsObject



56
57
58
59
60
61
62
63
# File 'lib/google/protobuf/ffi/oneof_descriptor.rb', line 56

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