-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotification.rs
39 lines (32 loc) · 853 Bytes
/
notification.rs
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
use serde::Serialize;
#[derive(Serialize, Debug)]
#[serde(untagged)]
pub enum Params {
Solution(SolutionParams),
Project(ProjectParams),
}
#[derive(Serialize, Debug)]
pub struct Notification {
pub jsonrpc: String,
pub method: String,
pub params: Params,
}
#[derive(Serialize, Debug)]
pub struct SolutionParams {
pub solution: String,
}
#[derive(Serialize, Debug)]
pub struct ProjectParams {
pub projects: Vec<String>,
}
impl Notification {
pub fn serialize(self) -> String {
let body = serde_json::to_string(&self).expect("Unable to serialize notification");
add_content_length_header(&body)
}
}
pub fn add_content_length_header(body: &str) -> String {
let header = format!("Content-Length: {}\r\n\r\n", body.len());
let full_message = format!("{}{}", header, body);
full_message
}