summaryrefslogtreecommitdiffstats
path: root/src/transport/mycelium.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/mycelium.rs')
-rw-r--r--src/transport/mycelium.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/transport/mycelium.rs b/src/transport/mycelium.rs
index 4c03839..51bbfab 100644
--- a/src/transport/mycelium.rs
+++ b/src/transport/mycelium.rs
@@ -877,6 +877,7 @@ pub struct HelloRequestShadow {
epoch: EpochShadow,
auth: ByteBuf,
ready: bool,
+ run_id: ByteBuf,
}
#[derive(Serialize, Deserialize)]
@@ -890,6 +891,7 @@ pub struct HelloReplyShadow<'a> {
#[serde(default)]
auth: ByteBuf,
ready: bool,
+ run_id: ByteBuf,
}
#[derive(Serialize, Deserialize)]
@@ -940,6 +942,7 @@ pub fn hello_request_to_bytes(msg: &HelloRequest) -> Result<Vec<u8>, rmp_serde::
epoch: epoch_to_shadow(&msg.epoch),
auth: ByteBuf::from(msg.auth.clone()),
ready: msg.ready,
+ run_id: ByteBuf::from(msg.run_id.to_vec()),
})
}
pub fn bytes_to_hello_request(bytes: &[u8]) -> Result<HelloRequest, TransportError> {
@@ -949,9 +952,17 @@ pub fn bytes_to_hello_request(bytes: &[u8]) -> Result<HelloRequest, TransportErr
epoch: epoch_from_shadow(shadow.epoch)?,
auth: shadow.auth.into_vec(),
ready: shadow.ready,
+ run_id: run_id_from_shadow(&shadow.run_id)?,
})
}
+fn run_id_from_shadow(bytes: &ByteBuf) -> Result<crate::transport::RunId, TransportError> {
+ bytes
+ .as_slice()
+ .try_into()
+ .map_err(|_| TransportError::InvalidPayload("run id must be 16 bytes".into()))
+}
+
// --- HelloReply ---
pub fn hello_reply_to_bytes(msg: &HelloReply) -> Result<Vec<u8>, rmp_serde::encode::Error> {
let shadow = HelloReplyShadow {
@@ -960,6 +971,7 @@ pub fn hello_reply_to_bytes(msg: &HelloReply) -> Result<Vec<u8>, rmp_serde::enco
epoch: epoch_to_shadow(&msg.epoch),
auth: ByteBuf::from(msg.auth.clone()),
ready: msg.ready,
+ run_id: ByteBuf::from(msg.run_id.to_vec()),
};
rmp_serde::to_vec(&shadow)
}
@@ -971,6 +983,7 @@ pub fn bytes_to_hello_reply(bytes: &[u8]) -> Result<HelloReply, TransportError>
epoch: epoch_from_shadow(shadow.epoch)?,
auth: shadow.auth.into_vec(),
ready: shadow.ready,
+ run_id: run_id_from_shadow(&shadow.run_id)?,
})
}