// Put places a key-value pair into the WriteBatch for writing later. // // Both the key and value byte slices may be reused as WriteBatch takes a copy // of them before returning. // func (w *WriteBatch) Put(key, value []byte) { // leveldb_writebatch_put, 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. C.leveldb_writebatch_put(w.wbatch, (*C.char)(unsafe.Pointer(&key[0])), C.size_t(len(key)), (*C.char)(unsafe.Pointer(&value[0])), C.size_t(len(value))) }
func (w *WriteBatch) Put(key, value []byte) { 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_writebatch_put(w.wbatch, k, C.size_t(lenk), v, C.size_t(lenv)) }
func (wb *Writebatch) Put(key, value []byte) error { 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_writebatch_put(wb.wb, key_c, C.size_t(key_len), value_c, C.size_t(value_len)) return nil }
// Put places a key-value pair into the WriteBatch for writing later. // // Both the key and value byte slices may be reused as WriteBatch takes a copy // of them before returning. // func (w *WriteBatch) Put(key, value []byte) { // leveldb_writebatch_put, 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_writebatch_put(w.wbatch, k, C.size_t(lenk), v, C.size_t(lenv)) }