mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 06:21:31 +11:00
Packet inspector fixes (#375)
## Description packet_to_string now returns a Result as not to crash the app when showing TextView on a packet that fails to decode for whatever reason.
This commit is contained in:
parent
3a3fd9f202
commit
d36998dc9c
|
@ -162,7 +162,7 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {
|
||||||
|
|
||||||
match_arms.extend(quote! {
|
match_arms.extend(quote! {
|
||||||
#name::ID => {
|
#name::ID => {
|
||||||
format!("{:#?}", #name::decode(&mut data).unwrap())
|
Ok(format!("{:#?}", #name::decode(&mut data)))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -172,14 +172,14 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {
|
||||||
side_arms.extend(quote! {
|
side_arms.extend(quote! {
|
||||||
PacketState::#state => match packet.id {
|
PacketState::#state => match packet.id {
|
||||||
#match_arms
|
#match_arms
|
||||||
_ => NOT_AVAILABLE.to_string(),
|
_ => Ok(NOT_AVAILABLE.to_string()),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if side == "Clientbound" {
|
if side == "Clientbound" {
|
||||||
side_arms.extend(quote! {
|
side_arms.extend(quote! {
|
||||||
_ => NOT_AVAILABLE.to_string(),
|
_ => Ok(NOT_AVAILABLE.to_string()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {
|
||||||
let generated = quote! {
|
let generated = quote! {
|
||||||
const NOT_AVAILABLE: &str = "Not yet implemented";
|
const NOT_AVAILABLE: &str = "Not yet implemented";
|
||||||
|
|
||||||
pub fn packet_to_string(packet: &ProxyPacket) -> String {
|
pub fn packet_to_string(packet: &ProxyPacket) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let bytes = packet.data.as_ref().unwrap();
|
let bytes = packet.data.as_ref().unwrap();
|
||||||
let mut data = &bytes.clone()[..];
|
let mut data = &bytes.clone()[..];
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,11 @@ impl View for TextView {
|
||||||
|
|
||||||
if self.last_packet_id != Some(packet_index) {
|
if self.last_packet_id != Some(packet_index) {
|
||||||
self.last_packet_id = Some(packet_index);
|
self.last_packet_id = Some(packet_index);
|
||||||
self.packet_str = utils::packet_to_string(&packets[packet_index]);
|
|
||||||
|
self.packet_str = match utils::packet_to_string(&packets[packet_index]) {
|
||||||
|
Ok(str) => str,
|
||||||
|
Err(err) => format!("Error: {}", err),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
code_view_ui(ui, &self.packet_str);
|
code_view_ui(ui, &self.packet_str);
|
||||||
|
|
Loading…
Reference in a new issue