Esempio n. 1
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Equals
func GOLUCY_Doc_Equals(d *C.lucy_Doc, other *C.cfish_Obj) C.bool {
	twin := (*C.lucy_Doc)(unsafe.Pointer(other))
	if twin == d {
		return true
	}
	if !C.cfish_Obj_is_a(other, C.LUCY_DOC) {
		return false
	}
	ivars := C.lucy_Doc_IVARS(d)
	ovars := C.lucy_Doc_IVARS(twin)
	hash := (*C.cfish_Hash)(ivars.fields)
	otherHash := (*C.cfish_Obj)(ovars.fields)
	return C.CFISH_Hash_Equals(hash, otherHash)
}
Esempio n. 2
0
//export GOLUCY_Doc_Serialize
func GOLUCY_Doc_Serialize(d *C.lucy_Doc, outstream *C.lucy_OutStream) {
	ivars := C.lucy_Doc_IVARS(d)
	fields := fetchDocFields(d)
	hash := clownfish.GoToClownfish(fields, unsafe.Pointer(C.CFISH_HASH), false)
	defer C.cfish_decref(hash)
	C.lucy_Freezer_serialize_hash((*C.cfish_Hash)(hash), outstream)
	C.LUCY_OutStream_Write_C32(outstream, C.uint32_t(ivars.doc_id))
}
Esempio n. 3
0
func (d *DocIMP) SetFields(fields map[string]interface{}) {
	self := (*C.lucy_Doc)(clownfish.Unwrap(d, "d"))
	ivars := C.lucy_Doc_IVARS(self)
	oldID := uintptr(unsafe.Pointer(ivars.fields))
	newFieldsID := registry.store(fields)
	ivars.fields = unsafe.Pointer(newFieldsID)
	registry.delete(oldID)
}
Esempio n. 4
0
func fetchDocFields(d *C.lucy_Doc) map[string]interface{} {
	ivars := C.lucy_Doc_IVARS(d)
	fieldsID := uintptr(ivars.fields)
	fieldsGo, ok := registry.fetch(fieldsID).(map[string]interface{})
	if !ok {
		panic(clownfish.NewErr(fmt.Sprintf("Failed to fetch doc %d from registry ", fieldsID)))
	}
	return fieldsGo
}
Esempio n. 5
0
//export GOLUCY_Doc_Deserialize
func GOLUCY_Doc_Deserialize(d *C.lucy_Doc, instream *C.lucy_InStream) *C.lucy_Doc {
	ivars := C.lucy_Doc_IVARS(d)
	hash := unsafe.Pointer(C.lucy_Freezer_read_hash(instream))
	defer C.cfish_decref(hash)
	fields := clownfish.ToGo(hash)
	fieldsID := registry.store(fields)
	ivars.fields = unsafe.Pointer(fieldsID)
	ivars.doc_id = C.int32_t(C.LUCY_InStream_Read_C32(instream))
	return d
}
Esempio n. 6
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_init
func GOLUCY_Doc_init(d *C.lucy_Doc, fields unsafe.Pointer, docID C.int32_t) *C.lucy_Doc {
	ivars := C.lucy_Doc_IVARS(d)
	if fields != nil {
		ivars.fields = unsafe.Pointer(C.cfish_inc_refcount(fields))
	} else {
		ivars.fields = unsafe.Pointer(C.cfish_Hash_new(0))
	}
	ivars.doc_id = docID
	return d
}
Esempio n. 7
0
//export GOLUCY_Doc_init
func GOLUCY_Doc_init(d *C.lucy_Doc, fields unsafe.Pointer, docID C.int32_t) *C.lucy_Doc {
	ivars := C.lucy_Doc_IVARS(d)
	if fields == nil {
		fieldsGo := make(map[string]interface{})
		fieldsID := registry.store(fieldsGo)
		ivars.fields = unsafe.Pointer(fieldsID)
	} else {
		ivars.fields = fields
	}
	ivars.doc_id = docID
	return d
}
Esempio n. 8
0
//export GOLUCY_Doc_Destroy
func GOLUCY_Doc_Destroy(d *C.lucy_Doc) {
	ivars := C.lucy_Doc_IVARS(d)
	fieldsID := uintptr(ivars.fields)
	registry.delete(fieldsID)
	C.cfish_super_destroy(unsafe.Pointer(d), C.LUCY_DOC)
}
Esempio n. 9
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Destroy
func GOLUCY_Doc_Destroy(d *C.lucy_Doc) {
	ivars := C.lucy_Doc_IVARS(d)
	C.cfish_decref(unsafe.Pointer(ivars.fields))
	C.cfish_super_destroy(unsafe.Pointer(d), C.LUCY_DOC)
}
Esempio n. 10
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Field_Names
func GOLUCY_Doc_Field_Names(d *C.lucy_Doc) *C.cfish_Vector {
	ivars := C.lucy_Doc_IVARS(d)
	hash := (*C.cfish_Hash)(ivars.fields)
	return C.CFISH_Hash_Keys(hash)
}
Esempio n. 11
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Extract
func GOLUCY_Doc_Extract(d *C.lucy_Doc, field *C.cfish_String) *C.cfish_Obj {
	ivars := C.lucy_Doc_IVARS(d)
	hash := (*C.cfish_Hash)(ivars.fields)
	val := C.CFISH_Hash_Fetch(hash, field)
	return C.cfish_inc_refcount(unsafe.Pointer(val))
}
Esempio n. 12
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Deserialize
func GOLUCY_Doc_Deserialize(d *C.lucy_Doc, instream *C.lucy_InStream) *C.lucy_Doc {
	ivars := C.lucy_Doc_IVARS(d)
	ivars.fields = unsafe.Pointer(C.lucy_Freezer_read_hash(instream))
	ivars.doc_id = C.int32_t(C.LUCY_InStream_Read_C32(instream))
	return d
}
Esempio n. 13
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Serialize
func GOLUCY_Doc_Serialize(d *C.lucy_Doc, outstream *C.lucy_OutStream) {
	ivars := C.lucy_Doc_IVARS(d)
	hash := (*C.cfish_Hash)(ivars.fields)
	C.lucy_Freezer_serialize_hash(hash, outstream)
	C.LUCY_OutStream_Write_C32(outstream, C.uint32_t(ivars.doc_id))
}
Esempio n. 14
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Store
func GOLUCY_Doc_Store(d *C.lucy_Doc, field *C.cfish_String, value *C.cfish_Obj) {
	ivars := C.lucy_Doc_IVARS(d)
	hash := (*C.cfish_Hash)(ivars.fields)
	C.CFISH_Hash_Store(hash, field, C.cfish_inc_refcount(unsafe.Pointer(value)))
}
Esempio n. 15
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Get_Size
func GOLUCY_Doc_Get_Size(d *C.lucy_Doc) C.uint32_t {
	ivars := C.lucy_Doc_IVARS(d)
	hash := ((*C.cfish_Hash)(ivars.fields))
	return C.uint32_t(C.CFISH_Hash_Get_Size(hash))
}
Esempio n. 16
0
File: lucy.go Progetto: kidaa/lucy
//export GOLUCY_Doc_Set_Fields
func GOLUCY_Doc_Set_Fields(d *C.lucy_Doc, fields unsafe.Pointer) {
	ivars := C.lucy_Doc_IVARS(d)
	temp := ivars.fields
	ivars.fields = unsafe.Pointer(C.cfish_inc_refcount(fields))
	C.cfish_decref(temp)
}