Class: GVariantBasicType
- Inherits:
-
Object
- Object
- GVariantBasicType
- Defined in:
- lib/gvariant.rb
Direct Known Subclasses
GVariantBooleanType, GVariantByteType, GVariantDoubleType, GVariantMaybeType, GVariantOffsetType, GVariantSignedIntType, GVariantSignedLongType, GVariantSignedShortType, GVariantStringType, GVariantUnsignedIntType, GVariantUnsignedLongType, GVariantUnsignedShortType, GVariantVariantType
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#fixed_size ⇒ Object
readonly
Returns the value of attribute fixed_size.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #align(i) ⇒ Object
-
#initialize(id, pack_format, alignment, fixed_size, default_value) ⇒ GVariantBasicType
constructor
A new instance of GVariantBasicType.
- #pad(buf) ⇒ Object
- #read(buf) ⇒ Object
- #write(value) ⇒ Object
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
#alignment ⇒ Object (readonly)
Returns the value of attribute alignment.
2 3 4 |
# File 'lib/gvariant.rb', line 2 def alignment @alignment end |
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
2 3 4 |
# File 'lib/gvariant.rb', line 2 def default_value @default_value end |
#fixed_size ⇒ Object (readonly)
Returns the value of attribute fixed_size.
2 3 4 |
# File 'lib/gvariant.rb', line 2 def fixed_size @fixed_size end |
#id ⇒ Object (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 |