module HrrRbSftp::Protocol::Common::DataTypes::ExtensionPairs

This module provides methods to convert list of extension-name and extension-data pair represented in ::Array and binary string each other.

Public Class Methods

decode(io) click to toggle source

Convert binary string into list of extension-name and extension-data pair represented in ::Array.

@param io [::IO] ::IO instance that has buffer to be read. @return [::Array<::Hash{::Symbol=>::String}>] Converted list of extension-name and extension-data pair represented in ::Array.

# File lib/hrr_rb_sftp/protocol/common/data_types/extension_pairs.rb, line 31
def self.decode io
  extension_pairs = Array.new
  until io.eof?
    extension_pairs.push ExtensionPair.decode(io)
  end
  extension_pairs
end
encode(arg) click to toggle source

Convert list of extension-name and extension-data pair represented in ::Array into binary string.

@param arg [::Array<::Hash{::Symbol=>::String}>] List of extension-name and extension-data pair represented in ::Array to be converted. @raise [::ArgumentError] When arg is not ::Array value. @return [::String] Converted binary string.

# File lib/hrr_rb_sftp/protocol/common/data_types/extension_pairs.rb, line 18
def self.encode arg
  unless arg.kind_of? ::Array
    raise ArgumentError, "must be a kind of Array, but got #{arg.inspect}"
  end
  arg.map{|arg| ExtensionPair.encode(arg)}.join
end