Skip to content

Commit

Permalink
mshv-bindings: serialize and deserilize state components
Browse files Browse the repository at this point in the history
Signed-off-by: Muminul Islam <[email protected]>
  • Loading branch information
russell-islam committed Apr 9, 2024
1 parent 8a70cbf commit 1d7f4d7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mshv-bindings/src/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ impl Serialize for XSave {
data_buffer.serialize(serializer)
}
}

impl Serialize for AllVpStateComponents {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
let data_buffer = &self.buffer[..];
data_buffer.serialize(serializer)
}
}

impl<'de> Deserialize<'de> for AllVpStateComponents {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let data_buffer: Vec<u8> = Vec::deserialize(deserializer)?;
let mut val = AllVpStateComponents::default();
// This panics if the source and destination have different lengths.
val.buffer.copy_from_slice(&data_buffer[..]);
Ok(val)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 1d7f4d7

Please sign in to comment.