From fc64e11cdd35051a2ea87237f548ae0497a2f7f9 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 29 Apr 2020 00:00:44 +0200 Subject: refactor everything --- src/primitive/datetime.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/primitive/datetime.rs (limited to 'src/primitive/datetime.rs') diff --git a/src/primitive/datetime.rs b/src/primitive/datetime.rs new file mode 100644 index 0000000..e6946b9 --- /dev/null +++ b/src/primitive/datetime.rs @@ -0,0 +1,107 @@ +use crate::Deserialize; +use crate::Serialize; + +/// The DateTime struct represents a DateTime as received in IRC +/// +/// DateTime is, like all other struct based types, serialized sequentially. +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct DateTime { + /// Day in Julian calendar, unknown if signed or unsigned + julian_day: i32, + /// Milliseconds since start of day + millis_of_day: i32, + /// Timezone of DateTime, 0x00 is local, 0x01 is UTC + zone: u8, +} + +impl Serialize for DateTime { + fn serialize(&self) -> Result, failure::Error> { + let mut values: Vec = Vec::new(); + + values.append(&mut i32::serialize(&self.julian_day)?); + values.append(&mut i32::serialize(&self.millis_of_day)?); + values.append(&mut u8::serialize(&(self.zone))?); + + Ok(values) + } +} + +impl Deserialize for DateTime { + fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> + where + Self: Sized, + { + let (_, julian_day) = i32::parse(&b[0..4])?; + let (_, millis_of_day) = i32::parse(&b[4..8])?; + let (_, zone) = u8::parse(&b[8..9])?; + + return Ok(( + 9, + DateTime { + julian_day, + millis_of_day, + zone, + }, + )); + } +} + +/// The Date struct represents a Date as received in IRC +/// +/// Date is, like all other struct based types, serialized sequentially. +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct Date { + /// Day in Julian calendar, unknown if signed or unsigned + julian_day: i32, +} + +impl Serialize for Date { + fn serialize(&self) -> Result, failure::Error> { + let mut values: Vec = Vec::new(); + + values.append(&mut i32::serialize(&self.julian_day)?); + + Ok(values) + } +} + +impl Deserialize for Date { + fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> + where + Self: Sized, + { + let (_, julian_day) = i32::parse(&b[0..4])?; + + return Ok((9, Date { julian_day })); + } +} + +/// The Time struct represents a Time as received in IRC +/// +/// Time is, like all other struct based types, serialized sequentially. +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct Time { + /// Milliseconds since start of day + millis_of_day: i32, +} + +impl Serialize for Time { + fn serialize(&self) -> Result, failure::Error> { + let mut values: Vec = Vec::new(); + + values.append(&mut i32::serialize(&self.millis_of_day)?); + + Ok(values) + } +} + +impl Deserialize for Time { + fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> + where + Self: Sized, + { + let (_, millis_of_day) = i32::parse(&b[0..4])?; + + return Ok((4, Time { millis_of_day })); + } +} -- cgit v1.2.3 10-20 17:36:48 +0200'>2021-10-20prepare for release on crates.ioMax Audron-39/+65 2021-10-20add async docs to macro crate and bump versionMax Audron-9/+10 2021-10-20change hook errors to be logged as warningsMax Audron-3/+3 they in nearly all cases aren't critical enough to warrant an actual error messages 2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23 2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358 This replaces the sedregex crate with our own implementation for multiple reasons: 1. We required to access the parsed regex, this required a patch to the sedregex crate which did not get merged due to an inactive dev, blocking us from publishing on crates.Io 2. We wanted to highlight the changes done in bold 3. We want to add execution of multiple chained sed commands in the future which would require more modification 2021-10-19add formatting trait for irc codesMax Audron-0/+129 add an impl off the formatting trait on String to format Strings with the typical irc formatting codes for bold, italic etc 2021-10-17fix links in readmeMax Audron-2/+2