I've tested following code for inserting integer values like uint64_t to the rocksdb database using casting . Is that a correct approach ?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
#include<unistd.h>
#include<stdint.h>
const char DBPath[] = "/tmp/test_sample";
#include "rocksdb/c.h"
int main(int argc, char **argv){
// Intialize basic parameters
rocksdb_t *db;
rocksdb_options_t *options = rocksdb_options_create();
// Create the database if it's not already present
rocksdb_options_set_create_if_missing(options,1);
// Open database
char *err = NULL;
db = rocksdb_open(options,DBPath,&err);
assert(!err);
//Put key value
//Insert insert value to the database
rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create();
int intKey = 256;
int intValue = 256*256;
const char* key;
const char* value;
//Convert integer value to char array
key = (char*)&intKey;
value = (char*)&intValue ;
rocksdb_put(db,writeoptions,key,strlen(key),value,strlen(value) + 1,&err);
assert(!err);
//Cleanup
rocksdb_writeoptions_destroy(writeoptions);
rocksdb_options_destroy(options);
rocksdb_close(db);
return 0;
}
I have referred the following reference Can integer keys / values be stored in LevelDB?