Skip to content

Commit

Permalink
chore: Optimize public parameter serialization with bincode
Browse files Browse the repository at this point in the history
- Introduce `bincode` dependency to replace `serde_json` in serialization and deserialization
- Improve error message for cache deserialization issues in `public_parameters` module
  • Loading branch information
huitseeker committed May 5, 2023
1 parent 011bfc5 commit 05261c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 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 @@ -50,6 +50,7 @@ nom = "7.1.3"
clap = "4.1.8"
tap = "1.0.1"
anymap = "0.12.1"
bincode = "1.3.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
memmap = { version = "0.5.10", package = "memmap2" }
Expand Down
5 changes: 3 additions & 2 deletions src/public_parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,14 @@ where
let file = File::create(path).expect("failed to create file");
let writer = BufWriter::new(&file);

serde_json::to_writer(writer, &self).expect("failed to write file");
bincode::serialize_into(writer, &self).expect("failed to write file");
}

fn read_from_path<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let file = File::open(path)?;
let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?)
bincode::deserialize_from(reader)
.map_err(|e| Error::CacheError(format!("Cache deserialization error: {}", e)))
}

fn read_from_stdin() -> Result<Self, Error> {
Expand Down

0 comments on commit 05261c6

Please sign in to comment.