From d6693254e00af826ada7d6ff4364fd0462a99044 Mon Sep 17 00:00:00 2001 From: Pure White Date: Wed, 18 Oct 2023 09:49:47 -0500 Subject: [PATCH] feat: use afit and rpitit to optimize Message trait (#201) --- .github/workflows/ci.yaml | 12 +- .../src/codegen/thrift/decode_helper.rs | 8 +- pilota-build/src/codegen/thrift/mod.rs | 3 +- pilota-build/src/codegen/thrift/ty.rs | 3 +- pilota-build/test_data/must_gen_items.rs | 1 - pilota-build/test_data/plugin/serde.rs | 3 - pilota-build/test_data/thrift/binary_bytes.rs | 1 - pilota-build/test_data/thrift/const_val.rs | 1 - pilota-build/test_data/thrift/decode_error.rs | 13 +- .../test_data/thrift/default_value.rs | 14 +- pilota-build/test_data/thrift/enum_test.rs | 1 - pilota-build/test_data/thrift/normal.rs | 304 +++++++++--------- pilota-build/test_data/thrift/pilota_name.rs | 25 +- .../test_data/thrift/recursive_type.rs | 4 +- pilota-build/test_data/thrift/self_kw.rs | 2 - pilota-build/test_data/thrift/string.rs | 1 - pilota-build/test_data/thrift/union.rs | 8 +- pilota-build/test_data/thrift/void.rs | 4 - pilota-build/test_data/thrift/wrapper_arc.rs | 25 +- pilota-build/test_data/unknown_fields.rs | 139 ++++---- pilota/benches/skip.rs | 1 - pilota/src/thrift/mod.rs | 3 - 22 files changed, 274 insertions(+), 302 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 40c991b1..4915b89a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy # - uses: Swatinem/rust-cache@v1 @@ -41,7 +41,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy # - uses: Swatinem/rust-cache@v1 @@ -55,7 +55,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy - uses: Swatinem/rust-cache@v1 @@ -69,7 +69,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy - uses: Swatinem/rust-cache@v1 @@ -84,11 +84,11 @@ jobs: strategy: matrix: rust: - - stable + - nightly steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy # - uses: Swatinem/rust-cache@v1 diff --git a/pilota-build/src/codegen/thrift/decode_helper.rs b/pilota-build/src/codegen/thrift/decode_helper.rs index 7f865337..2f7365dc 100644 --- a/pilota-build/src/codegen/thrift/decode_helper.rs +++ b/pilota-build/src/codegen/thrift/decode_helper.rs @@ -80,9 +80,13 @@ impl DecodeHelper { } } - pub fn codegen_item_decode(&self) -> FastStr { + pub fn codegen_item_decode(&self, name: FastStr) -> FastStr { if self.is_async { - "::pilota::thrift::Message::decode_async(protocol).await?".into() + format!( + "<{} as ::pilota::thrift::Message>::decode_async(protocol).await?", + name + ) + .into() } else { "::pilota::thrift::Message::decode(protocol)?".into() } diff --git a/pilota-build/src/codegen/thrift/mod.rs b/pilota-build/src/codegen/thrift/mod.rs index b1e3b05e..e986afb2 100644 --- a/pilota-build/src/codegen/thrift/mod.rs +++ b/pilota-build/src/codegen/thrift/mod.rs @@ -100,7 +100,6 @@ impl ThriftBackend { decode_async: String, ) -> String { format! {r#" - #[::async_trait::async_trait] impl ::pilota::thrift::Message for {name} {{ fn encode( &self, @@ -666,7 +665,7 @@ impl CodegenBackend for ThriftBackend { return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, "received multiple fields for union from remote Message" - )); + )); }}"# ) } else { diff --git a/pilota-build/src/codegen/thrift/ty.rs b/pilota-build/src/codegen/thrift/ty.rs index 4fc23d9c..9b6f00ce 100644 --- a/pilota-build/src/codegen/thrift/ty.rs +++ b/pilota-build/src/codegen/thrift/ty.rs @@ -418,7 +418,8 @@ impl ThriftBackend { } .into() } - ty::Path(_) => helper.codegen_item_decode(), + ty::Path(_) => helper + .codegen_item_decode(format!("{}", self.codegen_item_ty(ty.kind.clone())).into()), ty::Arc(ty) => { let inner = self.codegen_decode_ty(helper, ty); format!("::std::sync::Arc::new({inner})").into() diff --git a/pilota-build/test_data/must_gen_items.rs b/pilota-build/test_data/must_gen_items.rs index 26970435..635cea7b 100644 --- a/pilota-build/test_data/must_gen_items.rs +++ b/pilota-build/test_data/must_gen_items.rs @@ -6,7 +6,6 @@ pub mod must_gen_items { pub struct A { pub a: ::std::option::Option, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, diff --git a/pilota-build/test_data/plugin/serde.rs b/pilota-build/test_data/plugin/serde.rs index 682543b1..9575adaf 100644 --- a/pilota-build/test_data/plugin/serde.rs +++ b/pilota-build/test_data/plugin/serde.rs @@ -20,7 +20,6 @@ pub mod serde { pub b: i32, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -222,7 +221,6 @@ pub mod serde { E = 1, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for C { fn encode( &self, @@ -294,7 +292,6 @@ pub mod serde { } } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, diff --git a/pilota-build/test_data/thrift/binary_bytes.rs b/pilota-build/test_data/thrift/binary_bytes.rs index 717a64f4..e4a4b58a 100644 --- a/pilota-build/test_data/thrift/binary_bytes.rs +++ b/pilota-build/test_data/thrift/binary_bytes.rs @@ -8,7 +8,6 @@ pub mod binary_bytes { pub vec: ::std::vec::Vec, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, diff --git a/pilota-build/test_data/thrift/const_val.rs b/pilota-build/test_data/thrift/const_val.rs index 5649b27b..e69495b3 100644 --- a/pilota-build/test_data/thrift/const_val.rs +++ b/pilota-build/test_data/thrift/const_val.rs @@ -38,7 +38,6 @@ pub mod const_val { B = 1, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Index { fn encode( &self, diff --git a/pilota-build/test_data/thrift/decode_error.rs b/pilota-build/test_data/thrift/decode_error.rs index 9f7ed21b..2c46e351 100644 --- a/pilota-build/test_data/thrift/decode_error.rs +++ b/pilota-build/test_data/thrift/decode_error.rs @@ -6,7 +6,6 @@ pub mod decode_error { pub struct A { pub b: B, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -104,7 +103,10 @@ pub mod decode_error { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - b = Some(::pilota::thrift::Message::decode_async(protocol).await?); + b = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -154,7 +156,6 @@ pub mod decode_error { pub struct C { pub a: ::pilota::FastStr, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for C { fn encode( &self, @@ -302,7 +303,6 @@ pub mod decode_error { pub struct B { pub c: C, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, @@ -400,7 +400,10 @@ pub mod decode_error { Some(2) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - c = Some(::pilota::thrift::Message::decode_async(protocol).await?); + c = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; diff --git a/pilota-build/test_data/thrift/default_value.rs b/pilota-build/test_data/thrift/default_value.rs index f3943ea2..5f2445a8 100644 --- a/pilota-build/test_data/thrift/default_value.rs +++ b/pilota-build/test_data/thrift/default_value.rs @@ -36,7 +36,6 @@ pub mod default_value { Write = 2, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, @@ -124,7 +123,6 @@ pub mod default_value { pub alias_str: ::std::option::Option<::pilota::FastStr>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -343,12 +341,16 @@ pub mod default_value { a = Some(protocol.read_bool().await?); } Some(4) if field_ident.field_type == ::pilota::thrift::TType::I32 => { - test_b = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + test_b = Some( + ::decode_async(protocol) + .await?, + ); } Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { - test_b2 = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + test_b2 = Some( + ::decode_async(protocol) + .await?, + ); } Some(6) if field_ident.field_type == ::pilota::thrift::TType::Map => { map = Some({ diff --git a/pilota-build/test_data/thrift/enum_test.rs b/pilota-build/test_data/thrift/enum_test.rs index e6ba053e..f57a83a5 100644 --- a/pilota-build/test_data/thrift/enum_test.rs +++ b/pilota-build/test_data/thrift/enum_test.rs @@ -38,7 +38,6 @@ pub mod enum_test { B = 16, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Index { fn encode( &self, diff --git a/pilota-build/test_data/thrift/normal.rs b/pilota-build/test_data/thrift/normal.rs index a995024a..29ae677f 100644 --- a/pilota-build/test_data/thrift/normal.rs +++ b/pilota-build/test_data/thrift/normal.rs @@ -6,7 +6,6 @@ pub mod normal { pub struct A { pub a: ::std::option::Option, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -141,7 +140,6 @@ pub mod normal { pub trait Test {} #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct TestTest123ArgsSend {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { fn encode( &self, @@ -279,7 +277,6 @@ pub mod normal { pub mock_cost: ::std::option::Option<::pilota::FastStr>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for ObjReq { fn encode( &self, @@ -492,97 +489,79 @@ pub mod normal { protocol.read_struct_begin().await?; if let Err(err) = async { loop { - let field_ident = protocol.read_field_begin().await?; - if field_ident.field_type == ::pilota::thrift::TType::Stop { - break; - } else { - } - __pilota_decoding_field_id = field_ident.id; - match field_ident.id { - Some(1) - if field_ident.field_type == ::pilota::thrift::TType::Struct => - { - msg = - Some(::pilota::thrift::Message::decode_async(protocol).await?); - } - Some(2) if field_ident.field_type == ::pilota::thrift::TType::Map => { - msg_map = Some({ - let map_ident = protocol.read_map_begin().await?; - let mut val = - ::std::collections::HashMap::with_capacity(map_ident.size); - for _ in 0..map_ident.size { - val.insert( - ::pilota::thrift::Message::decode_async(protocol) - .await?, - ::pilota::thrift::Message::decode_async(protocol) - .await?, - ); - } - protocol.read_map_end().await?; - val - }); - } - Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => { - sub_msgs = Some({ - let list_ident = protocol.read_list_begin().await?; - let mut val = Vec::with_capacity(list_ident.size); - for _ in 0..list_ident.size { - val.push( - ::pilota::thrift::Message::decode_async(protocol) - .await?, - ); - } - protocol.read_list_end().await?; - val - }); - } - Some(4) if field_ident.field_type == ::pilota::thrift::TType::Set => { - msg_set = Some({ - let list_ident = protocol.read_set_begin().await?; - let mut val = - ::std::collections::HashSet::with_capacity(list_ident.size); - for _ in 0..list_ident.size { - val.insert( - ::pilota::thrift::Message::decode_async(protocol) - .await?, - ); - } - protocol.read_set_end().await?; - val - }); - } - Some(5) - if field_ident.field_type == ::pilota::thrift::TType::Binary => - { - flag_msg = Some(protocol.read_faststr().await?); - } - Some(6) - if field_ident.field_type == ::pilota::thrift::TType::Binary => - { - mock_cost = Some(protocol.read_faststr().await?); - } - _ => { - protocol.skip(field_ident.field_type).await?; - } + + + let field_ident = protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + msg = Some(::decode_async(protocol).await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Map => { + msg_map = Some({ + let map_ident = protocol.read_map_begin().await?; + let mut val = ::std::collections::HashMap::with_capacity(map_ident.size); + for _ in 0..map_ident.size { + val.insert(::decode_async(protocol).await?, ::decode_async(protocol).await?); } + protocol.read_map_end().await?; + val + }); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => { + sub_msgs = Some({ + let list_ident = protocol.read_list_begin().await?; + let mut val = Vec::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.push(::decode_async(protocol).await?); + }; + protocol.read_list_end().await?; + val + }); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Set => { + msg_set = Some({let list_ident = protocol.read_set_begin().await?; + let mut val = ::std::collections::HashSet::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.insert(::decode_async(protocol).await?); + }; + protocol.read_set_end().await?; + val}); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + flag_msg = Some(protocol.read_faststr().await?); + + },Some(6) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + mock_cost = Some(protocol.read_faststr().await?); + + }, + _ => { + protocol.skip(field_ident.field_type).await?; - protocol.read_field_end().await?; - } + }, + } + + protocol.read_field_end().await?; + + + }; Ok::<_, ::pilota::thrift::DecodeError>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + return Err(::pilota::thrift::DecodeError::new( + ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new(err)), + format!("decode struct `ObjReq` field(#{}) failed", field_id), + )); + } else { + return Err(err) } - .await - { - if let Some(field_id) = __pilota_decoding_field_id { - return Err(::pilota::thrift::DecodeError::new( - ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new( - err, - )), - format!("decode struct `ObjReq` field(#{}) failed", field_id), - )); - } else { - return Err(err); - } - }; + }; protocol.read_struct_end().await?; let Some(msg) = msg else { @@ -661,7 +640,6 @@ pub mod normal { pub struct B { pub a: ::std::option::Option, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, @@ -754,7 +732,10 @@ pub mod normal { Some(2) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - a = Some(::pilota::thrift::Message::decode_async(protocol).await?); + a = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -800,7 +781,6 @@ pub mod normal { pub struct TestTestExceptionArgsSend { pub req: ObjReq, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionArgsSend { fn encode( &self, @@ -903,8 +883,10 @@ pub mod normal { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -956,7 +938,6 @@ pub mod normal { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct TestTest123ArgsRecv {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { fn encode( &self, @@ -1089,7 +1070,6 @@ pub mod normal { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultSend { fn encode( &self, @@ -1179,7 +1159,6 @@ pub mod normal { pub struct StException { pub message: ::std::option::Option<::pilota::FastStr>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for StException { fn encode( &self, @@ -1321,7 +1300,6 @@ pub mod normal { pub struct SubMessage { pub value: ::std::option::Option<::pilota::FastStr>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for SubMessage { fn encode( &self, @@ -1461,7 +1439,6 @@ pub mod normal { pub struct TestTestExceptionArgsRecv { pub req: ObjReq, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionArgsRecv { fn encode( &self, @@ -1564,8 +1541,10 @@ pub mod normal { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -1624,7 +1603,6 @@ pub mod normal { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionException { fn encode( &self, @@ -1705,7 +1683,10 @@ pub mod normal { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionException::StException(field_ident)); } else { @@ -1756,7 +1737,6 @@ pub mod normal { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionResultSend { fn encode( &self, @@ -1852,7 +1832,8 @@ pub mod normal { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestTestExceptionResultSend::Ok(field_ident)); } else { @@ -1865,7 +1846,10 @@ pub mod normal { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionResultSend::StException(field_ident)); } else { @@ -1919,7 +1903,6 @@ pub mod normal { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionResultRecv { fn encode( &self, @@ -2015,7 +1998,8 @@ pub mod normal { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestTestExceptionResultRecv::Ok(field_ident)); } else { @@ -2028,7 +2012,10 @@ pub mod normal { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionResultRecv::StException(field_ident)); } else { @@ -2080,7 +2067,6 @@ pub mod normal { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultRecv { fn encode( &self, @@ -2174,7 +2160,6 @@ pub mod normal { pub sub_messages: ::std::option::Option<::std::vec::Vec>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Message { fn encode( &self, @@ -2297,57 +2282,56 @@ pub mod normal { protocol.read_struct_begin().await?; if let Err(err) = async { loop { - let field_ident = protocol.read_field_begin().await?; - if field_ident.field_type == ::pilota::thrift::TType::Stop { - break; - } else { - } - __pilota_decoding_field_id = field_ident.id; - match field_ident.id { - Some(1) if field_ident.field_type == ::pilota::thrift::TType::Uuid => { - uid = Some(protocol.read_uuid().await?); - } - Some(2) - if field_ident.field_type == ::pilota::thrift::TType::Binary => - { - value = Some(protocol.read_faststr().await?); - } - Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => { - sub_messages = Some({ - let list_ident = protocol.read_list_begin().await?; - let mut val = Vec::with_capacity(list_ident.size); - for _ in 0..list_ident.size { - val.push( - ::pilota::thrift::Message::decode_async(protocol) - .await?, - ); - } - protocol.read_list_end().await?; - val - }); - } - _ => { - protocol.skip(field_ident.field_type).await?; - } - } - protocol.read_field_end().await?; - } + + let field_ident = protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Uuid => { + uid = Some(protocol.read_uuid().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + value = Some(protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => { + sub_messages = Some({ + let list_ident = protocol.read_list_begin().await?; + let mut val = Vec::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.push(::decode_async(protocol).await?); + }; + protocol.read_list_end().await?; + val + }); + + }, + _ => { + protocol.skip(field_ident.field_type).await?; + + }, + } + + protocol.read_field_end().await?; + + + }; Ok::<_, ::pilota::thrift::DecodeError>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + return Err(::pilota::thrift::DecodeError::new( + ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new(err)), + format!("decode struct `Message` field(#{}) failed", field_id), + )); + } else { + return Err(err) } - .await - { - if let Some(field_id) = __pilota_decoding_field_id { - return Err(::pilota::thrift::DecodeError::new( - ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new( - err, - )), - format!("decode struct `Message` field(#{}) failed", field_id), - )); - } else { - return Err(err); - } - }; + }; protocol.read_struct_end().await?; let data = Self { diff --git a/pilota-build/test_data/thrift/pilota_name.rs b/pilota-build/test_data/thrift/pilota_name.rs index 7cac951c..3ce34c70 100644 --- a/pilota-build/test_data/thrift/pilota_name.rs +++ b/pilota-build/test_data/thrift/pilota_name.rs @@ -6,7 +6,6 @@ pub mod pilota_name { pub struct Test2 { pub id: ::pilota::FastStr, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Test2 { fn encode( &self, @@ -154,7 +153,6 @@ pub mod pilota_name { pub struct TestServiceTestArgsRecv { pub req: Test2, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestArgsRecv { fn encode( &self, @@ -257,8 +255,10 @@ pub mod pilota_name { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -317,7 +317,6 @@ pub mod pilota_name { Ok(Test1), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestResultSend { fn encode( &self, @@ -398,7 +397,8 @@ pub mod pilota_name { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestServiceTestResultSend::Ok(field_ident)); } else { @@ -444,7 +444,6 @@ pub mod pilota_name { pub hello: ::pilota::FastStr, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Test1 { fn encode( &self, @@ -618,7 +617,6 @@ pub mod pilota_name { pub struct TestServiceTestArgsSend { pub req: Test2, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestArgsSend { fn encode( &self, @@ -721,8 +719,10 @@ pub mod pilota_name { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -784,7 +784,6 @@ pub mod pilota_name { Ok(Test1), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestResultRecv { fn encode( &self, @@ -865,7 +864,8 @@ pub mod pilota_name { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestServiceTestResultRecv::Ok(field_ident)); } else { @@ -940,7 +940,6 @@ pub mod pilota_name { B = 1, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Index { fn encode( &self, diff --git a/pilota-build/test_data/thrift/recursive_type.rs b/pilota-build/test_data/thrift/recursive_type.rs index c875a64b..2d03ba52 100644 --- a/pilota-build/test_data/thrift/recursive_type.rs +++ b/pilota-build/test_data/thrift/recursive_type.rs @@ -6,7 +6,6 @@ pub mod recursive_type { pub struct A { pub a: ::std::option::Option<::std::boxed::Box>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -102,7 +101,8 @@ pub mod recursive_type { if field_ident.field_type == ::pilota::thrift::TType::Struct => { a = Some(::std::boxed::Box::new( - ::pilota::thrift::Message::decode_async(protocol).await?, + ::decode_async(protocol) + .await?, )); } _ => { diff --git a/pilota-build/test_data/thrift/self_kw.rs b/pilota-build/test_data/thrift/self_kw.rs index 51b04208..126af0ec 100644 --- a/pilota-build/test_data/thrift/self_kw.rs +++ b/pilota-build/test_data/thrift/self_kw.rs @@ -38,7 +38,6 @@ pub mod self_kw { Self_ = 1, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Index { fn encode( &self, @@ -86,7 +85,6 @@ pub mod self_kw { pub struct A { pub r#type: ::pilota::FastStr, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, diff --git a/pilota-build/test_data/thrift/string.rs b/pilota-build/test_data/thrift/string.rs index cd8c2fcc..122f3dcc 100644 --- a/pilota-build/test_data/thrift/string.rs +++ b/pilota-build/test_data/thrift/string.rs @@ -8,7 +8,6 @@ pub mod string { pub string: ::std::string::String, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, diff --git a/pilota-build/test_data/thrift/union.rs b/pilota-build/test_data/thrift/union.rs index 2d7cf323..a4ac8cad 100644 --- a/pilota-build/test_data/thrift/union.rs +++ b/pilota-build/test_data/thrift/union.rs @@ -13,7 +13,6 @@ pub mod union { B(::pilota::Bytes), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Union { fn encode( &self, @@ -162,7 +161,6 @@ pub mod union { pub enum Empty {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Empty { fn encode( &self, @@ -257,7 +255,6 @@ pub mod union { pub struct A { pub u: ::std::option::Option, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -350,7 +347,10 @@ pub mod union { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - u = Some(::pilota::thrift::Message::decode_async(protocol).await?); + u = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; diff --git a/pilota-build/test_data/thrift/void.rs b/pilota-build/test_data/thrift/void.rs index 98e83c80..e748ec15 100644 --- a/pilota-build/test_data/thrift/void.rs +++ b/pilota-build/test_data/thrift/void.rs @@ -11,7 +11,6 @@ pub mod void { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultRecv { fn encode( &self, @@ -99,7 +98,6 @@ pub mod void { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct TestTest123ArgsSend {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { fn encode( &self, @@ -225,7 +223,6 @@ pub mod void { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct TestTest123ArgsRecv {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { fn encode( &self, @@ -358,7 +355,6 @@ pub mod void { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultSend { fn encode( &self, diff --git a/pilota-build/test_data/thrift/wrapper_arc.rs b/pilota-build/test_data/thrift/wrapper_arc.rs index 7cabf696..e6f82c26 100644 --- a/pilota-build/test_data/thrift/wrapper_arc.rs +++ b/pilota-build/test_data/thrift/wrapper_arc.rs @@ -4,7 +4,6 @@ pub mod wrapper_arc { pub mod wrapper_arc { #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct A {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -130,7 +129,6 @@ pub mod wrapper_arc { Ok(Test), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestResultRecv { fn encode( &self, @@ -211,7 +209,8 @@ pub mod wrapper_arc { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestServiceTestResultRecv::Ok(field_ident)); } else { @@ -255,7 +254,6 @@ pub mod wrapper_arc { pub struct TestServiceTestArgsRecv { pub req: Test, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestArgsRecv { fn encode( &self, @@ -358,8 +356,10 @@ pub mod wrapper_arc { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -418,7 +418,6 @@ pub mod wrapper_arc { Ok(::std::sync::Arc), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestResultSend { fn encode( &self, @@ -501,7 +500,8 @@ pub mod wrapper_arc { Some(0) => { if ret.is_none() { let field_ident = ::std::sync::Arc::new( - ::pilota::thrift::Message::decode_async(protocol).await?, + ::decode_async(protocol) + .await?, ); ret = Some(TestServiceTestResultSend::Ok(field_ident)); @@ -550,7 +550,6 @@ pub mod wrapper_arc { pub name3: ::std::collections::HashMap>>, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Test { fn encode( &self, @@ -770,7 +769,7 @@ pub mod wrapper_arc { let mut val = Vec::with_capacity(list_ident.size); for _ in 0..list_ident.size { val.push(::std::sync::Arc::new( - ::pilota::thrift::Message::decode_async( + ::decode_async( protocol, ) .await?, @@ -795,7 +794,7 @@ pub mod wrapper_arc { let mut val = Vec::with_capacity(list_ident.size); for _ in 0..list_ident.size { val.push(::std::sync::Arc::new( - ::pilota::thrift::Message::decode_async( + ::decode_async( protocol, ) .await?, @@ -895,7 +894,6 @@ pub mod wrapper_arc { pub struct TestServiceTestArgsSend { pub req: ::std::sync::Arc, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestServiceTestArgsSend { fn encode( &self, @@ -1001,7 +999,8 @@ pub mod wrapper_arc { if field_ident.field_type == ::pilota::thrift::TType::Struct => { req = Some(::std::sync::Arc::new( - ::pilota::thrift::Message::decode_async(protocol).await?, + ::decode_async(protocol) + .await?, )); } _ => { diff --git a/pilota-build/test_data/unknown_fields.rs b/pilota-build/test_data/unknown_fields.rs index 93b26147..57d59dc8 100644 --- a/pilota-build/test_data/unknown_fields.rs +++ b/pilota-build/test_data/unknown_fields.rs @@ -18,7 +18,6 @@ pub mod unknown_fields { pub a: ::std::option::Option, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -180,7 +179,6 @@ pub mod unknown_fields { pub a: ::std::option::Option, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, @@ -284,7 +282,10 @@ pub mod unknown_fields { Some(2) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - a = Some(::pilota::thrift::Message::decode_async(protocol).await?); + a = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -351,7 +352,6 @@ pub mod unknown_fields { pub vec: ::std::vec::Vec, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for A { fn encode( &self, @@ -557,7 +557,6 @@ pub mod unknown_fields { pub td: Td, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for D { fn encode( &self, @@ -665,7 +664,10 @@ pub mod unknown_fields { __pilota_decoding_field_id = field_ident.id; match field_ident.id { Some(1) if field_ident.field_type == ::pilota::thrift::TType::List => { - td = Some(::pilota::thrift::Message::decode_async(protocol).await?); + td = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -730,7 +732,6 @@ pub mod unknown_fields { PartialEq, )] pub struct TestTest123ArgsSend {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { fn encode( &self, @@ -875,7 +876,6 @@ pub mod unknown_fields { pub list: ::std::vec::Vec<::std::vec::Vec<::pilota::FastStr>>, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for B { fn encode( &self, @@ -1168,7 +1168,6 @@ pub mod unknown_fields { pub struct SubMessage { pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for SubMessage { fn encode( &self, @@ -1314,7 +1313,6 @@ pub mod unknown_fields { pub message: ::std::option::Option<::pilota::FastStr>, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for StException { fn encode( &self, @@ -1483,7 +1481,6 @@ pub mod unknown_fields { PartialEq, )] pub struct TestTest123ArgsRecv {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { fn encode( &self, @@ -1630,7 +1627,6 @@ pub mod unknown_fields { pub a: super::must_gen_items::A, pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for C { fn encode( &self, @@ -1729,40 +1725,42 @@ pub mod unknown_fields { protocol.read_struct_begin().await?; if let Err(err) = async { loop { - let field_ident = protocol.read_field_begin().await?; - if field_ident.field_type == ::pilota::thrift::TType::Stop { - break; - } else { - } - __pilota_decoding_field_id = field_ident.id; - match field_ident.id { - Some(1) - if field_ident.field_type == ::pilota::thrift::TType::Struct => - { - a = Some(::pilota::thrift::Message::decode_async(protocol).await?); - } - _ => { - protocol.skip(field_ident.field_type).await?; - } - } - protocol.read_field_end().await?; - } + + let field_ident = protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + a = Some(::decode_async(protocol).await?); + + }, + _ => { + protocol.skip(field_ident.field_type).await?; + + }, + } + + protocol.read_field_end().await?; + + + }; Ok::<_, ::pilota::thrift::DecodeError>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + return Err(::pilota::thrift::DecodeError::new( + ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new(err)), + format!("decode struct `C` field(#{}) failed", field_id), + )); + } else { + return Err(err) } - .await - { - if let Some(field_id) = __pilota_decoding_field_id { - return Err(::pilota::thrift::DecodeError::new( - ::pilota::thrift::DecodeErrorKind::WithContext(::std::boxed::Box::new( - err, - )), - format!("decode struct `C` field(#{}) failed", field_id), - )); - } else { - return Err(err); - } - }; + }; protocol.read_struct_end().await?; let Some(a) = a else { @@ -1804,7 +1802,6 @@ pub mod unknown_fields { pub struct Message { pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Message { fn encode( &self, @@ -1945,7 +1942,6 @@ pub mod unknown_fields { _UnknownFields(::pilota::LinkedBytes), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestUnion { fn encode( &self, @@ -2064,7 +2060,8 @@ pub mod unknown_fields { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestUnion::A(field_ident)); } else { @@ -2077,7 +2074,8 @@ pub mod unknown_fields { Some(2) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestUnion::B(field_ident)); } else { @@ -2127,7 +2125,6 @@ pub mod unknown_fields { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionException { fn encode( &self, @@ -2208,7 +2205,10 @@ pub mod unknown_fields { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionException::StException(field_ident)); } else { @@ -2259,7 +2259,6 @@ pub mod unknown_fields { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionResultRecv { fn encode( &self, @@ -2355,7 +2354,8 @@ pub mod unknown_fields { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestTestExceptionResultRecv::Ok(field_ident)); } else { @@ -2368,7 +2368,10 @@ pub mod unknown_fields { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionResultRecv::StException(field_ident)); } else { @@ -2420,7 +2423,6 @@ pub mod unknown_fields { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultRecv { fn encode( &self, @@ -2541,7 +2543,6 @@ pub mod unknown_fields { B = 1, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Index { fn encode( &self, @@ -2600,7 +2601,6 @@ pub mod unknown_fields { pub struct ObjReq { pub _unknown_fields: ::pilota::LinkedBytes, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for ObjReq { fn encode( &self, @@ -2751,7 +2751,6 @@ pub mod unknown_fields { pub struct TestTestExceptionArgsSend { pub req: ObjReq, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionArgsSend { fn encode( &self, @@ -2854,8 +2853,10 @@ pub mod unknown_fields { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -2914,7 +2915,6 @@ pub mod unknown_fields { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultSend { fn encode( &self, @@ -3028,7 +3028,6 @@ pub mod unknown_fields { } } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for Td { fn encode( &self, @@ -3131,7 +3130,6 @@ pub mod unknown_fields { pub struct TestTestExceptionArgsRecv { pub req: ObjReq, } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionArgsRecv { fn encode( &self, @@ -3234,8 +3232,10 @@ pub mod unknown_fields { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - req = - Some(::pilota::thrift::Message::decode_async(protocol).await?); + req = Some( + ::decode_async(protocol) + .await?, + ); } _ => { protocol.skip(field_ident.field_type).await?; @@ -3296,7 +3296,6 @@ pub mod unknown_fields { StException(StException), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTestExceptionResultSend { fn encode( &self, @@ -3392,7 +3391,8 @@ pub mod unknown_fields { Some(0) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async(protocol) + .await?; ret = Some(TestTestExceptionResultSend::Ok(field_ident)); } else { @@ -3405,7 +3405,10 @@ pub mod unknown_fields { Some(1) => { if ret.is_none() { let field_ident = - ::pilota::thrift::Message::decode_async(protocol).await?; + ::decode_async( + protocol, + ) + .await?; ret = Some(TestTestExceptionResultSend::StException(field_ident)); } else { @@ -3470,7 +3473,6 @@ pub mod unknown_fields { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultRecv { fn encode( &self, @@ -3565,7 +3567,6 @@ pub mod unknown_fields { Ok(()), } - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ResultSend { fn encode( &self, @@ -3664,7 +3665,6 @@ pub mod unknown_fields { PartialEq, )] pub struct TestTest123ArgsSend {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { fn encode( &self, @@ -3801,7 +3801,6 @@ pub mod unknown_fields { PartialEq, )] pub struct TestTest123ArgsRecv {} - #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { fn encode( &self, diff --git a/pilota/benches/skip.rs b/pilota/benches/skip.rs index 3617f4da..69bf34cf 100644 --- a/pilota/benches/skip.rs +++ b/pilota/benches/skip.rs @@ -7,7 +7,6 @@ use pilota::thrift::{ binary_unsafe::TBinaryUnsafeInputProtocol, DecodeError, TInputProtocol, TOutputProtocol, TOutputProtocolExt, TStructIdentifier, TType, }; - use rand::Rng; fn skip_bench(c: &mut Criterion) { diff --git a/pilota/src/thrift/mod.rs b/pilota/src/thrift/mod.rs index 8c6bb93e..2017d8b2 100644 --- a/pilota/src/thrift/mod.rs +++ b/pilota/src/thrift/mod.rs @@ -35,7 +35,6 @@ lazy_static::lazy_static! { pub static ref VOID_IDENT: TStructIdentifier = TStructIdentifier { name: "void" }; } -#[async_trait::async_trait] pub trait Message: Sized + Send { fn encode(&self, protocol: &mut T) -> Result<(), EncodeError>; @@ -46,7 +45,6 @@ pub trait Message: Sized + Send { fn size(&self, protocol: &mut T) -> usize; } -#[async_trait::async_trait] impl Message for Box { #[inline] fn encode(&self, protocol: &mut T) -> Result<(), EncodeError> { @@ -68,7 +66,6 @@ impl Message for Box { } } -#[async_trait::async_trait] impl Message for Arc { #[inline] fn encode(&self, protocol: &mut T) -> Result<(), EncodeError> {