示例#1
0
        public Slice Get(ReadOptions options, Slice key)
        {
            UIntPtr length;
            IntPtr  error;
            IntPtr  value = Native.leveldb_get(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out length, out error);

            NativeHelper.CheckError(error);
            if (value == IntPtr.Zero)
            {
                throw new LevelDBException("not found");
            }
            return(new Slice(value, length));
        }
示例#2
0
        public bool TryGet(ReadOptions options, Slice key, out Slice value)
        {
            UIntPtr length;
            IntPtr  error;
            IntPtr  v = Native.leveldb_get(handle, options.handle, key.buffer, (UIntPtr)key.buffer.Length, out length, out error);

            if (error != IntPtr.Zero)
            {
                Native.leveldb_free(error);
                value = default(Slice);
                return(false);
            }
            if (v == IntPtr.Zero)
            {
                value = default(Slice);
                return(false);
            }
            value = new Slice(v, length);
            return(true);
        }