lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r886910 - in /lucene/lucy/trunk: core/Lucy/Object/CharBuf.bp core/Lucy/Object/CharBuf.c perl/lib/Lucy.pm perl/lib/Lucy/Object/CharBuf.pm perl/t/binding/029-charbuf.t
Date Thu, 03 Dec 2009 20:29:15 GMT
Author: marvin
Date: Thu Dec  3 20:29:15 2009
New Revision: 886910

URL: http://svn.apache.org/viewvc?rev=886910&view=rev
Log:
Commit charbuf_serialization.diff from LUCY-81, adding serialization routines
to CharBuf.

Modified:
    lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
    lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
    lucene/lucy/trunk/perl/lib/Lucy.pm
    lucene/lucy/trunk/perl/lib/Lucy/Object/CharBuf.pm
    lucene/lucy/trunk/perl/t/binding/029-charbuf.t

Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp?rev=886910&r1=886909&r2=886910&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp Thu Dec  3 20:29:15 2009
@@ -214,6 +214,12 @@
     public incremented CharBuf*
     Load(CharBuf *self, Obj *dump);
 
+    public void
+    Serialize(CharBuf *self, OutStream *outstream);
+
+    public incremented CharBuf*
+    Deserialize(CharBuf *self, InStream *instream);
+
     /** Remove Unicode whitespace characters from both top and tail.
      */
     u32_t

Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.c?rev=886910&r1=886909&r2=886910&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.c Thu Dec  3 20:29:15 2009
@@ -13,6 +13,8 @@
 #include "Lucy/Object/CharBuf.h"
 
 #include "Lucy/Object/Err.h"
+#include "Lucy/Store/InStream.h"
+#include "Lucy/Store/OutStream.h"
 #include "Lucy/Util/Memory.h"
 #include "Lucy/Util/StringHelper.h"
 
@@ -456,6 +458,28 @@
 }
 
 void
+CB_serialize(CharBuf *self, OutStream *target)
+{
+    OutStream_Write_C32(target, self->size);
+    OutStream_Write_Bytes(target, self->ptr, self->size);
+}
+
+CharBuf*
+CB_deserialize(CharBuf *self, InStream *instream)
+{
+    self = self ? self : (CharBuf*)VTable_Make_Obj(CHARBUF);
+    self->size = InStream_Read_C32(instream);
+    self->cap  = self->size + 1;
+    self->ptr  = (char*)MALLOCATE(self->cap);
+    InStream_Read_Bytes(instream, self->ptr, self->size);
+    self->ptr[self->size] = '\0';
+    if (!StrHelp_utf8_valid(self->ptr, self->size)) {
+        S_die_invalid_utf8(self->ptr, self->size);
+    }
+    return self;
+}
+
+void
 CB_mimic_str(CharBuf *self, const char* ptr, size_t size) 
 {
     if (!StrHelp_utf8_valid(ptr, size))

Modified: lucene/lucy/trunk/perl/lib/Lucy.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy.pm?rev=886910&r1=886909&r2=886910&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy.pm Thu Dec  3 20:29:15 2009
@@ -46,6 +46,7 @@
         # actual CharBuf objects.)
         no warnings 'redefine';
         sub clone       { shift->_clone(@_) }
+        sub deserialize { shift->_deserialize(@_) }
     }
 
     package Lucy::Object::ViewCharBuf;

Modified: lucene/lucy/trunk/perl/lib/Lucy/Object/CharBuf.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Object/CharBuf.pm?rev=886910&r1=886909&r2=886910&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Object/CharBuf.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy/Object/CharBuf.pm Thu Dec  3 20:29:15 2009
@@ -32,6 +32,15 @@
 OUTPUT: RETVAL
 
 SV*
+_deserialize(either_sv, instream)
+    SV *either_sv;
+    lucy_InStream *instream;
+CODE:
+    CHY_UNUSED_VAR(either_sv);
+    RETVAL = LUCY_OBJ_TO_SV_NOINC(lucy_CB_deserialize(NULL, instream));
+OUTPUT: RETVAL
+
+SV*
 to_perl(self)
     lucy_CharBuf *self;
 CODE:

Modified: lucene/lucy/trunk/perl/t/binding/029-charbuf.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/binding/029-charbuf.t?rev=886910&r1=886909&r2=886910&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/t/binding/029-charbuf.t (original)
+++ lucene/lucy/trunk/perl/t/binding/029-charbuf.t Thu Dec  3 20:29:15 2009
@@ -3,7 +3,8 @@
 use lib 'buildlib';
 
 use Lucy::Test;
-use Test::More tests => 3;
+use Test::More tests => 6;
+use Storable qw( freeze thaw );
 
 my $smiley = "\x{263a}";
 
@@ -11,7 +12,24 @@
 isa_ok( $charbuf, "Lucy::Object::CharBuf" );
 is( $charbuf->to_perl, $smiley, "round trip UTF-8" );
 
+$charbuf = Lucy::Object::CharBuf->new($smiley);
+my $dupe = thaw( freeze($charbuf) );
+isa_ok( $dupe, "Lucy::Object::CharBuf",
+    "thaw/freeze produces correct object" );
+is( $dupe->to_perl, $charbuf->to_perl, "freeze/thaw" );
+
 my $clone = $charbuf->clone;
 is( $clone->to_perl, Lucy::Object::CharBuf->new($smiley)->to_perl,
     "clone" );
 
+my $ram_file = Lucy::Store::RAMFile->new;
+my $outstream = Lucy::Store::OutStream->open( file => $ram_file )
+    or die Lucy->error;
+$charbuf->serialize($outstream);
+$outstream->close;
+my $instream = Lucy::Store::InStream->open( file => $ram_file )
+    or die Lucy->error;
+my $deserialized = Lucy::Object::CharBuf->deserialize($instream);
+is_deeply( $charbuf->to_perl, $deserialized->to_perl,
+    "serialize/deserialize" );
+



Mime
View raw message