Class: GVariantBasicType

Inherits:
Object
  • Object
show all
Defined in:
lib/gvariant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, pack_format, alignment, fixed_size, default_value) ⇒ GVariantBasicType

Returns a new instance of GVariantBasicType.



4
5
6
7
# 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

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



2
3
4
# File 'lib/gvariant.rb', line 2

def alignment
  @alignment
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



2
3
4
# File 'lib/gvariant.rb', line 2

def default_value
  @default_value
end

#fixed_sizeObject (readonly)

Returns the value of attribute fixed_size.



2
3
4
# File 'lib/gvariant.rb', line 2

def fixed_size
  @fixed_size
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/gvariant.rb', line 2

def id
  @id
end

Instance Method Details

#align(i) ⇒ Object



9
10
11
# File 'lib/gvariant.rb', line 9

def align(i)
  (i + @alignment - 1) & ~(@alignment - 1)
end

#pad(buf) ⇒ Object



13
14
15
16
17
18
# File 'lib/gvariant.rb', line 13

def pad(buf)
  l = buf.length
  (align(l) - l).times do
    buf.concat(0)
  end
end

#read(buf) ⇒ Object



20
21
22
23
# 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) ⇒ Object



25
26
27
# File 'lib/gvariant.rb', line 25

def write(value)
  [value || @default_value].pack(@pack_format)
end