Skip to content

Commit d864716

Browse files
authored
Merge pull request #15 from GiGainfosystems/update_to_bincode_2
Update to bincode 2
2 parents 61d225d + 34d22df commit d864716

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

Cargo.lock

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,25 @@ impl From<Box<dyn Any + Send>> for SerializableError {
5757
}
5858
}
5959

60-
impl From<Box<bincode::ErrorKind>> for SerializableError {
61-
fn from(value: Box<bincode::ErrorKind>) -> Self {
60+
impl From<bincode::error::DecodeError> for SerializableError {
61+
fn from(value: bincode::error::DecodeError) -> Self {
6262
Self {
63-
message: format!("Bincode: {value}"),
63+
message: format!("Bincode Decode Error: {value}"),
6464
}
6565
}
6666
}
67+
68+
impl From<bincode::error::EncodeError> for SerializableError {
69+
fn from(value: bincode::error::EncodeError) -> Self {
70+
Self {
71+
message: format!("Bincode Encode Error: {value}"),
72+
}
73+
}
74+
}
75+
6776
```
6877

69-
Note that the module, the error itself, and the fields on the error need to be public. If that is not the case, you should receive an error during code generation that points you to this issue. You will have to add [Serde](https://crates.io/crates/serde) and [Bincode](https://crates.io/crates/bincode) to your crate for this to work.
78+
Note that the module, the error itself, and the fields on the error need to be public. If that is not the case, you should receive an error during code generation that points you to this issue. You will have to add [Serde](https://crates.io/crates/serde) and [Bincode 2](https://crates.io/crates/bincode) to your crate for this to work.
7079

7180
Furthermore, to release any memory allocated by the Rust side of your API, you will have to include a function for the C++ side to release memory. This function looks like this:
7281

buffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "buffi"
33
description = "A tool to generate ergonomic, buffer-based C++ APIs."
4-
version = "0.2.7+rust.1.86.0"
4+
version = "0.3.0+rust.1.86.0"
55
edition = "2024"
66
license = "MIT OR Apache-2.0"
77
documentation = "https://docs.rs/buffi"

buffi_macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "buffi_macro"
33
description = "A proc-macro to generate ergonomic, buffer-based C++ APIs."
4-
version = "0.2.7"
4+
version = "0.3.0"
55
edition = "2024"
66
license = "MIT OR Apache-2.0"
77
documentation = "https://docs.rs/buffi_macro"

buffi_macro/src/proc_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn generate_exported_function<'a>(
146146
std::slice::from_raw_parts(#n, #n_size)
147147
}
148148
};
149-
let #n = bincode::deserialize(slice)?;
149+
let #n = bincode::serde::decode_from_slice(slice, bincode::config::legacy())?.0;
150150
})
151151
} else {
152152
None
@@ -286,14 +286,14 @@ fn generate_exported_function<'a>(
286286
Err(crate::errors::SerializableError::from(e))
287287
}
288288
};
289-
let bytes = match bincode::serialize(&res) {
289+
let bytes = match bincode::serde::encode_to_vec(&res, bincode::config::legacy()) {
290290
Ok(bytes) => {
291291
bytes
292292
}
293293
Err(e) => {
294294
#tracing_serializable_w
295295
res = Err(e.into());
296-
match bincode::serialize(&res) {
296+
match bincode::serde::encode_to_vec(&res, bincode::config::legacy()) {
297297
Ok(bytes) => {
298298
bytes
299299
}

example/buffi_example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["staticlib"]
99

1010
[dependencies]
1111
buffi_macro = { path = "../../buffi_macro" }
12-
bincode = "1.3.3"
12+
bincode = { version = "2.0.1", features = ["std", "serde"], default-features = false }
1313
serde = { version = "1.0.214", features = ["derive"] }
1414
tokio = { version = "1.41.1", features = ["rt-multi-thread"] }
1515
cgmath = { version = "0.18.0", features = ["serde"] }

example/buffi_example/src/errors.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ impl From<Box<dyn Any + Send>> for SerializableError {
2424
}
2525
}
2626

27-
impl From<Box<bincode::ErrorKind>> for SerializableError {
28-
fn from(value: Box<bincode::ErrorKind>) -> Self {
27+
impl From<bincode::error::DecodeError> for SerializableError {
28+
fn from(value: bincode::error::DecodeError) -> Self {
2929
Self {
30-
message: format!("Bincode: {value}"),
30+
message: format!("Bincode Decode Error: {value}"),
31+
}
32+
}
33+
}
34+
35+
impl From<bincode::error::EncodeError> for SerializableError {
36+
fn from(value: bincode::error::EncodeError) -> Self {
37+
Self {
38+
message: format!("Bincode Encode Error: {value}"),
3139
}
3240
}
3341
}

0 commit comments

Comments
 (0)