Skip to content

Commit

Permalink
Merge pull request #48 from Lihis/json-as-non-formatted
Browse files Browse the repository at this point in the history
Send JSON without formatting
  • Loading branch information
Lihis authored Aug 12, 2020
2 parents 39f417c + 2b401c4 commit 4cfedb5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 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
2 changes: 1 addition & 1 deletion gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void MainWindow::server_changed() {
m_sender->serverChanged();
}

void MainWindow::on_about(wxCommandEvent &event) {
void MainWindow::on_about(wxCommandEvent &/*event*/) {
AboutDialog dialog(this);
dialog.ShowModal();
}
Expand Down

0 comments on commit 4cfedb5

Please sign in to comment.