-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrocksdb_get2.patch
More file actions
64 lines (60 loc) · 1.81 KB
/
Copy pathrocksdb_get2.patch
File metadata and controls
64 lines (60 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
commit ae15c5220e084ec88db6f500e19f4df36d213aa8
Author: Evgenii Gurianov <whats.eternal@gmail.com>
Date: Tue Dec 26 16:02:27 2017 +0300
add rocksdb_get2
diff --git a/db/c.cc b/db/c.cc
index b00f4a9..4c85950 100644
--- a/db/c.cc
+++ b/db/c.cc
@@ -817,6 +817,32 @@ char* rocksdb_get(
return result;
}
+// return the length of the value
+// if buflen is less then the value length
+// than nothing is copied
+
+size_t rocksdb_get2(
+ rocksdb_t* db,
+ const rocksdb_readoptions_t* options,
+ const char* key, size_t keylen,
+ char* buf, size_t buflen,
+ char** errptr) {
+ size_t vallen = 0;
+ std::string tmp;
+ Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp);
+ if (s.ok()) {
+ vallen = tmp.size();
+ if (buflen > vallen) {
+ memcpy(buf, tmp.data(), sizeof(char) * tmp.size());
+ }
+ } else {
+ if (!s.IsNotFound()) {
+ SaveError(errptr, s);
+ }
+ }
+ return vallen;
+}
+
char* rocksdb_get_cf(
rocksdb_t* db,
const rocksdb_readoptions_t* options,
diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h
index b4ed9b4..474a6f4 100644
--- a/include/rocksdb/c.h
+++ b/include/rocksdb/c.h
@@ -262,6 +262,16 @@ extern ROCKSDB_LIBRARY_API char* rocksdb_get(
rocksdb_t* db, const rocksdb_readoptions_t* options, const char* key,
size_t keylen, size_t* vallen, char** errptr);
+/* Returns the length of the value
+ If buflen is less then the value length
+ than nothing is copied */
+extern ROCKSDB_LIBRARY_API size_t rocksdb_get2(
+ rocksdb_t* db,
+ const rocksdb_readoptions_t* options,
+ const char* key, size_t keylen,
+ char* buf, size_t buflen,
+ char** errptr);
+
extern ROCKSDB_LIBRARY_API char* rocksdb_get_cf(
rocksdb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,