Skip to content

Commit d0baab1

Browse files
committed
Add NullStr type
This is a private type that is intended to be shared across wire types that act as a null-padded fixed length container format. This is intended to be used in a follow up PR for supporting oxidecomputer/hubris#2463, but this is separated to make reviewing this helper easier.
1 parent 0158ec7 commit d0baab1

3 files changed

Lines changed: 2 additions & 154 deletions

File tree

faux-mgs/src/main.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,27 +3281,8 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
32813281
Measurement(Measurement),
32823282
LastPostCode(u32),
32833283
PostCode(u32),
3284-
GpioToggleCount {
3285-
edge_count: u32,
3286-
cycles_since_last_edge: u32,
3287-
},
3288-
Pcie {
3289-
bar: u32,
3290-
offset: u32,
3291-
reg_result: Result<u32, u32>,
3292-
},
3293-
PmbusStatus {
3294-
status_word: u16,
3295-
status_vout: u8,
3296-
status_iout: u8,
3297-
status_temperature: u8,
3298-
status_cml: u8,
3299-
status_other: u8,
3300-
status_input: u8,
3301-
status_mfr_specific: u8,
3302-
status_fans_1_2: u8,
3303-
status_fans_3_4: u8,
3304-
},
3284+
GpioToggleCount { edge_count: u32, cycles_since_last_edge: u32 },
3285+
Pcie { bar: u32, offset: u32, reg_result: Result<u32, u32> },
33053286
}
33063287

33073288
#[derive(serde::Serialize)]
@@ -3344,20 +3325,6 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
33443325
reg_result: p.reg_result,
33453326
}
33463327
}
3347-
gateway_messages::ComponentDetails::PmbusStatus(stat) => {
3348-
ComponentDetails::PmbusStatus {
3349-
status_word: stat.status_word,
3350-
status_vout: stat.status_vout,
3351-
status_iout: stat.status_iout,
3352-
status_temperature: stat.status_temperature,
3353-
status_cml: stat.status_cml,
3354-
status_other: stat.status_other,
3355-
status_input: stat.status_input,
3356-
status_mfr_specific: stat.status_mfr_specific,
3357-
status_fans_1_2: stat.status_fans_1_2,
3358-
status_fans_3_4: stat.status_fans_3_4,
3359-
}
3360-
}
33613328
})
33623329
.collect::<Vec<_>>();
33633330

gateway-messages/src/lib.rs

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -618,71 +618,6 @@ impl TryFrom<&str> for SpComponent {
618618
}
619619
}
620620

