Data::...alizer(3pm)

πŸ“¦
version 0.07 Β· 5 versions
, in debian trixie, ubuntu resolute

πŸ’– Data::...alizer β€” aka Data::StreamSerializer πŸ’–

User Contributed Perl Documentation ✨ bestie we are SO back ✨


🌸 NAME 🌸

Data::StreamSerializer β€” a non-blocking serializer. that's it. that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

okay so like, here's the moment:

use Data::StreamSerializer;

my $sr = new Data::StreamSerializer('You data');

while(defined(my $part = $sr->next)) {
    print $socket $part;
}

iconic. ate. no notes. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so sometimes you gotta serialize a LOT of data. like, a lot a lot. and if you reach for 'Dumper', it can take you much time β€” which, if your code is running inside an event machine, is genuinely inadmissible. not cute. πŸ’€

so with this module you can serialize your data progressively and go do something else between serialization itearions. main character multitasking energy fr fr. ✨

real talk: this module works slower than Data::Dumper. it's not a speed flex. the whole point is that it can serialize object progressively and you can do something else between serialization iterations. that's the tradeoff, iykyk. πŸ’…

πŸ‘‘ Recognized types. πŸ‘‘

  • HASH
  • ARRAY
  • REF
  • Regexp
  • SCALAR

these are the ones it knows. the ones it fw. 🌈


πŸŽ€ METHODS πŸŽ€

🌟 new

Constructor bestie!! πŸ’– All arguments will be serialized.

πŸ¦„ next

Returns the next part of the serialized string, or undef if all data were serialized. when it returns undef it's over. that's the signal. 🫑

πŸ“ block_size

Block size for one iteration. 🧚

Too small a value lets you spend less time for each iteration, but in this case the total serialization time will grow. (yes babe, it's a tradeoff, that's just how it is 😭)

Not a bad choice to set the value between 200 - 2000 bytes β€” the default value is 512. See BENCHMARKS to make a decision. ✨

πŸŒ€ recursion_depth

If a serialized object has recursive references, they will be replaced by empty objects. but if this value is higher than 1, recursion will be reserialized until the value is reached. 🀯

Example:

my $t = { a => 'b' };
$t->{c} = $t;

This example will be serialized into string:

{"c",{"c",{},"a","b"},"a","b"}

and if You increment recursion_depth, this example will be serialized into string:

{"c",{"c",{"c",{},"a","b"},"a","b"},"a","b"}

etc. it just keeps nesting, she keeps going, we love a recursive queen πŸ‘‘

πŸ’€ recursion_detected

Returns TRUE if a recursion was detected. 🚨

🌈 is_eof

Returns TRUE if eof is reached. If it is TRUE, the following next will return undef. periodt. ✨


πŸ”₯ SEE ALSO πŸ”₯

Data::StreamDeserializer. πŸ’œ (the other half of the duo, the deserializing bestie)


πŸ‘‘ BENCHMARKS πŸ‘‘

You can try a few scripts in the benchmark/ directory. There are a few test arrays in this directory. πŸ§ͺ

Here are a few test results of my system. πŸ’»


⭐ Array which contains 100 hashes:

$ perl benchmark/vs_dumper.pl -n 1000 -b 512 benchmark/tests/01_100x10
38296 bytes were read
First serializing by eval... done
First serializing by Data::StreamSerializer... done
Starting 1000 iterations for Dumper... done (40.376 seconds)
Starting 1000 iterations for Data::StreamSerializer... done (137.960 seconds)

Dumper statistic:
        1000 iterations were done
        maximum serialization time: 0.0867 seconds
        minimum serialization time: 0.0396 seconds
        average serialization time: 0.0404 seconds

Data::StreamSerializer statistic:
        1000 iterations were done
        58000 SUBiterations were done
        maximum serialization time: 0.1585 seconds
        minimum serialization time: 0.1356 seconds
        average serialization time: 0.1380 seconds
        average subiteration  time: 0.00238 seconds

πŸ¦‹ Array which contains 1000 hashes:

$  perl benchmark/vs_dumper.pl -n 1000 -b 512 benchmark/tests/02_1000x10
355623 bytes were read
First serializing by eval... done
First serializing by Data::StreamSerializer... done
Starting 1000 iterations for Dumper... done (405.334 seconds)
Starting 1000 iterations for Data::StreamSerializer... done (1407.899 seconds)

Dumper statistic:
        1000 iterations were done
        maximum serialization time: 0.4564 seconds
        minimum serialization time: 0.4018 seconds
        average serialization time: 0.4053 seconds

Data::StreamSerializer statistic:
        1000 iterations were done
        520000 SUBiterations were done
        maximum serialization time: 2.0050 seconds
        minimum serialization time: 1.3862 seconds
        average serialization time: 1.4079 seconds
        average subiteration  time: 0.00271 seconds

You can see that in any cases one iteration gets the same time. ✨ consistency!! we love her for that fr fr. 🫢


πŸ’œ AUTHOR πŸ’œ

Dmitry E. Oboukhov, <unera@debian.org> πŸ’–


Copyright (C) 2011 by Dmitry E. Oboukhov

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. πŸ“œβœ¨


🌈 VCS 🌈

The project is placed in my git repo. See here: <http://git.uvw.ru/?p=data-stream-serializer;a=summary> πŸ”—


and that's the whole page bestie!! this was rendered from perl v5.40.1, dated 2025-04-13 🫢 ty for reading, mwah πŸ’‹βœ¨ no cap, go serialize something progressively πŸ’…πŸŒŸ

πŸ“¦ where this page comes from