Add missing derives, favicon field and new Packet struct.#21
Add missing derives, favicon field and new Packet struct.#21reitermarkus wants to merge 8 commits intoeihwaz:masterfrom
favicon field and new Packet struct.#21Conversation
| use crate::error::{DecodeError, EncodeError}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Packet { |
There was a problem hiding this comment.
When you will intergrate protocol in a network library like tokio this structure would not be necessary. There are more steps in packet codec. Like encryption and compression.
There was a problem hiding this comment.
When you will intergrate protocol in a network library like tokio this structure would not be necessary.
Do you have an example for how this works?
I am currently converting a tokio::net::TcpStream into std::net::TcpStream so I can use Packet::decode with it, so this would definitely be an improvement over what I have now.
I've bodged together packet reading/writing with compression support here: My implementation handles compression, but no encryption though. In the login stage, the server may send a SetCompression(n) packet after which compression should be enabled if the packet payload is Read more about compression here: https://wiki.vg/Protocol#Packet_format |
|
Thanks @timvisee, I will have a look, your “Lobby” feature looks very interesting. For my use case (a Kubernetes game server proxy for auto-scaling, pretty similar to your |
|
Okay, looking at @timvisee's implementation, this |
|
Okay, I renamed the |
|
@vaIgarashi, can you have another look? |
| Err(DecodeError::IoError { io_error }) | ||
| if io_error.kind() == io::ErrorKind::UnexpectedEof => | ||
| { | ||
| return Err(DecodeError::Incomplete { bytes_needed: 1 }) |
There was a problem hiding this comment.
This is not correct because read var int may vary from 1 to 4 bytes
There was a problem hiding this comment.
This is used only as an indication, so it should be read as “at least 1”. If more are needed, it will happen in the next iteration.
There was a problem hiding this comment.
Maybe it should be an Option so it works similar to https://docs.rs/nom/latest/nom/enum.Needed.html.
protocol/src/packet.rs
Outdated
| let mut buf = Vec::new(); | ||
| let packet = RawPacket { | ||
| id: self.id, | ||
| data: self.data.clone(), |
There was a problem hiding this comment.
Changed the method to take an owned self.
| id: self.id, | ||
| data: self.data.clone(), | ||
| }; | ||
| if let Some(threshold) = compression_threshold { |
There was a problem hiding this comment.
nth: match are more preferable when you use else branch
| encoder.write_all(&packet_buf)?; | ||
| encoder.finish()?; | ||
| } else { | ||
| writer.write_var_i32(0)?; |
There was a problem hiding this comment.
https://wiki.vg/Protocol#With_compression
If the size of the buffer containing the packet data and ID (as a VarInt) is smaller than the threshold specified in the packet Set Compression. It will be sent as uncompressed. This is done by setting the data length as 0. (Comparable to sending a non-compressed format with an extra 0 between the length, and packet data).
Debugfor every struct.faviconfield forServerStatus.Packetstruct to decode full packets.