forked from eranif/codelite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageWithParams.cpp
More file actions
52 lines (42 loc) · 1.18 KB
/
MessageWithParams.cpp
File metadata and controls
52 lines (42 loc) · 1.18 KB
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
#include "LSP/MessageWithParams.h"
#include "JSON.h"
#include <sstream>
#include <wx/string.h>
JSONItem LSP::MessageWithParams::ToJSON() const
{
JSONItem json = Message::ToJSON();
json.addProperty("method", GetMethod());
if (m_params) {
json.addProperty("params", m_params->ToJSON());
}
return json;
}
void LSP::MessageWithParams::FromJSON(const JSONItem& json)
{
// we don't need to un-serialize a request object
wxUnusedVar(json);
}
std::string LSP::MessageWithParams::ToString() const
{
// Serialize the object and construct a JSON-RPC message
JSONItem json = ToJSON();
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 << "Content-Type: application/json; charset=utf-8" << "\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;
}