Skip to content

Commit

Permalink
ran format and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokya committed Dec 28, 2023
1 parent 982da4c commit 7747122
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eolib"
version = "1.0.0-RC1"
version = "1.0.0-RC2"
authors = ["Richard Leek <richard@richardleek.com>"]
description = "A core rust library for writing applications related to Endless Online"
edition = "2021"
Expand Down
58 changes: 32 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,18 +1004,28 @@ fn generate_inner_field_serialize(

let length = match &field.length {
Some(length) => length.as_str(),
None => ""
None => "",
};

let padded = match field.padded {
Some(padded) => padded,
_ => false,
};

if padded && !length.is_empty() && matches!(field.data_type.as_str(), "string" | "encoded_string") {
code.push_str(&format!(" let padding_length = {} - {}.len();\n", length, name));
if padded
&& !length.is_empty()
&& matches!(field.data_type.as_str(), "string" | "encoded_string")
{
code.push_str(&format!(
" let padding_length = {} - {}.len();\n",
length, name
));
code.push_str(" let padding = \"ÿ\".repeat(padding_length);\n");
code.push_str(&format!(" writer.add_{}(&format!(\"{{}}{{}}\", {}, padding));\n", replace_keyword(&field.data_type), name));
code.push_str(&format!(
" writer.add_{}(&format!(\"{{}}{{}}\", {}, padding));\n",
replace_keyword(&field.data_type),
name
));
return;
}

Expand All @@ -1029,7 +1039,10 @@ fn generate_inner_field_serialize(
)
{
"*"
} else if matches!(field.data_type.as_str(), "string" | "encoded_string") && !name.starts_with('"') && name != "array_item" {
} else if matches!(field.data_type.as_str(), "string" | "encoded_string")
&& !name.starts_with('"')
&& name != "array_item"
{
"&"
} else {
""
Expand Down Expand Up @@ -1125,45 +1138,37 @@ fn generate_serialize_length(code: &mut String, field_name: String, length: &Len
}
}

fn generate_serialize_switch(
code: &mut String,
struct_name: &str,
switch: &Switch,
) {
fn generate_serialize_switch(code: &mut String, struct_name: &str, switch: &Switch) {
code.push_str(&format!(
" match &self.{}_data {{\n",
replace_keyword(&switch.field)
));
for case in switch.cases.iter().filter(|c| c.elements.is_some()) {
match case.value {
Some(ref value) => {
code.push_str(&format!(
" Some({}::{}(data)) => {{\n",
get_field_type(&format!("{}_{}_data", struct_name, switch.field)),
replace_keyword(value)
));
code.push_str(
" data.serialize(writer)?;\n",
);
code.push_str(" }\n");
code.push_str(&format!(
" Some({}::{}(data)) => {{\n",
get_field_type(&format!("{}_{}_data", struct_name, switch.field)),
replace_keyword(value)
));
code.push_str(" data.serialize(writer)?;\n");
code.push_str(" }\n");
}
None => match case.default {
Some(true) => {
code.push_str(&format!(
" Some({}::Default(data)) => {{\n",
get_field_type(&format!("{}_{}_data", struct_name, switch.field)),
));
code.push_str(
" data.serialize(writer)?;\n",
);
code.push_str(" data.serialize(writer)?;\n");
code.push_str(" }\n");
}
_ => panic!("Unnamed switch case with default=false"),
},
}
}

code.push_str(" _ => (),\n",);
code.push_str(" _ => (),\n");
code.push_str(" }\n");
}

Expand Down Expand Up @@ -1332,9 +1337,10 @@ fn generate_inner_field_deserialize(
} else if let Some(length) = &field.length {
match data_type {
"string" => code.push_str(&format!(" reader.get_fixed_string({})?", length)),
"encoded_string" => {
code.push_str(&format!(" reader.get_fixed_encoded_string({})?", length))
}
"encoded_string" => code.push_str(&format!(
" reader.get_fixed_encoded_string({})?",
length
)),
_ => panic!("Unexpected length for data type: {}", data_type),
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::single_match)]
#![allow(clippy::large_enum_variant)]
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
include!(concat!(env!("OUT_DIR"), "/mod.rs"));

0 comments on commit 7747122

Please sign in to comment.