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

Constructor Details

#initialize(arr) ⇒ Bytes

Returns a new instance of Bytes.



35
36
37
38
# File 'lib/ffi-glib/bytes.rb', line 35

def initialize(arr)
  data = GirFFI::SizedArray.from :guint8, arr.size, arr
  store_pointer Lib.g_bytes_new data.to_ptr, data.size
end

Class Method Details

.from(it) ⇒ Object



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

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

Instance Method Details

#each(&block) ⇒ Object



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

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

#get_dataObject



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

def get_data
  length_ptr = GirFFI::InOutPointer.for :gsize
  data_ptr = Lib.g_bytes_get_data self, length_ptr
  length = length_ptr.to_value
  # NOTE: Needed due to mis-identification of the element-type of the
  # resulting sized array for the default binding.
  GirFFI::SizedArray.wrap(:guint8, length, data_ptr)
end