class Google::Protobuf::DescriptorPool

Attributes

descriptor_class_by_def[RW]
descriptor_pool[R]

Public Class Methods

generated_pool() click to toggle source
# File lib/google/protobuf/ffi/descriptor_pool.rb, line 62
def self.generated_pool
  @@generated_pool ||= DescriptorPool.new
end
new() click to toggle source
# 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

Public Instance Methods

add_serialized_file(file_contents) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

get_file_descriptor(file_def) click to toggle source

Implementation details below are subject to breaking changes without warning and are intended for use only within the gem.

# File lib/google/protobuf/ffi/descriptor_pool.rb, line 71
def get_file_descriptor file_def
  return nil if file_def.null?
  @descriptor_class_by_def[file_def.address] ||= FileDescriptor.new(file_def, self)
end