@@ -2,7 +2,7 @@ use crate::varint::{VarInt, CONTINUE_BIT};
22use async_trait:: async_trait;
33use bytes:: { BufMut , BytesMut } ;
44use std:: io:: { Error , ErrorKind } ;
5- use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt , Result } ;
5+ use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , Result } ;
66
77/// Trait to allow for reading and writing `VarInt`s from the socket.
88///
@@ -12,26 +12,6 @@ pub(crate) trait ReadWriteVarInt {
1212 /// Read a [VarInt] from the socket.
1313 /// Returns the parsed value as [i32] in a [Result].
1414 async fn read_varint ( & mut self ) -> Result < i32 > ;
15-
16- /// Write a [VarInt] to the socket.
17- /// Writes the given integer in the form of a [VarInt].
18- /// Returns whether the operation was successful in a [Result].
19- async fn write_varint ( & mut self , value : i32 ) -> Result < ( ) > ;
20- }
21-
22- /// Trait to allow for reading and writing `VarLong`s from the socket.
23- ///
24- /// The type is specified [in wiki.vg](https://wiki.vg/Protocol#VarInt_and_VarLong).
25- #[ async_trait]
26- pub ( crate ) trait ReadWriteVarLong {
27- /// Read a `VarLong` from the socket.
28- /// Returns the parsed value as [i64] in a [Result].
29- async fn read_varlong ( & mut self ) -> Result < i64 > ;
30-
31- /// Write a `VarLong` to the socket.
32- /// Writes the given integer in the form of a `VarLong`.
33- /// Returns whether the operation was successful in a [Result].
34- async fn write_varlong ( & mut self , value : i64 ) -> Result < ( ) > ;
3515}
3616
3717/// Trait to allow for reading and writing strings from the socket.
@@ -43,22 +23,6 @@ pub(crate) trait ReadWriteMinecraftString {
4323 /// Read a [String] from the socket.
4424 /// Returns the parsed value recieved from the socket in a [Result].
4525 async fn read_mc_string ( & mut self ) -> Result < String > ;
46-
47- /// Write a [str] to the socket.
48- /// Returns whether the operation was successful in a [Result].
49- async fn write_mc_string ( & mut self , value : & str ) -> Result < ( ) > ;
50- }
51-
52- /// Trait to allow for reading and writing null terminated strings from the socket.
53- #[ async_trait]
54- pub ( crate ) trait ReadWriteNullTermString {
55- /// Read a [String] from the socket.
56- /// Returns the pased value recieved from the socket in a [Result].
57- async fn read_null_terminated_string ( & mut self ) -> Result < String > ;
58-
59- /// Write a [str] ot the socket
60- /// Returns whetehr the operation was successful in a [Result].
61- async fn write_null_terminated_string ( & mut self , value : & str ) -> Result < ( ) > ;
6226}
6327
6428#[ async_trait]
8246 . try_into ( )
8347 . map_err ( |err| Error :: new ( ErrorKind :: InvalidData , err) )
8448 }
85-
86- async fn write_varint ( & mut self , value : i32 ) -> Result < ( ) > {
87- self . write_all ( & VarInt :: from ( value) ) . await
88- }
8949}
9050
9151#[ async_trait]
@@ -100,37 +60,4 @@ where
10060
10161 String :: from_utf8 ( buffer) . map_err ( |err| Error :: new ( ErrorKind :: InvalidData , err) )
10262 }
103-
104- async fn write_mc_string ( & mut self , value : & str ) -> Result < ( ) > {
105- self . write_varint ( value. len ( ) as i32 ) . await ?;
106- self . write_all ( value. as_bytes ( ) ) . await ?;
107-
108- Ok ( ( ) )
109- }
110- }
111-
112- #[ async_trait]
113- impl < T > ReadWriteNullTermString for T
114- where
115- T : AsyncRead + AsyncWrite + Unpin + Send ,
116- {
117- async fn read_null_terminated_string ( & mut self ) -> Result < String > {
118- let mut string = String :: new ( ) ;
119-
120- loop {
121- let current = self . read_u8 ( ) . await ?;
122- if current == 0 {
123- break ;
124- }
125-
126- string. push ( current as char ) ;
127- }
128-
129- Ok ( string)
130- }
131-
132- async fn write_null_terminated_string ( & mut self , value : & str ) -> Result < ( ) > {
133- self . write_all ( value. as_bytes ( ) ) . await ?;
134- self . write_u8 ( 0 ) . await
135- }
136- }
63+ }
0 commit comments