Skip to content

Commit 4cfedb5

Browse files
authored
Merge pull request #48 from Lihis/json-as-non-formatted
Send JSON without formatting
2 parents 39f417c + 2b401c4 commit 4cfedb5

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

gui/Logger/JobSender.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <curl/curl.h>
2424
#include <sstream>
2525
#include <json/reader.h>
26+
#include <json/writer.h>
2627
#ifdef _WIN32
2728
#include <wincrypt.h>
2829
#include <windows.h>
@@ -170,6 +171,14 @@ std::string JobSender::generate_url(const std::string &endpoint) {
170171
return url;
171172
}
172173

174+
std::string JobSender::json_to_string(const Json::Value &json) {
175+
Json::StreamWriterBuilder builder;
176+
177+
builder["indentation"] = "";
178+
179+
return Json::writeString(builder, json);
180+
}
181+
173182
bool JobSender::query_capabilities() {
174183
std::string url = generate_url("capabilities");
175184
wxString response;
@@ -214,7 +223,7 @@ bool JobSender::send_job() {
214223

215224
job.Serialize(json);
216225

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

250-
send_data(url, json.toStyledString().c_str(), response, error);
259+
send_data(url, json_to_string(json).c_str(), response, error);
251260
}
252261

253262
void JobSender::send_fine() {
@@ -268,7 +277,7 @@ void JobSender::send_fine() {
268277

269278
fine.Serialize(json);
270279

271-
long code = send_data(url, json.toStyledString().c_str(), response, error);
280+
long code = send_data(url, json_to_string(json).c_str(), response, error);
272281
if (code != 200L) {
273282
LockGuard lock(m_lock);
274283
m_fine_queue.push_front(fine);

gui/Logger/JobSender.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ class JobSender : public wxThreadHelper {
101101
*/
102102
std::string generate_url(const std::string &endpoint);
103103

104+
/**
105+
* Convert Json::Value @p json to string
106+
*
107+
* @param json - Json::Value to convert
108+
* @return std::string
109+
*/
110+
static std::string json_to_string(const Json::Value &json);
111+
104112
/**
105113
* Query server of it's capabilities
106114
*

gui/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void MainWindow::server_changed() {
152152
m_sender->serverChanged();
153153
}
154154

155-
void MainWindow::on_about(wxCommandEvent &event) {
155+
void MainWindow::on_about(wxCommandEvent &/*event*/) {
156156
AboutDialog dialog(this);
157157
dialog.ShowModal();
158158
}

0 commit comments

Comments
 (0)