++ed by:

7 PAUSE users
6 non-PAUSE users.

Benjamin Trott


Net::SSH::Perl::Buffer - Low-level read/write buffer class


    use Net::SSH::Perl::Buffer;
    my $buffer = Net::SSH::Perl::Buffer->new;

    ## Add a 32-bit integer.

    ## Get it back.
    my $int = $buffer->get_32bit;


Net::SSH::Perl::Buffer implements the low-level binary buffer needed by the Net::SSH::Perl suite. Specifically, a Net::SSH::Perl::Buffer object is what makes up the data segment of a packet transferred between server and client (a Net::SSH::Perl::Packet object).

Buffers contain integers, strings, characters, etc. Because of the use of GMP integers in SSH, buffers can also contain multiple-precision integers (represented internally by Math::GMP objects).

Note: the method documentation here is in what some might call a slightly backwards order. The reason for this is that the get and put methods (listed first) are probably what most users/developers of Net::SSH::Perl need to care about; they're high-level methods used to get/put data from the buffer. The other methods (LOW-LEVEL METHODS) are much more low-level, and typically you won't need to use them explicitly.


All of the get_* and put_* methods respect the internal offset state in the buffer object. This means that, for example, if you call get_16bit twice in a row, you can be ensured that you'll get the next two 16-bit integers in the buffer. You don't need to worry about the number of bytes a certain piece of data takes up, for example.


Returns the next 16-bit integer from the buffer.


Appends a 16-bit integer to the buffer.


Returns the next 32-bit integer from the buffer.


Appends a 32-bit integer to the buffer.


More appropriately called get_byte, perhaps, this returns the next byte from the buffer.


Appends a byte (or a sequence of bytes) to the buffer. There is no restriction on the length of the byte string $bytes; if it makes you uncomfortable to call put_char to put multiple bytes, you can instead call this method as put_chars. It's the same thing.


Returns the next "string" from the buffer. A string here is represented as the length of the string (a 32-bit integer) followed by the string itself.


Appends a string (32-bit integer length and the string itself) to the buffer.


Returns a Math::GMP object representing a multiple precision integer read from the buffer. In the buffer itself, an mp_int is represented by a 16-bit integer (the number of bits in the integer), and the integer itself.


Appends a multiple precision integer (16-bit integer bit count and the integer itself) to the buffer.



Creates a new buffer object and returns it. The buffer is empty.

This method takes no arguments.


Appends raw data $bytes to the end of the in-memory buffer. Generally you don't need to use this method unless you're initializing an empty buffer, because when you need to add data to a buffer you should generally use one of the put_* methods.


Empties out the buffer object.

$buffer->bytes([ $offset [, $length [, $replacement ]]])

Behaves exactly like the substr built-in function, except on the buffer $buffer. Given no arguments, bytes returns the entire buffer; given one argument $offset, returns everything from that position to the end of the string; given $offset and $length, returns the segment of the buffer starting at $offset and consisting of $length bytes; and given all three arguments, replaces that segment with $replacement.

This is a very low-level method, and you generally won't need to use it.

Also be warned that you should not intermix use of this method with use of the get_* and put_* methods; the latter classes of methods maintain internal state of the buffer offset where arguments will be gotten from and put, respectively. The bytes method gives no thought to this internal offset state.


Returns the length of the buffer object.


Returns the internal offset state.

If you insist on intermixing calls to bytes with calls to the get_* and put_* methods, you'll probably want to use this method to get some status on that internal offset.


Returns a hex dump of the buffer.


A helper method: pads out the buffer so that the length of the transferred packet will be evenly divisible by 8, which is a requirement of the SSH protocol.


Benjamin Trott, ben@rhumba.pair.com


(C) 2001 Benjamin Trott. All rights reserved.