Skip to content
Snippets Groups Projects
Commit 29989ee8 authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

C++: first working version

TODO: compatibility with STR legacy payloads; more varied
access to inner payload objects (e.g. push_back)
parent 9022370f
No related branches found
No related tags found
No related merge requests found
......@@ -185,25 +185,25 @@ set (JSON_TEST_SOURCE
## compile all files to "ipaaca" shared library
#add_library(ipaaca SHARED ${SOURCE})
## and link all the required external libs (found above using find_package etc.)
#target_link_libraries(ipaaca ${LIBS})
# compile all files to "ipaaca" shared library
add_library(ipaaca SHARED ${SOURCE})
# and link all the required external libs (found above using find_package etc.)
target_link_libraries(ipaaca ${LIBS})
add_executable (ipaaca-test-json ${JSON_TEST_SOURCE})
target_link_libraries (ipaaca-test-json ${LIBS})
#add_executable (ipaaca-test-json ${JSON_TEST_SOURCE})
#target_link_libraries (ipaaca-test-json ${LIBS})
set(DEFAULT_BIN_SUBDIR bin)
set(DEFAULT_LIB_SUBDIR lib)
set(DEFAULT_DATA_SUBDIR share/data)
set(DEFAULT_INCLUDE_SUBDIR include)
#set(CMAKE_INSTALL_PREFIX "")
#install (
# TARGETS ipaaca
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib
# )
set(CMAKE_INSTALL_PREFIX "")
install (
TARGETS ipaaca
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(
DIRECTORY include
DESTINATION .
......@@ -214,10 +214,11 @@ install(
DESTINATION include/ipaaca/
)
install (
TARGETS ipaaca-test-json
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
#install (
# TARGETS ipaaca-test-json
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib
# )
......@@ -172,7 +172,7 @@ IPAACA_EXPORT std::string IUConverter::serialize(const AnnotatedData& data, std:
protobuf::PayloadItem* item = pbo->add_payload();
item->set_key(kv.first);
item->set_value( kv.second->to_json_string_representation() );
item->set_type("json");
item->set_type("JSON");
}
for (LinkMap::const_iterator it=obj->_links._links.begin(); it!=obj->_links._links.end(); ++it) {
protobuf::LinkSet* links = pbo->add_links();
......@@ -219,7 +219,7 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
PayloadDocumentEntry::ptr entry;
if (it.type() == "json") {
if (it.type() == "JSON") {
// fully parse json text
entry = PayloadDocumentEntry::from_json_string_representation( it.value() );
} else {
......@@ -257,7 +257,7 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
PayloadDocumentEntry::ptr entry;
if (it.type() == "json") {
if (it.type() == "JSON") {
// fully parse json text
entry = PayloadDocumentEntry::from_json_string_representation( it.value() );
} else {
......@@ -324,7 +324,7 @@ IPAACA_EXPORT std::string MessageConverter::serialize(const AnnotatedData& data,
protobuf::PayloadItem* item = pbo->add_payload();
item->set_key(kv.first);
item->set_value( kv.second->to_json_string_representation() );
item->set_type("json");
item->set_type("JSON");
}
for (LinkMap::const_iterator it=obj->_links._links.begin(); it!=obj->_links._links.end(); ++it) {
protobuf::LinkSet* links = pbo->add_links();
......@@ -368,7 +368,7 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
PayloadDocumentEntry::ptr entry;
if (it.type() == "json") {
if (it.type() == "JSON") {
// fully parse json text
entry = PayloadDocumentEntry::from_json_string_representation( it.value() );
} else {
......@@ -405,7 +405,7 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
PayloadDocumentEntry::ptr entry;
if (it.type() == "json") {
if (it.type() == "JSON") {
// fully parse json text
entry = PayloadDocumentEntry::from_json_string_representation( it.value() );
} else {
......@@ -454,7 +454,7 @@ IPAACA_EXPORT std::string IUPayloadUpdateConverter::serialize(const AnnotatedDat
protobuf::PayloadItem* item = pbo->add_new_items();
item->set_key(kv.first);
item->set_value( kv.second->to_json_string_representation() );
item->set_type("json");
item->set_type("JSON");
}
for (auto& key: obj->keys_to_remove) {
pbo->add_keys_to_remove(key);
......@@ -477,7 +477,7 @@ AnnotatedData IUPayloadUpdateConverter::deserialize(const std::string& wireSchem
for (int i=0; i<pbo->new_items_size(); i++) {
const protobuf::PayloadItem& it = pbo->new_items(i);
PayloadDocumentEntry::ptr entry;
if (it.type() == "json") {
if (it.type() == "JSON") {
// fully parse json text
entry = PayloadDocumentEntry::from_json_string_representation( it.value() );
IPAACA_INFO("New/updated payload entry: " << it.key() << " -> " << it.value() )
......
......@@ -160,14 +160,14 @@ int iu_main(int argc, char** argv)
if (event_type==IU_ADDED) {
std::cout << "Received a new IU, payload: " << iu->payload() << std::endl;
std::cout << "Will write something." << std::endl;
// iu->commit();
//iu->commit();
iu->payload()["list"][0] = "Overridden from C++";
}
});
std::cout << "--- Waiting for IUs for 10s " << std::endl;
sleep(10);
return 0;
ipaaca::OutputBuffer::ptr ob = ipaaca::OutputBuffer::create("jsonTestSender");
ob->register_handler([](ipaaca::IUInterface::ptr iu, ipaaca::IUEventType event_type, bool local) {
std::cout << "Received remote update, new payload: " << iu->payload() << std::endl;
......@@ -186,8 +186,7 @@ int iu_main(int argc, char** argv)
std::cout << iu->payload()["map"] << std::endl;
//
std::cout << "--- Creating a list" << std::endl;
std::vector<long> newlist = { 1, 0 };
iu->payload()["list"] = newlist;
iu->payload()["list"] = std::vector<long>{1, 0} ;
std::cout << "--- Waiting for changes for 5s " << std::endl;
sleep(5);
std::cout << "--- Final map " << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment