Class: Kafka::FFI::OpaquePointer
- Inherits:
-
Object
- Object
- Kafka::FFI::OpaquePointer
- Extended by:
- FFI::DataConverter
- Defined in:
- lib/kafka/ffi/opaque_pointer.rb
Overview
Kafka has several options for opaque
pointers that get passed to
callbacks. Those opaque pointers are not related to this opaque pointer.
OpaquePointer pointer provides a common pattern where we receive a pointer to a struct but don't care about the structure and need to pass it to functions. OpaquePointer gives type safety by checking types before converting.
Direct Known Subclasses
Admin::AdminOptions, Admin::ConfigEntry, Admin::ConfigResource, Admin::DeleteTopic, Admin::NewPartitions, Admin::NewTopic, Admin::TopicResult, Client, Config, Event, Message::Header, Queue, Topic, TopicConfig
Instance Attribute Summary collapse
- #pointer ⇒ Object readonly
Class Method Summary collapse
-
.by_ref ⇒ Object
Provide ::FFI::Struct API compatility for consistency with attach_function is called with an OpaquePointer.
-
.from_native(value, _ctx) ⇒ nil
Convert from a FFI::Pointer to the implementing class.
- .inherited(subclass) ⇒ Object
-
.to_native(value, _ctx) ⇒ FFI::Pointer
Convert from a Kafka::FFI type to a native FFI type.
Instance Method Summary collapse
-
#initialize(pointer) ⇒ OpaquePointer
constructor
A new instance of OpaquePointer.
Constructor Details
#initialize(pointer) ⇒ OpaquePointer
Returns a new instance of OpaquePointer.
69 70 71 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 69 def initialize(pointer) @pointer = pointer end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
17 18 19 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 17 def pointer @pointer end |
Class Method Details
.by_ref ⇒ Object
Provide ::FFI::Struct API compatility for consistency with attach_function is called with an OpaquePointer.
60 61 62 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 60 def by_ref self end |
.from_native(value, _ctx) ⇒ nil
Convert from a FFI::Pointer to the implementing class.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 26 def from_native(value, _ctx) if !value.is_a?(::FFI::Pointer) raise TypeError, "from_native can only convert from a ::FFI::Pointer to #{self}" end # The equivalent of a native NULL pointer is nil. if value.null? return nil end obj = allocate obj.send(:initialize, value) obj end |
.inherited(subclass) ⇒ Object
64 65 66 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 64 def inherited(subclass) subclass.native_type :pointer end |
.to_native(value, _ctx) ⇒ FFI::Pointer
Convert from a Kafka::FFI type to a native FFI type.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kafka/ffi/opaque_pointer.rb', line 46 def to_native(value, _ctx) if value.nil? return ::FFI::Pointer::NULL end if !value.is_a?(self) raise TypeError, "expected a kind of #{self}, was #{value.class}" end value.pointer end |