cloud_api_types: Add types for WebSocket protocol (#35753)
This PR adds types for the Cloud WebSocket protocol to the `cloud_api_types` crate. Release Notes: - N/A
This commit is contained in:
parent
53a3270410
commit
6ac4a57fce
5 changed files with 34 additions and 0 deletions
|
@ -12,7 +12,9 @@ workspace = true
|
|||
path = "src/cloud_api_types.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
chrono.workspace = true
|
||||
ciborium.workspace = true
|
||||
cloud_llm_client.workspace = true
|
||||
serde.workspace = true
|
||||
workspace-hack.workspace = true
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
mod timestamp;
|
||||
pub mod websocket_protocol;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
28
crates/cloud_api_types/src/websocket_protocol.rs
Normal file
28
crates/cloud_api_types/src/websocket_protocol.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use anyhow::{Context as _, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The version of the Cloud WebSocket protocol.
|
||||
pub const PROTOCOL_VERSION: u32 = 0;
|
||||
|
||||
/// The name of the header used to indicate the protocol version in use.
|
||||
pub const PROTOCOL_VERSION_HEADER_NAME: &str = "x-zed-protocol-version";
|
||||
|
||||
/// A message from Cloud to the Zed client.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum MessageToClient {
|
||||
/// The user was updated and should be refreshed.
|
||||
UserUpdated,
|
||||
}
|
||||
|
||||
impl MessageToClient {
|
||||
pub fn serialize(&self) -> Result<Vec<u8>> {
|
||||
let mut buffer = Vec::new();
|
||||
ciborium::into_writer(self, &mut buffer).context("failed to serialize message")?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn deserialize(data: &[u8]) -> Result<Self> {
|
||||
ciborium::from_reader(data).context("failed to deserialize message")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue