Fix backend list parsing

This commit is contained in:
Vladislavs Golubs 2021-02-09 03:14:55 +03:00
parent c6d1cdecc7
commit 2d9b9dd94f
2 changed files with 14 additions and 13 deletions

View File

@ -55,10 +55,6 @@ pub enum Container {
#[derive(Debug, Deserialize, PartialEq, Eq)] #[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)] #[serde(untagged)]
pub enum Switch { pub enum Switch {
Empty {
#[serde(rename = "compareTo")]
compare_to: String,
},
Value { Value {
#[serde(rename = "compareTo")] #[serde(rename = "compareTo")]
compare_to: String, compare_to: String,
@ -69,15 +65,15 @@ pub enum Switch {
compare_to: String, compare_to: String,
fields: LinkedHashMap<String, Vec<Data>>, fields: LinkedHashMap<String, Vec<Data>>,
}, },
Empty {
#[serde(rename = "compareTo")]
compare_to: String,
},
} }
#[derive(Debug, Deserialize, PartialEq, Eq)] #[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)] #[serde(untagged)]
pub enum List { pub enum List {
Empty {
#[serde(rename = "countType")]
count_type: String,
},
Value { Value {
#[serde(rename = "countType")] #[serde(rename = "countType")]
count_type: String, count_type: String,
@ -90,6 +86,10 @@ pub enum List {
#[serde(rename = "type")] #[serde(rename = "type")]
list_type: Vec<Data>, list_type: Vec<Data>,
}, },
Empty {
#[serde(rename = "countType")]
count_type: String,
},
} }
#[derive(Debug, Deserialize, PartialEq, Eq)] #[derive(Debug, Deserialize, PartialEq, Eq)]

View File

@ -28,7 +28,7 @@ pub fn main() {
let protocol_data_file = let protocol_data_file =
File::open(protocol_data_file_name).expect("Failed to open protocol data file"); File::open(protocol_data_file_name).expect("Failed to open protocol data file");
let protocol_input: backend::ProtocolHandler = let protocol_handler: backend::ProtocolHandler =
serde_json::from_reader(protocol_data_file).expect("Failed to parse protocol data"); serde_json::from_reader(protocol_data_file).expect("Failed to parse protocol data");
let mappings = CodeMappings {}; let mappings = CodeMappings {};
@ -38,7 +38,7 @@ pub fn main() {
transformers::transform_protocol( transformers::transform_protocol(
&mappings, &mappings,
frontend::State::Handshake, frontend::State::Handshake,
&protocol_input.handshaking, &protocol_handler.handshaking,
), ),
frontend::State::Handshake, frontend::State::Handshake,
), ),
@ -46,7 +46,7 @@ pub fn main() {
transformers::transform_protocol( transformers::transform_protocol(
&mappings, &mappings,
frontend::State::Status, frontend::State::Status,
&protocol_input.status, &protocol_handler.status,
), ),
frontend::State::Status, frontend::State::Status,
), ),
@ -54,7 +54,7 @@ pub fn main() {
transformers::transform_protocol( transformers::transform_protocol(
&mappings, &mappings,
frontend::State::Login, frontend::State::Login,
&protocol_input.login, &protocol_handler.login,
), ),
frontend::State::Login, frontend::State::Login,
), ),
@ -62,7 +62,7 @@ pub fn main() {
transformers::transform_protocol( transformers::transform_protocol(
&mappings, &mappings,
frontend::State::Game, frontend::State::Game,
&protocol_input.game, &protocol_handler.game,
), ),
frontend::State::Game, frontend::State::Game,
), ),
@ -73,6 +73,7 @@ pub fn main() {
"protocol/src/packet/{}.rs", "protocol/src/packet/{}.rs",
state.to_string().to_lowercase() state.to_string().to_lowercase()
); );
let file = File::create(file_name).expect("Failed to create file"); let file = File::create(file_name).expect("Failed to create file");
frontend::generate_rust_file(&protocol, &template_engine, &file) frontend::generate_rust_file(&protocol, &template_engine, &file)