API-MikroTik
view release on metacpan or search on metacpan
lib/API/MikroTik/Sentence.pm view on Meta::CPAN
$len += unpack 'C', substr $$buff, 0, 1, '';
}
elsif (($len & 0xe0) == 0xc0) {
$len &= ~0xc0;
$len <<= 16;
$len += unpack 'n', substr $$buff, 0, 2, '';
}
elsif (($len & 0xf0) == 0xe0) {
$len = unpack 'N', pack('C', ($len & ~0xe0)) . substr($$buff, 0, 3, '');
}
elsif (($len & 0xf8) == 0xf0) {
$len = unpack 'N', substr $$buff, 0, 4, '';
}
return $len;
}
1;
=encoding utf8
=head1 NAME
API::MikroTik::Sentence - Encode and decode API sentences
=head1 SYNOPSIS
use API::MikroTik::Sentence qw(encode_sentence);
my $command = '/interface/print';
my $attr = {'.proplist' => '.id,name,type'};
my $query = {type => ['ipip-tunnel', 'gre-tunnel'], running => 'true'};
my $tag = 1;
my $bytes = encode_sentence($command, $attr, $query, $tag);
my $sentence = API::MikroTik::Sentence->new();
my $words = $sentence->fetch(\$bytes);
say $_ for @$words;
=head1 DESCRIPTION
Provides subroutines for encoding API sentences and parsing them back into words.
=head1 METHODS
=head2 encode_sentence
my $bytes = encode_sentence($command, $attr, $query, $tag);
Encodes sentence. Attributes is a hashref with attribute-value pairs. Query will
be parsed with L<API::MikroTik::Query/build_query>.
Can be also called as an object method.
=head2 fetch
my $words = $sentence->fetch(\$buff);
Fetches a sentence from a buffer and parses it into a list of API words. In a
situation when amount of data in the buffer are insufficient to complete the
sentence, already processed words and the remaining buffer will be stored in an
object. On a next call will prepend a buffer with kept data and merge a result
with the one stored from a previous call.
=head2 is_incomplete
my $done = !$sentence->is_incomplete;
Indicates that a processed buffer was incomplete and remaining amount of data was
insufficient to complete a sentence.
=head2 reset
my $sentence->reset;
Clears an incomplete status and removes a remaining buffer.
=head1 SEE ALSO
L<API::MikroTik>
=cut
( run in 2.278 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )