use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub enum DataEncoding {
#[default]
Base64,
RawJson,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct StartConfig {
pub url: String,
pub token: Option<String>,
pub name: Option<String>,
pub version: Option<String>,
pub channels: Vec<String>,
pub use_protobuf: bool,
pub read_timeout: Option<u64>,
#[serde(default)]
pub http_stream_url: Option<String>,
#[serde(default)]
pub headers: Option<std::collections::HashMap<String, String>>,
#[serde(default)]
pub request_token: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ChannelConfig {
pub name: String,
pub token: Option<String>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SubscribeOptions {
pub channel: String,
pub token: Option<String>,
pub recoverable: Option<bool>,
pub join_leave: Option<bool>,
pub positioned: Option<bool>,
#[serde(default)]
pub delta: Option<bool>,
#[serde(default)]
pub since: Option<StreamPositionData>,
}
impl SubscribeOptions {
pub fn channel(channel: impl Into<String>) -> Self {
Self {
channel: channel.into(),
token: None,
recoverable: None,
join_leave: None,
positioned: None,
delta: None,
since: None,
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct StreamPositionData {
pub offset: u64,
pub epoch: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PublishRequest {
pub channel: String,
pub data: String,
pub data_encoding: Option<DataEncoding>,
pub r#type: Option<i32>,
pub key: Option<String>,
pub removed: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RpcRequest {
pub method: String,
pub data: String,
pub data_encoding: Option<DataEncoding>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PresenceRequest {
pub channel: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PresenceStatsRequest {
pub channel: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct HistoryRequest {
pub channel: String,
pub limit: Option<u32>,
pub since: Option<String>,
pub reverse: Option<bool>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SendRequest {
pub data: String,
pub data_encoding: Option<DataEncoding>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RefreshRequest {
pub token: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SubRefreshRequest {
pub channel: String,
pub token: String,
pub items: Option<Vec<KeyedItem>>,
pub untrack_keys: Option<Vec<String>>,
pub r#type: Option<i32>,
pub signature: Option<String>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KeyedItem {
pub key: String,
pub version: u64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConnectionStatus {
pub ts: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ChannelStatus {
pub channel: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ErrorData {
pub error: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PublicationData {
pub channel: String,
pub data: String,
pub data_encoding: Option<DataEncoding>,
pub raw_json: Option<serde_json::Value>,
pub offset: Option<u64>,
pub info: Option<ClientInfoData>,
pub tags: Option<std::collections::HashMap<String, String>>,
pub timestamp: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ClientInfoData {
pub client: String,
pub user: String,
pub conn_info: String,
pub chan_info: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RpcResponse {
pub method: String,
pub data: String,
pub timestamp: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PresenceResponse {
pub channel: String,
pub clients: Vec<String>,
pub timestamp: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PresenceStatsResponse {
pub channel: String,
pub num_clients: u32,
pub num_users: u32,
pub timestamp: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct HistoryResponse {
pub channel: String,
pub publications: Vec<PublicationData>,
pub timestamp: i64,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PingResponse {
pub timestamp: i64,
}