コード例 #1
0
 public static void CheckError(IntPtr error)
 {
     if (error != IntPtr.Zero)
     {
         string message = Marshal.PtrToStringAnsi(error);
         Native.leveldb_free(error);
         throw new LevelDBException(message);
     }
 }
コード例 #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);
            Native.leveldb_free(v);
            return(true);
        }
コード例 #3
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);

            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);
                }
            }
        }