class HrrRbSsh::DataType::Boolean

Boolean provides methods to convert boolean value and 8-bit unsigned binary string each other.

Public Class Methods

decode(io) click to toggle source

Convert 8-bit unsigned binary into boolean value.

@param [::IO] io IO instance that has buffer to be read @return [::Boolean] converted boolean value

# 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) click to toggle source

Convert boolean value into 8-bit unsigned binary string.

@param [::Boolean] arg boolean value to be converted @raise [::ArgumentError] when arg is not true nor false @return [::String] converted 8-bit unsigned binary string

# 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