Class: Oinky::Internal::DB_string
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Oinky::Internal::DB_string
- Includes:
- NativeBuffer
- Defined in:
- lib/oinky.rb
Instance Attribute Summary collapse
-
#refs ⇒ Object
Returns the value of attribute refs.
Class Method Summary collapse
- .make(val) ⇒ Object
-
.make_in_place(nv, val) ⇒ Object
Have to separate like this because FFI Doesn’t allow assigning to structs by value.
Instance Method Summary collapse
- #length ⇒ Object
-
#ptr ⇒ Object
These are required by NativeBuffer.
Methods included from NativeBuffer
#<=>, #clone, #each_byte, #each_char, #inspect, #rb_str
Instance Attribute Details
#refs ⇒ Object
Returns the value of attribute refs.
71 72 73 |
# File 'lib/oinky.rb', line 71 def refs @refs end |
Class Method Details
.make(val) ⇒ Object
73 74 75 76 77 |
# File 'lib/oinky.rb', line 73 def self.make(val) nv = DB_string.new nv.refs = make_in_place(nv, val) nv end |
.make_in_place(nv, val) ⇒ Object
Have to separate like this because FFI Doesn’t allow assigning to structs by value.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/oinky.rb', line 81 def self.make_in_place(nv, val) if val.is_a? String val = NativeMallocBuffer.new(val) nv[:bytes] = val.ptr nv[:length] = val.length elsif val.is_a? NativeBuffer nv[:bytes] = val.ptr nv[:length] = val.length else raise OinkyException.new("Argument is not a recognized string") end # Caller keeps the source object in memory as long as the variant. # This is important whatever the source, ruby strings and # NativeBuffers equally. return val end |
Instance Method Details
#length ⇒ Object
103 104 105 |
# File 'lib/oinky.rb', line 103 def length self[:length] end |
#ptr ⇒ Object
These are required by NativeBuffer
100 101 102 |
# File 'lib/oinky.rb', line 100 def ptr self[:bytes] end |