wasefire_protocol/transfer.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
15//! Protocol to transfer data from the host to the device.
16
17use alloc::borrow::Cow;
18
19use wasefire_wire::Wire;
20
21/// Requests to transfer data.
22#[derive(Debug, Wire)]
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24pub enum Request<'a> {
25 /// Starts a transfer.
26 Start {
27 /// Whether the transfer is a dry-run.
28 ///
29 /// In dry-run mode, nothing is erased or written, but the process is otherwise unchanged.
30 dry_run: bool,
31 },
32
33 /// Erases a page.
34 ///
35 /// See [`Response::Start::chunk_size`] for the number of pages to erase.
36 Erase,
37
38 /// Writes a chunk of data.
39 Write {
40 /// The next chunk of data to transfer.
41 ///
42 /// It should have [`Response::Start::chunk_size`] bytes unless it's the last chunk.
43 chunk: Cow<'a, [u8]>,
44 },
45
46 /// Finishes a transfer.
47 Finish,
48}
49
50#[derive(Debug, Wire)]
51#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
52pub enum Response {
53 Start {
54 /// Size in bytes of a complete chunk.
55 chunk_size: usize,
56
57 /// Number of pages to erase.
58 num_pages: usize,
59 },
60 Erase,
61 Write,
62 Finish,
63}
64
65#[derive(Debug, Wire)]
66#[cfg(feature = "host")]
67#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
68pub enum _Request0<'a> {
69 Start { dry_run: bool },
70 Write { chunk: Cow<'a, [u8]> },
71 Finish,
72}