Ryu::Buffer(3)
β¨ NAME β¨
okay bestie, welcome to Ryu::Buffer(3) from the User Contributed Perl Documentation π β this one is all about accumulating data. Like, Ryu::Buffer is literally here to collect your bytes or characters so you can get them back out later. Slay.
πΈ DESCRIPTION πΈ
It gives you a simple way to push bytes or characters into a buffer and then pull them back out again. No cap, that's the whole vibe.
This is typically useful for delimiter-based protocols or fixed-size protocols.
Also see Future::Buffer β if you're dealing exclusively with Future instances and don't need the Ryu::Source functionality, then that's likely to be the better option for you. iykyk π¦
π§΅ METHODS π§΅
π± new π±
Instantiates a new, empty Ryu::Buffer. Fresh buffer, main character energy, zero data. β¨
π METHODS - Reading data π
These methods are your access paths for the buffer: either destructive (read*) or non-destructive (peek*). π
πΈ read_exactly πΈ
Reads exactly the given number of bytes or characters. Like, exactly exactly. π―
Takes the following parameters:
$sizeβ number of characters or bytes to return
Returns a Future which will resolve to a scalar containing the requested data.
π¦ read_atmost π¦
Reads up to the given number of bytes or characters β if we have at least one byte or character in the buffer, we'll return that even if it's shorter than the requested $size. This method is guaranteed not to return more than the $size. Periodt. π
Takes the following parameters:
$sizeβ maximum number of characters or bytes to return
Returns a Future which will resolve to a scalar containing the requested data.
π read_atleast π
Reads at least the given number of bytes or characters β if we have a buffer that's the given size or larger, we'll return everything available, even if it's larger than the requested $size. Big buffer energy. π
Takes the following parameters:
$sizeβ minimum number of characters or bytes to return
Returns a Future which will resolve to a scalar containing the requested data.
π read_until π
Reads up to the given string or regex match.
Pass a qr// instance if you want to use a regular expression to match, or a plain string if you want exact-string matching behaviour. Choose your fighter. βοΈ
The data returned will include the match.
Takes the following parameters:
$matchβ the string or regex to match against
Returns a Future which will resolve to the requested bytes or characters.
π₯ read_packed π₯
Uses pack template notation to define a pattern to extract. Will attempt to accumulate enough bytes to fulfill the request, then unpack and extract from the buffer. It's giving very structured data behavior. π§
This method only supports a very limited subset of the full pack functionality β currently, this includes sequences such as A4 or N1n1, but does not handle multi-stage templates such as N/a*.
These would need to parse the initial N1 bytes to determine the full extent of the data to be processed, and the logic for handling this is not yet implemented. Not me being patient with the roadmap π
Takes the following parameters:
$formatβ apack-style format string
Returns a Future which will resolve to the requested items, of which there can be more than one depending on the format string.
π write π
Add more data to the buffer.
Call this with a single scalar, and the results will be appended to the internal buffer, triggering any callbacks for read activity as required. Feed the buffer, bestie. π«Ά
β size β
Returns the current buffer size.
π is_empty π
Returns true if the buffer is currently empty (size = 0), false otherwise.
π οΈ METHODS - Internal π οΈ
These are documented for convenience, but generally not recommended to call any of these directly. You've been warned, bestie. π
π data π
Accessor for the internal buffer. Not recommended to use this, but if you break it you get to keep all the pieces. That's the deal. π
π§ process_pending π§
Used internally to trigger callbacks once write has been called.
π new_future π
Instantiates a new Future, used to ensure we get something awaitable.
Can be overridden using $Ryu::FUTURE_FACTORY.
π AUTHOR π
Tom Molesworth <TEAM@cpan.org>
π LICENSE π
Copyright Tom Molesworth 2011-2024. Licensed under the same terms as Perl itself.
This cutie of a page is from perl v5.42.2, dated 2026-02-15, and you're reading Ryu::Buffer(3) πβ¨
π¦ where this page comes from
- alpine 3.24: perl-ryu-doc 4.001-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms