-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resurrect ServerAgent for external tool access #6044
base: master
Are you sure you want to change the base?
Resurrect ServerAgent for external tool access #6044
Conversation
ServerAgent.cpp needs work on JSON Reader and Writer
src/ServerAgent.cpp
Outdated
@@ -153,8 +156,7 @@ void HTTPServerAgent::ThreadMain() | |||
// done with the queue | |||
SDL_UnlockMutex(m_requestQueueLock); | |||
|
|||
Json::FastWriter writer; | |||
req.buffer = writer.write(req.data); | |||
req.buffer = req.data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sturnclaw this is one of the two problems I could do with some advice about, this line is not an equivalent replacement for the writer.write(req.data)
which used to be there which I believe serialised the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want req.buffer = req.data.dump()
; the arguments to the dump function are the amount of indentation and the indent character, neither of which should be used for over-the-wire serialization.
src/ServerAgent.cpp
Outdated
resp.success = reader.parse(resp.buffer, resp.data, false); | ||
if (!resp.success) | ||
resp.buffer = std::string("JSON parse error: " + reader.getFormattedErrorMessages()); | ||
//Json::Reader reader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sturnclaw second is this section which I think deserialised a response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be resp.data = Json::parse(resp.buffer); resp.success = !resp.data.is_null();
. Substitute the !is_null()
check for an is_object()
or is_array()
depending on the wire format of your message type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll likely also need to wrap it in a try block or use a non-throwing method; still getting my development environment back up so that's an exercise left to the reader.
Before this could be considered working it will probably need to use updated libcurl, this was written against 7.40.0 which is considerably out of date being from late 2014. It will also need some testing, and if I recall robn wrote it more as a proof of concept for people to improve and build upon. |
This is not a new feature but after a discussion on the Discord channel I did promise to take a look at it and to stop me forgetting (again) I'm going to track this here as a WIP 😁
Todo: