class Net::SSH::Packet
never need to use this class directly.
protocol-level manipulation or are extending Net::SSH in some way, you’ll
This is used exclusively internally by Net::SSH, and unless you’re doing
p packet[:want_reply]
p packet[:request]
p packet.type #-> 98 (CHANNEL_REQUEST)
packet = Net::SSH::Packet.new(data)
data = some_channel_request_packet
be accessed via the #[] accessor.
packet types. It auto-parses those packet types, and allows them to
A specialization of Buffer that knows the format of certain common
def self.register(type, *pairs)
and the second is the type.
tuples, where the first element of each tuple is the name of the field,
The +pairs+ parameter must be either empty, or an array of two-element
will not be autoparsed.
Net::SSH::Packet. Note that any packet type that is not preregistered
Register a new packet type that should be recognized and auto-parsed by
def self.register(type, *pairs) @@types[type] = pairs end
def [](name)
Access one of the auto-parsed fields by name. Raises an error if no
def [](name) name = name.to_sym raise ArgumentError, "no such element #{name}" unless @named_elements.key?(name) @named_elements[name] end
def initialize(payload)
Packet.register; otherwise, the packet will need to be manually parsed
parse the packet if it is one that has been previously registered with
Create a new packet from the given payload. This will automatically
def initialize(payload) @named_elements = {} super @type = read_byte instantiate! end
def instantiate!
Parse the packet's contents and assign the named elements, as described
def instantiate! (@@types[type] || []).each do |name, datatype| @named_elements[name.to_sym] = if datatype == :buffer remainder_as_buffer else send("read_#{datatype}") end end end