Class: Google::Protobuf::Internal::Arena

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter, TypeSafety
Defined in:
lib/google/protobuf/ffi/internal/arena.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TypeSafety

to_native

Constructor Details

#initialize(pointer) ⇒ Arena

Returns a new instance of Arena.



38
39
40
41
# File 'lib/google/protobuf/ffi/internal/arena.rb', line 38

def initialize(pointer)
  @arena = ::FFI::AutoPointer.new(pointer, Google::Protobuf::FFI.method(:free_arena))
  @pinned_messages = []
end

Instance Attribute Details

#pinned_messagesObject (readonly)

Returns the value of attribute pinned_messages.



15
16
17
# File 'lib/google/protobuf/ffi/internal/arena.rb', line 15

def pinned_messages
  @pinned_messages
end

Class Method Details

.from_native(value, _) ⇒ Object

Parameters:

  • value (::FFI::Pointer)

    Arena pointer to be wrapped

  • _ (Object)

    Unused



33
34
35
# File 'lib/google/protobuf/ffi/internal/arena.rb', line 33

def from_native(value, _)
  new(value)
end

.to_native(value, _) ⇒ Object

Parameters:

  • value (Arena)

    Arena to convert to an FFI native type

  • _ (Object)

    Unused



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

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

Instance Method Details

#fuse(other_arena) ⇒ Object



43
44
45
46
47
48
# File 'lib/google/protobuf/ffi/internal/arena.rb', line 43

def fuse(other_arena)
  return if other_arena == self
  unless Google::Protobuf::FFI.fuse_arena(self, other_arena)
    raise RuntimeError.new "Unable to fuse arenas. This should never happen since Ruby does not use initial blocks"
  end
end

#pin(message) ⇒ Object



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

def pin(message)
  pinned_messages.push message
end