public static void CheckError(IntPtr error) { if (error != IntPtr.Zero) { string message = Marshal.PtrToStringAnsi(error); Native.leveldb_free(error); throw new LevelDBException(message); } }
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); Native.leveldb_free(v); return(true); }
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); try { NativeHelper.CheckError(error); if (value == IntPtr.Zero) { throw new LevelDBException("not found"); } return(new Slice(value, length)); } finally { if (value != IntPtr.Zero) { Native.leveldb_free(value); } } }