Ryu::Buffer - accumulate data
Provides a simple way to push bytes or characters into a buffer, and get them back out again.
Typically of use for delimiter-based or fixed-size protocols.
See also Future::Buffer, if you're dealing exclusively with Future instances and don't need the Ryu::Source functionality then that's likely to be a better option.
Instantiates a new, empty Ryu::Buffer.
These methods provide ways of accessing the buffer either destructively (read*) or non-destructively (peek*).
read*
peek*
Reads exactly the given number of bytes or characters.
Takes the following parameters:
$size - number of characters or bytes to return
$size
Returns a Future which will resolve to a scalar containing the requested data.
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.
$size - maximum number of characters or bytes to return
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.
$size - minimum number of characters or bytes to return
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.
qr//
The data returned will include the match.
$match - the string or regex to match against
$match
Returns a Future which will resolve to the requested bytes or characters.
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.
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*.
A4
N1n1
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.
N1
$format - a pack-style format string
$format
Returns a Future which will resolve to the requested items, of which there can be more than one depending on the format string.
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.
Returns the current buffer size.
Returns true if the buffer is currently empty (size = 0), false otherwise.
These are documented for convenience, but generally not recommended to call any of these directly.
Accessor for the internal buffer. Not recommended to use this, but if you break it you get to keep all the pieces.
Used internally to trigger callbacks once "write" has been called.
Instantiates a new Future, used to ensure we get something awaitable.
Can be overridden using $Ryu::FUTURE_FACTORY.
$Ryu::FUTURE_FACTORY
completed, describe, flow_control, is_paused, label, parent, pause, resume, unblocked
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2011-2023. Licensed under the same terms as Perl itself.
To install Ryu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ryu
CPAN shell
perl -MCPAN -e shell install Ryu
For more information on module installation, please visit the detailed CPAN module installation guide.