C API: support constructing write batch from serialized representation
This commit is contained in:
parent
d33657a4a5
commit
9fc23d0c56
7
db/c.cc
7
db/c.cc
@ -607,6 +607,13 @@ rocksdb_writebatch_t* rocksdb_writebatch_create() {
|
|||||||
return new rocksdb_writebatch_t;
|
return new rocksdb_writebatch_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rocksdb_writebatch_t* rocksdb_writebatch_create_from(const char* rep,
|
||||||
|
size_t size) {
|
||||||
|
rocksdb_writebatch_t* b = new rocksdb_writebatch_t;
|
||||||
|
b->rep = WriteBatch(std::string(rep, size));
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
void rocksdb_writebatch_destroy(rocksdb_writebatch_t* b) {
|
void rocksdb_writebatch_destroy(rocksdb_writebatch_t* b) {
|
||||||
delete b;
|
delete b;
|
||||||
}
|
}
|
||||||
|
18
db/c_test.c
18
db/c_test.c
@ -299,6 +299,24 @@ int main(int argc, char** argv) {
|
|||||||
rocksdb_writebatch_destroy(wb);
|
rocksdb_writebatch_destroy(wb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartPhase("writebatch_rep");
|
||||||
|
{
|
||||||
|
rocksdb_writebatch_t* wb1 = rocksdb_writebatch_create();
|
||||||
|
rocksdb_writebatch_put(wb1, "baz", 3, "d", 1);
|
||||||
|
rocksdb_writebatch_put(wb1, "quux", 4, "e", 1);
|
||||||
|
rocksdb_writebatch_delete(wb1, "quux", 4);
|
||||||
|
size_t repsize1 = 0;
|
||||||
|
const char* rep = rocksdb_writebatch_data(wb1, &repsize1);
|
||||||
|
rocksdb_writebatch_t* wb2 = rocksdb_writebatch_create_from(rep, repsize1);
|
||||||
|
CheckCondition(rocksdb_writebatch_count(wb1) ==
|
||||||
|
rocksdb_writebatch_count(wb2));
|
||||||
|
size_t repsize2 = 0;
|
||||||
|
CheckCondition(
|
||||||
|
memcmp(rep, rocksdb_writebatch_data(wb2, &repsize2), repsize1) == 0);
|
||||||
|
rocksdb_writebatch_destroy(wb1);
|
||||||
|
rocksdb_writebatch_destroy(wb2);
|
||||||
|
}
|
||||||
|
|
||||||
StartPhase("iter");
|
StartPhase("iter");
|
||||||
{
|
{
|
||||||
rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
|
rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
|
||||||
|
@ -205,6 +205,8 @@ extern void rocksdb_iter_get_error(const rocksdb_iterator_t*, char** errptr);
|
|||||||
/* Write batch */
|
/* Write batch */
|
||||||
|
|
||||||
extern rocksdb_writebatch_t* rocksdb_writebatch_create();
|
extern rocksdb_writebatch_t* rocksdb_writebatch_create();
|
||||||
|
extern rocksdb_writebatch_t* rocksdb_writebatch_create_from(const char* rep,
|
||||||
|
size_t size);
|
||||||
extern void rocksdb_writebatch_destroy(rocksdb_writebatch_t*);
|
extern void rocksdb_writebatch_destroy(rocksdb_writebatch_t*);
|
||||||
extern void rocksdb_writebatch_clear(rocksdb_writebatch_t*);
|
extern void rocksdb_writebatch_clear(rocksdb_writebatch_t*);
|
||||||
extern int rocksdb_writebatch_count(rocksdb_writebatch_t*);
|
extern int rocksdb_writebatch_count(rocksdb_writebatch_t*);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user