module HrrRbSftp::Protocol::Common::DataTypes::Uint32

This module provides methods to convert ::Integer value and 32-bit unsigned binary string each other.

Public Class Methods

decode(io) click to toggle source

Convert 32-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/uint32.rb, line 33
def self.decode io
  io.read(4).unpack("N")[0]
end
encode(arg) click to toggle source

Convert ::Integer value into 32-bit unsigned binary string.

@param arg [::Integer] ::Integer value to be converted. @raise [::ArgumentError] When arg is not between 0x0000_0000 and 0xffff_ffff. @return [::String] Converted 32-bit unsigned binary string.

# File lib/hrr_rb_sftp/protocol/common/data_types/uint32.rb, line 18
def self.encode arg
  case arg
  when 0x0000_0000..0xffff_ffff
    [arg].pack("N")
  else
    raise ArgumentError, "must be in #{0x0000_0000}..#{0xffff_ffff}, but got #{arg.inspect}"
  end
end