diff --git a/Cargo.lock b/Cargo.lock index 94e2169a..f0371e03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,9 +54,9 @@ checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "async-recursion" @@ -66,18 +66,18 @@ checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -130,9 +130,9 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytes" @@ -151,9 +151,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.90" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" [[package]] name = "cfg-if" @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "equivalent" @@ -366,9 +366,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "libc", @@ -383,9 +383,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "half" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eceaaeec696539ddaf7b333340f1af35a5aa87ae3e4f3ead0532f72affab2e" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ "cfg-if", "crunchy", @@ -747,7 +747,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -784,7 +784,7 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.11.2" +version = "0.11.3" dependencies = [ "ahash", "anyhow", @@ -814,7 +814,7 @@ dependencies = [ "scoped-tls", "serde", "serde_yaml", - "syn 2.0.58", + "syn 2.0.60", "tempfile", "tokio", "toml", @@ -871,9 +871,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -942,9 +942,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1084,9 +1084,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad" dependencies = [ "bitflags 2.5.0", "errno", @@ -1165,29 +1165,29 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -1256,9 +1256,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1279,22 +1279,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1351,9 +1351,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" dependencies = [ "indexmap 2.2.6", "serde", @@ -1381,7 +1381,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1505,7 +1505,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -1527,7 +1527,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1597,7 +1597,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -1617,17 +1617,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -1638,9 +1639,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -1650,9 +1651,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -1662,9 +1663,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -1674,9 +1681,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -1686,9 +1693,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -1698,9 +1705,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -1710,15 +1717,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" dependencies = [ "memchr", ] @@ -1740,5 +1747,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] diff --git a/pilota-build/Cargo.toml b/pilota-build/Cargo.toml index 7c43056c..684b70c9 100644 --- a/pilota-build/Cargo.toml +++ b/pilota-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota-build" -version = "0.11.2" +version = "0.11.3" edition = "2021" description = "Compile thrift and protobuf idl into rust code at compile-time." documentation = "https://docs.rs/pilota-build" diff --git a/pilota-build/src/middle/workspace_graph.rs b/pilota-build/src/middle/workspace_graph.rs index f5fb69a6..b6682549 100644 --- a/pilota-build/src/middle/workspace_graph.rs +++ b/pilota-build/src/middle/workspace_graph.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use petgraph::{graph::NodeIndex, Graph}; +use petgraph::{algo::has_path_connecting, graph::NodeIndex, Graph}; use rustc_hash::FxHashMap; use super::{ @@ -77,4 +77,10 @@ impl WorkspaceGraph { id_map, } } + + pub fn is_nested(&self, a: DefId, b: DefId) -> bool { + let a = self.node_map[&a]; + let b = self.node_map[&b]; + has_path_connecting(&self.graph, a, b, None) + } } diff --git a/pilota-build/src/plugin/mod.rs b/pilota-build/src/plugin/mod.rs index 14a6ca09..0924915a 100644 --- a/pilota-build/src/plugin/mod.rs +++ b/pilota-build/src/plugin/mod.rs @@ -258,10 +258,11 @@ where .count(); if paths_can_derive.iter().any(|(_, p)| *p == CanDerive::No) { - delayed.iter().for_each(|def_id| { - self.can_derive.insert(*def_id, CanDerive::No); + delayed.iter().for_each(|delayed_def_id| { + if cx.workspace_graph().is_nested(*delayed_def_id, def_id) { + self.can_derive.insert(*delayed_def_id, CanDerive::No); + } }); - CanDerive::No } else if delayed_count > 0 { delayed.insert(def_id); diff --git a/pilota-build/test_data/thrift/multi.rs b/pilota-build/test_data/thrift/multi.rs index c89abee9..e55f6b91 100644 --- a/pilota-build/test_data/thrift/multi.rs +++ b/pilota-build/test_data/thrift/multi.rs @@ -3,6 +3,255 @@ pub mod multi { pub mod default_value { + impl Default for C { + fn default() -> Self { + C { + off: Some(::pilota::FastStr::from_static_str("off")), + test_byte: Some(0i8), + } + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq)] + pub struct C { + pub off: ::std::option::Option<::pilota::FastStr>, + + pub test_byte: ::std::option::Option, + } + impl ::pilota::thrift::Message for C { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "C" }; + + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.off.as_ref() { + protocol.write_faststr_field(1, (value).clone())?; + } + if let Some(value) = self.test_byte.as_ref() { + protocol.write_i8_field(2, *value)?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; + Ok(()) + } + + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut off = Some(::pilota::FastStr::from_static_str("off")); + let mut test_byte = Some(0i8); + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + off = Some(protocol.read_faststr()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::I8 => { + test_byte = Some(protocol.read_i8()?); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + let data = Self { off, test_byte }; + Ok(data) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut off = Some(::pilota::FastStr::from_static_str("off")); + let mut test_byte = Some(0i8); + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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::Binary => + { + off = Some(protocol.read_faststr().await?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::I8 => + { + test_byte = Some(protocol.read_i8().await?); + } + _ => { + protocol.skip(field_ident.field_type).await?; + } + } + + protocol.read_field_end().await?; + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + let data = Self { off, test_byte }; + Ok(data) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "C" }) + + self + .off + .as_ref() + .map_or(0, |value| protocol.faststr_field_len(Some(1), value)) + + self + .test_byte + .as_ref() + .map_or(0, |value| protocol.i8_field_len(Some(2), *value)) + + protocol.field_stop_len() + + protocol.struct_end_len() + } + } + pub const A_S: &'static str = "string"; + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq, Copy)] + #[repr(transparent)] + pub struct B(i32); + + impl B { + pub const READ: Self = Self(1); + pub const WRITE: Self = Self(2); + + pub fn inner(&self) -> i32 { + self.0 + } + } + + impl ::std::convert::From for B { + fn from(value: i32) -> Self { + Self(value) + } + } + + impl ::std::convert::From for i32 { + fn from(value: B) -> i32 { + value.0 + } + } + + impl ::pilota::thrift::Message for B { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + protocol.write_i32(self.inner())?; + Ok(()) + } + + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let value = protocol.read_i32()?; + Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for B, value: {}", value), + ) + })?) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let value = protocol.read_i32().await?; + Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for B, value: {}", value), + ) + })?) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.i32_len(self.inner()) + } + } impl Default for A { fn default() -> Self { A { @@ -436,34 +685,182 @@ pub mod multi { + protocol.struct_end_len() } } - pub const A_S: &'static str = "string"; - #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] - #[derivative(Default)] - #[derive(Clone, PartialEq, Copy)] - #[repr(transparent)] - pub struct B(i32); + } - impl B { - pub const READ: Self = Self(1); - pub const WRITE: Self = Self(2); + pub mod multi { - pub fn inner(&self) -> i32 { - self.0 + impl Default for A { + fn default() -> Self { + A { + c: Some(super::default_value::C { + off: Some(::pilota::FastStr::from_static_str("off")), + test_byte: Default::default(), + }), + } } } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq)] + pub struct A { + pub c: ::std::option::Option, + } + impl ::pilota::thrift::Message for A { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "A" }; - impl ::std::convert::From for B { - fn from(value: i32) -> Self { - Self(value) + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.c.as_ref() { + protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; + Ok(()) } - } - impl ::std::convert::From for i32 { - fn from(value: B) -> i32 { - value.0 + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + c = Some(::pilota::thrift::Message::decode(protocol)?); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `A` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + if c.is_none() { + c = Some(super::default_value::C { + off: Some(::pilota::FastStr::from_static_str("off")), + test_byte: Default::default(), + }); + } + + let data = Self { c }; + Ok(data) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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 => { + c = Some(::decode_async(protocol).await?); + + }, + _ => { + protocol.skip(field_ident.field_type).await?; + + }, + } + + protocol.read_field_end().await?; + + + }; + Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `A` field(#{}) failed, caused by: ", field_id)); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + if c.is_none() { + c = Some(super::default_value::C { + off: Some(::pilota::FastStr::from_static_str("off")), + test_byte: Default::default(), + }); + } + + let data = Self { c }; + Ok(data) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "A" }) + + self + .c + .as_ref() + .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + + protocol.field_stop_len() + + protocol.struct_end_len() } } + #[derive(Debug, Default, Clone, PartialEq)] + pub struct B { + pub a: ::std::option::Option, + pub c: ::std::option::Option, + } impl ::pilota::thrift::Message for B { fn encode( &self, @@ -471,22 +868,243 @@ pub mod multi { ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { #[allow(unused_imports)] use ::pilota::thrift::TOutputProtocolExt; - protocol.write_i32(self.inner())?; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "B" }; + + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.a.as_ref() { + protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; + } + if let Some(value) = self.c.as_ref() { + protocol.write_struct_field(2, value, ::pilota::thrift::TType::Struct)?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; Ok(()) } - fn decode( - protocol: &mut T, - ) -> ::std::result::Result { - #[allow(unused_imports)] - use ::pilota::{thrift::TLengthProtocolExt, Buf}; - let value = protocol.read_i32()?; - Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { - ::pilota::thrift::new_protocol_exception( - ::pilota::thrift::ProtocolExceptionKind::InvalidData, - format!("invalid enum value for B, value: {}", value), - ) - })?) + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut a = None; + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __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(protocol)?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + c = Some(::pilota::thrift::Message::decode(protocol)?); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `B` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + let data = Self { a, c }; + Ok(data) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut a = None; + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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(::decode_async(protocol).await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + c = Some(::decode_async(protocol).await?); + + }, + _ => { + protocol.skip(field_ident.field_type).await?; + + }, + } + + protocol.read_field_end().await?; + + + }; + Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `B` field(#{}) failed, caused by: ", field_id)); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + let data = Self { a, c }; + Ok(data) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "B" }) + + self + .a + .as_ref() + .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + + self + .c + .as_ref() + .map_or(0, |value| protocol.struct_field_len(Some(2), value)) + + protocol.field_stop_len() + + protocol.struct_end_len() + } + } + } + + pub mod recursive_type { + #[derive(Debug, Default, Clone, PartialEq)] + pub struct C { + pub c: ::std::option::Option<::pilota::AHashSet<::pilota::FastStr>>, + } + impl ::pilota::thrift::Message for C { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "C" }; + + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.c.as_ref() { + protocol.write_set_field( + 1, + ::pilota::thrift::TType::Binary, + &value, + |protocol, val| { + protocol.write_faststr((val).clone())?; + Ok(()) + }, + )?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; + Ok(()) + } + + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Set => { + c = Some({ + let list_ident = protocol.read_set_begin()?; + let mut val = + ::pilota::AHashSet::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.insert(protocol.read_faststr()?); + } + protocol.read_set_end()?; + val + }); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + let data = Self { c }; + Ok(data) } fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( @@ -500,51 +1118,97 @@ pub mod multi { >, > { ::std::boxed::Box::pin(async move { - let value = protocol.read_i32().await?; - Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { - ::pilota::thrift::new_protocol_exception( - ::pilota::thrift::ProtocolExceptionKind::InvalidData, - format!("invalid enum value for B, value: {}", value), - ) - })?) + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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::Set => + { + c = Some({ + let list_ident = protocol.read_set_begin().await?; + let mut val = + ::pilota::AHashSet::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.insert(protocol.read_faststr().await?); + } + protocol.read_set_end().await?; + val + }); + } + _ => { + protocol.skip(field_ident.field_type).await?; + } + } + + protocol.read_field_end().await?; + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + let data = Self { c }; + Ok(data) }) } fn size(&self, protocol: &mut T) -> usize { #[allow(unused_imports)] use ::pilota::thrift::TLengthProtocolExt; - protocol.i32_len(self.inner()) - } - } - impl Default for C { - fn default() -> Self { - C { - off: Some(::pilota::FastStr::from_static_str("off")), - test_byte: Some(0i8), - } + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "C" }) + + self.c.as_ref().map_or(0, |value| { + protocol.set_field_len( + Some(1), + ::pilota::thrift::TType::Binary, + value, + |protocol, el| protocol.faststr_len(el), + ) + }) + + protocol.field_stop_len() + + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq)] - pub struct C { - pub off: ::std::option::Option<::pilota::FastStr>, + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct A { + pub a: ::std::option::Option<::std::boxed::Box>, - pub test_byte: ::std::option::Option, + pub a_b: ::std::option::Option<::std::boxed::Box>, } - impl ::pilota::thrift::Message for C { + impl ::pilota::thrift::Message for A { fn encode( &self, protocol: &mut T, ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { #[allow(unused_imports)] use ::pilota::thrift::TOutputProtocolExt; - let struct_ident = ::pilota::thrift::TStructIdentifier { name: "C" }; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "A" }; protocol.write_struct_begin(&struct_ident)?; - if let Some(value) = self.off.as_ref() { - protocol.write_faststr_field(1, (value).clone())?; + if let Some(value) = self.a.as_ref() { + protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; } - if let Some(value) = self.test_byte.as_ref() { - protocol.write_i8_field(2, *value)?; + if let Some(value) = self.a_b.as_ref() { + protocol.write_struct_field(2, value, ::pilota::thrift::TType::Struct)?; } protocol.write_field_stop()?; protocol.write_struct_end()?; @@ -557,8 +1221,8 @@ pub mod multi { #[allow(unused_imports)] use ::pilota::{thrift::TLengthProtocolExt, Buf}; - let mut off = Some(::pilota::FastStr::from_static_str("off")); - let mut test_byte = Some(0i8); + let mut a = None; + let mut a_b = None; let mut __pilota_decoding_field_id = None; @@ -575,12 +1239,18 @@ pub mod multi { __pilota_decoding_field_id = field_ident.id; match field_ident.id { Some(1) - if field_ident.field_type == ::pilota::thrift::TType::Binary => + if field_ident.field_type == ::pilota::thrift::TType::Struct => { - off = Some(protocol.read_faststr()?); + a = Some(::std::boxed::Box::new( + ::pilota::thrift::Message::decode(protocol)?, + )); } - Some(2) if field_ident.field_type == ::pilota::thrift::TType::I8 => { - test_byte = Some(protocol.read_i8()?); + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + a_b = Some(::std::boxed::Box::new( + ::pilota::thrift::Message::decode(protocol)?, + )); } _ => { protocol.skip(field_ident.field_type)?; @@ -594,7 +1264,7 @@ pub mod multi { })() { if let Some(field_id) = __pilota_decoding_field_id { err.prepend_msg(&format!( - "decode struct `C` field(#{}) failed, caused by: ", + "decode struct `A` field(#{}) failed, caused by: ", field_id )); } @@ -602,7 +1272,7 @@ pub mod multi { }; protocol.read_struct_end()?; - let data = Self { off, test_byte }; + let data = Self { a, a_b }; Ok(data) } @@ -617,8 +1287,8 @@ pub mod multi { >, > { ::std::boxed::Box::pin(async move { - let mut off = Some(::pilota::FastStr::from_static_str("off")); - let mut test_byte = Some(0i8); + let mut a = None; + let mut a_b = None; let mut __pilota_decoding_field_id = None; @@ -634,14 +1304,21 @@ pub mod multi { match field_ident.id { Some(1) if field_ident.field_type - == ::pilota::thrift::TType::Binary => + == ::pilota::thrift::TType::Struct => { - off = Some(protocol.read_faststr().await?); + a = Some(::std::boxed::Box::new( + ::decode_async(protocol) + .await?, + )); } Some(2) - if field_ident.field_type == ::pilota::thrift::TType::I8 => + if field_ident.field_type + == ::pilota::thrift::TType::Struct => { - test_byte = Some(protocol.read_i8().await?); + a_b = Some(::std::boxed::Box::new( + ::decode_async(protocol) + .await?, + )); } _ => { protocol.skip(field_ident.field_type).await?; @@ -656,7 +1333,7 @@ pub mod multi { { if let Some(field_id) = __pilota_decoding_field_id { err.prepend_msg(&format!( - "decode struct `C` field(#{}) failed, caused by: ", + "decode struct `A` field(#{}) failed, caused by: ", field_id )); } @@ -664,7 +1341,7 @@ pub mod multi { }; protocol.read_struct_end().await?; - let data = Self { off, test_byte }; + let data = Self { a, a_b }; Ok(data) }) } @@ -672,48 +1349,34 @@ pub mod multi { fn size(&self, protocol: &mut T) -> usize { #[allow(unused_imports)] use ::pilota::thrift::TLengthProtocolExt; - protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "C" }) + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "A" }) + self - .off + .a .as_ref() - .map_or(0, |value| protocol.faststr_field_len(Some(1), value)) + .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + self - .test_byte + .a_b .as_ref() - .map_or(0, |value| protocol.i8_field_len(Some(2), *value)) + .map_or(0, |value| protocol.struct_field_len(Some(2), value)) + protocol.field_stop_len() + protocol.struct_end_len() } } - } - - pub mod multi { - - impl Default for A { - fn default() -> Self { - A { - c: Some(super::default_value::C { - off: Some(::pilota::FastStr::from_static_str("off")), - test_byte: Default::default(), - }), - } - } - } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq)] - pub struct A { - pub c: ::std::option::Option, + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct B { + pub b_a: ::std::option::Option<::std::boxed::Box>, } - impl ::pilota::thrift::Message for A { + impl ::pilota::thrift::Message for B { fn encode( &self, protocol: &mut T, ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { #[allow(unused_imports)] use ::pilota::thrift::TOutputProtocolExt; - let struct_ident = ::pilota::thrift::TStructIdentifier { name: "A" }; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "B" }; protocol.write_struct_begin(&struct_ident)?; - if let Some(value) = self.c.as_ref() { + if let Some(value) = self.b_a.as_ref() { protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; } protocol.write_field_stop()?; @@ -727,7 +1390,7 @@ pub mod multi { #[allow(unused_imports)] use ::pilota::{thrift::TLengthProtocolExt, Buf}; - let mut c = None; + let mut b_a = None; let mut __pilota_decoding_field_id = None; @@ -746,7 +1409,9 @@ pub mod multi { Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { - c = Some(::pilota::thrift::Message::decode(protocol)?); + b_a = Some(::std::boxed::Box::new( + ::pilota::thrift::Message::decode(protocol)?, + )); } _ => { protocol.skip(field_ident.field_type)?; @@ -760,7 +1425,7 @@ pub mod multi { })() { if let Some(field_id) = __pilota_decoding_field_id { err.prepend_msg(&format!( - "decode struct `A` field(#{}) failed, caused by: ", + "decode struct `B` field(#{}) failed, caused by: ", field_id )); } @@ -768,14 +1433,7 @@ pub mod multi { }; protocol.read_struct_end()?; - if c.is_none() { - c = Some(super::default_value::C { - off: Some(::pilota::FastStr::from_static_str("off")), - test_byte: Default::default(), - }); - } - - let data = Self { c }; + let data = Self { b_a }; Ok(data) } @@ -790,55 +1448,51 @@ pub mod multi { >, > { ::std::boxed::Box::pin(async move { - let mut c = None; + let mut b_a = None; let mut __pilota_decoding_field_id = None; protocol.read_struct_begin().await?; if let Err(mut 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 => { - c = Some(::decode_async(protocol).await?); - - }, - _ => { - protocol.skip(field_ident.field_type).await?; - - }, - } - - protocol.read_field_end().await?; - - - }; - Ok::<_, ::pilota::thrift::ThriftException>(()) - }.await { - if let Some(field_id) = __pilota_decoding_field_id { - err.prepend_msg(&format!("decode struct `A` field(#{}) failed, caused by: ", field_id)); - } - return Err(err); - }; - protocol.read_struct_end().await?; + 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 => + { + b_a = Some(::std::boxed::Box::new( + ::decode_async(protocol) + .await?, + )); + } + _ => { + protocol.skip(field_ident.field_type).await?; + } + } - if c.is_none() { - c = Some(super::default_value::C { - off: Some(::pilota::FastStr::from_static_str("off")), - test_byte: Default::default(), - }); + protocol.read_field_end().await?; + } + Ok::<_, ::pilota::thrift::ThriftException>(()) } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `B` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end().await?; - let data = Self { c }; + let data = Self { b_a }; Ok(data) }) } @@ -846,9 +1500,9 @@ pub mod multi { fn size(&self, protocol: &mut T) -> usize { #[allow(unused_imports)] use ::pilota::thrift::TLengthProtocolExt; - protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "A" }) + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "B" }) + self - .c + .b_a .as_ref() .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + protocol.field_stop_len() diff --git a/pilota-build/test_data/thrift/multi.thrift b/pilota-build/test_data/thrift/multi.thrift index dabceafb..cc3fb25c 100644 --- a/pilota-build/test_data/thrift/multi.thrift +++ b/pilota-build/test_data/thrift/multi.thrift @@ -1,5 +1,11 @@ include "default_value.thrift" +include "recursive_type.thrift" struct A { 1: default_value.C c = {"off": "off"}, -} \ No newline at end of file +} + +struct B { + 1: recursive_type.A a, + 2: recursive_type.C c, +} diff --git a/pilota-build/test_data/thrift/recursive_type.rs b/pilota-build/test_data/thrift/recursive_type.rs index 3e7d00fd..89f79350 100644 --- a/pilota-build/test_data/thrift/recursive_type.rs +++ b/pilota-build/test_data/thrift/recursive_type.rs @@ -5,6 +5,8 @@ pub mod recursive_type { #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] pub struct A { pub a: ::std::option::Option<::std::boxed::Box>, + + pub a_b: ::std::option::Option<::std::boxed::Box>, } impl ::pilota::thrift::Message for A { fn encode( @@ -19,6 +21,9 @@ pub mod recursive_type { if let Some(value) = self.a.as_ref() { protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; } + if let Some(value) = self.a_b.as_ref() { + protocol.write_struct_field(2, value, ::pilota::thrift::TType::Struct)?; + } protocol.write_field_stop()?; protocol.write_struct_end()?; Ok(()) @@ -31,6 +36,7 @@ pub mod recursive_type { use ::pilota::{thrift::TLengthProtocolExt, Buf}; let mut a = None; + let mut a_b = None; let mut __pilota_decoding_field_id = None; @@ -53,6 +59,13 @@ pub mod recursive_type { ::pilota::thrift::Message::decode(protocol)?, )); } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + a_b = Some(::std::boxed::Box::new( + ::pilota::thrift::Message::decode(protocol)?, + )); + } _ => { protocol.skip(field_ident.field_type)?; } @@ -73,7 +86,7 @@ pub mod recursive_type { }; protocol.read_struct_end()?; - let data = Self { a }; + let data = Self { a, a_b }; Ok(data) } @@ -89,6 +102,7 @@ pub mod recursive_type { > { ::std::boxed::Box::pin(async move { let mut a = None; + let mut a_b = None; let mut __pilota_decoding_field_id = None; @@ -111,6 +125,15 @@ pub mod recursive_type { .await?, )); } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + a_b = Some(::std::boxed::Box::new( + ::decode_async(protocol) + .await?, + )); + } _ => { protocol.skip(field_ident.field_type).await?; } @@ -132,7 +155,7 @@ pub mod recursive_type { }; protocol.read_struct_end().await?; - let data = Self { a }; + let data = Self { a, a_b }; Ok(data) }) } @@ -145,6 +168,326 @@ pub mod recursive_type { .a .as_ref() .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + + self + .a_b + .as_ref() + .map_or(0, |value| protocol.struct_field_len(Some(2), value)) + + protocol.field_stop_len() + + protocol.struct_end_len() + } + } + #[derive(Debug, Default, Clone, PartialEq)] + pub struct C { + pub c: ::std::option::Option<::pilota::AHashSet<::pilota::FastStr>>, + } + impl ::pilota::thrift::Message for C { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "C" }; + + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.c.as_ref() { + protocol.write_set_field( + 1, + ::pilota::thrift::TType::Binary, + &value, + |protocol, val| { + protocol.write_faststr((val).clone())?; + Ok(()) + }, + )?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; + Ok(()) + } + + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Set => { + c = Some({ + let list_ident = protocol.read_set_begin()?; + let mut val = + ::pilota::AHashSet::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.insert(protocol.read_faststr()?); + } + protocol.read_set_end()?; + val + }); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + let data = Self { c }; + Ok(data) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut c = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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::Set => + { + c = Some({ + let list_ident = protocol.read_set_begin().await?; + let mut val = + ::pilota::AHashSet::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.insert(protocol.read_faststr().await?); + } + protocol.read_set_end().await?; + val + }); + } + _ => { + protocol.skip(field_ident.field_type).await?; + } + } + + protocol.read_field_end().await?; + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `C` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + let data = Self { c }; + Ok(data) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "C" }) + + self.c.as_ref().map_or(0, |value| { + protocol.set_field_len( + Some(1), + ::pilota::thrift::TType::Binary, + value, + |protocol, el| protocol.faststr_len(el), + ) + }) + + protocol.field_stop_len() + + protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct B { + pub b_a: ::std::option::Option<::std::boxed::Box>, + } + impl ::pilota::thrift::Message for B { + fn encode( + &self, + protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "B" }; + + protocol.write_struct_begin(&struct_ident)?; + if let Some(value) = self.b_a.as_ref() { + protocol.write_struct_field(1, value, ::pilota::thrift::TType::Struct)?; + } + protocol.write_field_stop()?; + protocol.write_struct_end()?; + Ok(()) + } + + fn decode( + protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut b_a = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin()?; + if let Err(mut err) = (|| { + loop { + let field_ident = protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + protocol.field_stop_len(); + break; + } else { + protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + b_a = Some(::std::boxed::Box::new( + ::pilota::thrift::Message::decode(protocol)?, + )); + } + _ => { + protocol.skip(field_ident.field_type)?; + } + } + + protocol.read_field_end()?; + protocol.field_end_len(); + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `B` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end()?; + + let data = Self { b_a }; + Ok(data) + } + + 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, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut b_a = None; + + let mut __pilota_decoding_field_id = None; + + protocol.read_struct_begin().await?; + if let Err(mut 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 => + { + b_a = Some(::std::boxed::Box::new( + ::decode_async(protocol) + .await?, + )); + } + _ => { + protocol.skip(field_ident.field_type).await?; + } + } + + protocol.read_field_end().await?; + } + Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `B` field(#{}) failed, caused by: ", + field_id + )); + } + return Err(err); + }; + protocol.read_struct_end().await?; + + let data = Self { b_a }; + Ok(data) + }) + } + + fn size(&self, protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "B" }) + + self + .b_a + .as_ref() + .map_or(0, |value| protocol.struct_field_len(Some(1), value)) + protocol.field_stop_len() + protocol.struct_end_len() } diff --git a/pilota-build/test_data/thrift/recursive_type.thrift b/pilota-build/test_data/thrift/recursive_type.thrift index 10d74531..c5828f68 100644 --- a/pilota-build/test_data/thrift/recursive_type.thrift +++ b/pilota-build/test_data/thrift/recursive_type.thrift @@ -1,4 +1,12 @@ - struct A { 1: optional A a, + 2: optional B a_b, +} + +struct B { + 1: optional A b_a, +} + +struct C { + 1: set c, }