module DBus::Data

Exact/explicit representation of D-Bus data types:

The common base type is {Base}.

There are other intermediate classes in the inheritance hierarchy, using the names the specification uses, but they are an implementation detail:

Constants

BY_TYPE_CODE

{ “b” => Data::Boolean, “s” => Data::String, …}

Format

Format strings for String#unpack, both little- and big-endian.

Public Class Methods

make_typed(type, value) click to toggle source

Given a plain Ruby value and wanting a D-Bus type, construct an appropriate {Data::Base} instance.

@param type [SingleCompleteType,Type] @param value [::Object,Data::Base] a plain value; exact values also allowed @return [Data::Base] @raise TypeError

# File lib/dbus/data.rb, line 40
def make_typed(type, value)
  type = DBus.type(type) unless type.is_a?(Type)
  data_class = Data::BY_TYPE_CODE[type.sigtype]
  # not nil because DBus.type validates

  data_class.from_typed(value, type: type)
end

Private Instance Methods

make_typed(type, value) click to toggle source

Given a plain Ruby value and wanting a D-Bus type, construct an appropriate {Data::Base} instance.

@param type [SingleCompleteType,Type] @param value [::Object,Data::Base] a plain value; exact values also allowed @return [Data::Base] @raise TypeError

# File lib/dbus/data.rb, line 40
def make_typed(type, value)
  type = DBus.type(type) unless type.is_a?(Type)
  data_class = Data::BY_TYPE_CODE[type.sigtype]
  # not nil because DBus.type validates

  data_class.from_typed(value, type: type)
end