Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_lazy_value #293

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions fe2o3-amqp-management/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![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`
//!
Expand All @@ -25,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);
}
}
1 change: 1 addition & 0 deletions fe2o3-amqp-ws/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ fn map_amqp_websocket_request(req: impl IntoClientRequest) -> Result<Request, tu
Ok(request)
}

#[allow(clippy::result_large_err)] // TODO: refactor
fn verify_response(response: Response) -> Result<Response, Error> {
use http::StatusCode;

Expand Down
1 change: 1 addition & 0 deletions fe2o3-amqp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![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.
//!
Expand Down
2 changes: 1 addition & 1 deletion serde_amqp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions serde_amqp/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.13.1

1. Added `to_lazy_value`

## 0.13.0

### Breaking
Expand Down
9 changes: 9 additions & 0 deletions serde_amqp/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ use crate::{
__constants::LAZY_VALUE,
};

/// Serialize a value into a [`LazyValue`].
pub fn to_lazy_value<T>(value: &T) -> Result<LazyValue, Error>
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
Expand Down
23 changes: 23 additions & 0 deletions serde_amqp/src/size_ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
}
}
Loading