Skip to content

Commit

Permalink
feat(sdr/record): move functions to contents and call those from
Browse files Browse the repository at this point in the history
the full record.
  • Loading branch information
datdenkikniet committed May 15, 2024
1 parent 0d9424b commit 162c3e0
Showing 1 changed file with 51 additions and 25 deletions.
76 changes: 51 additions & 25 deletions src/storage/sdr/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,38 +712,19 @@ pub enum RecordContents {

impl Record {
pub fn common_data(&self) -> Option<&SensorRecordCommon> {
match &self.contents {
RecordContents::FullSensor(s) => Some(s.common()),
RecordContents::CompactSensor(s) => Some(s.common()),
RecordContents::EventOnlySensor(_) => None,
RecordContents::FruDeviceLocator(_) => None,
RecordContents::McDeviceLocator(_) => None,
RecordContents::Unknown { .. } => None,
}
self.contents.common_data()
}

pub fn full_sensor(&self) -> Option<&FullSensorRecord> {
if let RecordContents::FullSensor(full_sensor) = &self.contents {
Some(full_sensor)
} else {
None
}
self.contents.full_sensor()
}

pub fn compact_sensor(&self) -> Option<&CompactSensorRecord> {
if let RecordContents::CompactSensor(compact_sensor) = &self.contents {
Some(compact_sensor)
} else {
None
}
self.contents.compact_sensor()
}

pub fn event_only(&self) -> Option<&EventOnlySensorRecord> {
if let RecordContents::EventOnlySensor(event) = &self.contents {
Some(event)
} else {
None
}
self.contents.event_only()
}

pub fn parse(data: &[u8]) -> Result<Self, ParseError> {
Expand Down Expand Up @@ -790,7 +771,52 @@ impl Record {
}

pub fn id(&self) -> Option<&SensorId> {
match &self.contents {
self.contents.id()
}

pub fn sensor_number(&self) -> Option<SensorNumber> {
self.contents.sensor_number()
}
}

impl RecordContents {
pub fn common_data(&self) -> Option<&SensorRecordCommon> {
match self {
RecordContents::FullSensor(s) => Some(s.common()),
RecordContents::CompactSensor(s) => Some(s.common()),
RecordContents::EventOnlySensor(_) => None,
RecordContents::FruDeviceLocator(_) => None,
RecordContents::McDeviceLocator(_) => None,
RecordContents::Unknown { .. } => None,
}
}

pub fn full_sensor(&self) -> Option<&FullSensorRecord> {
if let RecordContents::FullSensor(full_sensor) = self {
Some(full_sensor)
} else {
None
}
}

pub fn compact_sensor(&self) -> Option<&CompactSensorRecord> {
if let RecordContents::CompactSensor(compact_sensor) = self {
Some(compact_sensor)
} else {
None
}
}

pub fn event_only(&self) -> Option<&EventOnlySensorRecord> {
if let RecordContents::EventOnlySensor(event) = self {
Some(event)
} else {
None
}
}

pub fn id(&self) -> Option<&SensorId> {
match self {
RecordContents::FullSensor(full) => Some(full.id_string()),
RecordContents::CompactSensor(compact) => Some(compact.id_string()),
RecordContents::EventOnlySensor(event) => Some(&event.id_string),
Expand All @@ -801,7 +827,7 @@ impl Record {
}

pub fn sensor_number(&self) -> Option<SensorNumber> {
match &self.contents {
match self {
RecordContents::FullSensor(full) => Some(full.sensor_number()),
RecordContents::CompactSensor(compact) => Some(compact.sensor_number()),
RecordContents::EventOnlySensor(event) => Some(event.key.sensor_number),
Expand Down

0 comments on commit 162c3e0

Please sign in to comment.