Class: DBus::PacketUnmarshaller

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

Overview

D-Bus packet unmarshaller class

Class that handles the conversion (unmarshalling) of payload data to #Objects (in plain mode) or to Data::Base (in exact mode)

Spelling note: this codebase always uses a double L in the “marshall” word and its inflections.

Instance Method Summary collapse

Constructor Details

#initialize(buffer, endianness) ⇒ PacketUnmarshaller

Create a new unmarshaller for the given data buffer.

Parameters:

  • buffer (String)
  • endianness (:little, :big)


36
37
38
39
40
41
# File 'lib/dbus/marshall.rb', line 36

def initialize(buffer, endianness)
  # TODO: this dup can be avoided if we can prove
  # that an IncompleteBufferException leaves the original *buffer* intact
  buffer = buffer.dup
  @raw_msg = RawMessage.new(buffer, endianness)
end

Instance Method Details

#align_bodyObject

after the headers, the body starts 8-aligned



66
67
68
# File 'lib/dbus/marshall.rb', line 66

def align_body
  @raw_msg.align(8)
end

#consumed_sizeInteger

Returns:

  • (Integer)


71
72
73
# File 'lib/dbus/marshall.rb', line 71

def consumed_size
  @raw_msg.pos
end

#unmarshall(signature, len = nil, mode: :plain) ⇒ Array<::Object,DBus::Data::Base>

Unmarshall the buffer for a given signature and length len. Return an array of unmarshalled objects.

Parameters:

  • signature (Signature)
  • len (Integer, nil) (defaults to: nil)

    if given, and there is not enough data in the buffer, raise IncompleteBufferException

  • mode (:plain, :exact) (defaults to: :plain)

Returns:

  • (Array<::Object,DBus::Data::Base>)

    Objects in ‘:plain` mode, Data::Base in `:exact` mode The array size corresponds to the number of types in signature.

Raises:

  • IncompleteBufferException

  • InvalidPacketException



54
55
56
57
58
59
60
61
62
63
# File 'lib/dbus/marshall.rb', line 54

def unmarshall(signature, len = nil, mode: :plain)
  @raw_msg.want!(len) if len

  sigtree = Type::Parser.new(signature).parse
  ret = []
  sigtree.each do |elem|
    ret << do_parse(elem, mode: mode)
  end
  ret
end