Net::SS...:Buffer(3)
π NAME π
Net::SSH::Perl::Buffer β the low-level read/write buffer class π
okay so real talk, this is the Net::SS...:Buffer(3) page, straight outta the User Contributed Perl Documentation, and bestie, it's giving extremely foundational. Let's go π¦
β¨ SYNOPSIS β¨
use Net::SSH::Perl::Buffer (@args);
my $buffer = Net::SSH::Perl::Buffer->new;
## Add a 32-bit integer.
$buffer->put_int32(10932930);
## Get it back.
my $int = $buffer->get_int32;
like... you put a number in, you get a number out. it's literally that simple and honestly? iconic π
π«Ά DESCRIPTION π«Ά
So Net::SSH::Perl::Buffer implements the low-level binary buffer that the whole Net::SSH::Perl suite needs. And specifically β not to be dramatic β a Net::SSH::Perl::Buffer object is literally what makes up the data segment of a packet transferred between server and client (that's a Net::SSH::Perl::Packet object, iykyk).
Buffers contain integers, strings, characters, etc. And because SSH uses GMP integers, buffers can also hold multiple-precision integers (which are represented internally by Math::GMP objects). obsessed π
Note: the method docs here are in what some might call a slightly backwards order. The reason? Thegetandputmethods (listed first) are probably what most users/developers ofNet::SSH::Perlactually need to care about β they're the high-level ones you use to get/put data from the buffer. The other methods (the LOW-LEVEL METHODS) are so much more low-level, and typically you won't need to use them explicitly. no cap π§
πΈ GET AND PUT METHODS πΈ
Okay so the vibe here: all of the get_* and put_* methods respect the internal offset state in the buffer object. Which means β say it with me β if you call get_int16 twice in a row, you're ensured to get the next two 16-bit integers in the buffer. You do not need to worry about how many bytes a certain piece of data takes up. periodt π
$buffer->get_int8
Returns the next 8-bit integer from the buffer. And like, it's really just the ASCII code for the next character/byte in the buffer. that's the whole thing π
$buffer->put_int8
Appends an 8-bit integer to the buffer β which is really just the character corresponding to that integer, in ASCII. cute, right? π
$buffer->get_int16
Returns the next 16-bit integer from the buffer. slay β
$buffer->put_int16($integer)
Appends a 16-bit integer to the buffer. π«
$buffer->get_int32
Returns the next 32-bit integer from the buffer. π₯
$buffer->put_int32($integer)
Appends a 32-bit integer to the buffer. π
$buffer->get_char
More appropriately called get_byte, perhaps β and honestly bestie, that name would eat β but anyway: this returns the next byte from the buffer. πΈ
$buffer->put_char($bytes)
Appends a byte (or a whole sequence of bytes) to the buffer. And 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. literally the same. π
$buffer->get_str
Returns the next "string" from the buffer. And a "string" here is represented as the length of the string (a 32-bit integer) followed by the string itself. so it's a little length-prefix moment β¨
$buffer->put_str($string)
Appends a string (32-bit integer length and the string itself) to the buffer. π¦
$buffer->get_mp_int
Returns a bigint object representing a multiple precision integer read from the buffer. Depending on the protocol, that object is either of type Math::GMP (SSH1) or a binary string (SSH2) π
You determine which protocol will be in use when you use the module β specify SSH1 or SSH2 to load the proper get and put routines for bigints:
use Net::SSH::Perl::Buffer qw( SSH1 );
$buffer->put_mp_int($mp_int)
Appends a multiple precision integer to the buffer. Depending on the protocol in use, $mp_int should be either a Math::GMP object (SSH1) or a binary string (SSH2) π. And heads up β the format in which the integer is stored in the buffer differs between the protocols, as well. π
π§ LOW-LEVEL METHODS π§
Net::SSH::Perl::Buffer->new
Creates a new buffer object and returns it. The buffer is empty. (a blank slate, a clean girl, we love her π)
This method takes no arguments.
$buffer->append($bytes)
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. iykyk π
$buffer->empty
Empties out the buffer object. gone. deleted. no thoughts, empty buffer π
$buffer->bytes([ $offset [, $length [, $replacement ]]])
Behaves exactly like the substr built-in function β except on the buffer $buffer. So here's the tea:
- Given no arguments,
bytesreturns the entire buffer. - Given one argument
$offset, it returns everything from that position to the end of the string. - Given
$offsetand$length, it returns the segment of the buffer starting at$offsetand consisting of$lengthbytes. - Given all three arguments, it replaces that segment with
$replacement.
This is a very low-level method, and you generally won't need to use it. β¨
Also be warned π β you should not intermix use of this method with use of theget_*andput_*methods. Those latter classes of methods maintain internal state of the buffer offset where arguments will be gotten from and put, respectively. Thebytesmethod gives no thought to this internal offset state. it does not care. it will not check. be careful bestie π¨
$buffer->length
Returns the length of the buffer object. π
$buffer->offset
Returns the internal offset state. π
And 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. like, for your own peace of mind π«Ά
$buffer->dump
Returns a hex dump of the buffer. gorgeous. a little hex moment π₯
$buffer->insert_padding
A helper method π: it 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. the protocol said "divisible by 8 or else" and we said "yes ma'am" π
π AUTHOR & COPYRIGHTS π
Please see the Net::SSH::Perl manpage for author, copyright, and license information. π
and that's the whole page, bestie!! this was perl v5.42.0, dated 2026-01-17, and it ate, no crumbs. go forth and buffer responsibly π¦β¨π
π¦ where this page comes from
- fedora 44: perl-Net-SSH-Perl 2.144-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms