Skip to content

Commit

Permalink
run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Feb 18, 2024
1 parent b19160b commit 3a4224c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 27 deletions.
6 changes: 3 additions & 3 deletions pilota-build/src/codegen/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl ThriftBackend {
// r#"fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>(
// protocol: &'a mut T,
// ) -> ::std::pin::Pin<::std::boxed::Box<dyn ::std::future::Future<Output =
// ::std::result::Result<Self, ::pilota::thrift::ThriftException>> + Send +
// 'a>> {{ ::std::boxed::Box::pin(async move {{ {decode_async} }})
// }}"#
// ::std::result::Result<Self, ::pilota::thrift::ThriftException>> + Send
// + 'a>> {{ ::std::boxed::Box::pin(async move {{ {decode_async}
// }}) }}"#
// )
// } else {
// format!(
Expand Down
17 changes: 14 additions & 3 deletions pilota/src/thrift/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use linkedbytes::LinkedBytes;
use tokio::io::{AsyncRead, AsyncReadExt};

use super::{
error::ProtocolExceptionKind, new_protocol_exception, rw_ext::{ReadExt, WriteExt}, ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD
error::ProtocolExceptionKind,
new_protocol_exception,
rw_ext::{ReadExt, WriteExt},
ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol,
TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol,
TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD,
};

static VERSION_1: u32 = 0x80010000;
Expand Down Expand Up @@ -184,7 +189,10 @@ impl TOutputProtocol for TBinaryProtocol<&mut BytesMut> {
type BufMut = BytesMut;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_1 | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down Expand Up @@ -364,7 +372,10 @@ impl TOutputProtocol for TBinaryProtocol<&mut LinkedBytes> {
type BufMut = LinkedBytes;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_1 | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down
17 changes: 14 additions & 3 deletions pilota/src/thrift/binary_le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use linkedbytes::LinkedBytes;
use tokio::io::{AsyncRead, AsyncReadExt};

use super::{
error::ProtocolExceptionKind, new_protocol_exception, rw_ext::{ReadExt, WriteExt}, ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD
error::ProtocolExceptionKind,
new_protocol_exception,
rw_ext::{ReadExt, WriteExt},
ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol,
TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol,
TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD,
};

const VERSION_LE: u32 = 0x88880000;
Expand Down Expand Up @@ -184,7 +189,10 @@ impl TOutputProtocol for TBinaryProtocol<&mut BytesMut> {
type BufMut = BytesMut;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_LE | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down Expand Up @@ -364,7 +372,10 @@ impl TOutputProtocol for TBinaryProtocol<&mut LinkedBytes> {
type BufMut = LinkedBytes;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_LE | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down
21 changes: 17 additions & 4 deletions pilota/src/thrift/binary_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use linkedbytes::LinkedBytes;
use smallvec::SmallVec;

use super::{
error::ProtocolExceptionKind, new_protocol_exception, ProtocolException, TFieldIdentifier, TInputProtocol, TLengthProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, ThriftException, BINARY_BASIC_TYPE_FIXED_SIZE, ZERO_COPY_THRESHOLD
error::ProtocolExceptionKind, new_protocol_exception, ProtocolException, TFieldIdentifier,
TInputProtocol, TLengthProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier,
TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, ThriftException,
BINARY_BASIC_TYPE_FIXED_SIZE, ZERO_COPY_THRESHOLD,
};

static VERSION_1: u32 = 0x80010000;
Expand Down Expand Up @@ -202,7 +205,10 @@ impl TOutputProtocol for TBinaryUnsafeOutputProtocol<&mut BytesMut> {
type BufMut = BytesMut;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_1 | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down Expand Up @@ -444,7 +450,10 @@ impl TOutputProtocol for TBinaryUnsafeOutputProtocol<&mut LinkedBytes> {
type BufMut = LinkedBytes;

#[inline]
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException> {
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException> {
let msg_type_u8: u8 = identifier.message_type.into();
let version = (VERSION_1 | msg_type_u8 as u32) as i32;
self.write_i32(version)?;
Expand Down Expand Up @@ -975,7 +984,11 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
}

#[inline]
fn get_bytes(&mut self, ptr: Option<*const u8>, mut len: usize) -> Result<Bytes, ThriftException> {
fn get_bytes(
&mut self,
ptr: Option<*const u8>,
mut len: usize,
) -> Result<Bytes, ThriftException> {
if ptr.is_none() {
len -= self.index;
self.trans.advance(self.index);
Expand Down
8 changes: 7 additions & 1 deletion pilota/src/thrift/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ use linkedbytes::LinkedBytes;
use tokio::io::{AsyncRead, AsyncReadExt};

use super::{
error::ProtocolExceptionKind, new_protocol_exception, rw_ext::{ReadExt, WriteExt}, varint_ext::VarIntProcessor, ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD
error::ProtocolExceptionKind,
new_protocol_exception,
rw_ext::{ReadExt, WriteExt},
varint_ext::VarIntProcessor,
ProtocolException, TAsyncInputProtocol, TFieldIdentifier, TInputProtocol, TLengthProtocol,
TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol,
TSetIdentifier, TStructIdentifier, TType, ThriftException, ZERO_COPY_THRESHOLD,
};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions pilota/src/thrift/error/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use std::{

use faststr::FastStr;

use super::ThriftException;
use crate::thrift::{
Message, TAsyncInputProtocol, TInputProtocol, TLengthProtocol, TOutputProtocol,
TStructIdentifier, TType,
};

use super::ThriftException;

// use super::{DecodeError, EncodeError};

const TAPPLICATION_EXCEPTION: TStructIdentifier = TStructIdentifier {
Expand Down
7 changes: 3 additions & 4 deletions pilota/src/thrift/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ mod application;
mod protocol;
mod transport;

pub use application::*;
pub use protocol::*;
pub use transport::*;

use std::{
fmt::{self, Debug, Display, Formatter},
string,
};

pub use application::*;
use faststr::FastStr;
pub use protocol::*;
pub use transport::*;

/// A Thrift exception.
///
Expand Down
34 changes: 27 additions & 7 deletions pilota/src/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl<M: Message> Message for Box<M> {
Ok(Box::new(M::decode(protocol)?))
}

async fn decode_async<T: TAsyncInputProtocol>(protocol: &mut T) -> Result<Self, ThriftException> {
async fn decode_async<T: TAsyncInputProtocol>(
protocol: &mut T,
) -> Result<Self, ThriftException> {
Ok(Box::new(M::decode_async(protocol).await?))
}

Expand All @@ -75,7 +77,9 @@ impl<M: Message + Send + Sync> Message for Arc<M> {
Ok(Arc::new(M::decode(protocol)?))
}

async fn decode_async<T: TAsyncInputProtocol>(protocol: &mut T) -> Result<Self, ThriftException> {
async fn decode_async<T: TAsyncInputProtocol>(
protocol: &mut T,
) -> Result<Self, ThriftException> {
Ok(Arc::new(M::decode_async(protocol).await?))
}

Expand Down Expand Up @@ -521,7 +525,12 @@ pub trait TOutputProtocolExt: TOutputProtocol + Sized {
}

#[inline]
fn write_list<T, F>(&mut self, el_ttype: TType, els: &[T], encode: F) -> Result<(), ThriftException>
fn write_list<T, F>(
&mut self,
el_ttype: TType,
els: &[T],
encode: F,
) -> Result<(), ThriftException>
where
F: Fn(&mut Self, &T) -> Result<(), ThriftException>,
{
Expand Down Expand Up @@ -645,11 +654,15 @@ pub trait TOutputProtocol: TLengthProtocol {
type BufMut: BufMut;

/// Write the beginning of a Thrift message.
fn write_message_begin(&mut self, identifier: &TMessageIdentifier) -> Result<(), ThriftException>;
fn write_message_begin(
&mut self,
identifier: &TMessageIdentifier,
) -> Result<(), ThriftException>;
/// Write the end of a Thrift message.
fn write_message_end(&mut self) -> Result<(), ThriftException>;
/// Write the beginning of a Thrift struct.
fn write_struct_begin(&mut self, identifier: &TStructIdentifier) -> Result<(), ThriftException>;
fn write_struct_begin(&mut self, identifier: &TStructIdentifier)
-> Result<(), ThriftException>;
/// Write the end of a Thrift struct.
fn write_struct_end(&mut self) -> Result<(), ThriftException>;
/// Write the beginning of a Thrift field.
Expand Down Expand Up @@ -791,13 +804,20 @@ pub trait TAsyncInputProtocol: Send {
/// Skip a field with type `field_type` recursively until the default
/// maximum skip depth is reached.
#[inline]
fn skip(&mut self, field_type: TType) -> impl Future<Output = Result<(), ThriftException>> + Send {
fn skip(
&mut self,
field_type: TType,
) -> impl Future<Output = Result<(), ThriftException>> + Send {
self.skip_till_depth(field_type, MAXIMUM_SKIP_DEPTH)
}

/// Skip a field with type `field_type` recursively up to `depth` levels.
#[async_recursion::async_recursion]
async fn skip_till_depth(&mut self, field_type: TType, depth: i8) -> Result<(), ThriftException> {
async fn skip_till_depth(
&mut self,
field_type: TType,
depth: i8,
) -> Result<(), ThriftException> {
// async move {
if depth == 0 {
return Err(new_protocol_exception(
Expand Down

0 comments on commit 3a4224c

Please sign in to comment.