1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include "JSON.h"
#include "LSP/MessageWithParams.h"
#include "file_logger.h"
#include "fileutils.h"
#include <sstream>
#include <wx/string.h>
LSP::MessageWithParams::MessageWithParams() {}
LSP::MessageWithParams::~MessageWithParams() {}
JSONItem LSP::MessageWithParams::ToJSON(const wxString& name, IPathConverter::Ptr_t pathConverter) const
{
JSONItem json = Message::ToJSON(name, pathConverter);
json.addProperty("method", GetMethod());
if(m_params) { json.append(m_params->ToJSON("params", pathConverter)); }
return json;
}
void LSP::MessageWithParams::FromJSON(const JSONItem& json, IPathConverter::Ptr_t pathConverter)
{
// we dont need to un-serialize a request object
wxUnusedVar(json);
wxUnusedVar(pathConverter);
}
std::string LSP::MessageWithParams::ToString(IPathConverter::Ptr_t pathConverter) const
{
// Serialize the object and construct a JSON-RPC message
JSONItem json = ToJSON("", pathConverter);
char* data = json.FormatRawString(false);
std::string s;
size_t len = strlen(data);
// Build the request header
std::stringstream ss;
ss << "Content-Length: " << len << "\r\n";
ss << "\r\n";
s = ss.str();
// append the data
s.append(data, len);
// release the buffer
free(data);
return s;
}
LSP::MessageWithParams::Ptr_t LSP::MessageWithParams::MakeRequest(LSP::MessageWithParams* message_ptr)
{
LSP::MessageWithParams::Ptr_t p(message_ptr);
return p;
}
|