Class: GLib::ByteArray

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-glib/byte_array.rb

Overview

Overrides for GByteArray, GLib’s automatically growing array of bytes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(data) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ffi-glib/byte_array.rb', line 19

def self.from(data)
  case data
  when self
    data
  else
    new.append(data)
  end
end

Instance Method Details

#append(data) ⇒ Object



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

def append(data)
  bytes = GirFFI::InPointer.from_utf8 data
  len = data.bytesize
  Lib.g_byte_array_append(to_ptr, bytes, len)
  self
end

#to_stringObject



8
9
10
# File 'lib/ffi-glib/byte_array.rb', line 8

def to_string
  data.read_string len
end