/// <summary> /// Set the database entry for "key" to "value". /// </summary> public void Put(Byte[] key, Byte[] value, WriteOptions options) { LevelDBInterop.leveldb_put(this.Handle, options.Handle, key, (IntPtr)key.Length, value, (IntPtr)value.LongLength, out IntPtr error); LevelDBException.Check(error); GC.KeepAlive(options); GC.KeepAlive(this); }
/// <summary> /// If the database contains an entry for "key" return the value, /// otherwise return null. /// </summary> public unsafe Byte[] Get(Byte[] key, ReadOptions options) { IntPtr valuePtr = LevelDBInterop.leveldb_get(this.Handle, options.Handle, key, (IntPtr)key.Length, out IntPtr lengthPtr, out IntPtr error); LevelDBException.Check(error); if (valuePtr == IntPtr.Zero) { return(null); } try { Int64 length = (Int64)lengthPtr; Byte[] value = new Byte[length]; Byte * valueNative = (Byte *)valuePtr.ToPointer(); for (Int64 i = 0; i < length; ++i) { value[i] = valueNative[i]; } return(value); } finally { LevelDBInterop.leveldb_free(valuePtr); GC.KeepAlive(options); GC.KeepAlive(this); } }
/// <summary> /// Remove the database entry (if any) for "key". /// It is not an error if "key" did not exist in the database. /// </summary> public void Delete(Byte[] key, WriteOptions options) { LevelDBInterop.leveldb_delete(this.Handle, options.Handle, key, (IntPtr)key.Length, out IntPtr error); LevelDBException.Check(error); GC.KeepAlive(options); GC.KeepAlive(this); }
///DOLATER <summary>Add Description</summary> /// <param name="batch">FILL IN</param> /// <param name="options">FILL IN</param> public void Write(WriteBatch batch, WriteOptions options) { LevelDBInterop.leveldb_write(this.Handle, options.Handle, batch.Handle, out IntPtr error); LevelDBException.Check(error); GC.KeepAlive(batch); GC.KeepAlive(options); GC.KeepAlive(this); }
/// <summary> /// If an error has occurred, throw it. /// </summary> void Throw() { IntPtr error; LevelDBInterop.leveldb_iter_get_error(Handle, out error); LevelDBException.Check(error); GC.KeepAlive(this); }
/// <summary> /// Destroy the contents of the specified database. /// Be very careful using this method. /// Options should not be modified after calling this method. /// </summary> public static void Destroy(string name, Options options) { IntPtr error; LevelDBInterop.leveldb_destroy_db(options.Handle, name, out error); LevelDBException.Check(error); GC.KeepAlive(options); }
/// <summary> /// Open the database with the specified "name". /// Options should not be modified after calling this method. /// </summary> public DB(string name, Options options) { Options = options ?? new Options(); IntPtr error; Handle = LevelDBInterop.leveldb_open(Options.Handle, name, out error); LevelDBException.Check(error); GC.KeepAlive(Options); }
public void Put(byte[] key, byte[] value, int offset, int length, WriteOptions options) { IntPtr error; LevelDBInterop.leveldb_put(this.Handle, options.Handle, key, (IntPtr)key.Length, value, (IntPtr)length, out error); LevelDBException.Check(error); GC.KeepAlive(options); GC.KeepAlive(this); }
public static DB Open(string name, Options options) { IntPtr error; IntPtr handle = LevelDBInterop.leveldb_open(options.Handle, name, out error); LevelDBException.Check(error); return(new DB(handle)); }
public void Delete(WriteOptions options, Slice key) { IntPtr error; LevelDBInterop.leveldb_delete(Handle, options.Handle, key.buffer, (IntPtr)key.buffer.Length, out error); LevelDBException.Check(error); GC.KeepAlive(options); GC.KeepAlive(this); }
public void Put(WriteOptions options, Slice key, Slice value) { IntPtr error; LevelDBInterop.leveldb_put(this.Handle, options.Handle, key.buffer, (IntPtr)key.buffer.Length, value.buffer, (IntPtr)value.buffer.LongLength, out error); LevelDBException.Check(error); GC.KeepAlive(options); GC.KeepAlive(this); }
/// <summary> Open the database with the specified "name". Options should not be modified after calling this method. </summary> /// <param name="name">The name (subfolder) of the database</param> /// <param name="options">Options should not be modified after calling this method.</param> public DB(String name, Options options) { this._Options = options ?? new Options(); this.Handle = LevelDBInterop.leveldb_open(this._Options.Handle, name, out IntPtr error); LevelDBException.Check(error); GC.KeepAlive(this._Options); #if DEBUG System.Diagnostics.Debug.WriteLine("Opened leveldb: " + name); #endif }
public unsafe long Get(byte[] key, byte[] buffer, ReadOptions options) { IntPtr error; IntPtr lengthPtr; var valuePtr = LevelDBInterop.leveldb_get(this.Handle, options.Handle, key, (IntPtr)key.Length, out lengthPtr, out error); LevelDBException.Check(error); if (valuePtr == IntPtr.Zero) { return(0); } try { var length = (long)lengthPtr; var valueNative = (byte *)valuePtr.ToPointer(); Marshal.Copy((IntPtr)valuePtr, buffer, 0, (int)length); return(length); } finally { LevelDBInterop.leveldb_free(valuePtr); } }
/// <summary> /// If a DB cannot be opened, you may attempt to call this method to /// resurrect as much of the contents of the database as possible. /// Some data may be lost, so be careful when calling this function /// on a database that contains important information. /// Options should not be modified after calling this method. /// </summary> public static void Repair(String name, Options options) { LevelDBInterop.leveldb_repair_db(options.Handle, name, out IntPtr error); LevelDBException.Check(error); GC.KeepAlive(options); }