Skip to content

Commit 965e6d9

Browse files
committed
rename Native.Raw.cs -> Native.cs and auto-generate exception-throwing wrappers
1 parent aad0f20 commit 965e6d9

File tree

3 files changed

+2137
-256
lines changed

3 files changed

+2137
-256
lines changed

RocksDbSharp/Native.Marshaled.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,5 +1171,26 @@ public void rocksdb_writebatch_wi_put_log_data(IntPtr writeBatch, byte[] blob, u
11711171
rocksdb_writebatch_wi_put_log_data(writeBatch, blob, new UIntPtr(len));
11721172
}
11731173

1174+
public byte[] rocksdb_iter_key(IntPtr iterator)
1175+
{
1176+
IntPtr buffer = rocksdb_iter_key(iterator, out UIntPtr length);
1177+
byte[] result = new byte[(int)length];
1178+
Marshal.Copy(buffer, result, 0, (int)length);
1179+
// Do not free, this is owned by the iterator and will be freed there
1180+
//rocksdb_free(buffer);
1181+
return result;
1182+
}
1183+
1184+
public byte[] rocksdb_iter_value(IntPtr iterator)
1185+
{
1186+
IntPtr buffer = rocksdb_iter_value(iterator, out UIntPtr length);
1187+
byte[] result = new byte[(int)length];
1188+
Marshal.Copy(buffer, result, 0, (int)length);
1189+
// Do not free, this is owned by the iterator and will be freed there
1190+
//rocksdb_free(buffer);
1191+
return result;
1192+
}
1193+
1194+
11741195
}
11751196
}

RocksDbSharp/Native.Wrap.cs

