rename classes to methods

This commit is contained in:
nora 2022-02-20 15:34:04 +01:00
parent 9b48dec533
commit 7ce8f8058d
8 changed files with 26 additions and 26 deletions

View file

@ -1,7 +1,7 @@
use crate::classes::Method;
use crate::error::{ConException, ProtocolError, Result}; use crate::error::{ConException, ProtocolError, Result};
use crate::frame::{Frame, FrameType}; use crate::frame::{Frame, FrameType};
use crate::{classes, frame, sasl}; use crate::methods::Method;
use crate::{frame, methods, sasl};
use amqp_core::GlobalData; use amqp_core::GlobalData;
use anyhow::Context; use anyhow::Context;
use std::collections::HashMap; use std::collections::HashMap;
@ -90,7 +90,7 @@ impl Connection {
async fn send_method(&mut self, channel: u16, method: Method) -> Result<()> { async fn send_method(&mut self, channel: u16, method: Method) -> Result<()> {
let mut payload = Vec::with_capacity(64); let mut payload = Vec::with_capacity(64);
classes::write::write_method(method, &mut payload)?; methods::write::write_method(method, &mut payload)?;
frame::write_frame( frame::write_frame(
&Frame { &Frame {
kind: FrameType::Method, kind: FrameType::Method,
@ -107,7 +107,7 @@ impl Connection {
ensure_conn(start_ok_frame.kind == FrameType::Method)?; ensure_conn(start_ok_frame.kind == FrameType::Method)?;
let class = classes::parse_method(&start_ok_frame.payload)?; let class = methods::parse_method(&start_ok_frame.payload)?;
Ok(class) Ok(class)
} }
@ -210,7 +210,7 @@ impl Connection {
} }
async fn dispatch_method(&mut self, frame: Frame) -> Result<()> { async fn dispatch_method(&mut self, frame: Frame) -> Result<()> {
let method = classes::parse_method(&frame.payload)?; let method = methods::parse_method(&frame.payload)?;
debug!(?method, "Received method"); debug!(?method, "Received method");
match method { match method {
@ -326,9 +326,9 @@ impl Drop for Channel {
} }
} }
fn server_properties(host: SocketAddr) -> classes::Table { fn server_properties(host: SocketAddr) -> methods::Table {
fn ls(str: &str) -> classes::FieldValue { fn ls(str: &str) -> methods::FieldValue {
classes::FieldValue::LongString(str.into()) methods::FieldValue::LongString(str.into())
} }
let host_str = host.ip().to_string(); let host_str = host.ip().to_string();

View file

@ -1,9 +1,9 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
mod classes;
mod connection; mod connection;
mod error; mod error;
mod frame; mod frame;
mod methods;
mod sasl; mod sasl;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View file

@ -787,8 +787,8 @@ pub enum Method {
pub mod parse { pub mod parse {
use super::*; use super::*;
use crate::classes::parse_helper::*;
use crate::error::TransError; use crate::error::TransError;
use crate::methods::parse_helper::*;
use nom::{branch::alt, bytes::complete::tag}; use nom::{branch::alt, bytes::complete::tag};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
@ -1843,8 +1843,8 @@ pub mod parse {
} }
pub mod write { pub mod write {
use super::*; use super::*;
use crate::classes::write_helper::*;
use crate::error::TransError; use crate::error::TransError;
use crate::methods::write_helper::*;
use std::io::Write; use std::io::Write;
pub fn write_method<W: Write>(class: Method, mut writer: W) -> Result<(), TransError> { pub fn write_method<W: Write>(class: Method, mut writer: W) -> Result<(), TransError> {
@ -2261,7 +2261,7 @@ pub mod write {
#[cfg(test)] #[cfg(test)]
mod random { mod random {
use super::*; use super::*;
use crate::classes::tests::RandomMethod; use crate::methods::tests::RandomMethod;
use rand::Rng; use rand::Rng;
impl<R: Rng> RandomMethod<R> for Method { impl<R: Rng> RandomMethod<R> for Method {

View file

@ -1,8 +1,8 @@
use crate::classes::generated::parse::IResult; use crate::error::{ConException, ProtocolError, TransError};
use crate::classes::generated::{ use crate::methods::generated::parse::IResult;
use crate::methods::generated::{
Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp, Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp,
}; };
use crate::error::{ConException, ProtocolError, TransError};
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::{tag, take}; use nom::bytes::complete::{tag, take};
use nom::error::ErrorKind; use nom::error::ErrorKind;
@ -73,7 +73,7 @@ macro_rules! fail {
}; };
} }
use crate::classes::{FieldValue, TableFieldName}; use crate::methods::{FieldValue, TableFieldName};
pub use fail; pub use fail;
pub fn octet(input: &[u8]) -> IResult<'_, Octet> { pub fn octet(input: &[u8]) -> IResult<'_, Octet> {

View file

@ -1,7 +1,7 @@
// create random methods to test the ser/de code together. if they diverge, we have a bug // 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 tha's an ok tradeoff // this is not perfect, if they both have the same bug it won't be found, but tha's an ok tradeoff
use crate::classes::{FieldValue, Method}; use crate::methods::{FieldValue, Method};
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use std::collections::HashMap; use std::collections::HashMap;
@ -138,10 +138,10 @@ fn nested_table() {
eprintln!("{table:?}"); eprintln!("{table:?}");
let mut bytes = Vec::new(); let mut bytes = Vec::new();
crate::classes::write_helper::table(table.clone(), &mut bytes).unwrap(); crate::methods::write_helper::table(table.clone(), &mut bytes).unwrap();
eprintln!("{bytes:?}"); eprintln!("{bytes:?}");
let (rest, parsed_table) = crate::classes::parse_helper::table(&bytes).unwrap(); let (rest, parsed_table) = crate::methods::parse_helper::table(&bytes).unwrap();
assert!(rest.is_empty()); assert!(rest.is_empty());
assert_eq!(table, parsed_table); assert_eq!(table, parsed_table);

View file

@ -1,8 +1,8 @@
use crate::classes::generated::{ use crate::error::TransError;
use crate::methods::generated::{
Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp, Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp,
}; };
use crate::classes::FieldValue; use crate::methods::FieldValue;
use crate::error::TransError;
use anyhow::Context; use anyhow::Context;
use std::io::Write; use std::io::Write;

View file

@ -1,6 +1,6 @@
use crate::classes::{FieldValue, Method};
use crate::frame::FrameType; use crate::frame::FrameType;
use crate::{classes, frame}; use crate::methods::{FieldValue, Method};
use crate::{frame, methods};
use std::collections::HashMap; use std::collections::HashMap;
#[tokio::test] #[tokio::test]
@ -17,7 +17,7 @@ async fn write_start_ok_frame() {
locales: "en_US".into(), locales: "en_US".into(),
}; };
classes::write::write_method(method, &mut payload).unwrap(); methods::write::write_method(method, &mut payload).unwrap();
let frame = frame::Frame { let frame = frame::Frame {
kind: FrameType::Method, kind: FrameType::Method,
@ -136,7 +136,7 @@ fn read_start_ok_payload() {
5, 101, 110, 95, 85, 83, 5, 101, 110, 95, 85, 83,
]; ];
let method = classes::parse_method(&raw_data).unwrap(); let method = methods::parse_method(&raw_data).unwrap();
assert_eq!( assert_eq!(
method, method,