Esempio n. 1
0
func (r *rocksDBBatch) GetProto(key proto.EncodedKey, msg gogoproto.Message) (
	ok bool, keyBytes, valBytes int64, err error) {
	if len(key) == 0 {
		err = emptyKeyError()
		return
	}
	var result C.DBString
	if err = statusToError(C.DBBatchGet(r.parent.rdb, r.batch, goToCSlice(key), &result)); err != nil {
		return
	}
	if result.len <= 0 {
		return
	}
	ok = true
	if msg != nil {
		// Make a byte slice that is backed by result.data. This slice
		// cannot live past the lifetime of this method, but we're only
		// using it to unmarshal the proto.
		data := cSliceToUnsafeGoBytes(C.DBSlice(result))
		err = gogoproto.Unmarshal(data, msg)
	}
	C.free(unsafe.Pointer(result.data))
	keyBytes = int64(len(key))
	valBytes = int64(result.len)
	return
}
Esempio n. 2
0
func (r *rocksDBBatch) Get(key proto.EncodedKey) ([]byte, error) {
	if len(key) == 0 {
		return nil, emptyKeyError()
	}
	var result C.DBString
	err := statusToError(C.DBBatchGet(r.parent.rdb, r.batch, goToCSlice(key), &result))
	if err != nil {
		return nil, err
	}
	return cStringToGoBytes(result), nil
}