Class: GVariantOffsetType
- Inherits:
-
GVariantBasicType
- Object
- GVariantBasicType
- GVariantOffsetType
- Defined in:
- lib/gvariant.rb
Direct Known Subclasses
GVariantArrayType, GVariantDictionaryType, GVariantTupleType
Instance Attribute Summary
Attributes inherited from GVariantBasicType
#alignment, #default_value, #fixed_size, #id
Instance Method Summary collapse
-
#initialize(id, alignment, default_value) ⇒ GVariantOffsetType
constructor
A new instance of GVariantOffsetType.
- #read_offset(buf, n) ⇒ Object
- #write_offsets(buf, offsets) ⇒ Object
Methods inherited from GVariantBasicType
Constructor Details
#initialize(id, alignment, default_value) ⇒ GVariantOffsetType
Returns a new instance of GVariantOffsetType.
155 156 157 158 |
# File 'lib/gvariant.rb', line 155 def initialize(id, alignment, default_value) @offset_size = nil super(id, nil, alignment, nil, default_value) end |
Instance Method Details
#read_offset(buf, n) ⇒ Object
160 161 162 163 164 |
# File 'lib/gvariant.rb', line 160 def read_offset(buf, n) l = buf.length determine_offset_type(l) buf.unpack("@#{l + @offset_size * n}#{@offset_pack_format}")[0] end |
#write_offsets(buf, offsets) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/gvariant.rb', line 166 def write_offsets(buf, offsets) return buf if offsets.empty? offset_size_prev = nil packed_size = 0 packed = "" loop do determine_offset_type(buf.length + packed_size, false) break if @offset_size == offset_size_prev offset_size_prev = @offset_size packed_size = offsets.count * @offset_size packed = offsets.pack("#{@offset_pack_format}*") end buf << packed end |