chore(proto): crate formatting
This commit is contained in:
parent
505f59b354
commit
a08376766c
18 changed files with 103 additions and 75 deletions
|
|
@ -1,16 +1,13 @@
|
|||
use crate::message::errors::ProtoDeserializeError;
|
||||
use thiserror::Error;
|
||||
use tokio::io;
|
||||
use crate::message::errors::{ProtoDeserializeError};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ProtoReadError {
|
||||
#[error("message has invalid length, got {0}")]
|
||||
InvalidLength(i32),
|
||||
#[error("message has too much data, got {actual}, limit is {limit}")]
|
||||
LengthOverflow {
|
||||
limit: usize,
|
||||
actual: usize
|
||||
},
|
||||
LengthOverflow { limit: usize, actual: usize },
|
||||
#[error("reading from socket failed")]
|
||||
Io(#[from] io::Error),
|
||||
#[error("deserialization of inner data failed")]
|
||||
|
|
@ -20,10 +17,7 @@ pub enum ProtoReadError {
|
|||
#[derive(Debug, Error)]
|
||||
pub enum ProtoPeekError {
|
||||
#[error("message has too much data, got {actual}, limit is {limit}")]
|
||||
LengthOverflow {
|
||||
limit: usize,
|
||||
actual: usize
|
||||
},
|
||||
LengthOverflow { limit: usize, actual: usize },
|
||||
#[error("reading from socket failed")]
|
||||
Io(#[from] io::Error),
|
||||
#[error("deserialization of inner data failed")]
|
||||
|
|
@ -33,10 +27,7 @@ pub enum ProtoPeekError {
|
|||
#[derive(Debug, Error)]
|
||||
pub enum ProtoConsumeError {
|
||||
#[error("unexpected data length, expected {expected}, got {actual}")]
|
||||
UnexpectedDataLength {
|
||||
expected: usize,
|
||||
actual: usize
|
||||
},
|
||||
UnexpectedDataLength { expected: usize, actual: usize },
|
||||
#[error("reading from socket failed")]
|
||||
Io(#[from] io::Error),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
use crate::message::frontend::FrontendMessage;
|
||||
use crate::message::primitive::data::MessageData;
|
||||
use crate::message::special::{CancelRequestData, SpecialMessage, StartupMessageData};
|
||||
use crate::reader::errors::{ProtoConsumeError, ProtoPeekError};
|
||||
use crate::reader::oneway::OneWayProtoReader;
|
||||
use crate::reader::protoreader::ProtoReader;
|
||||
use crate::reader::utils::AsyncPeek;
|
||||
use async_trait::async_trait;
|
||||
use tokio::io;
|
||||
use tokio::io::{AsyncBufRead, AsyncBufReadExt};
|
||||
use crate::message::primitive::data::MessageData;
|
||||
use crate::reader::errors::{ProtoConsumeError, ProtoPeekError};
|
||||
|
||||
#[async_trait]
|
||||
pub trait FrontendProtoReader: OneWayProtoReader<FrontendMessage> {
|
||||
async fn peek_special_message(&mut self) -> Result<Option<SpecialMessage>, ProtoPeekError>;
|
||||
async fn consume_special_message(&mut self, msg: &SpecialMessage) -> Result<(), ProtoConsumeError>;
|
||||
async fn consume_special_message(
|
||||
&mut self,
|
||||
msg: &SpecialMessage,
|
||||
) -> Result<(), ProtoConsumeError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -36,7 +39,10 @@ where
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
async fn consume_special_message(&mut self, msg: &SpecialMessage) -> Result<(), ProtoConsumeError> {
|
||||
async fn consume_special_message(
|
||||
&mut self,
|
||||
msg: &SpecialMessage,
|
||||
) -> Result<(), ProtoConsumeError> {
|
||||
Ok(match msg {
|
||||
SpecialMessage::CancelRequest(_) => consume_cancel_request(self),
|
||||
SpecialMessage::SSLRequest => consume_ssl_request(self),
|
||||
|
|
@ -159,16 +165,16 @@ where
|
|||
if size != 4 {
|
||||
return Err(ProtoConsumeError::UnexpectedDataLength {
|
||||
expected: 4,
|
||||
actual: size
|
||||
})
|
||||
actual: size,
|
||||
});
|
||||
}
|
||||
|
||||
let length = i32::from_be_bytes([header[0], header[1], header[2], header[3]]) as usize;
|
||||
if length < 8 {
|
||||
return Err(ProtoConsumeError::UnexpectedDataLength {
|
||||
expected: 8,
|
||||
actual: length
|
||||
})
|
||||
actual: length,
|
||||
});
|
||||
}
|
||||
|
||||
reader.inner.consume(length);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub mod backend;
|
||||
pub mod errors;
|
||||
pub mod frontend;
|
||||
pub mod oneway;
|
||||
pub mod protoreader;
|
||||
mod utils;
|
||||
pub mod errors;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::message::proto_message::ProtoMessage;
|
||||
use crate::reader::errors::ProtoReadError;
|
||||
use crate::reader::protoreader::ProtoReader;
|
||||
use crate::reader::utils::AsyncPeek;
|
||||
use async_trait::async_trait;
|
||||
use tokio::io::{AsyncBufRead, AsyncReadExt};
|
||||
use crate::reader::errors::ProtoReadError;
|
||||
|
||||
#[async_trait]
|
||||
pub trait OneWayProtoReader<T>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue