Skip to content

Commit

Permalink
GUI: JobSender: send JSON as non-formatted string
Browse files Browse the repository at this point in the history
  • Loading branch information
Lihis committed Aug 9, 2020
1 parent 0aafa46 commit 2b401c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gui/Logger/JobSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <curl/curl.h>
#include <sstream>
#include <json/reader.h>
#include <json/writer.h>
#ifdef _WIN32
#include <wincrypt.h>
#include <windows.h>
Expand Down Expand Up @@ -170,6 +171,14 @@ std::string JobSender::generate_url(const std::string &endpoint) {
return url;
}

std::string JobSender::json_to_string(const Json::Value &json) {
Json::StreamWriterBuilder builder;

builder["indentation"] = "";

return Json::writeString(builder, json);
}

bool JobSender::query_capabilities() {
std::string url = generate_url("capabilities");
wxString response;
Expand Down Expand Up @@ -214,7 +223,7 @@ bool JobSender::send_job() {

job.Serialize(json);

long code = send_data(url, json.toStyledString().c_str(), response, error);
long code = send_data(url, json_to_string(json).c_str(), response, error);
if (code != 200L) {
auto event = new wxThreadEvent(wxEVT_COMMAND_THREAD, wxID_ABORT);
event->SetString("API returned error code: " + std::to_string(code) + " " + error);
Expand Down Expand Up @@ -247,7 +256,7 @@ void JobSender::send_truck() {
json["speed"] = truck.speed;
truck.position.Serialize(json);

send_data(url, json.toStyledString().c_str(), response, error);
send_data(url, json_to_string(json).c_str(), response, error);
}

void JobSender::send_fine() {
Expand All @@ -268,7 +277,7 @@ void JobSender::send_fine() {

fine.Serialize(json);

long code = send_data(url, json.toStyledString().c_str(), response, error);
long code = send_data(url, json_to_string(json).c_str(), response, error);
if (code != 200L) {
LockGuard lock(m_lock);
m_fine_queue.push_front(fine);
Expand Down
8 changes: 8 additions & 0 deletions gui/Logger/JobSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ class JobSender : public wxThreadHelper {
*/
std::string generate_url(const std::string &endpoint);

/**
* Convert Json::Value @p json to string
*
* @param json - Json::Value to convert
* @return std::string
*/
static std::string json_to_string(const Json::Value &json);

/**
* Query server of it's capabilities
*
Expand Down

0 comments on commit 2b401c4

Please sign in to comment.