Skip to content

Commit 53abcb5

Browse files
committed
113 Add Permissive Serializer.
1 parent 0865be5 commit 53abcb5

File tree

3 files changed

+161
-49
lines changed

3 files changed

+161
-49
lines changed

src/ondisk.rs

+48-41
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,30 @@ macro_rules! make_bitfield_serde {(
12711271
)*
12721272
}
12731273
}
1274+
1275+
/// Use this for serialization in order to make serde skip those fields
1276+
/// where the meaning of a raw value is unknown to us.
1277+
///
1278+
/// Caller can then override Serializer::skip_field and thus find out
1279+
/// which fields were skipped, inferring where errors were.
1280+
#[cfg(feature = "serde")]
1281+
paste::paste!{
1282+
#[doc(hidden)]
1283+
#[allow(non_camel_case_types)]
1284+
#[cfg_attr(feature = "serde", derive(Serialize))]
1285+
//#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1286+
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
1287+
//#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
1288+
pub(crate) struct [<SerdePermissiveSerializing $StructName>] {
1289+
$(
1290+
$(#[serde(skip_serializing_if="Option::is_none")]
1291+
pub $field_name: Option<$field_ty>,)?
1292+
$(#[serde(skip_serializing_if="Option::is_none")]
1293+
$(#[$serde_field_orig_meta])*
1294+
pub $field_name: Option<$serde_ty>,)?
1295+
)*
1296+
}
1297+
}
12741298
}}
12751299

