Class: HrrRbSsh::DataType::Uint32
- Inherits:
-
HrrRbSsh::DataType
- Object
- HrrRbSsh::DataType
- HrrRbSsh::DataType::Uint32
- Defined in:
- lib/hrr_rb_ssh/data_type/uint32.rb
Overview
Uint32 provides methods to convert integer value and 32-bit unsigned binary string each other.
Class Method Summary collapse
-
.decode(io) ⇒ ::Integer
Convert 32-bit unsigned binary into Integer value.
-
.encode(arg) ⇒ ::String
Convert integer value into 32-bit unsigned binary string.
Class Method Details
.decode(io) ⇒ ::Integer
Convert 32-bit unsigned binary into Integer value.
26 27 28 |
# File 'lib/hrr_rb_ssh/data_type/uint32.rb', line 26 def self.decode io io.read(4).unpack("N")[0] end |
.encode(arg) ⇒ ::String
Convert integer value into 32-bit unsigned binary string.
13 14 15 16 17 18 19 20 |
# File 'lib/hrr_rb_ssh/data_type/uint32.rb', line 13 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 |