formatting!

This commit is contained in:
nora 2022-03-10 19:18:26 +01:00
parent 770762b920
commit cae9683bd4
33 changed files with 147 additions and 87 deletions

View file

@ -1,5 +1,7 @@
use amqp_core::methods::Method;
use amqp_transport::methods::{self, RandomMethod};
use amqp_transport::methods::{
RandomMethod, {self},
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::SeedableRng;

View file

@ -1,9 +1,7 @@
use crate::{
error::{ConException, ProtocolError, Result, TransError},
frame,
frame::{parse_content_header, Frame, FrameType, MaxFrameSize},
methods, sasl,
use std::{
cmp::Ordering, collections::HashMap, net::SocketAddr, pin::Pin, sync::Arc, time::Duration,
};
use amqp_core::{
connection::{
Channel, ChannelInner, ChannelNum, ConEventReceiver, ConEventSender, Connection,
@ -20,9 +18,6 @@ use amqp_core::{
use anyhow::{anyhow, Context};
use bytes::Bytes;
use smallvec::SmallVec;
use std::{
cmp::Ordering, collections::HashMap, net::SocketAddr, pin::Pin, sync::Arc, time::Duration,
};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::TcpStream,
@ -30,6 +25,12 @@ use tokio::{
};
use tracing::{debug, error, info, trace, warn};
use crate::{
error::{ConException, ProtocolError, Result, TransError},
frame::{self, parse_content_header, Frame, FrameType, MaxFrameSize},
methods, sasl,
};
fn ensure_conn(condition: bool) -> Result<()> {
if condition {
Ok(())

View file

@ -1,14 +1,16 @@
use crate::error::{ConException, ProtocolError, Result};
use amqp_core::connection::{ChannelNum, ContentHeader};
use anyhow::Context;
use bytes::Bytes;
use std::{
fmt::{Debug, Formatter},
num::NonZeroUsize,
};
use amqp_core::connection::{ChannelNum, ContentHeader};
use anyhow::Context;
use bytes::Bytes;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tracing::trace;
use crate::error::{ConException, ProtocolError, Result};
const REQUIRED_FRAME_END: u8 = 0xCE;
mod frame_type {
@ -37,20 +39,23 @@ pub enum FrameType {
}
mod content_header_parse {
use crate::{
error::TransError,
methods::parse_helper::{octet, shortstr, table, timestamp},
};
use amqp_core::{
connection::ContentHeader,
methods,
methods::FieldValue::{FieldTable, ShortShortUInt, ShortString, Timestamp},
methods::{
self,
FieldValue::{FieldTable, ShortShortUInt, ShortString, Timestamp},
},
};
use nom::number::{
complete::{u16, u64},
Endianness::Big,
};
use crate::{
error::TransError,
methods::parse_helper::{octet, shortstr, table, timestamp},
};
type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
pub fn basic_properties(flags: u16, input: &[u8]) -> IResult<'_, methods::Table> {
@ -133,10 +138,8 @@ pub fn parse_content_header(input: &[u8]) -> Result<ContentHeader> {
}
mod content_header_write {
use crate::{
error::Result,
methods::write_helper::{longlong, octet, short, shortstr, table, timestamp},
};
use std::io::Write;
use amqp_core::{
connection::ContentHeader,
methods::{
@ -144,7 +147,11 @@ mod content_header_write {
Table,
},
};
use std::io::Write;
use crate::{
error::Result,
methods::write_helper::{longlong, octet, short, shortstr, table, timestamp},
};
pub fn write_content_header<W: Write>(buf: &mut W, header: &ContentHeader) -> Result<()> {
short(&header.class_id, buf)?;
@ -325,9 +332,10 @@ fn parse_frame_type(kind: u8, channel: ChannelNum) -> Result<FrameType> {
#[cfg(test)]
mod tests {
use crate::frame::{ChannelNum, Frame, FrameType, MaxFrameSize};
use bytes::Bytes;
use crate::frame::{ChannelNum, Frame, FrameType, MaxFrameSize};
#[tokio::test]
async fn read_small_body() {
let mut bytes: &[u8] = &[

View file

@ -10,13 +10,15 @@ mod tests;
// TODO: handle big types
use crate::connection::TransportConnection;
use std::{future::Future, net::SocketAddr};
use amqp_core::{connection::ConnectionEvent, queue::QueueEvent, GlobalData};
use anyhow::Context;
use std::{future::Future, net::SocketAddr};
use tokio::{net, net::TcpStream, select};
use tracing::{info, info_span, Instrument};
use crate::connection::TransportConnection;
pub async fn do_thing_i_guess(
global_data: GlobalData,
terminate: impl Future + Send,

View file

@ -2,12 +2,13 @@
// This file has been generated by `xtask/src/codegen`. Do not edit it manually.
pub mod parse {
use crate::{error::TransError, methods::parse_helper::*};
use amqp_core::methods::*;
use nom::{branch::alt, bytes::complete::tag};
use once_cell::sync::Lazy;
use regex::Regex;
use crate::{error::TransError, methods::parse_helper::*};
pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
pub fn parse_method(input: &[u8]) -> Result<(&[u8], Method), nom::Err<TransError>> {
@ -886,10 +887,12 @@ pub mod parse {
}
}
pub mod write {
use crate::{error::TransError, methods::write_helper::*};
use amqp_core::methods::*;
use std::io::Write;
use amqp_core::methods::*;
use crate::{error::TransError, methods::write_helper::*};
pub fn write_method<W: Write>(method: &Method, mut writer: W) -> Result<(), TransError> {
match method {
Method::ConnectionStart(ConnectionStart {
@ -1303,10 +1306,11 @@ pub mod write {
}
mod random {
use crate::methods::RandomMethod;
use amqp_core::methods::*;
use rand::Rng;
use crate::methods::RandomMethod;
impl<R: Rng> RandomMethod<R> for Method {
#[allow(unused_variables)]
fn random(rng: &mut R) -> Self {

View file

@ -1,10 +1,11 @@
use crate::error::TransError;
use amqp_core::{
error::ConException,
methods::{FieldValue, Method, Table},
};
use rand::Rng;
use crate::error::TransError;
mod generated;
pub mod parse_helper;
#[cfg(test)]

View file

@ -1,4 +1,3 @@
use crate::{error::TransError, methods::generated::parse::IResult};
use amqp_core::{
error::{ConException, ProtocolError},
methods::{
@ -18,6 +17,8 @@ use nom::{
Err,
};
use crate::{error::TransError, methods::generated::parse::IResult};
impl<T> nom::error::ParseError<T> for TransError {
fn from_error_kind(_input: T, _kind: ErrorKind) -> Self {
ConException::SyntaxError(vec![]).into()

View file

@ -1,10 +1,12 @@
// create random methods to test the ser/de code together. if they diverge, we have a bug
// this is not perfect, if they both have the same bug it won't be found, but that's an ok tradeoff
use crate::methods::{FieldValue, Method, RandomMethod};
use rand::SeedableRng;
use std::collections::HashMap;
use rand::SeedableRng;
use crate::methods::{FieldValue, Method, RandomMethod};
#[test]
fn pack_few_bits() {
let bits = [true, false, true];

View file

@ -1,7 +1,9 @@
use crate::{error::TransError, methods::FieldValue};
use std::io::Write;
use amqp_core::methods::{Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp};
use anyhow::Context;
use std::io::Write;
use crate::{error::TransError, methods::FieldValue};
pub fn octet<W: Write>(value: &Octet, writer: &mut W) -> Result<(), TransError> {
writer.write_all(&[*value])?;

View file

@ -2,9 +2,10 @@
//!
//! Currently only supports PLAIN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616))
use crate::error::Result;
use amqp_core::error::ConException;
use crate::error::Result;
pub struct PlainUser {
pub authorization_identity: String,
pub authentication_identity: String,

View file

@ -1,9 +1,11 @@
use crate::{frame, frame::FrameType, methods};
use std::collections::HashMap;
use amqp_core::{
connection::ChannelNum,
methods::{ConnectionStart, ConnectionStartOk, FieldValue, Method},
};
use std::collections::HashMap;
use crate::{frame, frame::FrameType, methods};
#[tokio::test]
async fn write_start_ok_frame() {