diff options
author | trinity-1686a <trinity@deuxfleurs.fr> | 2022-06-05 15:33:43 +0200 |
---|---|---|
committer | trinity-1686a <trinity@deuxfleurs.fr> | 2022-06-05 15:33:43 +0200 |
commit | 368ba908794901bc793c6a087c02241be046bdf2 (patch) | |
tree | 389910f1e1476c9531a01d2e53060e1056cca266 /src/util.rs | |
parent | 648e015e3a73b96973343e0a1f861c9ea41cc24d (diff) | |
download | netapp-368ba908794901bc793c6a087c02241be046bdf2.tar.gz netapp-368ba908794901bc793c6a087c02241be046bdf2.zip |
initial work on associated stream
still require testing, and fixing a few kinks:
- sending packets > 16k truncate them
- send one more packet than it could at eos
- probably update documentation
/!\ contains breaking changes
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/util.rs b/src/util.rs index f4dfac7..4333080 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,10 @@ +use crate::endpoint::SerializeMessage; + use std::net::SocketAddr; use std::net::ToSocketAddrs; +use std::pin::Pin; -use serde::Serialize; +use futures::Stream; use log::info; @@ -14,21 +17,25 @@ pub type NodeKey = sodiumoxide::crypto::sign::ed25519::SecretKey; /// A network key pub type NetworkKey = sodiumoxide::crypto::auth::Key; +pub type AssociatedStream = Pin<Box<dyn Stream<Item = Vec<u8>> + Send>>; + /// Utility function: encodes any serializable value in MessagePack binary format /// using the RMP library. /// /// Field names and variant names are included in the serialization. /// This is used internally by the netapp communication protocol. -pub fn rmp_to_vec_all_named<T>(val: &T) -> Result<Vec<u8>, rmp_serde::encode::Error> +pub fn rmp_to_vec_all_named<T>( + val: &T, +) -> Result<(Vec<u8>, Option<AssociatedStream>), rmp_serde::encode::Error> where - T: Serialize + ?Sized, + T: SerializeMessage + ?Sized, { let mut wr = Vec::with_capacity(128); let mut se = rmp_serde::Serializer::new(&mut wr) .with_struct_map() .with_string_variants(); - val.serialize(&mut se)?; - Ok(wr) + let (_, stream) = val.serialize_msg(&mut se)?; + Ok((wr, stream)) } /// This async function returns only when a true signal was received |