Included Modules

Class Index [+]

Quicksearch

Net::SSH::Packet

A specialization of Buffer that knows the format of certain common packet types. It auto-parses those packet types, and allows them to be accessed via the #[] accessor.

  data = some_channel_request_packet
  packet = Net::SSH::Packet.new(data)

  p packet.type #-> 98 (CHANNEL_REQUEST)
  p packet[:request]
  p packet[:want_reply]

This is used exclusively internally by Net::SSH, and unless you’re doing protocol-level manipulation or are extending Net::SSH in some way, you’ll never need to use this class directly.

Attributes

type[R]

The (integer) type of this packet.

Public Class Methods

new(payload) click to toggle source

Create a new packet from the given payload. This will automatically parse the packet if it is one that has been previously registered with Packet.register; otherwise, the packet will need to be manually parsed using the methods provided in the Net::SSH::Buffer superclass.

    # File lib/net/ssh/packet.rb, line 73
73:     def initialize(payload)
74:       @named_elements = {}
75:       super
76:       @type = read_byte
77:       instantiate!
78:     end
register(type, *pairs) click to toggle source

Register a new packet type that should be recognized and auto-parsed by Net::SSH::Packet. Note that any packet type that is not preregistered will not be autoparsed.

The pairs parameter must be either empty, or an array of two-element tuples, where the first element of each tuple is the name of the field, and the second is the type.

  register DISCONNECT, [:reason_code, :long], [:description, :string], [:language, :string]
    # File lib/net/ssh/packet.rb, line 34
34:     def self.register(type, *pairs)
35:       @@types[type] = pairs
36:     end

Public Instance Methods

[](name) click to toggle source

Access one of the auto-parsed fields by name. Raises an error if no element by the given name exists.

    # File lib/net/ssh/packet.rb, line 82
82:     def [](name)
83:       name = name.to_sym
84:       raise ArgumentError, "no such element #{name}" unless @named_elements.key?(name)
85:       @named_elements[name]
86:     end

Private Instance Methods

instantiate!() click to toggle source

Parse the packet’s contents and assign the named elements, as described by the registered format for the packet.

     # File lib/net/ssh/packet.rb, line 92
 92:       def instantiate!
 93:         (@@types[type] || []).each do |name, datatype|
 94:           @named_elements[name.to_sym] = if datatype == :buffer
 95:             remainder_as_buffer
 96:           else
 97:             send("read_#{datatype}")
 98:           end
 99:         end
100:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.