API-MikroTik
view release on metacpan or search on metacpan
t/sentence.t view on Meta::CPAN
for (0x7f, 0x3fff, 0x1fffff, 0xfffffff, 0x10000000) {
$packed = API::MikroTik::Sentence::_encode_length($_);
($len, undef) = API::MikroTik::Sentence::_strip_length(\$packed);
is $len, $_, "length encoding: $_";
}
# encode word
my $encoded = API::MikroTik::Sentence::_encode_word('bla' x 3);
$encoded .= API::MikroTik::Sentence::_encode_word('bla' x 50);
is length($encoded), 162, 'right length';
is $s->_fetch_word(\$encoded), 'bla' x 3, 'right decoded word';
is length($encoded), 152, 'right length';
is $s->_fetch_word(\$encoded), 'bla' x 50, 'right decoded word';
$packed = encode_sentence('/cmd/1', {a => 1, b => 2});
$packed
.= encode_sentence('/cmd/2', {c => 'foo', d => 'bar'}, {e => 'baz'}, 11);
my $words = $s->fetch(\$packed);
is shift @$words, '/cmd/1', 'right command';
is_deeply [sort @$words], ['=a=1', '=b=2'], 'right attributes';
$words = $s->fetch(\$packed);
is shift @$words, '/cmd/2', 'right command';
is_deeply [sort @$words], ['.tag=11', '=c=foo', '=d=bar', '?e=baz'],
( run in 1.107 second using v1.01-cache-2.11-cpan-26ccb49234f )