use bytes::Bytes

This commit is contained in:
nora 2022-02-10 01:32:15 +01:00
parent c333f20531
commit 970fdbb9b5
5 changed files with 9 additions and 5 deletions

1
Cargo.lock generated
View file

@ -58,6 +58,7 @@ dependencies = [
"amqp_core",
"amqp_messaging",
"anyhow",
"bytes",
"criterion",
"nom",
"once_cell",

View file

@ -9,6 +9,7 @@ edition = "2021"
amqp_core = { path = "../amqp_core" }
amqp_messaging = { path = "../amqp_messaging" }
anyhow = "1.0.53"
bytes = "1.1.0"
nom = "7.1.0"
once_cell = "1.9.0"
rand = "0.8.4"

View file

@ -95,7 +95,7 @@ impl Connection {
&Frame {
kind: FrameType::Method,
channel,
payload,
payload: payload.into(),
},
&mut self.stream,
)

View file

@ -1,5 +1,6 @@
use crate::error::{ConException, ProtocolError, Result};
use anyhow::Context;
use bytes::Bytes;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tracing::trace;
@ -18,7 +19,7 @@ pub struct Frame {
pub kind: FrameType,
pub channel: u16,
/// Includes the whole payload, also including the metadata from each type.
pub payload: Vec<u8>,
pub payload: Bytes,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@ -72,7 +73,7 @@ where
let frame = Frame {
kind,
channel,
payload,
payload: payload.into(),
};
trace!(?frame, "Received frame");
@ -99,6 +100,7 @@ fn parse_frame_type(kind: u8, channel: u16) -> Result<FrameType> {
#[cfg(test)]
mod tests {
use crate::frame::{Frame, FrameType};
use bytes::Bytes;
#[tokio::test]
async fn read_small_body() {
@ -127,7 +129,7 @@ mod tests {
Frame {
kind: FrameType::Method,
channel: 0,
payload: vec![1, 2, 3],
payload: Bytes::from_static(&[1, 2, 3]),
}
);
}

View file

@ -22,7 +22,7 @@ async fn write_start_ok_frame() {
let frame = frame::Frame {
kind: FrameType::Method,
channel: 0,
payload,
payload: payload.into(),
};
let mut output = Vec::new();