aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src')
-rwxr-xr-xazalea-protocol/src/connect.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs
index 37df0f08..00685d3c 100755
--- a/azalea-protocol/src/connect.rs
+++ b/azalea-protocol/src/connect.rs
@@ -302,7 +302,8 @@ where
R1: ProtocolPacket + Debug,
W1: ProtocolPacket + Debug,
{
- fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
+ /// Creates a `Connection` of a type from a `Connection` of another type. Useful for servers or custom packets.
+ pub fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
where
R2: ProtocolPacket + Debug,
W2: ProtocolPacket + Debug,
@@ -323,4 +324,25 @@ where
},
}
}
+
+ /// Convert an existing `TcpStream` into a `Connection`. Useful for servers.
+ pub fn wrap(stream: TcpStream) -> Connection<R1, W1> {
+ let (read_stream, write_stream) = stream.into_split();
+
+ Connection {
+ reader: ReadConnection {
+ read_stream,
+ buffer: BytesMut::new(),
+ compression_threshold: None,
+ dec_cipher: None,
+ _reading: PhantomData,
+ },
+ writer: WriteConnection {
+ write_stream,
+ compression_threshold: None,
+ enc_cipher: None,
+ _writing: PhantomData,
+ },
+ }
+ }
}