From a7fe09ff170367fb9e043d65ec7c4889509007de Mon Sep 17 00:00:00 2001 From: minghuaw Date: Tue, 29 Oct 2024 05:09:11 -0700 Subject: [PATCH 1/5] add to_lazy_value --- serde_amqp/Cargo.toml | 2 +- serde_amqp/Changelog.md | 4 ++++ serde_amqp/src/lazy.rs | 9 +++++++++ serde_amqp/src/size_ser.rs | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/serde_amqp/Cargo.toml b/serde_amqp/Cargo.toml index b9a65f09..e2637c30 100644 --- a/serde_amqp/Cargo.toml +++ b/serde_amqp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_amqp" -version = "0.13.0" +version = "0.13.1" edition = "2021" description = "A serde implementation of AMQP1.0 protocol." license = "MIT/Apache-2.0" diff --git a/serde_amqp/Changelog.md b/serde_amqp/Changelog.md index 67669609..cdbbcb4c 100644 --- a/serde_amqp/Changelog.md +++ b/serde_amqp/Changelog.md @@ -1,5 +1,9 @@ # Change Log +## 0.13.1 + +1. Added `to_lazy_value` + ## 0.13.0 ### Breaking diff --git a/serde_amqp/src/lazy.rs b/serde_amqp/src/lazy.rs index 972be236..4e6e14e1 100644 --- a/serde_amqp/src/lazy.rs +++ b/serde_amqp/src/lazy.rs @@ -9,6 +9,15 @@ use crate::{ __constants::LAZY_VALUE, }; +/// Serialize a value into a [`LazyValue`]. +pub fn to_lazy_value(value: &T) -> Result +where + T: Serialize, +{ + let bytes = crate::to_vec(value)?; + Ok(LazyValue(Bytes::from(bytes))) +} + /// A lazy value. /// /// This is a thin wrapper around a [`Bytes`] value that can be accessed via diff --git a/serde_amqp/src/size_ser.rs b/serde_amqp/src/size_ser.rs index 152296cc..5a32bf7d 100644 --- a/serde_amqp/src/size_ser.rs +++ b/serde_amqp/src/size_ser.rs @@ -871,6 +871,7 @@ mod tests { use serde_bytes::ByteBuf; use crate::{ + lazy::to_lazy_value, primitives::{Array, Dec128, Dec32, Dec64, Symbol, Timestamp, Uuid}, to_vec, }; @@ -1311,4 +1312,26 @@ mod tests { let size_result = serialized_size(&value); assert!(size_result.is_ok()); } + + #[test] + fn serialized_size_of_lazy_value_match_with_value() { + use crate::{described::Described, descriptor::Descriptor, primitives::*, Value}; + + let timestamp = Timestamp::from_milliseconds(12345); + let mut list = List::new(); + list.push(Value::Timestamp(timestamp)); + + let described = Described { + descriptor: Descriptor::Code(0x73), + value: Value::List(list), + }; + + let value = Value::Described(Box::new(described)); + let lazy_value = to_lazy_value(&value).unwrap(); + + let value_size = serialized_size(&value).unwrap(); + let lazy_value_size = serialized_size(&lazy_value).unwrap(); + + assert_eq!(value_size, lazy_value_size); + } } From f8e829621d5c1a9f8d0e8147e157b4272a4f7df4 Mon Sep 17 00:00:00 2001 From: minghuaw Date: Tue, 29 Oct 2024 05:42:45 -0700 Subject: [PATCH 2/5] suppress clippy::result_large_err due to breaking change required --- fe2o3-amqp-ws/src/native.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/fe2o3-amqp-ws/src/native.rs b/fe2o3-amqp-ws/src/native.rs index d64110db..f52718a0 100644 --- a/fe2o3-amqp-ws/src/native.rs +++ b/fe2o3-amqp-ws/src/native.rs @@ -301,6 +301,7 @@ fn map_amqp_websocket_request(req: impl IntoClientRequest) -> Result Result { use http::StatusCode; From a489bcc1f54c1eac59e73481a35a579ab2bae10a Mon Sep 17 00:00:00 2001 From: minghuaw Date: Tue, 29 Oct 2024 05:48:29 -0700 Subject: [PATCH 3/5] suppress clippy::result_large_err --- fe2o3-amqp-management/src/lib.rs | 2 ++ fe2o3-amqp/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fe2o3-amqp-management/src/lib.rs b/fe2o3-amqp-management/src/lib.rs index 32b0c877..664997f6 100644 --- a/fe2o3-amqp-management/src/lib.rs +++ b/fe2o3-amqp-management/src/lib.rs @@ -1,5 +1,7 @@ #![deny(missing_docs, missing_debug_implementations)] +#![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 + //! An experimental implementation of AMQP 1.0 management working draft with `fe2o3-amqp` //! //! Because the AMQP 1.0 management working draft itself isn't stable yet, this crate is diff --git a/fe2o3-amqp/src/lib.rs b/fe2o3-amqp/src/lib.rs index f4d5649c..15e59824 100644 --- a/fe2o3-amqp/src/lib.rs +++ b/fe2o3-amqp/src/lib.rs @@ -2,6 +2,8 @@ #![deny(missing_docs, missing_debug_implementations)] #![warn(clippy::unused_async)] +#![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 + //! A rust implementation of AMQP 1.0 protocol based on serde and tokio. //! //! [![crate_version](https://img.shields.io/crates/v/fe2o3-amqp.svg?style=flat)](https://crates.io/crates/fe2o3-amqp) From 003cb26beaeea25c0d2b6b48c98652da9b6629bf Mon Sep 17 00:00:00 2001 From: minghuaw Date: Tue, 29 Oct 2024 05:50:39 -0700 Subject: [PATCH 4/5] cargo fmt --- fe2o3-amqp-management/src/lib.rs | 1 - fe2o3-amqp/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/fe2o3-amqp-management/src/lib.rs b/fe2o3-amqp-management/src/lib.rs index 664997f6..9363a083 100644 --- a/fe2o3-amqp-management/src/lib.rs +++ b/fe2o3-amqp-management/src/lib.rs @@ -1,5 +1,4 @@ #![deny(missing_docs, missing_debug_implementations)] - #![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 //! An experimental implementation of AMQP 1.0 management working draft with `fe2o3-amqp` diff --git a/fe2o3-amqp/src/lib.rs b/fe2o3-amqp/src/lib.rs index 15e59824..f0df00b8 100644 --- a/fe2o3-amqp/src/lib.rs +++ b/fe2o3-amqp/src/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(missing_docs, missing_debug_implementations)] #![warn(clippy::unused_async)] - #![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 //! A rust implementation of AMQP 1.0 protocol based on serde and tokio. From 74d97c184170f3277341e5ec7dc16e8b17737185 Mon Sep 17 00:00:00 2001 From: minghuaw Date: Tue, 29 Oct 2024 05:51:20 -0700 Subject: [PATCH 5/5] remove unused unit test --- fe2o3-amqp-management/src/lib.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fe2o3-amqp-management/src/lib.rs b/fe2o3-amqp-management/src/lib.rs index 9363a083..43a14ef3 100644 --- a/fe2o3-amqp-management/src/lib.rs +++ b/fe2o3-amqp-management/src/lib.rs @@ -26,12 +26,3 @@ pub const DEFAULT_CLIENT_NODE_ADDRESS: &str = "mgmt-client"; pub use client::MgmtClient; pub use request::Request; pub use response::Response; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -}