-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from QED-it/streaming
streaming and unified workspace
- Loading branch information
Showing
18 changed files
with
314 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "zkinterface" | ||
version = "1.2.1" | ||
version = "1.3.0" | ||
authors = ["Aurélien Nicolas <[email protected]>"] | ||
license = "MIT" | ||
build = "build.rs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod validator; | |
pub mod simulator; | ||
pub mod stats; | ||
pub mod reader; | ||
pub mod workspace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::path::{PathBuf, Path}; | ||
use std::fs::File; | ||
use std::iter; | ||
use std::io::{Read, stdin}; | ||
use crate::consumers::reader::read_buffer; | ||
use crate::Message; | ||
|
||
pub struct Workspace { | ||
paths: Vec<PathBuf>, | ||
stdin: bool, | ||
} | ||
|
||
impl Workspace { | ||
pub fn new(mut paths: Vec<PathBuf>) -> Self { | ||
if paths == vec![PathBuf::from("-")] { | ||
Workspace { paths: vec![], stdin: true } | ||
} else { | ||
paths.sort(); | ||
paths.sort_by_key(|path| { | ||
let name = path.file_name().unwrap().to_str().unwrap(); | ||
match () { | ||
_ if name.contains("header") => 0, | ||
_ if name.contains("witness") => 1, | ||
_ if name.contains("constraint") => 3, | ||
_ => 4, | ||
} | ||
}); | ||
Workspace { paths, stdin: false } | ||
} | ||
} | ||
|
||
pub fn iter_messages<'w>(&'w self) -> impl Iterator<Item=Message> + 'w { | ||
let buffers: Box<dyn Iterator<Item=Vec<u8>>> = if self.stdin { | ||
Box::new(iterate_stream(stdin())) | ||
} else { | ||
Box::new(iterate_files(&self.paths)) | ||
}; | ||
|
||
buffers.map(|buffer| Message::from(&buffer[..])) | ||
} | ||
} | ||
|
||
pub fn iterate_files<'w>(paths: &'w [PathBuf]) -> impl Iterator<Item=Vec<u8>> + 'w { | ||
paths.iter().flat_map(|path| | ||
iterate_file(path)) | ||
} | ||
|
||
pub fn iterate_file(path: &Path) -> Box<dyn Iterator<Item=Vec<u8>>> { | ||
match File::open(path) { | ||
Err(err) => { | ||
eprintln!("Error opening workspace file {}: {}", path.display(), err); | ||
Box::new(iter::empty()) | ||
} | ||
Ok(file) => Box::new( | ||
iterate_stream(file)), | ||
} | ||
} | ||
|
||
pub fn iterate_stream<'s>(mut stream: impl Read + 's) -> impl Iterator<Item=Vec<u8>> + 's { | ||
iter::from_fn(move || | ||
match read_buffer(&mut stream) { | ||
Err(err) => { | ||
eprintln!("Error reading: {}", err); | ||
None | ||
} | ||
Ok(buffer) => { | ||
if buffer.len() == 0 { | ||
None | ||
} else { | ||
Some(buffer) | ||
} | ||
} | ||
} | ||
) | ||
} |
Oops, something went wrong.