12761300
make_bitfield_serde! {
@@ -2657,21 +2681,11 @@ pub mod memory {
26572681
#[repr(u32)]
26582682
#[derive(Clone, Copy)]
26592683
pub struct RdimmDdr4Voltages {
2660-
pub _1_2V || #[serde(default)] bool : bool | pub get bool : pub set bool,
2684+
pub _1_2V || #[serde(default)] #[serde(rename = "1.2 V")] bool : bool | pub get bool : pub set bool,
26612685
pub _reserved_1 || #[serde(default)] SerdeHex32 : B31,
26622686
// all = 7
26632687
}
26642688
}
2665-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2666-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
2667-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2668-
#[cfg_attr(feature = "serde", serde(rename = "RdimmDdr4Voltages"))]
2669-
pub struct CustomSerdeRdimmDdr4Voltages {
2670-
#[cfg_attr(feature = "serde", serde(rename = "1.2 V"))]
2671-
pub _1_2V: bool,
2672-
#[cfg_attr(feature = "serde", serde(default))]
2673-
pub _reserved_1: u32,
2674-
}
26752689
macro_rules! define_compat_bitfield_field {
26762690
($compat_field:ident, $current_field:ident) => {
26772691
paste! {
@@ -2820,27 +2834,13 @@ pub mod memory {
28202834
#[repr(u32)]
28212835
#[derive(Clone, Copy)]
28222836
pub struct UdimmDdr4Voltages {
2823-
pub _1_5V || #[serde(default)] bool : bool | pub get bool : pub set bool,
2824-
pub _1_35V || #[serde(default)] bool : bool | pub get bool : pub set bool,
2825-
pub _1_25V || #[serde(default)] bool : bool | pub get bool : pub set bool,
2837+
pub _1_5V || #[serde(default)] #[serde(rename = "1.5 V")] bool : bool | pub get bool : pub set bool,
2838+
pub _1_35V || #[serde(default)] #[serde(rename = "1.35 V")] bool : bool | pub get bool : pub set bool,
2839+
pub _1_25V || #[serde(default)] #[serde(rename = "1.25 V")] bool : bool | pub get bool : pub set bool,
28262840
// all = 7
28272841
pub _reserved_1 || #[serde(default)] SerdeHex32 : B29,
28282842
}
28292843
}
2830-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2831-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
2832-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2833-
#[cfg_attr(feature = "serde", serde(rename = "UdimmDdr4Voltages"))]
2834-
pub struct CustomSerdeUdimmDdr4Voltages {
2835-
#[cfg_attr(feature = "serde", serde(rename = "1.5 V"))]
2836-
pub _1_5V: bool,
2837-
#[cfg_attr(feature = "serde", serde(rename = "1.35 V"))]
2838-
pub _1_35V: bool,
2839-
#[cfg_attr(feature = "serde", serde(rename = "1.25 V"))]
2840-
pub _1_25V: bool,
2841-
#[cfg_attr(feature = "serde", serde(default))]
2842-
pub _reserved_1: u32,
2843-
}
28442844
impl UdimmDdr4Voltages {
28452845
define_compat_bitfield_field!(v_1_5, _1_5V);
28462846
define_compat_bitfield_field!(v_1_35, _1_35V);
@@ -2915,21 +2915,11 @@ pub mod memory {
29152915
#[repr(u32)]
29162916
#[derive(Clone, Copy)]
29172917
pub struct LrdimmDdr4Voltages {
2918-
pub _1_2V || #[serde(default)] bool : bool | pub get bool : pub set bool,
2918+
pub _1_2V || #[serde(default)] #[serde(rename = "1.2 V")] bool : bool | pub get bool : pub set bool,
29192919
// all = 7
29202920
pub _reserved_1 || #[serde(default)] SerdeHex32 : B31,
29212921
}
29222922
}
2923-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2924-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
2925-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2926-
#[cfg_attr(feature = "serde", serde(rename = "LrdimmDdr4Voltages"))]
2927-
pub struct CustomSerdeLrdimmDdr4Voltages {
2928-
#[cfg_attr(feature = "serde", serde(rename = "1.2 V"))]
2929-
pub _1_2V: bool,
2930-
#[cfg_attr(feature = "serde", serde(default))]
2931-
pub _reserved_1: u32,
2932-
}
29332923

29342924
impl LrdimmDdr4Voltages {
29352925
define_compat_bitfield_field!(v_1_2, _1_2V);
@@ -3843,7 +3833,7 @@ pub mod memory {
38433833
}
38443834
}
38453835
#[cfg(feature = "serde")]
3846-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3836+
#[cfg_attr(feature = "serde", derive(Deserialize))]
38473837
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
38483838
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
38493839
#[cfg_attr(feature = "serde", serde(rename = "ErrorOutControlBeepCode"))]
@@ -3853,6 +3843,14 @@ pub mod memory {
38533843
pub peak_attr: ErrorOutControlBeepCodePeakAttr,
38543844
}
38553845
#[cfg(feature = "serde")]
3846+
#[cfg_attr(feature = "serde", derive(Serialize))]
3847+
#[cfg_attr(feature = "serde", serde(rename = "ErrorOutControlBeepCode"))]
3848+
pub(crate) struct CustomSerdePermissiveSerializingErrorOutControlBeepCode {
3849+
pub custom_error_type: Option<ErrorOutControlBeepCodeErrorType>,
3850+
pub peak_map: Option<SerdeHex16>,
3851+
pub peak_attr: Option<ErrorOutControlBeepCodePeakAttr>,
3852+
}
3853+
#[cfg(feature = "serde")]
38563854
impl ErrorOutControlBeepCode {
38573855
pub(crate) fn serde_custom_error_type(
38583856
&self,
@@ -4330,7 +4328,7 @@ Clone)]
43304328
}
43314329

43324330
#[cfg(feature = "serde")]
4333-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4331+
#[cfg_attr(feature = "serde", derive(Deserialize))]
43344332
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
43354333
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
43364334
#[cfg_attr(
@@ -4341,6 +4339,15 @@ Clone)]
43414339
pub raw_body: DdrPostPackageRepairBody,
43424340
}
43434341
#[cfg(feature = "serde")]
4342+
#[cfg_attr(feature = "serde", derive(Serialize))]
4343+
#[cfg_attr(
4344+
feature = "serde",
4345+
serde(rename = "DdrPostPackageRepairElement")
4346+
)]
4347+
pub struct CustomSerdePermissiveSerializingDdrPostPackageRepairElement {
4348+
pub raw_body: Option<DdrPostPackageRepairBody>,
4349+
}
4350+
#[cfg(feature = "serde")]
43444351
impl DdrPostPackageRepairElement {
43454352
pub(crate) fn serde_raw_body(
43464353
&self,

0 commit comments

Comments
 (0)