Class: HrrRbSsh::DataType::Boolean
- Inherits:
-
HrrRbSsh::DataType
- Object
- HrrRbSsh::DataType
- HrrRbSsh::DataType::Boolean
- Defined in:
- lib/hrr_rb_ssh/data_type/boolean.rb
Overview
Boolean provides methods to convert boolean value and 8-bit unsigned binary string each other.
Class Method Summary collapse
-
.decode(io) ⇒ ::Boolean
Convert 8-bit unsigned binary into boolean value.
-
.encode(arg) ⇒ ::String
Convert boolean value into 8-bit unsigned binary string.
Class Method Details
.decode(io) ⇒ ::Boolean
Convert 8-bit unsigned binary into boolean value.
28 29 30 31 32 33 34 |
# File 'lib/hrr_rb_ssh/data_type/boolean.rb', line 28 def self.decode io if 0 == io.read(1).unpack("C")[0] false else true end end |
.encode(arg) ⇒ ::String
Convert boolean value into 8-bit unsigned binary string.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hrr_rb_ssh/data_type/boolean.rb', line 13 def self.encode arg case arg when false [0].pack("C") when true [1].pack("C") else raise ArgumentError, "must be #{true} or #{false}, but got #{arg.inspect}" end end |