-
Notifications
You must be signed in to change notification settings - Fork 10
Add missing derives, favicon field and new Packet struct.
#21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| use crate::error::{DecodeError, EncodeError}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Packet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct because read var int may vary from 1 to 4 bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid data cloning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.