C++ client unable to access the blob data #858
-
Describe your problemI was trying to use the c++ client to put "hello vineyard" into the vineyard instance and get "hello vineyard" from the instance. However, the blob that I got from the vineyard instance can not provide the "hello vineyard". If is is a bug report, to help us reproducing this bug, please provide information below:
My main.cc #include<vineyard/client/client.h>
#include<vineyard/client/ds/blob.h>
#include<vineyard/client/ds/core_types.h>
#include<vineyard/client/ds/i_object.h>
using namespace vineyard;
int main(){
vineyard::Client* c = new vineyard::Client();
VINEYARD_CHECK_OK( c->Connect("/var/run/vineyard.sock3"));
//create a metadata and store it in the vineyard instance
auto id = vineyard::InvalidObjectID();
auto om = vineyard::ObjectMeta();
om.AddKeyValue("date","xxx");
om.AddKeyValue("location","xxx");
om.SetTypeName("string");
std::string str ( "Hello Vineyard");
std::unique_ptr<BlobWriter> blob;
VINEYARD_CHECK_OK(c->CreateBlob(str.size(), blob));
std::memcpy(blob->data(), str.c_str(), str.size());
om.AddMember("_buffer",blob->Seal(*c));
std::cout<<blob->data()<<"blob size"<<blob->size()<<std::endl;
VINEYARD_CHECK_OK(c->CreateMetaData(om,id));
//get the object from vienayrd instance
std::unique_ptr<ObjectMeta> rom;//received object meta
c->GetMetaData(id,*rom);
auto buffer = rom->GetMember("_buffer");
// auto receivedBlob = std::reinterpret_pointer_cast<Blob>(buffer);
auto receivedBlob = std::dynamic_pointer_cast<vineyard::Blob>(buffer);
receivedBlob->data();
std::cout<<receivedBlob->data()<<std::endl;
}
My CMakeLists.txt: PROJECT(FuseWrapper)
SET(SRC_LIST main.cc)
set(VINEYARD_CLIENT_HEADER /usr/local/include)
set(VINEYARD_HEADER /usr/local/include/vineyard)
set(VINEYARD_COMMON_HEADER /usr/local/include/vineyard/common)
set(VINEYARD_CONTRIB_HEADER /usr/local/include/vineyard/contrib)
# set(VIENYARD_CLIENT_DS_HEADER /usr/local/include/vineyard/client/ds)
link_directories(BEFORE /usr/local/lib)
include_directories(BEFORE SYSTEM ${VINEYARD_CLIENT_HEADER} ${VINEYARD_HEADER} ${VINEYARD_COMMON_HEADER} ${VINEYARD_CONTRIB_HEADER})
add_executable(hello_vineyard ${SRC_LIST})
set_property(TARGET hello_vineyard PROPERTY CXX_STANDARD 14)
# target_link_libraries(hello_vineyard -L)
target_link_libraries(hello_vineyard PUBLIC vineyard_client
vineyard_basic)
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Beta Was this translation helpful? Give feedback.
-
The error is because you are dereferencing a null //get the object from vienayrd instance
- std::unique_ptr<ObjectMeta> rom;//received object meta
+ std::unique_ptr<ObjectMeta> rom(new ObjectMeta{});//received object meta
c->GetMetaData(id,*rom);
auto buffer = rom->GetMember("_buffer");
// auto receivedBlob = std::reinterpret_pointer_cast<Blob>(buffer);
auto receivedBlob = std::dynamic_pointer_cast<vineyard::Blob>(buffer);
receivedBlob->data();
std::cout<<receivedBlob->data()<<std::endl; |
Beta Was this translation helpful? Give feedback.
-
Close as answered. |
Beta Was this translation helpful? Give feedback.
The error is because you are dereferencing a null
std::unique_ptr
. To make your code work, you need