Skip to content

Commit

Permalink
Made config files a bit smaller by skipping defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Feb 9, 2025
1 parent 9a1383f commit f4159e7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/dizbase/src/file_base_scanner/bbstro_fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn is_null_64(b: impl std::borrow::Borrow<u64>) -> bool {
fn is_null_32(b: impl std::borrow::Borrow<u32>) -> bool {
*b.borrow() == 0
}

impl Fingerprint {
pub fn new(file_name: String, crc: u32, crc_file_size: u64) -> Self {
Self {
Expand Down
24 changes: 23 additions & 1 deletion crates/icy_board_engine/src/icy_board/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Res;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{serde_as, DisplayFromStr};

use super::{security_expr::SecurityExpression, IcyBoardSerializer, PCBoardRecordImporter};
use super::{is_null_64, security_expr::SecurityExpression, IcyBoardSerializer, PCBoardRecordImporter};

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug, Default)]
pub enum CommandType {
Expand Down Expand Up @@ -520,6 +520,10 @@ pub struct Position {
}

impl Position {
pub fn is_default(&self) -> bool {
*self == Position::default()
}

pub fn parse(txt: &str) -> Self {
let mut parts = txt.split(',');
let x = parts.next().unwrap_or("0").trim().parse().unwrap_or(0);
Expand Down Expand Up @@ -571,6 +575,12 @@ pub enum AutoRun {
Loop,
}

impl AutoRun {
pub fn is_default(&self) -> bool {
matches!(self, AutoRun::Disabled)
}
}

impl FromStr for AutoRun {
type Err = String;

Expand All @@ -596,22 +606,26 @@ impl AutoRun {
#[derive(Serialize, Deserialize, Clone, Default, PartialEq)]
pub struct Command {
#[serde(default)]
#[serde(skip_serializing_if = "String::is_empty")]
pub display: String,

#[serde(default)]
#[serde(skip_serializing_if = "String::is_empty")]
pub lighbar_display: String,

#[serde(default)]
#[serde(skip_serializing_if = "Position::is_default")]
pub position: Position,

#[serde(default)]
pub keyword: String,

#[serde(default)]
#[serde(skip_serializing_if = "AutoRun::is_default")]
pub auto_run: AutoRun,

#[serde(default)]
#[serde(skip_serializing_if = "is_null_64")]
pub autorun_time: u64,

#[serde(default)]
Expand All @@ -635,6 +649,12 @@ pub enum ActionTrigger {
Selection,
}

impl ActionTrigger {
pub fn is_default(&self) -> bool {
matches!(self, ActionTrigger::Activation)
}
}

#[derive(Serialize, Clone, Deserialize, Default, PartialEq)]
pub struct CommandAction {
pub command_type: CommandType,
Expand All @@ -643,6 +663,8 @@ pub struct CommandAction {
#[serde(skip_serializing_if = "String::is_empty")]
pub parameter: String,

#[serde(default)]
#[serde(skip_serializing_if = "ActionTrigger::is_default")]
pub trigger: ActionTrigger,
}

Expand Down
1 change: 0 additions & 1 deletion crates/icy_board_engine/src/icy_board/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ pub fn is_null_64(b: impl std::borrow::Borrow<u64>) -> bool {
pub fn is_null_32(b: impl std::borrow::Borrow<u32>) -> bool {
*b.borrow() == 0
}

pub fn is_null_16(b: impl std::borrow::Borrow<u16>) -> bool {
*b.borrow() == 0
}
Expand Down
26 changes: 25 additions & 1 deletion crates/icy_board_engine/src/icy_board/security_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Display for Value {
}
}

#[derive(Clone, PartialEq, Serialize, Deserialize)]
#[derive(Clone, PartialEq)]
pub enum SecurityExpression {
UnaryExpression(UnaryOp, Box<SecurityExpression>),
BinaryExpression(BinaryOp, Box<SecurityExpression>, Box<SecurityExpression>),
Expand Down Expand Up @@ -103,6 +103,30 @@ impl FromStr for SecurityExpression {
}
}

impl From<String> for SecurityExpression {
fn from(s: String) -> Self {
SecurityExpression::from_str(&s).unwrap_or_default()
}
}

impl<'de> Deserialize<'de> for SecurityExpression {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
String::deserialize(deserializer).map(Self::from)
}
}

impl serde::Serialize for SecurityExpression {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.to_string().serialize(serializer)
}
}

#[derive(Logos, Debug, PartialEq)]
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
enum Token {
Expand Down

0 comments on commit f4159e7

Please sign in to comment.