Commit 390fc9e8 authored by legoc's avatar legoc

Adapted to removal of JSON.h from cameo public interface

parent 7cf1bb18
......@@ -15,7 +15,9 @@
*/
#include <cameo/cameo.h>
#include <cameo/JSON.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
using namespace std;
using namespace cameo;
......@@ -27,17 +29,20 @@ int main(int argc, char *argv[]) {
{
string key = "fr.ill.ics.cameo.test.testkey";
json::StringObject valueObject;
valueObject.pushKey("x");
valueObject.pushInt(12);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("x");
writer.Int(12);
writer.EndObject();
application::This::getCom().storeKeyValue(key, valueObject.toString());
application::This::getCom().storeKeyValue(key, buffer.GetString());
try {
string valueString = application::This::getCom().getKeyValue(key);
json::Object value;
json::parse(value, valueString);
rapidjson::Document value;
value.Parse(static_cast<const char *>(valueString.c_str()), valueString.size());
cout << "x = " << value["x"].GetInt() << endl;
......
......@@ -15,7 +15,9 @@
*/
#include <cameo/cameo.h>
#include <cameo/JSON.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
using namespace std;
using namespace cameo;
......@@ -27,14 +29,17 @@ int main(int argc, char *argv[]) {
{
string key = "fr.ill.ics.cameo.test.testkey";
json::StringObject valueObject;
valueObject.pushKey("x");
valueObject.pushInt(12);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("x");
writer.Int(12);
writer.EndObject();
try {
// Sleep 100ms.
this_thread::sleep_for(chrono::milliseconds(100));
application::This::getCom().storeKeyValue(key, valueObject.toString());
application::This::getCom().storeKeyValue(key, buffer.GetString());
// Sleep 100ms.
this_thread::sleep_for(chrono::milliseconds(100));
......
......@@ -15,7 +15,9 @@
*/
#include <cameo/cameo.h>
#include <cameo/JSON.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
#include <iostream>
using namespace std;
......@@ -23,15 +25,20 @@ using namespace cameo;
std::string serializeToJSON(const std::string& message, int i) {
json::StringObject object;
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
object.pushKey("message");
object.pushString("message");
writer.StartObject();
object.pushKey("value");
object.pushInt(i);
writer.Key("message");
writer.String("message");
return object.toString();
writer.Key("value");
writer.Int(i);
writer.EndObject();
return buffer.GetString();
}
int main(int argc, char *argv[]) {
......
......@@ -15,7 +15,9 @@
*/
#include <cameo/cameo.h>
#include <cameo/JSON.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
#include <iostream>
using namespace std;
......@@ -66,8 +68,8 @@ int main(int argc, char *argv[]) {
while (subscriber->receive(message)) {
cout << "Received " << message << endl;
json::Object object;
json::parse(object, message);
rapidjson::Document object;
object.Parse(static_cast<const char *>(message.c_str()), message.size());
cout << "\tmessage : " << object["message"].GetString() << endl;
cout << "\tvalue : " << object["value"].GetInt() << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment