Permalink
Browse files

Allow (de)serializing from file descriptors

  • Loading branch information...
1 parent babf793 commit 66335fa781dbac2da65c4c44b2d6151c262e35e4 @caio committed May 3, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/Data/FlexSerializer.pm
View
@@ -227,6 +227,35 @@ sub serialize_to_file {
return 1;
}
+sub deserialize_from_fd {
+ my $self = shift;
+ my $fd = shift;
+
+ if (not defined $fd) {
+ Carp::croak("Need file descriptor argument");
+ }
+
+ local $/;
+ my $data = <$fd>;
+ my ($rv) = $self->deserialize($data);
+
+ return $rv;
+}
+
+sub serialize_to_fd {
+ my $self = shift;
+ my $data = shift;
+ my $fd = shift;
+
+ if (not defined $fd) {
+ Carp::croak("Need file descriptor argument");
+ }
+
+ print $fd $self->serialize($data);
+
+ return 1;
+}
+
1;

0 comments on commit 66335fa

Please sign in to comment.