From 9d63807cce16f77bb00baae355458d457483fec2 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Wed, 15 Jan 2020 18:33:06 +0200 Subject: [PATCH] feat(packet): implement From for bytes05::BytesMut ILP-Packet is built using Bytes 0.4. The Futures 0.3 ecosystem's HTTP crates use Bytes 0.5. Porting this crate to use Bytes 0.5 is non-trivial due to significant breaking changes in the Bytes API: https://github.com/tokio-rs/bytes/issues/350 https://github.com/tokio-rs/bytes/pull/288 --- crates/interledger-packet/Cargo.toml | 1 + crates/interledger-packet/src/errors.rs | 2 +- crates/interledger-packet/src/packet.rs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/interledger-packet/Cargo.toml b/crates/interledger-packet/Cargo.toml index 4ec721e16..d3d926ed4 100644 --- a/crates/interledger-packet/Cargo.toml +++ b/crates/interledger-packet/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/interledger-rs/interledger-rs" [dependencies] byteorder = { version = "1.3.2", default-features = false } +bytes05 = { package = "bytes", version = "0.5", default-features = false, features = ["serde"] } bytes = { version = "0.4.12", default-features = false, features = ["serde"] } chrono = { version = "0.4.9", default-features = false } hex = { version = "0.4.0", default-features = false } diff --git a/crates/interledger-packet/src/errors.rs b/crates/interledger-packet/src/errors.rs index 25d8ef6ae..33beeccea 100644 --- a/crates/interledger-packet/src/errors.rs +++ b/crates/interledger-packet/src/errors.rs @@ -41,7 +41,7 @@ quick_error! { description(descr) display("Invalid Packet {}", descr) } - Other(err: Box) { + Other(err: Box) { cause(&**err) description(err.description()) display("Error {}", err.description()) diff --git a/crates/interledger-packet/src/packet.rs b/crates/interledger-packet/src/packet.rs index 9c527a746..9d3d1b1c6 100644 --- a/crates/interledger-packet/src/packet.rs +++ b/crates/interledger-packet/src/packet.rs @@ -359,6 +359,15 @@ impl From for BytesMut { } } +impl From for bytes05::BytesMut { + fn from(fulfill: Fulfill) -> Self { + // bytes 0.4 + let b = fulfill.buffer.as_ref(); + // convert to Bytes05 + bytes05::BytesMut::from(b) + } +} + impl fmt::Debug for Fulfill { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter @@ -481,6 +490,15 @@ impl From for BytesMut { } } +impl From for bytes05::BytesMut { + fn from(reject: Reject) -> Self { + // bytes 0.4 + let b = reject.buffer.as_ref(); + // convert to Bytes05 + bytes05::BytesMut::from(b) + } +} + impl fmt::Debug for Reject { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter