Skip to content

Commit ce30cfd

Browse files
authored
Properly serialize ACPI tables (#519)
Adds a new vec_base64_vec module for deserializing a Vec of Vec's. Used for the ACPI tables.
1 parent b682370 commit ce30cfd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

support/serde_helpers/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,34 @@ pub mod opt_base64_vec {
141141
}
142142
}
143143

144+
pub mod vec_base64_vec {
145+
use base64::Engine;
146+
use ser::SerializeSeq;
147+
use serde::*;
148+
149+
#[allow(clippy::ptr_arg)] // required by serde
150+
pub fn serialize<S: Serializer>(v: &Vec<Vec<u8>>, ser: S) -> Result<S::Ok, S::Error> {
151+
let mut seq = ser.serialize_seq(Some(v.len()))?;
152+
for element in v {
153+
seq.serialize_element(&base64::engine::general_purpose::STANDARD.encode(element))?;
154+
}
155+
seq.end()
156+
}
157+
158+
pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<Vec<u8>>, D::Error> {
159+
let ss: Vec<&str> = Deserialize::deserialize(d)?;
160+
let mut vs = Vec::new();
161+
for s in ss {
162+
vs.push(
163+
base64::engine::general_purpose::STANDARD
164+
.decode(s)
165+
.map_err(de::Error::custom)?,
166+
);
167+
}
168+
Ok(vs)
169+
}
170+
}
171+
144172
#[cfg(test)]
145173
mod test {
146174
use super::*;

vm/devices/get/get_protocol/src/dps_json.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct HclDevicePlatformSettingsV2Dynamic {
157157
pub is_servicing_scenario: bool,
158158

159159
#[serde(default)]
160+
#[serde(with = "serde_helpers::vec_base64_vec")]
160161
pub acpi_tables: Vec<Vec<u8>>,
161162
}
162163

0 commit comments

Comments
 (0)