lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [09/13] lucy git commit: Tune and test Go bindings for Stepper.
Date Tue, 24 Nov 2015 23:38:31 GMT
Tune and test Go bindings for Stepper.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d5063a51
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d5063a51
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d5063a51

Branch: refs/heads/master
Commit: d5063a519200d52c1abeec263bd008f176fa94bd
Parents: dd4328b
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Nov 16 16:11:22 2015 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Nov 20 18:49:34 2015 -0800

----------------------------------------------------------------------
 go/build.go          |  8 ++++++
 go/lucy/util.go      | 69 +++++++++++++++++++++++++++++++++++++++++++++++
 go/lucy/util_test.go | 53 ++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/d5063a51/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 6c55250..3b6fc68 100644
--- a/go/build.go
+++ b/go/build.go
@@ -365,6 +365,14 @@ func specClasses(parcel *cfc.Parcel) {
 	cfWriterBinding := cfc.NewGoClass(parcel, "Lucy::Store::CompoundFileWriter")
 	cfWriterBinding.SpecMethod("Consolidate", "Consolidate() error")
 	cfWriterBinding.Register()
+
+	stepperBinding := cfc.NewGoClass(parcel, "Lucy::Util::Stepper")
+	stepperBinding.SpecMethod("Write_Key_Frame", "WriteKeyFrame(OutStream, interface{}) error")
+	stepperBinding.SpecMethod("Write_Delta", "WriteDelta(OutStream, interface{}) error")
+	stepperBinding.SpecMethod("Read_Key_Frame", "ReadKeyFrame(InStream) error")
+	stepperBinding.SpecMethod("Read_Delta", "ReadDelta(InStream) error")
+	stepperBinding.SpecMethod("Read_Record", "readRecord(InStream) error")
+	stepperBinding.Register()
 }
 
 func build() {

http://git-wip-us.apache.org/repos/asf/lucy/blob/d5063a51/go/lucy/util.go
----------------------------------------------------------------------
diff --git a/go/lucy/util.go b/go/lucy/util.go
new file mode 100644
index 0000000..a57de89
--- /dev/null
+++ b/go/lucy/util.go
@@ -0,0 +1,69 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+/*
+#include "Lucy/Util/Stepper.h"
+*/
+import "C"
+import "unsafe"
+
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func (s *StepperIMP) WriteKeyFrame(outstream OutStream, value interface{}) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s"))
+		outstreamCF := (*C.lucy_OutStream)(clownfish.Unwrap(outstream, "outstream"))
+		valueCF := (*C.cfish_Obj)(clownfish.GoToClownfish(value, unsafe.Pointer(C.CFISH_OBJ), false))
+		defer C.cfish_decref(unsafe.Pointer(valueCF))
+		C.LUCY_Stepper_Write_Key_Frame(self, outstreamCF, valueCF)
+	})
+}
+
+func (s *StepperIMP) WriteDelta(outstream OutStream, value interface{}) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s"))
+		outstreamCF := (*C.lucy_OutStream)(clownfish.Unwrap(outstream, "outstream"))
+		valueCF := (*C.cfish_Obj)(clownfish.GoToClownfish(value, unsafe.Pointer(C.CFISH_OBJ), false))
+		defer C.cfish_decref(unsafe.Pointer(valueCF))
+		C.LUCY_Stepper_Write_Delta(self, outstreamCF, valueCF)
+	})
+}
+
+func (s *StepperIMP) ReadKeyFrame(instream InStream) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s"))
+		instreamCF := (*C.lucy_InStream)(clownfish.Unwrap(instream, "instream"))
+		C.LUCY_Stepper_Read_Key_Frame(self, instreamCF)
+	})
+}
+
+func (s *StepperIMP) ReadDelta(instream InStream) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s"))
+		instreamCF := (*C.lucy_InStream)(clownfish.Unwrap(instream, "instream"))
+		C.LUCY_Stepper_Read_Delta(self, instreamCF)
+	})
+}
+
+func (s *StepperIMP) readRecord(instream InStream) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Stepper)(clownfish.Unwrap(s, "s"))
+		instreamCF := (*C.lucy_InStream)(clownfish.Unwrap(instream, "instream"))
+		C.LUCY_Stepper_Read_Record(self, instreamCF)
+	})
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/d5063a51/go/lucy/util_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/util_test.go b/go/lucy/util_test.go
new file mode 100644
index 0000000..38a4503
--- /dev/null
+++ b/go/lucy/util_test.go
@@ -0,0 +1,53 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+import "testing"
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func TestStepperMisc(t *testing.T) {
+	var err error
+	stepper := NewTextTermStepper()
+	folder := NewRAMFolder("")
+	out, _ := folder.OpenOut("foo.dat")
+	err = stepper.WriteKeyFrame(out, "foo")
+	if err != nil {
+		t.Errorf("WriteKeyFrame: %v", err)
+	}
+
+	bb := clownfish.NewByteBuf(0)
+	//bb.Cat([]byte("food"))
+	err = stepper.WriteDelta(out, bb)
+	if err != nil {
+		t.Errorf("WriteDelta: %v", err)
+	}
+	out.Close()
+	stepper.Reset()
+	in, _ := folder.OpenIn("foo.dat")
+	err = stepper.ReadKeyFrame(in)
+	if err != nil {
+		t.Errorf("ReadKeyFrame: %v", err)
+	}
+	err = stepper.ReadDelta(in)
+	if err != nil {
+		t.Errorf("ReadDelta: %v", err)
+	}
+	err = stepper.ReadDelta(in)
+	if err == nil {
+		t.Errorf("Expected error when reading past EOF")
+	}
+}


Mime
View raw message