本文整理匯總了Golang中C.leveldb_put函數的典型用法代碼示例。如果您正苦於以下問題:Golang leveldb_put函數的具體用法?Golang leveldb_put怎麽用?Golang leveldb_put使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了leveldb_put函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Put
// Put writes data associated with a key to the database.
//
// If a nil []byte is passed in as value, it will be returned by Get as an
// zero-length slice.
//
// The key and value byte slices may be reused safely. Put takes a copy of
// them before returning.
func (db *DB) Put(wo *WriteOptions, key, value []byte) error {
var errStr *C.char
// leveldb_put, _get, and _delete call memcpy() (by way of Memtable::Add)
// when called, so we do not need to worry about these []byte being
// reclaimed by GC.
var k, v *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
if len(value) != 0 {
v = (*C.char)(unsafe.Pointer(&value[0]))
}
lenk := len(key)
lenv := len(value)
C.leveldb_put(
db.Ldb, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr)
if errStr != nil {
gs := C.GoString(errStr)
C.free(unsafe.Pointer(errStr))
return DatabaseError(gs)
}
return nil
}
示例2: Put
func (db *LevelDB) Put(key, value []byte) error {
var err *C.char
C.leveldb_put(db.db, db.writeOpts.Opts, C.CString(string(key)), C.size_t(len(key)),
C.CString(string(value)), C.size_t(len(value)), &err)
if err != nil {
e := &DBError{}
e.Err = C.GoString(err)
return e
}
return nil
}
示例3: Set
func (self *Leveldb) Set(key string, obj interface{}) error {
buf := new(bytes.Buffer)
err := encode(buf, obj)
if err != nil {
return err
}
value := buf.Bytes()
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
header := (*reflect.SliceHeader)(unsafe.Pointer(&value))
var cerr *C.char
C.leveldb_put(self.cdb, self.write_options, cKey, C.size_t(len(key)), (*C.char)(unsafe.Pointer(header.Data)), C.size_t(header.Len), &cerr)
if cerr != nil {
return errors.New(fmt.Sprintf("%s", cerr))
}
return nil
}
示例4: put
func (db *DB) put(wo *WriteOptions, key, value []byte) error {
var errStr *C.char
var k, v *C.char
if len(key) != 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
if len(value) != 0 {
v = (*C.char)(unsafe.Pointer(&value[0]))
}
lenk := len(key)
lenv := len(value)
C.leveldb_put(
db.db, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr)
if errStr != nil {
return saveError(errStr)
}
return nil
}
示例5: Put
// Put key, value to database
func (db *LevelDB) Put(key, value string) (err error) {
opt := C.leveldb_writeoptions_create() // write option
defer C.leveldb_free(unsafe.Pointer(opt))
k := C.CString(key) // copy
defer C.leveldb_free(unsafe.Pointer(k))
v := C.CString(value)
defer C.leveldb_free(unsafe.Pointer(v))
var cerr *C.char
C.leveldb_put(db.CLevelDB, opt, k, C.size_t(len(key)), v, C.size_t(len(value)), &cerr)
if cerr != nil {
defer C.leveldb_free(unsafe.Pointer(cerr))
return errors.New(C.GoString(cerr))
}
return
}
示例6: Put
func (ldb *Db) Put(key, value []byte, w_options *Writeoptions) error {
var db_err *C.char
key_len := len(key)
value_len := len(value)
if key_len == 0 {
return ldb_error("key must be not empty")
}
if value_len == 0 {
return ldb_error("value must be not empty")
}
key_c := (*C.char)(unsafe.Pointer(&key[0]))
value_c := (*C.char)(unsafe.Pointer(&value[0]))
C.leveldb_put(ldb.ldb, w_options.options,
key_c, C.size_t(key_len),
value_c, C.size_t(value_len), &db_err)
if db_err != nil {
return ldb_error(C.GoString(db_err))
}
return nil
}