-
-
25 Feb 2016 12:02:22 UTC
- Distribution: Sereal-Splitter
- Module version: 0.840
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (646 / 21 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Perl: v5.8.0
- Activity
24 month- Tools
- Download (565.03KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- XSLoader
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Sereal::Splitter - splits a Sereal blob in chunks of roughly the same size
SYNOPSIS
use Sereal::Splitter qw(SRL_ZLIB create_header_data_template); my $splitter = Sereal::Splitter->new( { input => $data, chunk_size => 1, compress => SRL_ZLIB, header_data_template => create_header_data_template( { date => time(), elements_count => '__$CNT__' } ) } ); while (defined( my $chunk = $splitter->next_chunk())) { # do stuff with $chunk; }
DESCRIPTION
This library implements an efficient way of splitting a Sereal blob into smaller chunks. Currently, it only works with ArrayRefs Sereal blobs, like this:
[ $element_1, $element_2, ..., $element_n ]
In the future, it may also work with HashRefs.
CONSTRUCTOR
new
Takes a HashRef with options:
input
Mandatory, String, the Sereal blob to split
chunk_size
Mandatory, positive Int, the approximate size of the uncompressed chunk
compress
Optional, Int, one of SRL_UNCOMPRESSED, SRL_SNAPPY or SRL_ZLIB. These constant can be exported at use time. If set, indicates how chunks must be compressed. Defaults to SRL_UNCOMPRESSED.
header_data_template
Optional, Str, the header_data to inject in each chunk. This header_data can contain special scalar values, that will be replaced by values. Special scalar values are:
- '__$CNT__'
-
This will be replaced by the number of elements that the chunks contains. It must be encoded as SHORT_BINARY_08. It'll be replaced by a VARINT.
REMARK: In theory, it should be a string of lentgh 11, because varint max size are 11 bytes. However, the Sereal decoder code, can't cope with varint bigger than 8 bytes, because of a bug, and even if the varint is forged like 0x8180808080808080808080.
To make things easier, you can use
create_header_data_template
(see below) to create it for you.METHODS
next_chunk
returns the next chunk as a String, or Undef if it was the last chunk
EXPORTED FUNCTIONS
create_header_data_template
Given a structure, will return a Sereal *body*, that can be used as value for the
header_data_template
constructor option.This function loads
Sereal::Encoder
if it's not already loaded.Module Install Instructions
To install Sereal::Splitter, copy and paste the appropriate command in to your terminal.
cpanm Sereal::Splitter
perl -MCPAN -e shell install Sereal::Splitter
For more information on module installation, please visit the detailed CPAN module installation guide.