module HrrRbSftp::Protocol::Common::DataTypes::Byte
This module 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_sftp/protocol/common/data_types/byte.rb, line 33 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 arg [::Integer] ::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_sftp/protocol/common/data_types/byte.rb, line 18 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