Debian Codegraph @

CodeLite/LSP/MessageWithParams.cpp

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