pub enum Message {
Hello {
protocol: u64,
sdk: String,
commands: Vec<String>,
},
Ready {
protocol: u64,
app: AppInfo,
},
Shutdown {
timeout_ms: u64,
},
Request {
id: u64,
cmd: String,
channels: BTreeMap<String, u64>,
window: Option<String>,
payload: Inline,
},
Response {
id: u64,
payload: Inline,
},
Error {
id: u64,
code: Option<String>,
message: Option<String>,
data: Option<Value>,
},
Cancel {
id: u64,
reason: String,
},
Event {
event: String,
target: Option<String>,
window: Option<String>,
payload: Inline,
},
ChannelData {
channel: u64,
payload: Inline,
},
ChannelClose {
channel: u64,
},
}Expand description
帧头,即以 type 字段区分的 JSON 对象。
字段声明顺序即线上顺序,与 Python 模型一致(golden frames 依赖于此);反序列化时忽略未知字段。
Variants§
Hello
Python → Rust:握手首帧,声明协议版本、SDK 版本与已注册的命令。
Ready
Rust → Python:确认握手,Python 收到后执行 ready 钩子。
Shutdown
Rust → Python:请求退出,timeoutMs 是 Python 取消调用并执行 shutdown 钩子的总预算。
Request
Rust → Python:命令调用请求。
Fields
§
id: u64Rust 侧分配的调用 id,在单个 crate::bridge::Bridge 内唯一。
Response
Python → Rust:调用成功的结果。
Error
Python → Rust:调用失败;缺省的 code 按 internal 处理。
Cancel
Rust → Python:取消调用,reason 为 "client" 或 "timeout"。
Event
双向事件。Python → Rust 的事件携带 target,Rust → Python 的事件携带 window。
Fields
ChannelData
Python → Rust:向前端 Channel 推送一条数据。
ChannelClose
Python → Rust:关闭 channel,此后该 channel 的数据被丢弃。
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Forget for Message
impl Freeze for Message
impl Move for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more