kernel_sidecar/jupyter/
request.rs

1/*
2This file is all about serializing messages going from Client to Kernel.
3
4message_content T -> Message<T> -> Request -> WireProtocol -> zeromq::ZmqMessage
5
6The impl's for message_content T -> Message<T> -> Request are in individual message_content files
7*/
8
9use crate::jupyter::message::Message;
10use crate::jupyter::shell_content::execute::ExecuteRequest;
11use crate::jupyter::shell_content::kernel_info::KernelInfoRequest;
12use crate::jupyter::wire_protocol::WireProtocol;
13
14#[derive(Debug)]
15pub enum Request {
16    KernelInfo(Message<KernelInfoRequest>),
17    Execute(Message<ExecuteRequest>),
18}
19
20impl Request {
21    pub fn msg_id(&self) -> String {
22        // return msg_id from header
23        match self {
24            Request::KernelInfo(msg) => msg.header.msg_id.to_owned(),
25            Request::Execute(msg) => msg.header.msg_id.to_owned(),
26        }
27    }
28
29    pub fn into_wire_protocol(&self, hmac_signing_key: &str) -> WireProtocol {
30        match self {
31            Request::KernelInfo(msg) => WireProtocol::new(
32                msg.header.clone(),
33                Some(msg.content.clone()),
34                hmac_signing_key,
35            ),
36            Request::Execute(msg) => WireProtocol::new(
37                msg.header.clone(),
38                Some(msg.content.clone()),
39                hmac_signing_key,
40            ),
41        }
42    }
43}