lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r887025 - in /lucene/lucy/trunk/core/Lucy: Object/Num.bp Object/Num.c Test/Object/TestNum.c
Date Fri, 04 Dec 2009 01:09:20 GMT
Author: marvin
Date: Fri Dec  4 01:09:20 2009
New Revision: 887025

URL: http://svn.apache.org/viewvc?rev=887025&view=rev
Log:
Commit num_serialization.diff from LUCY-81, adding serialization routines to
Integer32, Integer64, Float32 and Float64.

Modified:
    lucene/lucy/trunk/core/Lucy/Object/Num.bp
    lucene/lucy/trunk/core/Lucy/Object/Num.c
    lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.bp?rev=887025&r1=887024&r2=887025&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.bp Fri Dec  4 01:09:20 2009
@@ -68,6 +68,12 @@
     public i32_t
     Hash_Code(Float32 *self);
 
+    public void
+    Serialize(Float32 *self, OutStream *outstream);
+
+    public incremented Float32*
+    Deserialize(Float32 *self, InStream *instream);
+
     public incremented Float32*
     Clone(Float32 *self);
 }
@@ -102,6 +108,12 @@
     public i32_t
     Hash_Code(Float64 *self);
 
+    public void
+    Serialize(Float64 *self, OutStream *outstream);
+
+    public incremented Float64*
+    Deserialize(Float64 *self, InStream *instream);
+
     public incremented Float64*
     Clone(Float64 *self);
 }
@@ -137,6 +149,12 @@
     public i32_t
     Hash_Code(Integer32 *self);
 
+    public void
+    Serialize(Integer32 *self, OutStream *outstream);
+
+    public incremented Integer32*
+    Deserialize(Integer32 *self, InStream *instream);
+
     public incremented Integer32*
     Clone(Integer32 *self);
 }
@@ -176,6 +194,12 @@
     public bool_t
     Equals(Integer64 *self, Obj *other);
 
+    public void
+    Serialize(Integer64 *self, OutStream *outstream);
+
+    public incremented Integer64*
+    Deserialize(Integer64 *self, InStream *instream);
+
     public incremented Integer64*
     Clone(Integer64 *self);
 }

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.c?rev=887025&r1=887024&r2=887025&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.c Fri Dec  4 01:09:20 2009
@@ -12,6 +12,8 @@
 #include "Lucy/Object/CharBuf.h"
 #include "Lucy/Object/Err.h"
 #include "Lucy/Object/VTable.h"
+#include "Lucy/Store/InStream.h"
+#include "Lucy/Store/OutStream.h"
 
 Num*
 Num_init(Num *self)
@@ -125,6 +127,19 @@
     return Float32_new(self->value);
 }
 
+void
+Float32_serialize(Float32 *self, OutStream *outstream)
+{
+    OutStream_Write_F32(outstream, self->value);
+}
+
+Float32*
+Float32_deserialize(Float32 *self, InStream *instream)
+{
+    float value = InStream_Read_F32(instream);
+    return self ? Float32_init(self, value) : Float32_new(value);
+}
+
 /***************************************************************************/
 
 Float64*
@@ -171,6 +186,19 @@
     return ints[0] ^ ints[1];
 }
 
+void
+Float64_serialize(Float64 *self, OutStream *outstream)
+{
+    OutStream_Write_F64(outstream, self->value);
+}
+
+Float64*
+Float64_deserialize(Float64 *self, InStream *instream)
+{
+    double value = InStream_Read_F64(instream);
+    return self ? Float64_init(self, value) : Float64_new(value);
+}
+
 /***************************************************************************/
 
 Integer32*
@@ -216,6 +244,19 @@
     return self->value;
 }
 
+void
+Int32_serialize(Integer32 *self, OutStream *outstream)
+{
+    OutStream_Write_C32(outstream, (u32_t)self->value);
+}
+
+Integer32*
+Int32_deserialize(Integer32 *self, InStream *instream)
+{
+    i32_t value = (i32_t)InStream_Read_C32(instream);
+    return self ? Int32_init(self, value) : Int32_new(value);
+}
+
 /***************************************************************************/
 
 Integer64*
@@ -280,6 +321,19 @@
     return true;
 }
 
+void
+Int64_serialize(Integer64 *self, OutStream *outstream)
+{
+    OutStream_Write_C64(outstream, (u64_t)self->value);
+}
+
+Integer64*
+Int64_deserialize(Integer64 *self, InStream *instream)
+{
+    i64_t value = (i64_t)InStream_Read_C64(instream);
+    return self ? Int64_init(self, value) : Int64_new(value);
+}
+
 /* Copyright 2009 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");

Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c?rev=887025&r1=887024&r2=887025&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c Fri Dec  4 01:09:20 2009
@@ -2,6 +2,7 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Test.h"
+#include "Lucy/Test/TestUtils.h"
 #include "Lucy/Test/Object/TestNum.h"
 
 static void
@@ -167,16 +168,48 @@
     DECREF(f32);
 }
 
+static void
+test_serialization(TestBatch *batch)
+{
+    Float32   *f32 = Float32_new(1.33f);
+    Float64   *f64 = Float64_new(1.33);
+    Integer32 *i32 = Int32_new(-1);
+    Integer64 *i64 = Int64_new(-1);
+    Float32   *f32_thaw = (Float32*)TestUtils_freeze_thaw((Obj*)f32);
+    Float64   *f64_thaw = (Float64*)TestUtils_freeze_thaw((Obj*)f64);
+    Integer32 *i32_thaw = (Integer32*)TestUtils_freeze_thaw((Obj*)i32);
+    Integer64 *i64_thaw = (Integer64*)TestUtils_freeze_thaw((Obj*)i64);
+
+    ASSERT_TRUE(batch, Float32_Equals(f32, (Obj*)f32_thaw), 
+        "Float32 freeze/thaw");
+    ASSERT_TRUE(batch, Float64_Equals(f64, (Obj*)f64_thaw),
+        "Float64 freeze/thaw");
+    ASSERT_TRUE(batch, Int32_Equals(i32, (Obj*)i32_thaw), 
+        "Integer32 freeze/thaw");
+    ASSERT_TRUE(batch, Int64_Equals(i64, (Obj*)i64_thaw),
+        "Integer64 freeze/thaw");
+
+    DECREF(i64_thaw);
+    DECREF(i32_thaw);
+    DECREF(f64_thaw);
+    DECREF(f32_thaw);
+    DECREF(i64);
+    DECREF(i32);
+    DECREF(f64);
+    DECREF(f32);
+}
+
 void
 TestNum_run_tests()
 {
-    TestBatch *batch = Test_new_batch("TestNum", 34, NULL);
+    TestBatch *batch = Test_new_batch("TestNum", 38, NULL);
     PLAN(batch);
 
     test_To_String(batch);
     test_accessors(batch);
     test_Equals_and_Compare_To(batch);
     test_Clone(batch);
+    test_serialization(batch);
     
     batch->destroy(batch);
 }



Mime
View raw message