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
41 def make_typed(type, value)
42   type = DBus.type(type) unless type.is_a?(Type)
43   data_class = Data::BY_TYPE_CODE[type.sigtype]
44   # not nil because DBus.type validates
45 
46   data_class.from_typed(value, type: type)
47 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
41 def make_typed(type, value)
42   type = DBus.type(type) unless type.is_a?(Type)
43   data_class = Data::BY_TYPE_CODE[type.sigtype]
44   # not nil because DBus.type validates
45 
46   data_class.from_typed(value, type: type)
47 end