Skip to content

Commit

Permalink
build!: update rmp serde to v1 (#48)
Browse files Browse the repository at this point in the history
* build: update rmp-serde and serde

* test(conductor_api): adapt enum output

* docs: update changelog

* build: update nix flake

* Fix build by not using scripts meant for a workspace with binaries

---------

Co-authored-by: ThetaSinner <[email protected]>
  • Loading branch information
jost-s and ThetaSinner authored Apr 17, 2024
1 parent 8394f1c commit fbdab15
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- name: Build Nix packages for dev shell
run: nix develop -c $SHELL -c "rustc --version --verbose"
- name: Run fmt
run: nix develop -c $SHELL -c "script-holochain-tests-static-fmt"
run: nix develop -c cargo fmt --all -- --check
- name: Run clippy
run: nix develop -c $SHELL -c "script-holochain-tests-static-clippy"
run: nix develop -c cargo clippy --all -- --deny warnings
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[Unreleased]
## Changed
- **BREAKING**: Updated dependencies `rmp-serde` and `serde`. Serialization format for Rust enums changed.
An enum
```rust
enum ConductorApi {
Request { param: i32 },
}
let request = ConductorApi::Request { param: 100 };
```
previously serialized to
```json
{
"type": {
"request": null
},
"data": {
"param": 100
}
}
```
and now serializes to
```json
{
"type": "request",
"data": {
"param": 100
}
}
```

## [0.0.53] - 2023-08-29

## Added
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ members = [

[profile.release]
debug = true

[workspace.lints.clippy]
style = "deny"
complexity = "deny"
perf = "deny"
correctness = "deny"
dbg_macro = "deny"
15 changes: 7 additions & 8 deletions crates/holochain_serialized_bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ repository = "https://github.com/holochain/holochain-serialization"
edition = "2018"

[dependencies]
serde = { version = "=1.0.193", features = ["serde_derive"] }
serde = { version = "=1.0.197", features = ["serde_derive"] }
serde_json = { version = "1.0.51", features = ["preserve_order"] }
holochain_serialized_bytes_derive = { version = "=0.0.53", path = "../holochain_serialized_bytes_derive" }
rmp-serde = "=0.15.5"
rmp-serde = "=1.1.2"
serde-transcode = "1.1.0"
thiserror = "1.0.10"
serde_bytes = "0.11"
Expand All @@ -27,18 +27,17 @@ proptest-derive = { version = "0.3", optional = true }

[dev-dependencies]
criterion = "0.3"
tracing-subscriber="0.2"
tracing-subscriber = "0.2"
test-fuzz = "=3.0.4"

[[bench]]
name = "bench"
harness = false

[features]
fuzzing = [
"arbitrary",
"proptest",
"proptest-derive",
]
fuzzing = ["arbitrary", "proptest", "proptest-derive"]

trace = ["tracing"]

[lints]
workspace = true
15 changes: 5 additions & 10 deletions crates/holochain_serialized_bytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub fn encode<T: serde::Serialize + std::fmt::Debug>(
val: &T,
) -> Result<Vec<u8>, SerializedBytesError> {
let buf = Vec::with_capacity(128);
let mut se = rmp_serde::encode::Serializer::new(buf)
.with_struct_map()
.with_string_variants();
let mut se = rmp_serde::encode::Serializer::new(buf).with_struct_map();
val.serialize(&mut se).map_err(|err| {
#[cfg(feature = "trace")]
tracing::warn!("Failed to serialize input");
Expand All @@ -38,7 +36,7 @@ where
R: AsRef<[u8]> + ?Sized + std::fmt::Debug,
T: Deserialize<'a> + std::fmt::Debug,
{
let ret = rmp_serde::from_read_ref(input).map_err(|err| {
let ret = rmp_serde::from_slice(input.as_ref()).map_err(|err| {
#[cfg(feature = "trace")]
tracing::warn!(
"Failed to deserialize input into: {}",
Expand Down Expand Up @@ -330,18 +328,15 @@ pub mod tests {
assert_eq!(
request_encoded,
[
130, 164, 116, 121, 112, 101, 129, 167, 114, 101, 113, 117, 101, 115, 116, 192,
164, 100, 97, 116, 97, 129, 165, 112, 97, 114, 97, 109, 100
130, 164, 116, 121, 112, 101, 167, 114, 101, 113, 117, 101, 115, 116, 164, 100, 97,
116, 97, 129, 165, 112, 97, 114, 97, 109, 100
]
);

let mut deserializer = Deserializer::new(&*request_encoded);
let value: Value = Deserialize::deserialize(&mut deserializer).unwrap();
let json_string = serde_json::to_string(&value).unwrap();
assert_eq!(
r#"{"type":{"request":null},"data":{"param":100}}"#,
json_string
);
assert_eq!(r#"{"type":"request","data":{"param":100}}"#, json_string);
}

/// struct with a utf8 string in it
Expand Down
3 changes: 3 additions & 0 deletions crates/holochain_serialized_bytes_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ proc-macro = true
[dependencies]
syn = "1.0"
quote = "1.0"

[lints]
workspace = true
Loading

0 comments on commit fbdab15

Please sign in to comment.