use anyhow::Result; use serde::{Deserialize, Serialize}; use super::super::errors::*; use super::super::sps_datatypes::{BitPosition, DataEvaluation, UnparsedSPSDataType}; #[derive(Debug, Serialize, Deserialize, Copy, Clone)] pub struct TimeType { length: u32, position: BitPosition, } impl TimeType { const LEN: usize = 4; pub fn new(byte: u32, bit: Option) -> Self { TimeType { length: Self::LEN as u32, position: BitPosition { byte, bit }, } } fn into_string(self) -> String { "time".to_string() } } impl DataEvaluation for TimeType { fn into_unparsed(&self) -> UnparsedSPSDataType { UnparsedSPSDataType { data_type: self.into_string(), data_byte: self.position.byte, data_bit: self.position.bit, data_length: None, } } fn get_end_byte(&self) -> u32 { self.position.byte + self.length } fn get_byte_positon(&self) -> u32 { self.position.byte } fn get_length(&self) -> u32 { self.length } fn parse_serial(&self, data: &[&str]) -> Result { Ok(data .get((self.position.byte) as usize) .ok_or_else(|| serial_error(self.into_string(), self.position.byte))? .to_string()) } fn parse_s7(&self, _data: &[u8]) -> Result { Ok("time".to_string()) } fn sql_equivalent(&self) -> &str { r"BIGINT UNSIGNED DEFAULT 0" } }