@@ -22,6 +22,7 @@ use thiserror::Error;
2222use tokio_stream:: Stream ;
2323use tracing:: { debug, trace} ;
2424
25+ /// Malformed message body
2526#[ derive( Error , Debug ) ]
2627#[ error( "Malformed message body for {0:?}: {1}" ) ]
2728pub struct MalformedBody ( MsgKind , MessageBodyError ) ;
@@ -32,6 +33,7 @@ impl MalformedBody {
3233 }
3334}
3435
36+ /// Error while parsing the message body
3537#[ derive( Error , Debug ) ]
3638#[ non_exhaustive]
3739pub enum MessageBodyError {
@@ -55,6 +57,11 @@ impl From<String> for MessageBodyError {
5557 }
5658}
5759
60+ /// A message which can be encoded and/or decoded
61+ ///
62+ /// Applications can implement this trait on a struct to allow sending it using
63+ /// [`raw_send_with_kind`](crate::ConnectionTrait::raw_send_with_kind). To use the higher level messages a struct also needs to implement
64+ /// [`NetMessage`]
5865pub trait EncodableMessage : Sized + Debug + Send {
5966 fn read_body ( _data : BytesMut , _header : & NetMessageHeader ) -> Result < Self , MalformedBody > {
6067 panic ! ( "Reading not implemented for {}" , type_name:: <Self >( ) )
@@ -71,14 +78,15 @@ pub trait EncodableMessage: Sized + Debug + Send {
7178 fn process_header ( & self , _header : & mut NetMessageHeader ) { }
7279}
7380
81+ /// A message with associated kind
7482pub trait NetMessage : EncodableMessage {
7583 type KindEnum : MsgKindEnum ;
7684 const KIND : Self :: KindEnum ;
7785 const IS_PROTOBUF : bool = false ;
7886}
7987
8088#[ derive( Debug , BinRead ) ]
81- pub struct ChannelEncryptRequest {
89+ pub ( crate ) struct ChannelEncryptRequest {
8290 pub protocol : u32 ,
8391 #[ allow( dead_code) ]
8492 pub universe : u32 ,
@@ -99,7 +107,7 @@ impl NetMessage for ChannelEncryptRequest {
99107}
100108
101109#[ derive( Debug , BinRead ) ]
102- pub struct ChannelEncryptResult {
110+ pub ( crate ) struct ChannelEncryptResult {
103111 pub result : u32 ,
104112}
105113
@@ -117,7 +125,7 @@ impl NetMessage for ChannelEncryptResult {
117125}
118126
119127#[ derive( Debug ) ]
120- pub struct ClientEncryptResponse {
128+ pub ( crate ) struct ClientEncryptResponse {
121129 pub protocol : u32 ,
122130 pub encrypted_key : Vec < u8 > ,
123131}
@@ -164,6 +172,7 @@ impl Read for MaybeZipReader {
164172 }
165173}
166174
175+ /// Flatten any "multi" messages in a stream of raw messages
167176pub fn flatten_multi < S : Stream < Item = Result < RawNetMessage , NetworkError > > > (
168177 source : S ,
169178) -> impl Stream < Item = Result < RawNetMessage , NetworkError > > {
@@ -226,7 +235,7 @@ impl<R: Read> Iterator for MultiBodyIter<R> {
226235}
227236
228237#[ derive( Debug ) ]
229- pub struct ServiceMethodMessage < Request : Debug > ( pub Request ) ;
238+ pub ( crate ) struct ServiceMethodMessage < Request : Debug > ( pub Request ) ;
230239
231240impl < Request : ServiceMethodRequest + Debug > EncodableMessage for ServiceMethodMessage < Request > {
232241 fn read_body ( data : BytesMut , _header : & NetMessageHeader ) -> Result < Self , MalformedBody > {
@@ -259,7 +268,7 @@ impl<Request: ServiceMethodRequest + Debug> NetMessage for ServiceMethodMessage<
259268}
260269
261270#[ derive( Debug ) ]
262- pub struct ServiceMethodResponseMessage {
271+ pub ( crate ) struct ServiceMethodResponseMessage {
263272 job_name : String ,
264273 body : BytesMut ,
265274}
@@ -301,7 +310,7 @@ impl NetMessage for ServiceMethodResponseMessage {
301310}
302311
303312#[ derive( Debug , Clone ) ]
304- pub struct ServiceMethodNotification {
313+ pub ( crate ) struct ServiceMethodNotification {
305314 pub ( crate ) job_name : String ,
306315 body : BytesMut ,
307316}
0 commit comments