mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 04:35:03 +01:00
use bytes::Bytes
This commit is contained in:
parent
c333f20531
commit
970fdbb9b5
5 changed files with 9 additions and 5 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -58,6 +58,7 @@ dependencies = [
|
||||||
"amqp_core",
|
"amqp_core",
|
||||||
"amqp_messaging",
|
"amqp_messaging",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"bytes",
|
||||||
"criterion",
|
"criterion",
|
||||||
"nom",
|
"nom",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||||
amqp_core = { path = "../amqp_core" }
|
amqp_core = { path = "../amqp_core" }
|
||||||
amqp_messaging = { path = "../amqp_messaging" }
|
amqp_messaging = { path = "../amqp_messaging" }
|
||||||
anyhow = "1.0.53"
|
anyhow = "1.0.53"
|
||||||
|
bytes = "1.1.0"
|
||||||
nom = "7.1.0"
|
nom = "7.1.0"
|
||||||
once_cell = "1.9.0"
|
once_cell = "1.9.0"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ impl Connection {
|
||||||
&Frame {
|
&Frame {
|
||||||
kind: FrameType::Method,
|
kind: FrameType::Method,
|
||||||
channel,
|
channel,
|
||||||
payload,
|
payload: payload.into(),
|
||||||
},
|
},
|
||||||
&mut self.stream,
|
&mut self.stream,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::error::{ConException, ProtocolError, Result};
|
use crate::error::{ConException, ProtocolError, Result};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use bytes::Bytes;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ pub struct Frame {
|
||||||
pub kind: FrameType,
|
pub kind: FrameType,
|
||||||
pub channel: u16,
|
pub channel: u16,
|
||||||
/// Includes the whole payload, also including the metadata from each type.
|
/// Includes the whole payload, also including the metadata from each type.
|
||||||
pub payload: Vec<u8>,
|
pub payload: Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
|
@ -72,7 +73,7 @@ where
|
||||||
let frame = Frame {
|
let frame = Frame {
|
||||||
kind,
|
kind,
|
||||||
channel,
|
channel,
|
||||||
payload,
|
payload: payload.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!(?frame, "Received frame");
|
trace!(?frame, "Received frame");
|
||||||
|
|
@ -99,6 +100,7 @@ fn parse_frame_type(kind: u8, channel: u16) -> Result<FrameType> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::frame::{Frame, FrameType};
|
use crate::frame::{Frame, FrameType};
|
||||||
|
use bytes::Bytes;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn read_small_body() {
|
async fn read_small_body() {
|
||||||
|
|
@ -127,7 +129,7 @@ mod tests {
|
||||||
Frame {
|
Frame {
|
||||||
kind: FrameType::Method,
|
kind: FrameType::Method,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
payload: vec![1, 2, 3],
|
payload: Bytes::from_static(&[1, 2, 3]),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ async fn write_start_ok_frame() {
|
||||||
let frame = frame::Frame {
|
let frame = frame::Frame {
|
||||||
kind: FrameType::Method,
|
kind: FrameType::Method,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
payload,
|
payload: payload.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue