Skip to main content

bulk_client/msgs/
subscription.rs

1use serde_json::Value;
2
3/// Subscription request message
4#[derive(Debug, Clone)]
5#[allow(unused)]
6pub struct SubscriptionRequest {
7    sub_type: String,
8    params: Value,
9}
10
11#[allow(unused)]
12impl SubscriptionRequest {
13    pub(crate) fn new(sub_type: impl Into<String>, params: Value) -> Self {
14        Self {
15            sub_type: sub_type.into(),
16            params,
17        }
18    }
19
20    pub(crate) fn to_json(&self) -> Value {
21        let mut obj = serde_json::Map::new();
22        obj.insert("type".into(), Value::String(self.sub_type.clone()));
23        if let Value::Object(map) = &self.params {
24            for (k, v) in map {
25                obj.insert(k.clone(), v.clone());
26            }
27        }
28        Value::Object(obj)
29    }
30}