store_fd#
Serialise a referenced structure in native byte order and write it to an open filehandle.
Σύνοψη#
use Storable qw(store_fd fd_retrieve);
open my $fh, ">", "data.bin" or die $!;
store_fd(\%data, $fh);
close $fh;
Τι επιστρέφεται#
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.
Παραδείγματα#
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)) { ... }
Οριακές περιπτώσεις#
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.
Διαφορές από το 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.
Δείτε επίσης#
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.