1use fidl_fuchsia_hwinfo::{BoardInfo, DeviceInfo, ProductInfo};
6use serde::Serialize;
7
8#[derive(Clone, Debug, Serialize)]
9pub struct SerializableDeviceInfo {
10 pub serial_number: Option<String>,
11}
12
13impl SerializableDeviceInfo {
15 pub fn new(device: &DeviceInfo) -> Self {
16 SerializableDeviceInfo { serial_number: device.serial_number.clone() }
17 }
18}
19
20#[derive(Clone, Debug, Serialize)]
21pub struct SerializableProductInfo {
22 pub sku: Option<String>,
23 pub language: Option<String>,
24 pub regulatory_domain: Option<String>,
25 pub locale_list: Option<Vec<String>>,
26 pub name: Option<String>,
27 pub model: Option<String>,
28 pub manufacturer: Option<String>,
29 pub build_date: Option<String>,
30 pub build_name: Option<String>,
31 pub colorway: Option<String>,
32 pub display: Option<String>,
33 pub memory: Option<String>,
34 pub nand_storage: Option<String>,
35 pub emmc_storage: Option<String>,
36 pub microphone: Option<String>,
37 pub audio_amplifier: Option<String>,
38}
39
40impl SerializableProductInfo {
42 pub fn new(product: &ProductInfo) -> Self {
43 let regulatory_domain = match &product.regulatory_domain {
44 Some(r) => r.country_code.clone(),
45 None => None,
46 };
47
48 let locale_list = match &product.locale_list {
49 Some(list) => {
50 let mut locale_id_list = Vec::new();
51 for locale in list.into_iter() {
52 locale_id_list.push(locale.id.to_string());
53 }
54 Some(locale_id_list)
55 }
56 None => None,
57 };
58
59 let build_date = match &product.build_date {
61 Some(date) => {
62 let sub = &date[2..10];
63 let result = sub.replace("-", "");
64 Some(result)
65 }
66 None => None,
67 };
68
69 SerializableProductInfo {
70 sku: product.sku.clone(),
71 language: product.language.clone(),
72 regulatory_domain: regulatory_domain,
73 locale_list: locale_list,
74 name: product.name.clone(),
75 model: product.model.clone(),
76 manufacturer: product.manufacturer.clone(),
77 build_date: build_date,
78 build_name: product.build_name.clone(),
79 colorway: product.colorway.clone(),
80 display: product.display.clone(),
81 memory: product.memory.clone(),
82 nand_storage: product.nand_storage.clone(),
83 emmc_storage: product.emmc_storage.clone(),
84 microphone: product.microphone.clone(),
85 audio_amplifier: product.audio_amplifier.clone(),
86 }
87 }
88}
89
90#[derive(Clone, Debug, Serialize)]
91pub struct SerializableBoardInfo {
92 pub name: Option<String>,
93 pub revision: Option<String>,
94}
95
96impl SerializableBoardInfo {
98 pub fn new(board: &BoardInfo) -> Self {
99 SerializableBoardInfo { name: board.name.clone(), revision: board.revision.clone() }
100 }
101}