Class: DBus::PacketUnmarshaller
- Inherits:
-
Object
- Object
- DBus::PacketUnmarshaller
- Defined in:
- lib/dbus/marshall.rb
Overview
D-Bus packet unmarshaller class
Class that handles the conversion (unmarshalling) of payload data to Array.
Instance Attribute Summary collapse
-
#idx ⇒ Object
readonly
Index pointer that points to the byte in the data that is currently being processed.
Instance Method Summary collapse
-
#align(a) ⇒ Object
Align the pointer index on a byte index of a, where a must be 1, 2, 4 or 8.
-
#initialize(buffer, endianness) ⇒ PacketUnmarshaller
constructor
Create a new unmarshaller for the given data buffer and endianness.
-
#unmarshall(signature, len = nil) ⇒ Object
Unmarshall the buffer for a given signature and length len.
Constructor Details
#initialize(buffer, endianness) ⇒ PacketUnmarshaller
Create a new unmarshaller for the given data buffer and endianness.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dbus/marshall.rb', line 34 def initialize(buffer, endianness) @buffy = buffer.dup @endianness = endianness if @endianness == BIG_END @uint32 = "N" @uint16 = "n" @double = "G" elsif @endianness == LIL_END @uint32 = "V" @uint16 = "v" @double = "E" else raise InvalidPacketException, "Incorrect endianness #{@endianness}" end @idx = 0 end |
Instance Attribute Details
#idx ⇒ Object (readonly)
Index pointer that points to the byte in the data that is currently being processed.
Used to kown what part of the buffer has been consumed by unmarshalling. FIXME: Maybe should be accessed with a “consumed_size” method.
31 32 33 |
# File 'lib/dbus/marshall.rb', line 31 def idx @idx end |
Instance Method Details
#align(a) ⇒ Object
Align the pointer index on a byte index of a, where a must be 1, 2, 4 or 8.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dbus/marshall.rb', line 69 def align(a) case a when 1 nil when 2, 4, 8 bits = a - 1 @idx = @idx + bits & ~bits raise IncompleteBufferException if @idx > @buffy.bytesize else raise "Unsupported alignment #{a}" end end |
#unmarshall(signature, len = nil) ⇒ Object
Unmarshall the buffer for a given signature and length len. Return an array of unmarshalled objects
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dbus/marshall.rb', line 53 def unmarshall(signature, len = nil) if !len.nil? if @buffy.bytesize < @idx + len raise IncompleteBufferException end end sigtree = Type::Parser.new(signature).parse ret = [] sigtree.each do |elem| ret << do_parse(elem) end ret end |