store_fd#
Serialise a referenced structure in native byte order and write it to an open filehandle.
Synopsis#
use Storable qw(store_fd fd_retrieve);
open my $fh, ">", "data.bin" or die $!;
store_fd(\%data, $fh);
close $fh;
What you get back#
Returns 1 on success. Writes a 4-byte length prefix followed
by the serialised payload, so multiple frozen structures can be
concatenated on the same stream and separated by matching
fd_retrieve calls.
Examples#
Stream multiple records through one filehandle:
open my $fh, ">", "log.bin" or die $!;
store_fd($_, $fh) for @events;
close $fh;
## reader side:
open my $r, "<", "log.bin" or die $!;
while (my $ev = fd_retrieve($r)) { ... }
Edge cases#
First argument must be a reference; croaks with
Not a referenceotherwise.$fhmust be an open filehandle with a real underlying file descriptor. A closed or non-file handle writes nothing.Bytes are native-order; use
nstore_fdfor portability.
Differences from upstream#
Upstream writes a header then raw payload; pperl prefixes each payload with a 4-byte little-endian length, enabling concatenation on the same stream. Readers on the pperl side (
fd_retrieve) understand this framing; upstream readers do not. Pinned byt/81-xs-native/Storable/080-fd.t.
See also#
fd_retrieve— matching reader.nstore_fd— portable (network-order) variant.store— write to a path instead of an open handle.freeze— return bytes to the caller instead of writing.