Different way of parsing packets

pull/5/head
Wyatt Herkamp 2 years ago
parent 4d1353afd2
commit 9d03b8ae51

@ -18,7 +18,11 @@ pub fn simple_test() {
let protocol = Protocol::new(arc.clone());
let protocol1 = protocol.get_protocol();
match protocol1 {
Ok(_) => {}
Ok(data) => {
for x in data.play.to_server.types {
println!("{:#?}", x);
}
}
Err(error) => {
panic!("Minecraft Version {} could not be parsed into a Protocol object: {}", arc.minecraft_version, error);
}

@ -63,7 +63,7 @@ impl Into<PacketDataType> for DataTypeReference {
#[derive(Debug, Clone)]
pub struct Packet {
pub name: String,
pub data: Vec<(String, DataTypeReference)>,
pub data: PacketDataType,
}
#[derive(Debug, Clone)]
@ -106,45 +106,15 @@ impl<'de> Deserialize<'de> for PacketTypes {
} else {
return Err(de::Error::custom("Invalid Packet Mapper"));
}
} else if let Value::Array(mut array) = value {
let last = array.pop().ok_or_else(|| de::Error::missing_field("missing content"))?;
if let Value::Array(array) = last {
let mut packet_content = Vec::new();
for value in array.into_iter() {
if let Value::Object(mut obj) = value {
let name = obj.remove("name");
let name = if let Some(name) = name {
name.to_string()
} else {
"anon".to_string()
};
let value = obj.remove("type").ok_or_else(|| de::Error::custom(format!("Packet ID {} missing type", key)))?;
let value = match value {
Value::String(simple) => {
DataTypeReference::Simple(simple)
}
Value::Array(mut array) => {
let properties = array.pop().ok_or_else(|| de::Error::custom(format!("Packet ID {} missing properties", key)))?;
let name = array.pop().ok_or_else(|| de::Error::custom(format!("Packet ID {} missing name", key)))?.to_string();
DataTypeReference::Complex {
name,
properties,
}
}
_ => return Err(de::Error::custom(format!("Invalid Packet Invalid Type {}", key)))
};
packet_content.push((name, value));
} else {
return Err(de::Error::custom(format!("Invalid Packet Expected Object {}", key)));
}
}
} else if let Value::Array( array) = value {
let value1 = Value::Array(vec![Value::String(key.clone()), Value::Array(array)]);
println!("{:#?}", value1);
let inner_type = types::build_inner_type(value1);
packets.push(Packet {
name: key,
data: packet_content,
data: *inner_type,
});
} else {
return Err(de::Error::custom(format!("Invalid Packet {}", key)));
}
} else {
return Err(de::Error::custom(format!("Invalid Packet Expected Array {}", key)));
}

@ -295,16 +295,14 @@ impl NativeType {
obj.remove("countType")
.unwrap_or_default()
.as_str()
.unwrap(),
.unwrap_or_default(),
Cow::Owned(Value::Null),
);
).unwrap_or(NativeType::VarInt);
let inner_type = build_inner_type(obj.remove("type").unwrap_or_default());
if let Some(v) = value {
return Some(NativeType::Array {
count_type: Box::new(v),
array_type: inner_type,
});
}
return Some(NativeType::Array {
count_type: Box::new(value),
array_type: inner_type,
});
}
None
}
@ -370,7 +368,7 @@ impl NativeType {
}
#[inline]
fn build_inner_type(value: Value) -> Box<PacketDataType> {
pub(crate) fn build_inner_type(value: Value) -> Box<PacketDataType> {
match value {
Value::String(simple_type) => {
return if let Some(simple_type) = NativeType::new(&simple_type, Cow::Owned(Value::Null))
@ -495,7 +493,7 @@ impl PacketDataType {
}
}
#[derive(Debug,Clone)]
#[derive(Debug, Clone)]
pub struct PacketDataTypes {
pub types: Vec<PacketDataType>,
}

Loading…
Cancel
Save