本文整理匯總了Golang中C.leveldb_get函數的典型用法代碼示例。如果您正苦於以下問題:Golang leveldb_get函數的具體用法?Golang leveldb_get怎麽用?Golang leveldb_get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了leveldb_get函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Get
func (db *LevelDB) Get(key []byte) ([]byte, error) {
var vlen C.size_t
var err *C.char
val := C.leveldb_get(db.db, db.readOpts.Opts, C.CString(string(key)), C.size_t(len(key)), &vlen, &err)
if err != nil {
e := &DBError{}
e.Err = C.GoString(err)
return nil, e
}
if vlen == 0 {
return nil, nil
}
return C.GoBytes(unsafe.Pointer(val), C.int(vlen)), nil
}
示例2: Get
func (self *Leveldb) Get(key string, obj interface{}) error {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
var valueLen C.size_t
var cerr *C.char
valueValue := C.leveldb_get(self.cdb, self.read_options, cKey, C.size_t(len(key)), &valueLen, &cerr)
if cerr != nil {
return errors.New(fmt.Sprintf("%s", cerr))
}
bs := C.GoBytes(unsafe.Pointer(valueValue), C.int(valueLen))
r := bytes.NewReader(bs)
err := decode(r, obj)
if err != nil {
return err
}
return nil
}
示例3: Get
// Get returns the data associated with the key from the database.
//
// If the key does not exist in the database, a nil []byte is returned. If the
// key does exist, but the data is zero-length in the database, a zero-length
// []byte will be returned.
//
// The key byte slice may be reused safely. Get takes a copy of
// them before returning.
func (db *DB) Get(ro *ReadOptions, key []byte) ([]byte, error) {
var errStr *C.char
var vallen C.size_t
var k *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
value := C.leveldb_get(db.Ldb, ro.Opt,
k, C.size_t(len(key)),
&vallen, &errStr)
if errStr != nil {
return nil, DatabaseError(C.GoString(errStr))
}
if value == nil {
return nil, nil
}
return C.GoBytes(unsafe.Pointer(value), C.int(vallen)), nil
}
示例4: Get
func (db *LevelDB) Get(key string) (value string, err error) {
opt := C.leveldb_readoptions_create() // write option
defer C.leveldb_free(unsafe.Pointer(opt))
k := C.CString(key) // copy
defer C.leveldb_free(unsafe.Pointer(k))
var vallen C.size_t
var cerr *C.char
cvalue := C.leveldb_get(db.CLevelDB, opt, k, C.size_t(len(key)), &vallen, &cerr)
if cerr != nil {
defer C.leveldb_free(unsafe.Pointer(cerr))
return "", errors.New(C.GoString(cerr))
}
if cvalue == nil {
return "", nil
}
defer C.leveldb_free(unsafe.Pointer(cvalue))
return C.GoString(cvalue), nil
}
示例5: getSlice
func (db *DB) getSlice(ro *ReadOptions, key []byte) (driver.ISlice, error) {
var errStr *C.char
var vallen C.size_t
var k *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
value := C.leveldb_get(
db.db, ro.Opt, k, C.size_t(len(key)), &vallen, &errStr)
if errStr != nil {
return nil, saveError(errStr)
}
if value == nil {
return nil, nil
}
return NewCSlice(unsafe.Pointer(value), int(vallen)), nil
}
示例6: Get
func (ldb *Db) Get(key []byte, read_option *Readoptions) ([]byte, error) {
var db_err *C.char
var value_len C.size_t
key_len := len(key)
if key_len == 0 {
return nil, ldb_error("key must not empty")
}
key_c := (*C.char)(unsafe.Pointer(&key[0]))
value := C.leveldb_get(ldb.ldb, read_option.options, key_c, C.size_t(key_len),
&value_len, &db_err)
if db_err != nil {
return nil, ldb_error(C.GoString(db_err))
}
if value == nil {
return nil, nil
}
return C.GoBytes(unsafe.Pointer(value), C.int(value_len)), nil
}