Skip to content

Commit

Permalink
Implement sending file chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 6, 2025
1 parent bf57c18 commit 99daf7a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
17 changes: 12 additions & 5 deletions src/api/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ impl Processor {

fn list_files(&self, path: &str) -> anyhow::Result<Response> {
let dir_path = Path::new(&self.root_dir).join(path);
log::info!("Listing files at {}", dir_path.to_str().unwrap_or("<Unknown>"));
log::info!(
"Listing files at {}",
dir_path.to_str().unwrap_or("<Unknown>")
);
// 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<File> = vec![];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 99daf7a

Please sign in to comment.