Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Perl Zlib last block

by Kroning (Initiate)
on Oct 26, 2020 at 11:36 UTC ( #11123177=perlquestion: print w/replies, xml ) Need Help??

Kroning has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I have some packet from app that looks like "ec bd ... 00 00 ff ff" which I am trying to decode.

From what I have found, it looks like "00 00 ff ff" is a Z_SYNC_FLUSH of deflate (zlib).

I tried to reproduce it on Compress::Raw::Zlib, Compress::Zlib and some others. But the ending pattern was "00 ff 00 ff". Am I missing something?

#!/usr/local/bin/perl use Compress::Zlib ; my $x = deflateInit() or die "Cannot create a deflation stream\n" ; ($output, $status) = $x->deflate('text') ; ($output, $status) = $x->flush(Z_SYNC_FLUSH) ; $output =~ s/(.)/sprintf '%04x', ord $1/seg; print "output=$output\n";
output=002a004900ad0028000100000000000000ff00ff00000000000000ff00ff

Replies are listed 'Best First'.
Re: Perl Zlib last block
by choroba (Archbishop) on Oct 26, 2020 at 11:39 UTC
    To get ffff, don't ask for 4 nibbles, but 2:
    $output =~ s/(.)/sprintf '%02x', ord $1/seg; # ^

    You can also use

    $output = unpack 'H*', $output;

    instead of the s/// with /e. It should be faster.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11123177]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-11-26 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?