@@ -119,16 +119,42 @@ public byte[] Get(byte[] key, long keyLength, ColumnFamilyHandle cf = null, Read
119119 return Native . Instance . rocksdb_get ( Handle , ( readOptions ?? DefaultReadOptions ) . Handle , key , keyLength , cf ) ;
120120 }
121121
122+ /// <summary>
123+ /// Reads the contents of the database value associated with <paramref name="key"/>, if present, into the supplied
124+ /// <paramref name="buffer"/> at <paramref name="offset"/> up to <paramref name="length"/> bytes, returning the
125+ /// length of the value in the database, or -1 if the key is not present.
126+ /// </summary>
127+ /// <param name="key"></param>
128+ /// <param name="buffer"></param>
129+ /// <param name="offset"></param>
130+ /// <param name="length"></param>
131+ /// <param name="cf"></param>
132+ /// <param name="readOptions"></param>
133+ /// <returns>The actual length of the database field if it exists, otherwise -1</returns>
122134 public long Get ( byte [ ] key , byte [ ] buffer , long offset , long length , ColumnFamilyHandle cf = null , ReadOptions readOptions = null )
123135 {
124136 return Get ( key , key . GetLongLength ( 0 ) , buffer , offset , length , cf , readOptions ) ;
125137 }
126138
139+ /// <summary>
140+ /// Reads the contents of the database value associated with <paramref name="key"/>, if present, into the supplied
141+ /// <paramref name="buffer"/> at <paramref name="offset"/> up to <paramref name="length"/> bytes, returning the
142+ /// length of the value in the database, or -1 if the key is not present.
143+ /// </summary>
144+ /// <param name="key"></param>
145+ /// <param name="buffer"></param>
146+ /// <param name="offset"></param>
147+ /// <param name="length"></param>
148+ /// <param name="cf"></param>
149+ /// <param name="readOptions"></param>
150+ /// <returns>The actual length of the database field if it exists, otherwise -1</returns>
127151 public long Get ( byte [ ] key , long keyLength , byte [ ] buffer , long offset , long length , ColumnFamilyHandle cf = null , ReadOptions readOptions = null )
128152 {
129153 unsafe
130154 {
131155 var ptr = Native . Instance . rocksdb_get ( Handle , ( readOptions ?? DefaultReadOptions ) . Handle , key , keyLength , out long valLength , cf ) ;
156+ if ( ptr == IntPtr . Zero )
157+ return - 1 ;
132158 var copyLength = Math . Min ( length , valLength ) ;
133159 Marshal . Copy ( ptr , buffer , ( int ) offset , ( int ) copyLength ) ;
134160 Native . Instance . rocksdb_free ( ptr ) ;
0 commit comments