This is the abstract base class for all packet assistant classes used by the supported SFTP protocol versions.

Methods
Attributes
[R] buffers The buffer factory in use by this packet assistant, used to build the packets.
[R] driver The protocol driver that will be used to obtain request ids.
Public Class methods
new( buffers, driver )

Create a new PacketAssistant, which will use the given buffer factory and SFTP protocol driver.

    # File lib/net/sftp/protocol/packet-assistant.rb, line 78
78:     def initialize( buffers, driver )
79:       @buffers = buffers
80:       @driver = driver
81:     end
packet( name, *args )

A helper method for defining a new packet type. The name is the name of the packet (and of the corresponding method that is created), and the arguments are symbols representing the types of each element in the packet. The supported types are:

  • :long
  • :int64
  • :short
  • :byte
  • :string
  • :attrs
  • :write

The :attrs and :write types both simply convert the argument to a string.

The method that is created always supports an id parameter in the first position, which if null will default to the next available request id. The method returns a tuple consisting of the request id, and a string consisting of the arguments formatted according to the packet’s description.

    # File lib/net/sftp/protocol/packet-assistant.rb, line 43
43:     def self.packet( name, *args )
44:       body = ""
45:       args.each do |arg|
46:         body << "b.write"
47:         case arg
48:           when :long, :int64, :short, :byte
49:             body << "_#{arg} args.shift.to_i"
50:           when :string
51:             body << "_#{arg} args.shift.to_s"
52:           when :attrs, :write
53:             body << " args.shift.to_s"
54:         end
55:         body << "\n"
56:       end
57:       class_eval "def \#{name}( id, *args )\nb = buffers.writer\nid ||= driver.next_request_id\nb.write_long id\n\#{body}\n[ id, b.to_s ]\nend\n", __FILE__, __LINE__+1
58:     end