Class: DBus::Data::Boolean
Overview
Boolean: encoded as a UInt32 but only 0 and 1 are valid.
Constant Summary
collapse
- FORMAT =
Format.new("L<", "L>")
Instance Attribute Summary
Attributes inherited from Base
#value
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Fixed
fixed?
Methods inherited from Basic
basic?, from_typed, type, #type
Methods inherited from Base
#==, assert_type_matches_class, basic?, #eql?, fixed?, from_typed, #type
Constructor Details
#initialize(value) ⇒ Boolean
Accept any value, store its Ruby truth value (excepting another instance of this class, where use its DBus::Data::Base#value).
So new(0).value is true.
235
236
237
238
|
# File 'lib/dbus/data.rb', line 235
def initialize(value)
value = value.value if value.is_a?(self.class)
super(value ? true : false)
end
|
Class Method Details
.alignment ⇒ Object
207
208
209
|
# File 'lib/dbus/data.rb', line 207
def self.alignment
4
end
|
211
212
213
|
# File 'lib/dbus/data.rb', line 211
def self.format
FORMAT
end
|
.from_raw(value, mode:) ⇒ Object
221
222
223
224
225
226
227
228
|
# File 'lib/dbus/data.rb', line 221
def self.from_raw(value, mode:)
validate_raw!(value)
value = value == 1
return value if mode == :plain
new(value)
end
|
.type_code ⇒ Object
203
204
205
|
# File 'lib/dbus/data.rb', line 203
def self.type_code
"b"
end
|
.validate_raw!(value) ⇒ Object
215
216
217
218
219
|
# File 'lib/dbus/data.rb', line 215
def self.validate_raw!(value)
return if [0, 1].member?(value)
raise InvalidPacketException, "BOOLEAN must be 0 or 1, found #{value}"
end
|
Instance Method Details
#marshall(endianness) ⇒ Object
241
242
243
244
|
# File 'lib/dbus/data.rb', line 241
def marshall(endianness)
int = value ? 1 : 0
[int].pack(UInt32.format[endianness])
end
|