Beispiel #1
0
// Value ...
func (curs *Cursor) Value() (value []byte, err error) {
	var n C.unqlite_int64
	res := C.unqlite_kv_cursor_data(curs.handle, nil, &n)
	if res != C.UNQLITE_OK {
		err = UnQLiteError(res)
		return
	}
	value = make([]byte, int(n))
	res = C.unqlite_kv_cursor_data(curs.handle, unsafe.Pointer(&value[0]), &n)
	if res != C.UNQLITE_OK {
		err = UnQLiteError(res)
	}
	return
}
Beispiel #2
0
//get data from the cursor, data can be nil
func (c *Cursor) Data(data []byte) ([]byte, error) {
	var v unsafe.Pointer
	outlen := C.unqlite_int64(len(data))
	if outlen == 0 {
		e := C.unqlite_kv_cursor_data(c.c, nil, &outlen)
		if e != C.UNQLITE_OK {
			return nil, code2Error(e)
		}
		data = make([]byte, outlen)
	}
	v = unsafe.Pointer(&data[0])
	e := C.unqlite_kv_cursor_data(c.c, v, &outlen)
	if e != C.UNQLITE_OK {
		return nil, code2Error(e)
	}
	return data[:outlen], code2Error(e)
}