Class: HrrRbSsh::DataType::String

Inherits:
Object
  • Object
show all
Defined in:
lib/hrr_rb_ssh/data_type.rb

Class Method Summary collapse

Class Method Details

.decode(io) ⇒ Object



85
86
87
88
# File 'lib/hrr_rb_ssh/data_type.rb', line 85

def self.decode io
  length = io.read(4).unpack("N")[0]
  io.read(length).unpack("a*")[0]
end

.encode(arg) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/hrr_rb_ssh/data_type.rb', line 75

def self.encode arg
  unless arg.kind_of? ::String
    raise ArgumentError, "must be a kind of String, but got #{arg.inspect}"
  end
  if arg.length > 0xffff_ffff
    raise ArgumentError, "must be shorter than or equal to #{0xffff_ffff}, but got length #{arg.length}"
  end
  [arg.length, arg].pack("Na*")
end