diff --git a/cpp/negentropy_wrapper.c b/cpp/negentropy_wrapper.c index 501e86d..9dc9277 100644 --- a/cpp/negentropy_wrapper.c +++ b/cpp/negentropy_wrapper.c @@ -42,23 +42,19 @@ void* negentropy_new(void* storage, uint64_t frameSizeLimit){ return ne; } -void negentropy_initiate(void* negentropy, void (*callback)(const char* buf, size_t len)){ +const char* negentropy_initiate(void* negentropy){ Negentropy* ngn_inst; ngn_inst = reinterpret_cast*>(negentropy); - std::string output; + std::string* output = new std::string(); try { - output = ngn_inst->initiate(); - std::cout << "output of initiate is, len:" << output.size() << std::hex << output << std::endl; + *output = ngn_inst->initiate(); + std::cout << "output of initiate is, len:" << output->size() << std::hex << *output << std::endl; } catch(negentropy::err e){ //TODO:Find a way to return this error - callback(NULL,0); - return ; + return NULL; } - callback(output.c_str(), output.size()); - //TODO: Avoid copy and use a callback - //memcpy(buf, output, output.size()) - return ; + return output->c_str(); } void negentropy_setinitiator(void* negentropy){ diff --git a/cpp/negentropy_wrapper.h b/cpp/negentropy_wrapper.h index 0416b54..4210816 100644 --- a/cpp/negentropy_wrapper.h +++ b/cpp/negentropy_wrapper.h @@ -1,3 +1,4 @@ + #ifndef _NEGENTROPY_WRAPPER_H #define _NEGENTROPY_WRAPPER_H @@ -19,7 +20,7 @@ EXTERNC void* storage_new(const char* db_path, const char* name); EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit); -EXTERNC void negentropy_initiate(void* negentropy, void *(const char* buf, size_t len)); +EXTERNC const char* negentropy_initiate(void* negentropy); EXTERNC void negentropy_setinitiator(void* negentropy);