2014-07-25 13:58:00 +04:00
|
|
|
// +build leveldb
|
|
|
|
|
2014-07-07 08:37:16 +04:00
|
|
|
#include "leveldb_ext.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-08-30 13:19:10 +04:00
|
|
|
//#include <string>
|
2014-07-07 08:37:16 +04:00
|
|
|
|
2014-08-30 13:19:10 +04:00
|
|
|
//#include "leveldb/db.h"
|
2014-07-07 08:37:16 +04:00
|
|
|
|
2014-08-30 13:19:10 +04:00
|
|
|
//using namespace leveldb;
|
2014-07-07 08:37:16 +04:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2014-08-30 13:19:10 +04:00
|
|
|
// static bool SaveError(char** errptr, const Status& s) {
|
|
|
|
// assert(errptr != NULL);
|
|
|
|
// if (s.ok()) {
|
|
|
|
// return false;
|
|
|
|
// } else if (*errptr == NULL) {
|
|
|
|
// *errptr = strdup(s.ToString().c_str());
|
|
|
|
// } else {
|
|
|
|
// free(*errptr);
|
|
|
|
// *errptr = strdup(s.ToString().c_str());
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void* leveldb_get_ext(
|
|
|
|
// leveldb_t* db,
|
|
|
|
// const leveldb_readoptions_t* options,
|
|
|
|
// const char* key, size_t keylen,
|
|
|
|
// char** valptr,
|
|
|
|
// size_t* vallen,
|
|
|
|
// char** errptr) {
|
|
|
|
|
|
|
|
// std::string *tmp = new(std::string);
|
|
|
|
|
|
|
|
// //very tricky, maybe changed with c++ leveldb upgrade
|
|
|
|
// Status s = (*(DB**)db)->Get(*(ReadOptions*)options, Slice(key, keylen), tmp);
|
|
|
|
|
|
|
|
// if (s.ok()) {
|
|
|
|
// *valptr = (char*)tmp->data();
|
|
|
|
// *vallen = tmp->size();
|
|
|
|
// } else {
|
|
|
|
// delete(tmp);
|
|
|
|
// tmp = NULL;
|
|
|
|
// *valptr = NULL;
|
|
|
|
// *vallen = 0;
|
|
|
|
// if (!s.IsNotFound()) {
|
|
|
|
// SaveError(errptr, s);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return tmp;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void leveldb_get_free_ext(void* context) {
|
|
|
|
// std::string* s = (std::string*)context;
|
|
|
|
|
|
|
|
// delete(s);
|
|
|
|
// }
|
2014-07-07 08:37:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
unsigned char leveldb_iter_seek_to_first_ext(leveldb_iterator_t* iter) {
|
|
|
|
leveldb_iter_seek_to_first(iter);
|
|
|
|
return leveldb_iter_valid(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char leveldb_iter_seek_to_last_ext(leveldb_iterator_t* iter) {
|
|
|
|
leveldb_iter_seek_to_last(iter);
|
|
|
|
return leveldb_iter_valid(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char leveldb_iter_seek_ext(leveldb_iterator_t* iter, const char* k, size_t klen) {
|
|
|
|
leveldb_iter_seek(iter, k, klen);
|
|
|
|
return leveldb_iter_valid(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char leveldb_iter_next_ext(leveldb_iterator_t* iter) {
|
|
|
|
leveldb_iter_next(iter);
|
|
|
|
return leveldb_iter_valid(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char leveldb_iter_prev_ext(leveldb_iterator_t* iter) {
|
|
|
|
leveldb_iter_prev(iter);
|
|
|
|
return leveldb_iter_valid(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|