class HrrRbSsh::DataType::Byte

Byte provides methods to convert integer value and 8-bit unsigned binary string each other.

Public Class Methods

decode(io) click to toggle source

Convert 8-bit unsigned binary into Integer value.

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

# File lib/hrr_rb_ssh/data_type/byte.rb, line 26
def self.decode io
  io.read(1).unpack("C")[0]
end
encode(arg) click to toggle source

Convert integer value into 8-bit unsigned binary string.

@param [::Integer] arg integer value to be converted @raise [::ArgumentError] when arg is not between 0x00 and 0xff @return [::String] converted 8-bit unsigned binary string

# File lib/hrr_rb_ssh/data_type/byte.rb, line 13
def self.encode arg
  case arg
  when 0x00..0xff
    [arg].pack("C")
  else
    raise ArgumentError, "must be in #{0x00}..#{0xff}, but got #{arg.inspect}"
  end
end