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