diff --git a/Cargo.lock b/Cargo.lock index 1f73b63..2192a4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -370,7 +370,6 @@ dependencies = [ "ryu", "serde", "serde_json", - "serde_repr", ] [[package]] @@ -679,17 +678,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "sha1" version = "0.10.6" diff --git a/base/Cargo.toml b/base/Cargo.toml index 629293a..0698ea8 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -12,8 +12,6 @@ readme = "README.md" [dependencies] serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -serde_repr = "0.1" ryu = "1.0" chrono = "0.4" chrono-tz = "0.9" @@ -21,6 +19,9 @@ regex = "1.0" once_cell = "1.16.0" bitcode = "0.6.0" +[dev-dependencies] +serde_json = "1.0" + [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = { version = "0.3.69" } diff --git a/base/src/cell.rs b/base/src/cell.rs index ab0c08e..70299f1 100644 --- a/base/src/cell.rs +++ b/base/src/cell.rs @@ -1,12 +1,9 @@ use crate::{ expressions::token::Error, language::Language, number_format::to_excel_precision_str, types::*, }; -use serde::{Deserialize, Serialize}; -use serde_json::json; /// A CellValue is the representation of the cell content. -#[derive(Serialize, Deserialize, Debug, PartialEq)] -#[serde(untagged)] +#[derive(Debug, PartialEq)] pub enum CellValue { None, String(String), @@ -14,17 +11,6 @@ pub enum CellValue { Boolean(bool), } -impl CellValue { - pub fn to_json_str(&self) -> String { - match &self { - CellValue::None => "null".to_string(), - CellValue::String(s) => json!(s).to_string(), - CellValue::Number(f) => json!(f).to_string(), - CellValue::Boolean(b) => json!(b).to_string(), - } - } -} - impl From for CellValue { fn from(value: f64) -> Self { Self::Number(value) diff --git a/base/src/expressions/token.rs b/base/src/expressions/token.rs index 639ef2e..9b97f0f 100644 --- a/base/src/expressions/token.rs +++ b/base/src/expressions/token.rs @@ -2,7 +2,6 @@ use std::fmt; use bitcode::{Decode, Encode}; use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; use crate::language::Language; @@ -81,8 +80,7 @@ impl fmt::Display for OpProduct { /// * "#ERROR!" means there was an error processing the formula (for instance "=A1+") /// * "#N/IMPL!" means the formula or feature in Excel but has not been implemented in IronCalc /// Note that they are serialized/deserialized by index -#[derive(Serialize_repr, Deserialize_repr, Encode, Decode, Debug, PartialEq, Eq, Clone)] -#[repr(u8)] +#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)] pub enum Error { REF, NAME, diff --git a/base/src/language/language.bin b/base/src/language/language.bin new file mode 100644 index 0000000..2838eb3 --- /dev/null +++ b/base/src/language/language.bin @@ -0,0 +1 @@ +PfrendeesD”VRAITRUEWAHRVERDADEROTVFAUXFALSEFALSCHFALSOUw#REF!#REF!#BEZUG!#¡REF!e¦#NOM?#NAME?#NAME?#¿NOMBRE?x–#VALEUR!#VALUE!#WERT!#¡VALOR!w—#DIV/0!#DIV/0!#DIV/0!#¡DIV/0!ˆ#N/A#N/A#NV#N/AXv#NOMBRE!#NUM!#ZAHL!#¡NUM!ˆˆ#N/IMPL!#N/IMPL!#N/IMPL!#N/IMPL!w{#SPILL!#SPILL!#ÜBERLAUF!#SPILL!ff#CALC!#CALC!#CALC!#CALC!ff#CIRC!#CIRC!#CIRC!#CIRC!ww#ERROR!#ERROR!#ERROR!#ERROR!ff#NULL!#NULL!#NULL!#NULL! \ No newline at end of file diff --git a/base/src/language/mod.rs b/base/src/language/mod.rs index e9a4235..4667a3f 100644 --- a/base/src/language/mod.rs +++ b/base/src/language/mod.rs @@ -1,15 +1,15 @@ -use once_cell::sync::Lazy; -use serde::{Deserialize, Serialize}; - use std::collections::HashMap; -#[derive(Serialize, Deserialize, Clone)] +use bitcode::{Decode, Encode}; +use once_cell::sync::Lazy; + +#[derive(Encode, Decode, Clone)] pub struct Booleans { pub r#true: String, pub r#false: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct Errors { pub r#ref: String, pub name: String, @@ -25,14 +25,14 @@ pub struct Errors { pub null: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct Language { pub booleans: Booleans, pub errors: Errors, } static LANGUAGES: Lazy> = Lazy::new(|| { - serde_json::from_str(include_str!("language.json")).expect("Failed parsing language file") + bitcode::decode(include_bytes!("language.bin")).expect("Failed parsing language file") }); pub fn get_language(id: &str) -> Result<&Language, String> { diff --git a/base/src/locale/locales.bin b/base/src/locale/locales.bin new file mode 100644 index 0000000..b0b9e42 Binary files /dev/null and b/base/src/locale/locales.bin differ diff --git a/base/src/locale/mod.rs b/base/src/locale/mod.rs index e257126..bb46f00 100644 --- a/base/src/locale/mod.rs +++ b/base/src/locale/mod.rs @@ -1,32 +1,29 @@ +use bitcode::{Decode, Encode}; use once_cell::sync::Lazy; -use serde::{Deserialize, Serialize}; use std::collections::HashMap; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct Locale { pub dates: Dates, pub numbers: NumbersProperties, pub currency: Currency, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct Currency { pub iso: String, pub symbol: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct NumbersProperties { - #[serde(rename = "symbols-numberSystem-latn")] pub symbols: NumbersSymbols, - #[serde(rename = "decimalFormats-numberSystem-latn")] pub decimal_formats: DecimalFormats, - #[serde(rename = "currencyFormats-numberSystem-latn")] pub currency_formats: CurrencyFormats, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct Dates { pub day_names: Vec, pub day_names_short: Vec, @@ -35,8 +32,7 @@ pub struct Dates { pub months_letter: Vec, } -#[derive(Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] +#[derive(Encode, Decode, Clone)] pub struct NumbersSymbols { pub decimal: String, pub group: String, @@ -54,31 +50,23 @@ pub struct NumbersSymbols { } // See: https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns -#[derive(Serialize, Deserialize, Clone)] +#[derive(Encode, Decode, Clone)] pub struct CurrencyFormats { pub standard: String, - #[serde(rename = "standard-alphaNextToNumber")] - #[serde(skip_serializing_if = "Option::is_none")] pub standard_alpha_next_to_number: Option, - #[serde(rename = "standard-noCurrency")] pub standard_no_currency: String, pub accounting: String, - #[serde(rename = "accounting-alphaNextToNumber")] - #[serde(skip_serializing_if = "Option::is_none")] pub accounting_alpha_next_to_number: Option, - #[serde(rename = "accounting-noCurrency")] pub accounting_no_currency: String, } -#[derive(Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] +#[derive(Encode, Decode, Clone)] pub struct DecimalFormats { pub standard: String, } -static LOCALES: Lazy> = Lazy::new(|| { - serde_json::from_str(include_str!("locales.json")).expect("Failed parsing locale") -}); +static LOCALES: Lazy> = + Lazy::new(|| bitcode::decode(include_bytes!("locales.bin")).expect("Failed parsing locale")); pub fn get_locale(id: &str) -> Result<&Locale, String> { // TODO: pass the locale once we implement locales in Rust