Folks-

Wow, no responses. Either this is a hard question, or nobody cares about doing something goofy like this :-)

After playing around with things, I've decided to go with POE::Filter::Block because it provides a way to override the default encode and decode routines with ones of your own. The following code illustrates how using POE::Filter::Block in standalone mode, works fine for extracting variable length binary messages beginning with 0xfefefefe (however using it as a filter on POE::Wheel::FollowTail still doesn't work - more on this later).

Update: Fixed buffering bug (removed '|$' in regular expression)

use strict; use warnings; my $data='ThisIsBeginningGarbagefefefefe037e01000001000a666c7832313100 +00000000000000003c0200000049b7e983000001030000015a000000000000000a003 +25b15000114b0fefefefe037e01000001000a666c78323131000000000000000036bc +0200000149b7e983000001030000015b44988c1a0000000a00000028000114b002000 +00249b7e983000001030000015a00000000000000070032343200018c640200000349 +b7e983000001030000015b4475066c000000080000000400018c640200000449b7e98 +3000001030000015a0000000000000003003233da0001877d0200000549b7e9830000 +01030000015b44c0f03f00000006000000020001877d0200fe49b7e98300000210000 +0015c00000000014a00010000000000011475020000ff49b7e983000002200000015a +000000000000000a0032a969000114d60200010049b7e983000002200000015b4427f +d090000000300000005000114d60200010149b7e983000002200000015a0000000000 +0000110032a9010001132a0200010249b7e983000002200000015b4190ca460000000 +00000005c0001132a0200010349b7e983000002200000015a00000000000000110032 +f6ec000112410200010449b7e983000002200000015b411dadd4000000000000005c0 +00112410200010549b7e983000002200000015a00000000000000110032a90200fefe +fefe037e01000001000a666c78323131000000000000000036bc0200000149b7e9830 +00001030000015b44988c1a0000000a00000028000114b00200000249b7e983000001 +030000015a00000000000000070032343200018c640200000349b7e98300000103000 +0015b4475066c000000080000000400018c640200000449b7e983000001030000015a +0000000000000003003233da0001877d0200000549b7e983000001030000015b44c0f +03f00000006000000020001877d0200000649b7e983000001030000015a0000000000 +0000070032340a00018b400200000749b7e983000001030000015b44407da20000000 +8000000040001'; $data = pack('H*', $data); use POE::Filter::Block; sub _myencode { print STDERR "_myencode\n" }; sub _mydecode { my $stuff = shift; print STDERR "M1: ", unpack('H72', $$stuff), "...\n"; # Extract everything through 1st 0xfe{4} flag, up to the 2nd... $$stuff =~ /^(.*?\xfe{4}.*?)(\xfe{4})/s || return; # Return its measured length (in characters)... my $length = length($1); return($length); } my $filter = POE::Filter::Block->new( LengthCodec => [ \&_myencode, \&_mydecode ] ); $filter->get_one_start([ $data ]); while (1) { my $block = $filter->get_one(); last unless @$block; print STDERR "M2: ", unpack('H72', $block->[0]), "...\n", length($block->[0]), " characters\n"; }
My output looks like this (the first message includes the 'ThisIsBeginningGarbage' stuff by design) (truncated for eye appeal):
M1: d12c2cbe02772700abba0efefefefe037e01000001000a666c7832313100000000 M2: d12c2cbe02772700abba0efefefefe037e01000001000a666c7832313100000000 71 characters M1: fefefefe037e01000001000a666c78323131000000000000000036bc0200000149 M2: fefefefe037e01000001000a666c78323131000000000000000036bc0200000149 440 characters M1: fefefefe037e01000001000a666c78323131000000000000000036bc0200000149 M2: fefefefe037e01000001000a666c78323131000000000000000036bc0200000149 250 characters M1: ...

In reply to POE::Wheel::FollowTail to read binary records - solved? by cmv
in thread POE::Wheel::FollowTail to read binary records!?! by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.