class GVariantBasicType
Attributes
alignment[R]
default_value[R]
fixed_size[R]
id[R]
Public Class Methods
new(id, pack_format, alignment, fixed_size, default_value)
click to toggle source
# File lib/gvariant.rb, line 4 def initialize(id, pack_format, alignment, fixed_size, default_value) @id, @pack_format, @alignment, @fixed_size, @default_value = id, pack_format, alignment, fixed_size, default_value end
Public Instance Methods
align(i)
click to toggle source
# File lib/gvariant.rb, line 9 def align(i) (i + @alignment - 1) & ~(@alignment - 1) end
pad(buf)
click to toggle source
# File lib/gvariant.rb, line 13 def pad(buf) l = buf.length (align(l) - l).times do buf.concat(0) end end
read(buf)
click to toggle source
# File lib/gvariant.rb, line 20 def read(buf) return @default_value if @fixed_size && buf.length != @fixed_size buf.unpack(@pack_format).first end
write(value)
click to toggle source
# File lib/gvariant.rb, line 25 def write(value) [value || @default_value].pack(@pack_format) end