Lines changed: 8 additions & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -12,106 +12,13 @@ These wrappers provide translation from the error output of the C API into excep
1212
*/
1313
public abstract partial class Native
1414
{
15-
public IntPtr rocksdb_open(
16-
/* const rocksdb_options_t* */ IntPtr options,
17-
string name)
18-
{
19-
var result = rocksdb_open(options, name, out IntPtr errptr);
20-
if (errptr != IntPtr.Zero)
21-
throw new RocksDbException(errptr);
22-
return result;
23-
}
24-
25-
public IntPtr rocksdb_open_for_read_only(
26-
/* const rocksdb_options_t* */ IntPtr options,
27-
string name,
28-
bool error_if_log_file_exists = false)
29-
{
30-
var result = rocksdb_open_for_read_only(options, name, error_if_log_file_exists, out IntPtr errptr);
31-
if (errptr != IntPtr.Zero)
32-
throw new RocksDbException(errptr);
33-
return result;
34-
}
35-
36-
public IntPtr rocksdb_open_with_ttl(
37-
/* const rocksdb_options_t* */ IntPtr options,
38-
string name,
39-
int ttlSeconds)
40-
{
41-
var result = rocksdb_open_with_ttl(options, name, ttlSeconds, out IntPtr errptr);
42-
if (errptr != IntPtr.Zero)
43-
throw new RocksDbException(errptr);
44-
return result;
45-
}
46-
47-
public IntPtr rocksdb_open_column_families(
48-
/* const rocksdb_options_t* */ IntPtr options,
49-
string name,
50-
int num_column_families,
51-
string[] column_family_names,
52-
IntPtr[] column_family_options,
53-
IntPtr[] column_family_handles)
54-
{
55-
var result = rocksdb_open_column_families(options, name, num_column_families, column_family_names, column_family_options, column_family_handles, out IntPtr errptr);
56-
if (errptr != IntPtr.Zero)
57-
throw new RocksDbException(errptr);
58-
return result;
59-
}
60-
61-
public IntPtr rocksdb_open_for_read_only_column_families(
62-
/* const rocksdb_options_t* */ IntPtr options,
63-
string name,
64-
int num_column_families,
65-
string[] column_family_names,
66-
IntPtr[] column_family_options,
67-
IntPtr[] column_family_handles,
68-
bool error_if_log_file_exists)
69-
{
70-
var result = rocksdb_open_for_read_only_column_families(options, name, num_column_families, column_family_names, column_family_options, column_family_handles, error_if_log_file_exists, out IntPtr errptr);
71-
if (errptr != IntPtr.Zero)
72-
throw new RocksDbException(errptr);
73-
return result;
74-
}
75-
76-
public /*(rocksdb_checkpoint_t*)*/ IntPtr rocksdb_checkpoint_object_create(
77-
/*(rocksdb_t*)*/ IntPtr db)
78-
{
79-
var result = rocksdb_checkpoint_object_create(db, out IntPtr errptr);
80-
if (errptr != IntPtr.Zero)
81-
throw new RocksDbException(errptr);
82-
return result;
83-
}
84-
85-
public void rocksdb_checkpoint_create(
86-
/*(rocksdb_checkpoint_t*)*/ IntPtr checkpoint,
87-
/*(const char*)*/ string checkpoint_dir,
88-
/*(uint64_t)*/ ulong log_size_for_flush)
89-
{
90-
rocksdb_checkpoint_create(checkpoint, checkpoint_dir, log_size_for_flush, out IntPtr errptr);
91-
if (errptr != IntPtr.Zero)
92-
throw new RocksDbException(errptr);
93-
}
94-
95-
public IntPtr rocksdb_list_column_families(
96-
/* const rocksdb_options_t* */ IntPtr options,
97-
string name,
98-
out ulong lencf
99-
)
100-
{
101-
var result = rocksdb_list_column_families(options, name, out UIntPtr lencfValue, out IntPtr errptr);
102-
if (errptr != IntPtr.Zero)
103-
throw new RocksDbException(errptr);
104-
lencf = (ulong)lencfValue;
105-
return result;
106-
}
107-
10815
public void rocksdb_put(
10916
/*rocksdb_t**/ IntPtr db,
11017
/*const rocksdb_writeoptions_t**/ IntPtr writeOptions,
11118
string key,
11219
string val,
11320
ColumnFamilyHandle cf = null,
114-
Encoding encoding = null)
21+
System.Text.Encoding encoding = null)
11522
{
11623
rocksdb_put(db, writeOptions, key, val, out IntPtr errptr, cf, encoding);
11724
if (errptr != IntPtr.Zero)
@@ -144,7 +51,7 @@ public string rocksdb_get(
14451
/*const rocksdb_readoptions_t**/ IntPtr read_options,
14552
string key,
14653
ColumnFamilyHandle cf,
147-
Encoding encoding = null)
54+
System.Text.Encoding encoding = null)
14855
{
14956
var result = rocksdb_get(db, read_options, key, out IntPtr errptr, cf, encoding);
15057
if (errptr != IntPtr.Zero)
@@ -183,15 +90,15 @@ public byte[] rocksdb_get(
18390
return result;
18491
}
18592

186-
public KeyValuePair<string, string>[] rocksdb_multi_get(
93+
public System.Collections.Generic.KeyValuePair<string, string>[] rocksdb_multi_get(
18794
IntPtr db,
18895
IntPtr read_options,
18996
string[] keys,
19097
ColumnFamilyHandle[] cf = null,
191-
Encoding encoding = null)
98+
System.Text.Encoding encoding = null)
19299
{
193100
if (encoding == null)
194-
encoding = Encoding.UTF8;
101+
encoding = System.Text.Encoding.UTF8;
195102
IntPtr[] errptrs = new IntPtr[keys.Length];
196103
var result = rocksdb_multi_get(db, read_options, keys, cf: cf, errptrs: errptrs, encoding: encoding);
197104
foreach (var errptr in errptrs)
@@ -201,7 +108,7 @@ public KeyValuePair<string, string>[] rocksdb_multi_get(
201108
}
202109

203110

204-
public KeyValuePair<byte[], byte[]>[] rocksdb_multi_get(
111+
public System.Collections.Generic.KeyValuePair<byte[], byte[]>[] rocksdb_multi_get(
205112
IntPtr db,
206113
IntPtr read_options,
207114
byte[][] keys,
@@ -251,109 +158,6 @@ public void rocksdb_delete_cf(
251158
throw new RocksDbException(errptr);
252159
}
253160

254-
public void rocksdb_write(
255-
/*rocksdb_t**/ IntPtr db,
256-
/*const rocksdb_writeoptions_t**/ IntPtr writeOptions,
257-
/*(rocksdb_writebatch_t*)*/ IntPtr writeBatch)
258-
{
259-
rocksdb_write(db, writeOptions, writeBatch, out IntPtr errptr);
260-
if (errptr != IntPtr.Zero)
261-
throw new RocksDbException(errptr);
262-
}
263-
264-
public void rocksdb_write_writebatch_wi(
265-
/*rocksdb_t**/ IntPtr db,
266-
/*const rocksdb_writeoptions_t**/ IntPtr writeOptions,
267-
/*(rocksdb_writebatch_wi_t*)*/ IntPtr writeBatchWithIndex)
268-
{
269-
rocksdb_write_writebatch_wi(db, writeOptions, writeBatchWithIndex, out IntPtr errptr);
270-
if (errptr != IntPtr.Zero)
271-
throw new RocksDbException(errptr);
272-
}
273-
274-
public byte[] rocksdb_iter_key(IntPtr iterator)
275-
{
276-
IntPtr buffer = rocksdb_iter_key(iterator, out UIntPtr length);
277-
byte[] result = new byte[(int)length];
278-
Marshal.Copy(buffer, result, 0, (int)length);
279-
// Do not free, this is owned by the iterator and will be freed there
280-
//rocksdb_free(buffer);
281-
return result;
282-
}
283-
284-
public byte[] rocksdb_iter_value(IntPtr iterator)
285-
{
286-
IntPtr buffer = rocksdb_iter_value(iterator, out UIntPtr length);
287-
byte[] result = new byte[(int)length];
288-
Marshal.Copy(buffer, result, 0, (int)length);
289-
// Do not free, this is owned by the iterator and will be freed there
290-
//rocksdb_free(buffer);
291-
return result;
292-
}
293-
294-
public IntPtr rocksdb_create_column_family(
295-
/*rocksdb_t**/ IntPtr db,
296-
/* const rocksdb_options_t* */ IntPtr column_family_options,
297-
string column_family_name)
298-
{
299-
var result = rocksdb_create_column_family(db, column_family_options, column_family_name, out IntPtr errptr);
300-
if (errptr != IntPtr.Zero)
301-
throw new RocksDbException(errptr);
302-
return result;
303-
}
304-
305-
public void rocksdb_drop_column_family(
306-
/*rocksdb_t**/ IntPtr db,
307-
/*(rocksdb_column_family_handle_t*)*/ IntPtr column_family_handle
308-
)
309-
{
310-
rocksdb_drop_column_family(db, column_family_handle, out IntPtr errptr);
311-
if (errptr != IntPtr.Zero)
312-
throw new RocksDbException(errptr);
313-
}
314-
315-
public void rocksdb_set_options(IntPtr db, int count, string[] keys, string[] values)
316-
{
317-
rocksdb_set_options(db, keys.Length, keys, values, out IntPtr errptr);
318-
if (errptr != IntPtr.Zero)
319-
throw new RocksDbException(errptr);
320-
}
321-
322-
public void rocksdb_sstfilewriter_open(IntPtr writer, string name)
323-
{
324-
rocksdb_sstfilewriter_open(writer, name, out IntPtr errptr);
325-
if (errptr != IntPtr.Zero)
326-
throw new RocksDbException(errptr);
327-
}
328-
329-
public void rocksdb_sstfilewriter_finish(IntPtr writer)
330-
{
331-
rocksdb_sstfilewriter_finish(writer, out IntPtr errptr);
332-
if (errptr != IntPtr.Zero)
333-
throw new RocksDbException(errptr);
334-
}
335-
336-
public void rocksdb_writebatch_rollback_to_save_point(IntPtr writeBatch)
337-
{
338-
rocksdb_writebatch_rollback_to_save_point(writeBatch, out IntPtr errptr);
339-
if (errptr != IntPtr.Zero)
340-
throw new RocksDbException(errptr);
341-
}
342-
343-
public void rocksdb_writebatch_pop_save_point(IntPtr writeBatch)
344-
{
345-
rocksdb_writebatch_pop_save_point(writeBatch, out IntPtr errptr);
346-
if (errptr != IntPtr.Zero)
347-
throw new RocksDbException(errptr);
348-
}
349-
350-
public void rocksdb_writebatch_wi_rollback_to_save_point(IntPtr writeBatch)
351-
{
352-
rocksdb_writebatch_wi_rollback_to_save_point(writeBatch, out IntPtr errptr);
353-
if (errptr != IntPtr.Zero)
354-
throw new RocksDbException(errptr);
355-
}
356-
357161
public void rocksdb_ingest_external_file(IntPtr db, string[] file_list, ulong list_len, IntPtr opt)
358162
{
359163
UIntPtr llen = (UIntPtr)list_len;
@@ -370,20 +174,6 @@ public void rocksdb_ingest_external_file_cf(IntPtr db, IntPtr handle, string[] f
370174
throw new RocksDbException(errptr);
371175
}
372176

373-
public unsafe void rocksdb_sstfilewriter_add(
374-
IntPtr writer,
375-
byte* key,
376-
ulong keylen,
377-
byte* val,
378-
ulong vallen)
379-
{
380-
UIntPtr sklength = (UIntPtr)keylen;
381-
UIntPtr svlength = (UIntPtr)vallen;
382-
rocksdb_sstfilewriter_add(writer, key, sklength, val, svlength, out IntPtr errptr);
383-
if (errptr != IntPtr.Zero)
384-
throw new RocksDbException(errptr);
385-
}
386-
387177
public unsafe void rocksdb_sstfilewriter_add(
388178
IntPtr writer,
389179
byte[] key,
@@ -410,46 +200,12 @@ public unsafe void rocksdb_sstfilewriter_add(
410200
throw new RocksDbException(errptr);
411201
}
412202

413-
public void rocksdb_sstfilewriter_put(
414-
/*(rocksdb_sstfilewriter_t*)*/ IntPtr writer,
415-
/*(const char*)*/ byte[] key,
416-
size_t keylen,
417-
/*(const char*)*/ byte[] val,
418-
size_t vallen)
419-
{
420-
rocksdb_sstfilewriter_put(writer, key, keylen, val, vallen, out IntPtr errptr);
421-
if (errptr != IntPtr.Zero)
422-
throw new RocksDbException(errptr);
423-
}
424-
425-
public void rocksdb_sstfilewriter_merge(
426-
/*(rocksdb_sstfilewriter_t*)*/ IntPtr writer,
427-
/*(const char*)*/ byte[] key,
428-
size_t keylen,
429-
/*(const char*)*/ byte[] val,
430-
size_t vallen)
431-
{
432-
rocksdb_sstfilewriter_merge(writer, key, keylen, val, vallen, out IntPtr errptr);
433-
if (errptr != IntPtr.Zero)
434-
throw new RocksDbException(errptr);
435-
}
436-
437-
public void rocksdb_sstfilewriter_delete(
438-
/*(rocksdb_sstfilewriter_t*)*/ IntPtr writer,
439-
/*(const char*)*/ byte[] key,
440-
size_t keylen)
441-
{
442-
rocksdb_sstfilewriter_delete(writer, key, keylen, out IntPtr errptr);
443-
if (errptr != IntPtr.Zero)
444-
throw new RocksDbException(errptr);
445-
}
446-
447203
public string rocksdb_writebatch_wi_get_from_batch(
448204
IntPtr wb,
449205
IntPtr options,
450206
string key,
451207
ColumnFamilyHandle cf,
452-
Encoding encoding = null)
208+
System.Text.Encoding encoding = null)
453209
{
454210
var result = rocksdb_writebatch_wi_get_from_batch(wb, options, key, out IntPtr errptr, cf, encoding);
455211
if (errptr != IntPtr.Zero)
@@ -494,7 +250,7 @@ public string rocksdb_writebatch_wi_get_from_batch_and_db(
494250
IntPtr read_options,
495251
string key,
496252
ColumnFamilyHandle cf,
497-
Encoding encoding = null)
253+
System.Text.Encoding encoding = null)
498254
{
499255
var result = rocksdb_writebatch_wi_get_from_batch_and_db(wb, db, read_options, key, out IntPtr errptr, cf, encoding);
500256
if (errptr != IntPtr.Zero)

0 commit comments

Comments
 (0)