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
9358690337
commit
58392b9c13
5 changed files with 34 additions and 0 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3081,7 +3081,9 @@ dependencies = [
|
||||||
name = "cloud_api_types"
|
name = "cloud_api_types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"ciborium",
|
||||||
"cloud_llm_client",
|
"cloud_llm_client",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -461,6 +461,7 @@ bytes = "1.0"
|
||||||
cargo_metadata = "0.19"
|
cargo_metadata = "0.19"
|
||||||
cargo_toml = "0.21"
|
cargo_toml = "0.21"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
|
ciborium = "0.2"
|
||||||
circular-buffer = "1.0"
|
circular-buffer = "1.0"
|
||||||
clap = { version = "4.4", features = ["derive"] }
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
cocoa = "0.26"
|
cocoa = "0.26"
|
||||||
|
|
|
@ -12,7 +12,9 @@ workspace = true
|
||||||
path = "src/cloud_api_types.rs"
|
path = "src/cloud_api_types.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow.workspace = true
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
|
ciborium.workspace = true
|
||||||
cloud_llm_client.workspace = true
|
cloud_llm_client.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
workspace-hack.workspace = true
|
workspace-hack.workspace = true
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
mod timestamp;
|
mod timestamp;
|
||||||
|
pub mod websocket_protocol;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
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