{
    "mode": "perldoc",
    "parameter": "POE::Filter::Block",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AFilter%3A%3ABlock/json",
    "generated": "2026-06-12T12:45:56Z",
    "synopsis": "#!perl\nuse warnings;\nuse strict;\nuse POE::Filter::Block;\nmy $filter = POE::Filter::Block->new( BlockSize => 8 );\n# Prints three lines: abcdefgh, ijklmnop, qrstuvwx.\n# Bytes \"y\" and \"z\" remain in the buffer and await completion of the\n# next 8-byte block.\n$filter->getonestart([ \"abcdefghijklmnopqrstuvwxyz\" ]);\nwhile (1) {\nmy $block = $filter->getone();\nlast unless @$block;\nprint $block->[0], \"\\n\";\n}\n# Print one line: yz123456\n$filter->getonestart([ \"123456\" ]);\nwhile (1) {\nmy $block = $filter->getone();\nlast unless @$block;\nprint $block->[0], \"\\n\";\n}",
    "sections": {
        "NAME": {
            "content": "POE::Filter::Block - translate data between streams and blocks\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#!perl\n\nuse warnings;\nuse strict;\nuse POE::Filter::Block;\n\nmy $filter = POE::Filter::Block->new( BlockSize => 8 );\n\n# Prints three lines: abcdefgh, ijklmnop, qrstuvwx.\n# Bytes \"y\" and \"z\" remain in the buffer and await completion of the\n# next 8-byte block.\n\n$filter->getonestart([ \"abcdefghijklmnopqrstuvwxyz\" ]);\nwhile (1) {\nmy $block = $filter->getone();\nlast unless @$block;\nprint $block->[0], \"\\n\";\n}\n\n# Print one line: yz123456\n\n$filter->getonestart([ \"123456\" ]);\nwhile (1) {\nmy $block = $filter->getone();\nlast unless @$block;\nprint $block->[0], \"\\n\";\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "POE::Filter::Block translates data between serial streams and blocks. It can handle fixed-length\nand length-prepended blocks, and it may be extended to handle other block types.\n\nFixed-length blocks are used when Block's constructor is called with a BlockSize value.\nOtherwise the Block filter uses length-prepended blocks.\n\nUsers who specify block sizes less than one deserve what they get.\n\nIn variable-length mode, a LengthCodec parameter may be specified. The LengthCodec value should\nbe a reference to a list of two functions: the length encoder, and the length decoder:\n\nLengthCodec => [ \\&encoder, \\&decoder ]\n\nThe encoder takes a reference to a buffer and prepends the buffer's length to it. The default\nencoder prepends the ASCII representation of the buffer's length and a chr(0) byte to separate\nthe length from the actual data:\n\nsub defaultencoder {\nmy $stuff = shift;\nsubstr($$stuff, 0, 0) = length($$stuff) . \"\\0\";\nreturn;\n}\n\nThe corresponding decoder returns the block length after removing it and the separator from the\nbuffer. It returns nothing if no length can be determined.\n\nsub defaultdecoder {\nmy $stuff = shift;\nunless ($$stuff =~ s/^(\\d+)\\0//s) {\nwarn length($1), \" strange bytes removed from stream\"\nif $$stuff =~ s/^(\\D+)//s;\nreturn;\n}\nreturn $1;\n}\n\nThis filter holds onto incomplete blocks until they are completed in a framing buffer. To\ncontrol memory usage, a maximum framing buffer size is imposed. This maximum size defaults to\n512 MB (512*1024*1024 octets). You may change this size limit with the \"MaxBuffer\" parameter.\n\nMaxBuffer => 1099511627776  # One terabyte!\n\nThe size of each individual block is also limited. By default, each block may be no more then 64\nMB. You may change this size limit with the \"MaxLength\" parameter.\n\nMaxLength => 10             # small blocks\n\nRemember that MaxBuffer needs to be larger then MaxLength. What's more, it needs to have room\nfor the length prefix.\n\nIf either the \"MaxLength\" or \"MaxBuffer\" constraint is exceeded, \"POE::Filter::Bock\" will throw\nan exception.\n",
            "subsections": []
        },
        "PUBLIC FILTER METHODS": {
            "content": "POE::Filter::Block has no additional public methods.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Please see POE::Filter for documentation regarding the base interface.\n\nThe SEE ALSO section in POE contains a table of contents covering the entire POE distribution.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The put() method doesn't verify block sizes.\n\nAUTHORS & COPYRIGHTS\nThe Block filter was contributed by Dieter Pearcey, with changes by Rocco Caputo.\n\nPlease see POE for more information about authors and contributors.\n",
            "subsections": []
        }
    },
    "summary": "POE::Filter::Block - translate data between streams and blocks",
    "flags": [],
    "examples": [],
    "see_also": []
}