wasefire_protocol/
platform.rs

1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use wasefire_common::platform::Side;
16use wasefire_error::Error;
17use wasefire_wire::Wire;
18
19#[derive(Debug, Wire)]
20pub struct Info<'a> {
21    pub serial: &'a [u8],
22    pub running_side: Side,
23    pub running_version: &'a [u8],
24    pub opposite_version: Result<&'a [u8], Error>,
25}
26
27#[cfg(feature = "host")]
28impl core::fmt::Display for Info<'_> {
29    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30        use data_encoding::HEXLOWER as HEX;
31        writeln!(f, "  serial: {}", HEX.encode_display(self.serial))?;
32        writeln!(f, "    side: {}", self.running_side)?;
33        writeln!(f, " version: {}", HEX.encode_display(self.running_version))?;
34        writeln!(
35            f,
36            "opposite: {}",
37            match self.opposite_version {
38                Ok(x) => HEX.encode(x),
39                Err(e) => alloc::format!("{e}"),
40            }
41        )
42    }
43}
44
45#[derive(Debug, Wire)]
46pub struct _Info0<'a> {
47    pub serial: &'a [u8],
48    pub version: &'a [u8],
49}