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