621-
/// Identifier for a single power rail.
622-
#[derive(
623-
Clone, Copy, PartialEq, Eq, Hash, SerializedSize, Serialize, Deserialize,
624-
)]
625-
#[serde(transparent)]
626-
pub struct PowerRailName {
627-
name: nullstr::NullStr<{ Self::MAX_NAME_LENGTH }>,
628-
}
629-
630-
impl core::fmt::Display for PowerRailName {
631-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
632-
self.name.fmt(f)
633-
}
634-
}
635-
636-
impl PowerRailName {
637-
/// Maximum number of bytes for a Power Rail Name.
638-
pub const MAX_NAME_LENGTH: usize = 32;
639-
640-
/// Interpret the power rail name as a human-readable string.
641-
///
642-
/// Our current expectation of power rail names is that this should never
643-
/// fail (i.e., we're always storing power rail names as human-readable
644-
/// strings), but because we reconstitute components from network messages
645-
/// we still need to check.
646-
#[inline]
647-
pub fn as_str(&self) -> Option<&str> {
648-
self.name.as_str()
649-
}
650-
651-
/// Interpret the power rail name as a human-readable string in a `const`
652-
/// context, panicking if the string is not human readable.
653-
///
654-
/// This function should only be used in const contexts when the caller
655-
/// knows the component is valid (e.g., one of this type's associated
656-
/// constants); for component names parsed or constructed at runtime, prefer
657-
/// [`PowerRailName::as_str()`] which performs runtime validation.
658-
#[inline]
659-
pub const fn const_as_str(&self) -> &str {
660-
self.name.const_as_str()
661-
}
662-
663-
#[inline]
664-
pub const fn from_const(val: &str) -> Self {
665-
Self { name: nullstr::NullStr::from_const(val) }
666-
}
667-
668-
#[inline]
669-
pub fn id(&self) -> &[u8; Self::MAX_NAME_LENGTH] {
670-
self.name.contents()
671-
}
672-
}
673-
674-
impl fmt::Debug for PowerRailName {
675-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
676-
let mut debug = f.debug_struct("PowerRailName");
677-
if let Some(s) = self.as_str() {
678-
debug.field("name", &s);
679-
} else {
680-
debug.field("name", self.name.contents());
681-
}
682-
debug.finish()
683-
}
684-
}
685-
686621
/// Minimum guaranteed space for trailing data in a single packet.
687622
///
688623
/// Depending on the [`Message`] payload, there may be more space for trailing
@@ -801,33 +736,4 @@ mod tests {
801736
(component, &[] as &[u8])
802737
);
803738
}
804-
805-
#[test]
806-
fn test_human_readable_power_rail() {
807-
let rail = const { PowerRailName::from_const("V0P96_NIC_VDD_A0HP") };
808-
let expected_value =
809-
serde_json::Value::String("V0P96_NIC_VDD_A0HP".to_string());
810-
811-
assert_eq!(serde_json::to_value(rail).unwrap(), expected_value);
812-
assert_eq!(
813-
serde_json::from_value::<PowerRailName>(expected_value).unwrap(),
814-
rail
815-
);
816-
}
817-
818-
#[test]
819-
fn test_non_human_readable_power_rail() {
820-
let rail = const { PowerRailName::from_const("V0P96_NIC_VDD_A0HP") };
821-
let expected_value = rail.name;
822-
823-
let mut out = [0; PowerRailName::MAX_SIZE];
824-
let n = hubpack::serialize(&mut out, &rail).unwrap();
825-
assert_eq!(&out[..n], expected_value.contents());
826-
827-
assert_eq!(
828-
hubpack::deserialize::<PowerRailName>(expected_value.contents())
829-
.unwrap(),
830-
(rail, &[] as &[u8])
831-
);
832-
}
833739
}

gateway-messages/src/sp_to_mgs.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -712,26 +712,6 @@ pub struct TlvPage {
712712
pub total: u32,
713713
}
714714

715-
#[derive(
716-
Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, SerializedSize,
717-
)]
718-
pub struct PmbusStatus {
719-
pub status_word: u16,
720-
pub status_vout: u8,
721-
pub status_iout: u8,
722-
pub status_temperature: u8,
723-
pub status_cml: u8,
724-
pub status_other: u8,
725-
pub status_input: u8,
726-
pub status_mfr_specific: u8,
727-
pub status_fans_1_2: u8,
728-
pub status_fans_3_4: u8,
729-
}
730-
731-
impl PmbusStatus {
732-
pub const TAG: tlv::Tag = tlv::Tag(*b"PMBS");
733-
}
734-
735715
/// Types of component details that can be included in the TLV-encoded data of
736716
/// an [`SpResponse::ComponentDetails(_)`] message.
737717
///
@@ -749,7 +729,6 @@ pub enum ComponentDetails {
749729
PostCode(PostCode),
750730
GpioToggleCount(GpioToggleCount),
751731
Pcie(PcieRegisterRead),
752-
PmbusStatus(PmbusStatus),
753732
}
754733

755734
impl ComponentDetails {
@@ -761,7 +740,6 @@ impl ComponentDetails {
761740
ComponentDetails::PostCode(_) => PostCode::TAG,
762741
ComponentDetails::GpioToggleCount(_) => GpioToggleCount::TAG,
763742
ComponentDetails::Pcie(_) => PcieRegisterRead::TAG,
764-
ComponentDetails::PmbusStatus(_) => PmbusStatus::TAG,
765743
}
766744
}
767745

@@ -791,9 +769,6 @@ impl ComponentDetails {
791769
hubpack::serialize(buf, code)
792770
}
793771
ComponentDetails::Pcie(p) => hubpack::serialize(buf, p),
794-
ComponentDetails::PmbusStatus(stat) => {
795-
hubpack::serialize(buf, stat)
796-
}
797772
}
798773
}
799774
}

0 commit comments

Comments
 (0)