Class: Google::Protobuf::DescriptorPool

Inherits:
Object
  • Object
show all
Defined in:
lib/google/protobuf/ffi/descriptor_pool.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDescriptorPool

Returns a new instance of DescriptorPool.



28
29
30
31
32
33
34
35
# File 'lib/google/protobuf/ffi/descriptor_pool.rb', line 28

def initialize
  @descriptor_pool = ::FFI::AutoPointer.new(Google::Protobuf::FFI.create_descriptor_pool, Google::Protobuf::FFI.method(:free_descriptor_pool))
  @descriptor_class_by_def = {}

  # Should always be the last expression of the initializer to avoid
  # leaking references to this object before construction is complete.
  Google::Protobuf::OBJECT_CACHE.try_add @descriptor_pool.address, self
end

Instance Attribute Details

#descriptor_class_by_defObject

Returns the value of attribute descriptor_class_by_def.



26
27
28
# File 'lib/google/protobuf/ffi/descriptor_pool.rb', line 26

def descriptor_class_by_def
  @descriptor_class_by_def
end

#descriptor_poolObject (readonly)

Returns the value of attribute descriptor_pool.



25
26
27
# File 'lib/google/protobuf/ffi/descriptor_pool.rb', line 25

def descriptor_pool
  @descriptor_pool
end

Class Method Details

.generated_poolObject



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

def self.generated_pool
  @@generated_pool ||= DescriptorPool.new
end

Instance Method Details

#add_serialized_file(file_contents) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/google/protobuf/ffi/descriptor_pool.rb', line 37

def add_serialized_file(file_contents)
  # Allocate memory sized to file_contents
  memBuf = ::FFI::MemoryPointer.new(:char, file_contents.bytesize)
  # Insert the data
  memBuf.put_bytes(0, file_contents)
  temporary_arena = Google::Protobuf::FFI.create_arena
  file_descriptor_proto = Google::Protobuf::FFI.parse memBuf, file_contents.bytesize, temporary_arena
  raise ArgumentError.new("Unable to parse FileDescriptorProto") if file_descriptor_proto.null?

  status = Google::Protobuf::FFI::Status.new
  file_descriptor = Google::Protobuf::FFI.add_serialized_file @descriptor_pool, file_descriptor_proto, status
  if file_descriptor.null?
    raise TypeError.new("Unable to build file to DescriptorPool: #{Google::Protobuf::FFI.error_message(status)}")
  else
    @descriptor_class_by_def[file_descriptor.address] = FileDescriptor.new file_descriptor, self
  end
end

#lookup(name) ⇒ Object



55
56
57
58
59
60
# File 'lib/google/protobuf/ffi/descriptor_pool.rb', line 55

def lookup name
  Google::Protobuf::FFI.lookup_msg(@descriptor_pool, name) ||
    Google::Protobuf::FFI.lookup_enum(@descriptor_pool, name) ||
    Google::Protobuf::FFI.lookup_extension(@descriptor_pool, name) ||
    Google::Protobuf::FFI.lookup_service(@descriptor_pool, name)
end