Class: FFI::Libfuse::FuseBufVec
- Inherits:
-
Struct
- Object
- Struct
- FFI::Libfuse::FuseBufVec
- Includes:
- Accessors
- Defined in:
- lib/ffi/libfuse/fuse_buf_vec.rb
Overview
Data buffer vector
An list of io buffers, each containing a memory pointer or a file descriptor.
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
The number of buffers in the array.
-
#idx ⇒ Integer
(also: #index)
readonly
Index of current buffer within the array.
-
#off ⇒ Integer
(also: #offset)
readonly
Current offset within the current buffer.
Class Method Summary collapse
-
.create(io, size, offset = nil) ⇒ FuseBufVec
Create and initialise from a ruby object that quacks like File, IO, or String.
-
.init(autorelease: true, count: 1, **buf_options) ⇒ FuseBufVec
Create and initialise a new FuseBufVec.
Instance Method Summary collapse
-
#buf_size ⇒ Integer
Total size of io in a fuse buffer vector (ie the size of all the fuse buffers).
-
#buffers ⇒ Array<FuseBuf>
List of buffers.
-
#copy_from(src, *flags) ⇒ Integer
Copy from another set of buffers to this one.
-
#copy_to(dst, *flags) ⇒ Integer
Copy data from this set of buffers to another set.
-
#copy_to_fd(fileno, offset = nil, *flags) ⇒ Integer
Copy direct to file descriptor.
-
#copy_to_io(io, offset = nil, *flags) ⇒ Integer
Write data from these buffers to another object.
-
#copy_to_str(*flags) ⇒ String
Copy to string via a temporary buffer.
- #seek(pos) ⇒ self
-
#store_to(bufp) ⇒ void
Store ourself into a pointer location as received by FFI::Libfuse::FuseOperations#read_buf.
Methods included from Accessors
#ffi_attr_fill, #ffi_attr_reader_member, #ffi_attr_writer_member, #fill, #inspect, #to_h
Methods included from Accessors::ClassMethods
#attr_accessor, #attr_reader, #attr_writer, #ffi_attr_accessor, #ffi_attr_reader, #ffi_attr_reader_method, #ffi_attr_readers, #ffi_attr_writer, #ffi_attr_writer_method, #ffi_attr_writers, #ffi_bitflag_accessor, #ffi_bitflag_reader, #ffi_bitflag_writer, #ffi_public_attr_readers, #ffi_public_attr_writers
Instance Attribute Details
#count ⇒ Integer (readonly)
Returns the number of buffers in the array.
|
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 29
|
#idx ⇒ Integer (readonly) Also known as: index
Returns index of current buffer within the array.
35 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 35 alias index idx |
#off ⇒ Integer (readonly) Also known as: offset
Returns current offset within the current buffer.
40 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 40 alias offset off |
Class Method Details
.create(io, size, offset = nil) ⇒ FuseBufVec
The returned object's memory is not auto-released, and thus suitable for use with FFI::Libfuse::FuseOperations#read_buf where the buffers are cleared by libfuse library..
Create and initialise from a ruby object that quacks like File, IO, or String
55 56 57 58 59 60 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 55 def self.create(io, size, offset = nil) fd = io.respond_to?(:fileno) ? io.fileno : io return init(autorelease: false, size: size, fd: fd, pos: offset || 0) if fd.is_a?(Integer) init(autorelease: false, str: Libfuse::IO.read(io, size, offset)) end |
.init(autorelease: true, count: 1, **buf_options) ⇒ FuseBufVec
Create and initialise a new FuseBufVec
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 69 def self.init(autorelease: true, count: 1, **) bufvec_ptr = FFI::MemoryPointer.new(:uchar, FuseBufVec.size + (FuseBuf::Native.size * (count - 1)), true) bufvec_ptr.autorelease = autorelease bufvec = new(bufvec_ptr) bufvec[:count] = count bufvec[:idx] = 0 bufvec[:off] = 0 bufvec.buffers[0].fill(**) unless .empty? bufvec end |
Instance Method Details
#buf_size ⇒ Integer
Returns total size of io in a fuse buffer vector (ie the size of all the fuse buffers).
81 82 83 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 81 def buf_size Libfuse.fuse_buf_size(self) end |
#buffers ⇒ Array<FuseBuf>
Returns list of buffers.
209 210 211 212 213 214 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 209 def buffers @buffers ||= Array.new(count) do |i| native = i.zero? ? self[:buf].first : FuseBuf::Native.new(self[:buf].to_ptr + (i * FuseBuf::Native.size)) FuseBuf.new(native) end.freeze end |
#copy_from(src, *flags) ⇒ Integer
Copy from another set of buffers to this one
164 165 166 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 164 def copy_from(src, *flags) Libfuse.fuse_buf_copy(self, src, flags) end |
#copy_to(dst, *flags) ⇒ Integer
Copy data from this set of buffers to another set
136 137 138 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 136 def copy_to(dst, *flags) Libfuse.fuse_buf_copy(dst, self, flags) end |
#copy_to_fd(fileno, offset = nil, *flags) ⇒ Integer
Copy direct to file descriptor
145 146 147 148 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 145 def copy_to_fd(fileno, offset = nil, *flags) dst = self.class.init(size: buf_size, fd: fileno, pos: offset) copy_to(dst, *flags) end |
#copy_to_io(io, *flags) ⇒ Integer #copy_to_io(io, offset = nil, *flags) ⇒ Integer
Write data from these buffers to another object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 191 def copy_to_io(io, offset = nil, *flags) if offset.is_a?(Symbol) flags.unshift(offset) offset = nil end if io.is_a?(FuseBufVec) io.seek(offset) if offset return copy_to(io, *flags) end fd = (io.respond_to?(:fileno) ? io.fileno : io) return copy_to_fd(fd, offset || 0, *flags) if fd.is_a?(Integer) Libfuse::IO.write(io, copy_to_str(*flags), offset) end |
#copy_to_str(*flags) ⇒ String
Copy to string via a temporary buffer
153 154 155 156 157 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 153 def copy_to_str(*flags) dst = self.class.init(size: buf_size) copied = copy_to(dst, *flags) dst.buffers.first.memory.read_string(copied) end |
#seek(pos) ⇒ self
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 89 def seek(pos) buffers.each_with_index do |b, i| if pos < b.size self[:idx] = i self[:off] = pos return self else pos -= b.size end end raise Errno::ERANGE end |
#store_to(bufp) ⇒ void
This method returns an undefined value.
Store ourself into a pointer location as received by FFI::Libfuse::FuseOperations#read_buf
171 172 173 |
# File 'lib/ffi/libfuse/fuse_buf_vec.rb', line 171 def store_to(bufp) bufp.write_pointer(to_ptr) end |