Class: GLib::Bytes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi-glib/bytes.rb

Overview

Overrides for GBytes, GLib’s immutable array of bytes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(it) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/ffi-glib/bytes.rb', line 23

def self.from it
  case it
  when self
    it
  when FFI::Pointer
    wrap it
  else
    new it
  end
end

.new(arr) ⇒ Object



38
39
40
41
# File 'lib/ffi-glib/bytes.rb', line 38

def self.new arr
  data = GirFFI::SizedArray.from :guint8, arr.size, arr
  wrap Lib.g_bytes_new data.to_ptr, data.size
end

Instance Method Details

#each(&block) ⇒ Object



19
20
21
# File 'lib/ffi-glib/bytes.rb', line 19

def each &block
  data.each(&block)
end

#get_dataObject

Override for GBytes#get_data, needed due to mis-identification of the element-type of the resulting sized array.



12
13
14
15
16
17
# File 'lib/ffi-glib/bytes.rb', line 12

def get_data
  length_ptr = GirFFI::InOutPointer.for :gsize
  data_ptr = Lib.g_bytes_get_data self, length_ptr
  length = length_ptr.to_value
  GirFFI::SizedArray.wrap(:guint8, length, data_ptr)
end