Class: Google::Protobuf::EnumDescriptor

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter, Internal::PointerHelper, Internal::TypeSafety
Includes:
Enumerable
Defined in:
lib/google/protobuf/ffi/enum_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/enum_descriptor.rb', line 11

def descriptor_pool
  @descriptor_pool
end

Class Method Details

.from_native(enum_def, _) ⇒ Object

Parameters:

  • enum_def (::FFI::Pointer)

    EnumDef pointer to be wrapped

  • _ (Object)

    Unused



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

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

.new(*arguments, &block) ⇒ Object



38
39
40
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 38

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

.to_native(value, _) ⇒ Object

Parameters:

  • value (EnumDescriptor)

    EnumDescriptor to convert to an FFI native type

  • _ (Object)

    Unused



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

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

Instance Method Details

#each(&block) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 66

def each &block
  n = Google::Protobuf::FFI.enum_value_count(self)
  0.upto(n - 1) do |i|
    enum_value = Google::Protobuf::FFI.enum_value_by_index(self, i)
    yield(Google::Protobuf::FFI.enum_name(enum_value).to_sym, Google::Protobuf::FFI.enum_number(enum_value))
  end
  nil
end

#enummoduleObject



75
76
77
78
79
80
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 75

def enummodule
  if @module.nil?
    @module = build_enum_module
  end
  @module
end

#file_descriptorObject



42
43
44
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 42

def file_descriptor
  @descriptor_pool.send(:get_file_descriptor, Google::Protobuf::FFI.get_enum_file_descriptor(self))
end

#inspectObject



54
55
56
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 54

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

#lookup_name(name) ⇒ Object



58
59
60
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 58

def lookup_name(name)
  self.class.send(:lookup_name, self, name)
end

#lookup_value(number) ⇒ Object



62
63
64
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 62

def lookup_value(number)
  self.class.send(:lookup_value, self, number)
end

#nameObject



46
47
48
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 46

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

#optionsObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 82

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

#to_sObject



50
51
52
# File 'lib/google/protobuf/ffi/enum_descriptor.rb', line 50

def to_s
  inspect
end