Skip to content

Commit 9d58101

Browse files
committed
Finish EfiGuidListEntry handling
Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
1 parent 5f113fa commit 9d58101

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

src/lib/efivar/types/efi_guid_list_entry.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::types::efi_guid::EfiGuid;
2-
use serde::de::{Deserialize};
2+
use crate::types::EfiGuidError;
3+
use serde::de::{Deserialize, Error, MapAccess, Visitor};
34
use std::fmt;
5+
use std::str::FromStr;
46

57
#[derive(PartialEq)]
68
pub struct EfiGuidListEntry {
@@ -9,12 +11,69 @@ pub struct EfiGuidListEntry {
911
pub description: String,
1012
}
1113

14+
struct EfiGuidListEntryVisitor {}
15+
16+
impl EfiGuidListEntryVisitor {
17+
fn new() -> Self {
18+
EfiGuidListEntryVisitor{}
19+
}
20+
}
21+
22+
impl<'de> Visitor<'de> for EfiGuidListEntryVisitor {
23+
type Value = EfiGuidListEntry;
24+
25+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
26+
formatter.write_str("EfiGuiListEntry object")
27+
}
28+
29+
fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
30+
where
31+
M: MapAccess<'de>,
32+
{
33+
let mut guid: Option<Result<EfiGuid, EfiGuidError>> = None;
34+
let mut name: Option<String> = None;
35+
let mut description: Option<String> = None;
36+
37+
while let Some((key, value)) = access.next_entry::<String, String>()? {
38+
if key == "description" {
39+
description = Some(value);
40+
} else if key == "guid" {
41+
guid = Some(EfiGuid::from_str(&value));
42+
} else if key == "name" {
43+
name = Some(value);
44+
} else {
45+
eprintln!("Unknown key: {} with value {}", key, value)
46+
}
47+
}
48+
49+
if description.is_none() {
50+
return Err(M::Error::custom(&"description missing"));
51+
};
52+
if guid.is_none() {
53+
return Err(M::Error::custom(&"guid missing"));
54+
};
55+
if name.is_none() {
56+
return Err(M::Error::custom(&"name missing"));
57+
};
58+
59+
let efiGuidResult = guid.unwrap();
60+
if efiGuidResult.is_err() {
61+
return Err(M::Error::custom(efiGuidResult.unwrap_err()));
62+
}
63+
Ok(EfiGuidListEntry{
64+
description: description.unwrap(),
65+
guid: efiGuidResult.unwrap(),
66+
name: name.unwrap(),
67+
})
68+
}
69+
}
70+
1271
impl<'de> Deserialize<'de> for EfiGuidListEntry {
1372
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1473
where
1574
D: serde::Deserializer<'de>,
1675
{
17-
todo!()
76+
deserializer.deserialize_map(EfiGuidListEntryVisitor::new())
1877
}
1978
}
2079

0 commit comments

Comments
 (0)