kernel_sidecar/jupyter/message.rs
1/*
2For the most part, Message<T> isn't something you as a developer will use in application code.
3
4For creating requests from client to kernel, the impl From<T> for Request is in the appropriate
5message_content files, where Message<T> is used as part of that impl.
6
7For deserialiing responses from kernel to client, the impl From<WireProtocol> for Response creates
8the appropriate Message<T> based on the msg_type in the header.
9
10Ref: https://jupyter-client.readthedocs.io/en/latest/messaging.html#a-full-message
11*/
12use crate::jupyter::header::Header;
13use crate::jupyter::metadata::Metadata;
14use serde::{Deserialize, Serialize};
15
16#[derive(Debug, Serialize, Deserialize)]
17pub struct Message<T> {
18 pub header: Header,
19 pub parent_header: Option<Header>,
20 pub metadata: Option<Metadata>,
21 pub content: T,
22}
23
24impl<T> Message<T> {
25 pub fn parent_msg_id(&self) -> Option<String> {
26 self.parent_header
27 .as_ref()
28 .map(|header| header.msg_id.to_owned())
29 }
30
31 pub fn msg_type(&self) -> String {
32 self.header.msg_type.to_owned()
33 }
34}