func (self *KcDb) Iter(fun func(string, Getter) bool) { cur := C.kcdbcursor(self.cdb) C.kccurjump(cur) var kSize, vSize C.size_t var vBuff, kBuff *C.char var ret bool for { kBuff = C.kccurget(cur, &kSize, &vBuff, &vSize, kcTrue) if kBuff == nil { C.kcfree(unsafe.Pointer(kBuff)) break } key := string(C.GoBytes(unsafe.Pointer(kBuff), C.int(kSize))) value := C.GoBytes(unsafe.Pointer(vBuff), C.int(vSize)) r := bytes.NewReader(value) ret = fun(key, func(e interface{}) error { return decode(r, e) }) C.kcfree(unsafe.Pointer(kBuff)) if ret == false { break } } C.kccurdel(cur) }
func (kc *KCDB) Status() (status string, err error) { cstatus := C.kcdbstatus(kc.db) if cstatus == nil { err = kc.error() } status = C.GoString(cstatus) C.kcfree(unsafe.Pointer(cstatus)) return }
func (kc *KCDB) Path() (path string, err error) { cpath := C.kcdbpath(kc.db) defer C.kcfree(unsafe.Pointer(cpath)) path = C.GoString(cpath) if path == "" { err = kc.error() } return }
func (kc *KCDB) Get(key []byte) (value []byte, err error) { ckey := (*C.char)(unsafe.Pointer(&key[0])) var vlen C.size_t cval := C.kcdbget(kc.db, ckey, C.size_t(len(key)), &vlen) if cval == nil { err = kc.error() } else { value = make([]byte, int(vlen)) C.memcpy(unsafe.Pointer(&value[0]), unsafe.Pointer(cval), vlen) C.kcfree(unsafe.Pointer(cval)) } return }
func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err error) { cregex := C.CString(regex) strarray := make([]*C.char, max) count := C.kcdbmatchregex(kc.db, cregex, &strarray[0], C.size_t(max)) if count == -1 { matches = nil err = kc.error() } else { matches = make([][]byte, count) for i := int64(0); i < int64(count); i++ { matches[i] = []byte(C.GoString(strarray[i])) C.kcfree(unsafe.Pointer(strarray[i])) } } C.free(unsafe.Pointer(cregex)) return }
func (kcc *KCCUR) GetValue(advance bool) (v []byte, err error) { var vsiz C.size_t var cadvance C.int32_t if advance { cadvance = 1 } else { cadvance = 0 } vp := C.kccurgetvalue(kcc.cur, &vsiz, cadvance) if vp != nil { v = make([]byte, vsiz) C.memcpy(unsafe.Pointer(&v[0]), unsafe.Pointer(vp), vsiz) C.kcfree(unsafe.Pointer(vp)) } else { err = kcc.error() } return }
func (kcc *KCCUR) GetKey(advance bool) (k []byte, err error) { var ksiz C.size_t var cadvance C.int32_t if advance { cadvance = 1 } else { cadvance = 0 } kp := C.kccurgetkey(kcc.cur, &ksiz, cadvance) if kp != nil { k = make([]byte, ksiz) C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz) C.kcfree(unsafe.Pointer(kp)) } else { err = kcc.error() } return }
func (self *KcDb) Get(key string, obj interface{}) error { var b []byte var err error cKey := C.CString(key) defer C.free(unsafe.Pointer(cKey)) var vSize C.size_t vBuf := C.kcdbget(self.cdb, cKey, C.size_t(len(key)), &vSize) if vBuf == nil { return errors.New(fmt.Sprintf("get: %s", key)) } defer C.kcfree(unsafe.Pointer(vBuf)) b = C.GoBytes(unsafe.Pointer(vBuf), C.int(vSize)) r := bytes.NewReader(b) err = decode(r, obj) if err != nil { return err } return nil }
func (kcc *KCCUR) Get(advance bool) (k, v []byte, err os.Error) { var ksiz, vsiz C.size_t var vp *C.char var cadvance C.int32_t if advance { cadvance = 1 } else { cadvance = 0 } kp := C.kccurget(kcc.cur, &ksiz, &vp, &vsiz, cadvance) if kp != nil { k = make([]byte, ksiz) C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz) v = make([]byte, vsiz) C.memcpy(unsafe.Pointer(&v[0]), unsafe.Pointer(vp), vsiz) C.kcfree(unsafe.Pointer(kp)) } else { err = kcc.error() } return }