diff --git a/Cargo.lock b/Cargo.lock index 79427c0..93f2695 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,6 +1062,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pin-project-lite" version = "0.2.15" @@ -1191,6 +1197,28 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "rustc-hash" version = "2.1.0" @@ -1242,6 +1270,7 @@ dependencies = [ "esp-idf-svc", "futures", "log", + "rmp-serde", "serde", "serde_json", "time", diff --git a/Cargo.toml b/Cargo.toml index 13d2b4e..bd4ab40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ futures = "0.3.31" serde = { version = "1.0.217", features = ["derive"] } serde_json = "1.0.134" time = { version = "0.3.37", features = ["std", "serde-human-readable"] } +rmp-serde = "1.3.0" [[package.metadata.esp-idf-sys.extra_components]] remote_component = { name = "espressif/esp_tinyusb", version = "96cbb5b308f92d2493a0c714f097dcfc51add807", git = "https://github.com/LaunchPlatform/esp-usb.git", path = "device/esp_tinyusb" } diff --git a/src/api/processor.rs b/src/api/processor.rs index 4b3423e..9031c1d 100644 --- a/src/api/processor.rs +++ b/src/api/processor.rs @@ -95,7 +95,10 @@ impl Processor { fn list_files(&self, path: &str) -> anyhow::Result { let dir_path = Path::new(&self.root_dir).join(path); - log::info!("Listing files at {}", dir_path.to_str().unwrap_or("")); + log::info!( + "Listing files at {}", + dir_path.to_str().unwrap_or("") + ); // Ideally we should find a way to learn the size of all files, but we need to // iterate over all files anyway... so.. maybe not? :/ let mut files: Vec = vec![]; @@ -143,7 +146,8 @@ impl Processor { let mut buf = vec![0; chunk_size as usize]; for offset in (0..file_size).step_by(chunk_size as usize) { file.read(&mut buf)?; - assert_eq!(file.stream_position().unwrap(), offset); + // TODO: somehow stream_position doesn't work correctly? + // assert_eq!(file.stream_position().unwrap(), offset); send(CommandResponse { id: req_id.to_string(), response: FetchFileChunk { @@ -216,9 +220,12 @@ pub async fn process_events( Ok(request) => processor.as_mut().unwrap().process( &request, |response: CommandResponse| match response.response { - FetchFileChunk { .. } => { - // TODO: - } + FetchFileChunk { .. } => client + .send( + FrameType::Binary(false), + &rmp_serde::to_vec(&response).unwrap(), + ) + .unwrap(), _ => client .send( FrameType::Text(false),