From dd94ed8f9774c253f4587b4c08341443a4d8b2a2 Mon Sep 17 00:00:00 2001 From: Richard Leek Date: Wed, 21 Aug 2024 22:17:28 +0200 Subject: [PATCH] Update dependencies and eo-protocol Fix problems in build script --- Cargo.toml | 2 +- build.rs | 13 +++++++++++-- eo-protocol | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a7ba850..1872ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eolib" -version = "1.0.0" +version = "2.0.0" authors = ["Richard Leek "] description = "A core rust library for writing applications related to Endless Online" edition = "2021" diff --git a/build.rs b/build.rs index 82e33b6..57c52ef 100644 --- a/build.rs +++ b/build.rs @@ -897,9 +897,14 @@ fn generate_serialize_field(code: &mut String, field: &Field, enums: &[Enum], st }; code.push_str(&format!( - " if let Some({}) = self.{} {{\n", + " if let Some({}) = self.{}{} {{\n", replace_keyword(name), - replace_keyword(name) + replace_keyword(name), + if is_primitive(&field.data_type) || enums.iter().any(|e| e.name == field.data_type) { + "" + } else { + ".as_ref()" + } )); generate_inner_field_serialize(code, field, enums, structs); code.push_str(" }\n"); @@ -1605,6 +1610,10 @@ static PRIMITIVE_TYPES: [&str; 9] = [ "blob", ]; +fn is_primitive(data_type: &str) -> bool { + PRIMITIVE_TYPES.contains(&data_type) +} + fn get_imports(elements: &[StructElement], protocols: &[(Protocol, PathBuf)]) -> Vec { let mut imports = vec![ "use crate::data::{EoReader, EoReaderError, EoWriter, EoSerialize, EoSerializeError};" diff --git a/eo-protocol b/eo-protocol index 690cfa6..319cb47 160000 --- a/eo-protocol +++ b/eo-protocol @@ -1 +1 @@ -Subproject commit 690cfa6d999cf88b7c0bcfa0437e0daa5f3ab54d +Subproject commit 319cb472d41ac9cf53b5bce9fa65c7d87022072b