Net::SS...:Buffer(3)

πŸ“¦
version 2.144 Β· 4 versions
, in fedora 44

πŸ‘‘ 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? The get and put methods (listed first) are probably what most users/developers of Net::SSH::Perl actually 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, bytes returns the entire buffer.
  • Given one argument $offset, it returns everything from that position to the end of the string.
  • Given $offset and $length, it returns the segment of the buffer starting at $offset and consisting of $length bytes.
  • 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 the get_* and put_* methods. Those 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. 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