1POE::Filter::Block(3) User Contributed Perl DocumentationPOE::Filter::Block(3)
2
3
4

NAME

6       POE::Filter::Block - translate data between streams and blocks
7

SYNOPSIS

9         #!perl
10
11         use warnings;
12         use strict;
13         use POE::Filter::Block;
14
15         my $filter = POE::Filter::Block->new( BlockSize => 8 );
16
17         # Prints three lines: abcdefgh, ijklmnop, qrstuvwx.
18         # Bytes "y" and "z" remain in the buffer and await completion of the
19         # next 8-byte block.
20
21         $filter->get_one_start([ "abcdefghijklmnopqrstuvwxyz" ]);
22         while (1) {
23           my $block = $filter->get_one();
24           last unless @$block;
25           print $block->[0], "\n";
26         }
27
28         # Print one line: yz123456
29
30         $filter->get_one_start([ "123456" ]);
31         while (1) {
32           my $block = $filter->get_one();
33           last unless @$block;
34           print $block->[0], "\n";
35         }
36

DESCRIPTION

38       POE::Filter::Block translates data between serial streams and blocks.
39       It can handle fixed-length and length-prepended blocks, and it may be
40       extended to handle other block types.
41
42       Fixed-length blocks are used when Block's constructor is called with a
43       BlockSize value.  Otherwise the Block filter uses length-prepended
44       blocks.
45
46       Users who specify block sizes less than one deserve what they get.
47
48       In variable-length mode, a LengthCodec parameter may be specified.  The
49       LengthCodec value should be a reference to a list of two functions: the
50       length encoder, and the length decoder:
51
52         LengthCodec => [ \&encoder, \&decoder ]
53
54       The encoder takes a reference to a buffer and prepends the buffer's
55       length to it.  The default encoder prepends the ASCII representation of
56       the buffer's length and a chr(0) byte to separate the length from the
57       actual data:
58
59         sub _default_encoder {
60           my $stuff = shift;
61           substr($$stuff, 0, 0) = length($$stuff) . "\0";
62           return;
63         }
64
65       The corresponding decoder returns the block length after removing it
66       and the separator from the buffer.  It returns nothing if no length can
67       be determined.
68
69         sub _default_decoder {
70           my $stuff = shift;
71           unless ($$stuff =~ s/^(\d+)\0//s) {
72             warn length($1), " strange bytes removed from stream"
73               if $$stuff =~ s/^(\D+)//s;
74             return;
75           }
76           return $1;
77         }
78
79       This filter holds onto incomplete blocks until they are completed in a
80       framing buffer.  To control memory usage, a maximum framing buffer size
81       is imposed.  This maximum size defaults to 512 MB (512*1024*1024
82       octets).  You may change this size limit with the "MaxBuffer"
83       parameter.
84
85           MaxBuffer => 1099511627776  # One terabyte!
86
87       The size of each individual block is also limited.  By default, each
88       block may be no more then 64 MB.  You may change this size limit with
89       the "MaxLength" parameter.
90
91           MaxLength => 10             # small blocks
92
93       Remember that MaxBuffer needs to be larger then MaxLength.  What's
94       more, it needs to have room for the length prefix.
95
96       If either the "MaxLength" or "MaxBuffer" constraint is exceeded,
97       "POE::Filter::Bock" will throw an exception.
98

PUBLIC FILTER METHODS

100       POE::Filter::Block has no additional public methods.
101

SEE ALSO

103       Please see POE::Filter for documentation regarding the base interface.
104
105       The SEE ALSO section in POE contains a table of contents covering the
106       entire POE distribution.
107

BUGS

109       The put() method doesn't verify block sizes.
110

AUTHORS & COPYRIGHTS

112       The Block filter was contributed by Dieter Pearcey, with changes by
113       Rocco Caputo.
114
115       Please see POE for more information about authors and contributors.
116
117
118
119perl v5.30.0                      2019-07-26             POE::Filter::Block(3)
Impressum