From acba6b2748cf3b1bda057d5e3e5dc26de57f1414 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Mon, 23 Sep 2024 17:21:30 +0200 Subject: [PATCH 01/10] Support splitting a single item into multiple files --- pilota-build/src/codegen/mod.rs | 34 +- pilota-build/src/codegen/workspace.rs | 1 + pilota-build/src/lib.rs | 13 + pilota-build/src/middle/context.rs | 4 + pilota-build/src/test/mod.rs | 103 +++++- .../thrift_with_split/wrapper_arc.rs | 20 + .../thrift_with_split/wrapper_arc.thrift | 13 + .../thrift_with_split/wrapper_arc/A.rs | 119 ++++++ .../thrift_with_split/wrapper_arc/TEST.rs | 345 ++++++++++++++++++ .../wrapper_arc/TestService.rs | 2 + .../wrapper_arc/TestServiceTestArgsRecv.rs | 152 ++++++++ .../wrapper_arc/TestServiceTestArgsSend.rs | 154 ++++++++ .../wrapper_arc/TestServiceTestResultRecv.rs | 140 +++++++ .../wrapper_arc/TestServiceTestResultSend.rs | 142 +++++++ 14 files changed, 1238 insertions(+), 4 deletions(-) create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc.thrift create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 0e67582e..36e66206 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -447,8 +447,12 @@ where ws.write_crates() } - pub fn write_items(&self, stream: &mut String, items: impl Iterator) - where + pub fn write_items( + &self, + stream: &mut String, + items: impl Iterator, + base_dir: &Path, + ) where B: Send, { let mods = items.into_group_map_by(|CodegenItem { def_id, .. }| { @@ -474,7 +478,29 @@ where let _enter = span.enter(); let mut dup = AHashMap::default(); for def_id in def_ids.iter() { - this.write_item(&mut stream, *def_id, &mut dup) + if this.split { + let mut item_stream = String::new(); + let node = this.db.node(def_id.def_id).unwrap(); + let file_name = format!("{}.rs", node.name()); + this.write_item(&mut item_stream, *def_id, &mut dup); + + let full_path = base_dir.join(file_name.clone()); + std::fs::create_dir_all(base_dir).unwrap(); + let mut file = + std::io::BufWriter::new(std::fs::File::create(full_path.clone()).unwrap()); + file.write_all(item_stream.as_bytes()).unwrap(); + file.flush().unwrap(); + fmt_file(full_path); + + let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); + + stream.push_str( + format!("\ninclude!(\"{}/{}\");\n", base_dir_local_path, file_name) + .as_str(), + ); + } else { + this.write_item(&mut stream, *def_id, &mut dup) + } } }); @@ -515,10 +541,12 @@ where } pub fn write_file(self, ns_name: Symbol, file_name: impl AsRef) { + let base_dir = file_name.as_ref().parent().unwrap(); let mut stream = String::default(); self.write_items( &mut stream, self.codegen_items.iter().map(|def_id| (*def_id).into()), + base_dir.join(ns_name.to_string()).as_path(), ); stream = format! {r#"pub mod {ns_name} {{ diff --git a/pilota-build/src/codegen/workspace.rs b/pilota-build/src/codegen/workspace.rs index 2f76b331..72f929a9 100644 --- a/pilota-build/src/codegen/workspace.rs +++ b/pilota-build/src/codegen/workspace.rs @@ -246,6 +246,7 @@ where def_id, kind: super::CodegenKind::RePub, })), + base_dir.as_ref(), ); if let Some(main_mod_path) = info.main_mod_path { gen_rs_stream.push_str(&format!( diff --git a/pilota-build/src/lib.rs b/pilota-build/src/lib.rs index 2d015fec..963e213d 100644 --- a/pilota-build/src/lib.rs +++ b/pilota-build/src/lib.rs @@ -78,6 +78,7 @@ pub struct Builder { parser: P, plugins: Vec>, ignore_unused: bool, + split: bool, touches: Vec<(std::path::PathBuf, Vec)>, change_case: bool, keep_unknown_fields: Vec, @@ -103,6 +104,7 @@ impl Builder { dedups: Vec::default(), special_namings: Vec::default(), common_crate_name: "common".into(), + split: false, } } } @@ -124,6 +126,7 @@ impl Builder { dedups: Vec::default(), special_namings: Vec::default(), common_crate_name: "common".into(), + split: false, } } } @@ -152,6 +155,7 @@ impl Builder { dedups: self.dedups, special_namings: self.special_namings, common_crate_name: self.common_crate_name, + split: self.split, } } @@ -161,6 +165,11 @@ impl Builder { self } + pub fn with_split(mut self) -> Self { + self.split = true; + self + } + pub fn change_case(mut self, change_case: bool) -> Self { self.change_case = change_case; self @@ -266,6 +275,7 @@ where dedups: Vec, special_namings: Vec, common_crate_name: FastStr, + split: bool, ) -> Context { let mut db = RootDatabase::default(); parser.inputs(services.iter().map(|s| &s.path)); @@ -341,6 +351,7 @@ where dedups, special_namings, common_crate_name, + split, ) } @@ -359,6 +370,7 @@ where self.dedups, self.special_namings, self.common_crate_name, + self.split, ); cx.exec_plugin(BoxedPlugin); @@ -441,6 +453,7 @@ where self.dedups, self.special_namings, self.common_crate_name, + self.split, ); std::thread::scope(|_scope| { diff --git a/pilota-build/src/middle/context.rs b/pilota-build/src/middle/context.rs index b224f127..80cbe020 100644 --- a/pilota-build/src/middle/context.rs +++ b/pilota-build/src/middle/context.rs @@ -67,6 +67,7 @@ pub struct Context { pub(crate) codegen_items: Arc<[DefId]>, pub(crate) path_resolver: Arc, pub(crate) mode: Arc, + pub(crate) split: bool, pub(crate) keep_unknown_fields: Arc>, pub location_map: Arc>, pub entry_map: Arc>>, @@ -86,6 +87,7 @@ impl Clone for Context { codegen_items: self.codegen_items.clone(), path_resolver: self.path_resolver.clone(), mode: self.mode.clone(), + split: self.split, services: self.services.clone(), keep_unknown_fields: self.keep_unknown_fields.clone(), location_map: self.location_map.clone(), @@ -327,6 +329,7 @@ impl ContextBuilder { dedups: Vec, special_namings: Vec, common_crate_name: FastStr, + split: bool, ) -> Context { SPECIAL_NAMINGS.get_or_init(|| special_namings); let mut cx = Context { @@ -341,6 +344,7 @@ impl ContextBuilder { Mode::SingleFile { .. } => Arc::new(DefaultPathResolver), }, mode: Arc::new(self.mode), + split, keep_unknown_fields: Arc::new(self.keep_unknown_fields), location_map: Arc::new(self.location_map), entry_map: Arc::new(self.entry_map), diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index b354e0c6..f3aae9bb 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,6 +1,6 @@ #![cfg(test)] -use std::path::Path; +use std::{fs, path::Path}; use tempfile::tempdir; @@ -19,6 +19,36 @@ fn diff_file(old: impl AsRef, new: impl AsRef) { } } +fn diff_dir(old: impl AsRef, new: impl AsRef) { + let old_files: Vec<_> = fs::read_dir(old.as_ref()) + .unwrap() + .map(|res| res.unwrap().path()) + .collect(); + let new_files: Vec<_> = fs::read_dir(new.as_ref()) + .unwrap() + .map(|res| res.unwrap().path()) + .collect(); + + if old_files.len() != new_files.len() { + panic!( + "Number of files are different between {} and {}: {} vs {}", + old.as_ref().to_str().unwrap(), + new.as_ref().to_str().unwrap(), + old_files.len(), + new_files.len() + ); + } + + for old_file in old_files { + let file_name = old_file.file_name().unwrap(); + let corresponding_new_file = new.as_ref().join(file_name); + if !corresponding_new_file.exists() { + panic!("File {:?} does not exist in the new directory", file_name); + } + diff_file(old_file, corresponding_new_file); + } +} + fn test_protobuf(source: impl AsRef, target: impl AsRef) { test_with_builder(source, target, |source, target| { crate::Builder::protobuf() @@ -55,6 +85,35 @@ fn test_with_builder( } } +fn test_with_split_builder( + source: impl AsRef, + target: impl AsRef, + gen_dir: impl AsRef, + f: F, +) { + if std::env::var("UPDATE_TEST_DATA").as_deref() == Ok("1") { + f(source.as_ref(), target.as_ref()); + } else { + let dir = tempdir().unwrap(); + let path = dir.path().join( + target + .as_ref() + .file_name() + .and_then(|s| s.to_str()) + .unwrap(), + ); + let mut base_dir_tmp = path.clone(); + base_dir_tmp.pop(); + base_dir_tmp.push(path.file_stem().unwrap()); + println!("{path:?}"); + + f(source.as_ref(), &path); + diff_file(target, path); + + diff_dir(gen_dir, base_dir_tmp); + } +} + fn test_thrift(source: impl AsRef, target: impl AsRef) { test_with_builder(source, target, |source, target| { crate::Builder::thrift() @@ -66,6 +125,22 @@ fn test_thrift(source: impl AsRef, target: impl AsRef) { }); } +fn test_thrift_with_split( + source: impl AsRef, + target: impl AsRef, + gen_dir: impl AsRef, +) { + test_with_split_builder(source, target, gen_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .with_split() + .compile_with_config( + vec![IdlService::from_path(source.to_owned())], + crate::Output::File(target.into()), + ) + }); +} + fn test_plugin_thrift(source: impl AsRef, target: impl AsRef) { test_with_builder(source, target, |source, target| { crate::Builder::thrift() @@ -111,6 +186,32 @@ fn test_thrift_gen() { }); } +#[test] +fn test_thrift_gen_with_split() { + let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join("thrift_with_split"); + + test_data_dir.read_dir().unwrap().for_each(|f| { + let f = f.unwrap(); + + let path = f.path(); + + if let Some(ext) = path.extension() { + if ext == "thrift" { + let mut rs_path = path.clone(); + rs_path.set_extension("rs"); + + let mut gen_dir = path.clone(); + gen_dir.pop(); + gen_dir.push(rs_path.file_stem().unwrap()); + + test_thrift_with_split(path, rs_path, gen_dir.as_path()); + } + } + }); +} + #[test] fn test_protobuf_gen() { let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs new file mode 100644 index 00000000..34fdaaa3 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs @@ -0,0 +1,20 @@ +pub mod wrapper_arc { + #![allow(warnings, clippy::all)] + + pub mod wrapper_arc { + + include!("wrapper_arc/A.rs"); + + include!("wrapper_arc/TestService.rs"); + + include!("wrapper_arc/TestServiceTestResultRecv.rs"); + + include!("wrapper_arc/TestServiceTestArgsRecv.rs"); + + include!("wrapper_arc/TestServiceTestResultSend.rs"); + + include!("wrapper_arc/TEST.rs"); + + include!("wrapper_arc/TestServiceTestArgsSend.rs"); + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc.thrift b/pilota-build/test_data/thrift_with_split/wrapper_arc.thrift new file mode 100644 index 00000000..6bb95526 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc.thrift @@ -0,0 +1,13 @@ +struct A { + +} + +struct TEST { + 1: required string ID, + 2: required list> Name2(pilota.rust_wrapper_arc="true"), + 3: required map> Name3(pilota.rust_wrapper_arc="true"), +} + +service TestService { + TEST(pilota.rust_wrapper_arc="true") test(1: TEST req(pilota.rust_wrapper_arc="true")); +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs new file mode 100644 index 00000000..b0c48761 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs @@ -0,0 +1,119 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct A {} +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" }; + + __protocol.write_struct_begin(&struct_ident)?; + + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 { + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::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 ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let data = Self {}; + ::std::result::Result::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 __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 { + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::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 ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let data = Self {}; + ::std::result::Result::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" }) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs new file mode 100644 index 00000000..2b7c05e9 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs @@ -0,0 +1,345 @@ +#[derive(Debug, Default, Clone, PartialEq)] +pub struct Test { + pub id: ::pilota::FastStr, + + pub name2: ::std::vec::Vec<::std::vec::Vec<::std::sync::Arc>>, + + pub name3: ::pilota::AHashMap>>, +} +impl ::pilota::thrift::Message for Test { + 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: "TEST" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_faststr_field(1, (&self.id).clone())?; + __protocol.write_list_field( + 2, + ::pilota::thrift::TType::List, + &&self.name2, + |__protocol, val| { + __protocol.write_list( + ::pilota::thrift::TType::Struct, + &val, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_map_field( + 3, + ::pilota::thrift::TType::I32, + ::pilota::thrift::TType::List, + &&self.name3, + |__protocol, key| { + __protocol.write_i32(*key)?; + ::std::result::Result::Ok(()) + }, + |__protocol, val| { + __protocol.write_list( + ::pilota::thrift::TType::Struct, + &val, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(__protocol.read_faststr()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_2 = Some(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::std::vec::Vec<::std::sync::Arc>> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr().offset(i as isize).write(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::std::sync::Arc> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr().offset(i as isize).write( + ::std::sync::Arc::new( + ::pilota::thrift::Message::decode(__protocol)?, + ), + ); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Map => { + var_3 = Some({ + let map_ident = __protocol.read_map_begin()?; + let mut val = ::pilota::AHashMap::with_capacity(map_ident.size); + for _ in 0..map_ident.size { + val.insert(__protocol.read_i32()?, unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::std::sync::Arc> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr().offset(i as isize).write( + ::std::sync::Arc::new( + ::pilota::thrift::Message::decode(__protocol)?, + ), + ); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + __protocol.read_map_end()?; + val + }); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TEST` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name2 is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name3 is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name2: var_2, + name3: var_3, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(__protocol.read_faststr().await?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_2 = 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({ + 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(::std::sync::Arc::new( + ::decode_async( + __protocol, + ) + .await?, + )); + } + __protocol.read_list_end().await?; + val + }); + } + __protocol.read_list_end().await?; + val + }); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Map => { + var_3 = Some({ + let map_ident = __protocol.read_map_begin().await?; + let mut val = ::pilota::AHashMap::with_capacity(map_ident.size); + for _ in 0..map_ident.size { + val.insert(__protocol.read_i32().await?, { + 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(::std::sync::Arc::new( + ::decode_async( + __protocol, + ) + .await?, + )); + } + __protocol.read_list_end().await?; + val + }); + } + __protocol.read_map_end().await?; + val + }); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TEST` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name2 is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name3 is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name2: var_2, + name3: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "TEST" }) + + __protocol.faststr_field_len(Some(1), &self.id) + + __protocol.list_field_len( + Some(2), + ::pilota::thrift::TType::List, + &self.name2, + |__protocol, el| { + __protocol.list_len(::pilota::thrift::TType::Struct, el, |__protocol, el| { + __protocol.struct_len(el) + }) + }, + ) + + __protocol.map_field_len( + Some(3), + ::pilota::thrift::TType::I32, + ::pilota::thrift::TType::List, + &self.name3, + |__protocol, key| __protocol.i32_len(*key), + |__protocol, val| { + __protocol.list_len(::pilota::thrift::TType::Struct, val, |__protocol, el| { + __protocol.struct_len(el) + }) + }, + ) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs new file mode 100644 index 00000000..bcfc2708 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs @@ -0,0 +1,2 @@ + +pub trait TestService {} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs new file mode 100644 index 00000000..71a1d9b1 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs @@ -0,0 +1,152 @@ +#[derive(Debug, Default, Clone, PartialEq)] +pub struct TestServiceTestArgsRecv { + pub req: Test, +} +impl ::pilota::thrift::Message for TestServiceTestArgsRecv { + 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: "TestServiceTestArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TestServiceTestArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async(__protocol) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TestServiceTestArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs new file mode 100644 index 00000000..12e37b2a --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs @@ -0,0 +1,154 @@ +#[derive(Debug, Default, Clone, PartialEq)] +pub struct TestServiceTestArgsSend { + pub req: ::std::sync::Arc, +} +impl ::pilota::thrift::Message for TestServiceTestArgsSend { + 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: "TestServiceTestArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::std::sync::Arc::new(::pilota::thrift::Message::decode( + __protocol, + )?)); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TestServiceTestArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::std::sync::Arc::new( + ::decode_async(__protocol) + .await?, + )); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `TestServiceTestArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs new file mode 100644 index 00000000..eb02d1a1 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs @@ -0,0 +1,140 @@ +#[derive(Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum TestServiceTestResultRecv { + #[derivative(Default)] + Ok(Test), +} + +impl ::pilota::thrift::Message for TestServiceTestResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestResultRecv", + })?; + match self { + TestServiceTestResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(TestServiceTestResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async(__protocol) + .await?; + + ret = Some(TestServiceTestResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestResultRecv", + }) + match self { + TestServiceTestResultRecv::Ok(ref value) => __protocol.struct_field_len(Some(0), value), + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs new file mode 100644 index 00000000..97b0f8b5 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs @@ -0,0 +1,142 @@ +#[derive(Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum TestServiceTestResultSend { + #[derivative(Default)] + Ok(::std::sync::Arc), +} + +impl ::pilota::thrift::Message for TestServiceTestResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestResultSend", + })?; + match self { + TestServiceTestResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::std::sync::Arc::new(::pilota::thrift::Message::decode(__protocol)?); + __protocol.struct_len(&field_ident); + ret = Some(TestServiceTestResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::std::sync::Arc::new( + ::decode_async(__protocol) + .await?, + ); + + ret = Some(TestServiceTestResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "TestServiceTestResultSend", + }) + match self { + TestServiceTestResultSend::Ok(ref value) => __protocol.struct_field_len(Some(0), value), + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} From b307a4953ef534ef1548bfe9b1de8c241da766cf Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Tue, 24 Sep 2024 10:38:34 +0200 Subject: [PATCH 02/10] Rename `with_split` to `split_generated_files`, provide an bool parameter to it --- pilota-build/src/lib.rs | 4 ++-- pilota-build/src/test/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pilota-build/src/lib.rs b/pilota-build/src/lib.rs index 963e213d..76bf2c02 100644 --- a/pilota-build/src/lib.rs +++ b/pilota-build/src/lib.rs @@ -165,8 +165,8 @@ impl Builder { self } - pub fn with_split(mut self) -> Self { - self.split = true; + pub fn split_generated_files(mut self, split: bool) -> Self { + self.split = split; self } diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index f3aae9bb..ff8bf1dd 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -133,7 +133,7 @@ fn test_thrift_with_split( test_with_split_builder(source, target, gen_dir, |source, target| { crate::Builder::thrift() .ignore_unused(false) - .with_split() + .split_generated_files(true) .compile_with_config( vec![IdlService::from_path(source.to_owned())], crate::Output::File(target.into()), From 35b7167308c3424bad72acf788312eb911cd5602 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Tue, 24 Sep 2024 10:48:54 +0200 Subject: [PATCH 03/10] Add item type to a generated file name --- pilota-build/src/codegen/mod.rs | 20 +++++++++++++++--- .../thrift_with_split/wrapper_arc.rs | 21 +++++++------------ ...v.rs => enum_TestServiceTestResultRecv.rs} | 0 ...d.rs => enum_TestServiceTestResultSend.rs} | 0 .../wrapper_arc/{A.rs => message_A.rs} | 0 .../wrapper_arc/{TEST.rs => message_TEST.rs} | 8 +++---- ....rs => message_TestServiceTestArgsRecv.rs} | 0 ....rs => message_TestServiceTestArgsSend.rs} | 0 ...{TestService.rs => service_TestService.rs} | 0 9 files changed, 28 insertions(+), 21 deletions(-) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TestServiceTestResultRecv.rs => enum_TestServiceTestResultRecv.rs} (100%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TestServiceTestResultSend.rs => enum_TestServiceTestResultSend.rs} (100%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{A.rs => message_A.rs} (100%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TEST.rs => message_TEST.rs} (98%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TestServiceTestArgsRecv.rs => message_TestServiceTestArgsRecv.rs} (100%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TestServiceTestArgsSend.rs => message_TestServiceTestArgsSend.rs} (100%) rename pilota-build/test_data/thrift_with_split/wrapper_arc/{TestService.rs => service_TestService.rs} (100%) diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 36e66206..b1ac52da 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -16,6 +16,7 @@ use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use traits::CodegenBackend; use self::workspace::Workspace; +use crate::rir::{Item, NodeKind}; use crate::{ db::RirDatabase, dedup::def_id_equal, @@ -481,7 +482,21 @@ where if this.split { let mut item_stream = String::new(); let node = this.db.node(def_id.def_id).unwrap(); - let file_name = format!("{}.rs", node.name()); + let name_prefix = match node.kind { + NodeKind::Item(ref item) => match item.as_ref() { + Item::Message(_) => "message", + Item::Enum(_) => "enum", + Item::Service(_) => "service", + Item::NewType(_) => "new_type", + Item::Const(_) => "const", + Item::Mod(_) => "mod", + }, + NodeKind::Variant(_) => "variant", + NodeKind::Field(_) => "field", + NodeKind::Method(_) => "method", + NodeKind::Arg(_) => "arg", + }; + let file_name = format!("{}_{}.rs", name_prefix, node.name()); this.write_item(&mut item_stream, *def_id, &mut dup); let full_path = base_dir.join(file_name.clone()); @@ -495,8 +510,7 @@ where let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); stream.push_str( - format!("\ninclude!(\"{}/{}\");\n", base_dir_local_path, file_name) - .as_str(), + format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(), ); } else { this.write_item(&mut stream, *def_id, &mut dup) diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs index 34fdaaa3..2f17a7a4 100644 --- a/pilota-build/test_data/thrift_with_split/wrapper_arc.rs +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs @@ -2,19 +2,12 @@ pub mod wrapper_arc { #![allow(warnings, clippy::all)] pub mod wrapper_arc { - - include!("wrapper_arc/A.rs"); - - include!("wrapper_arc/TestService.rs"); - - include!("wrapper_arc/TestServiceTestResultRecv.rs"); - - include!("wrapper_arc/TestServiceTestArgsRecv.rs"); - - include!("wrapper_arc/TestServiceTestResultSend.rs"); - - include!("wrapper_arc/TEST.rs"); - - include!("wrapper_arc/TestServiceTestArgsSend.rs"); + include!("wrapper_arc/message_A.rs"); + include!("wrapper_arc/service_TestService.rs"); + include!("wrapper_arc/enum_TestServiceTestResultRecv.rs"); + include!("wrapper_arc/message_TestServiceTestArgsRecv.rs"); + include!("wrapper_arc/enum_TestServiceTestResultSend.rs"); + include!("wrapper_arc/message_TEST.rs"); + include!("wrapper_arc/message_TestServiceTestArgsSend.rs"); } } diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultRecv.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultRecv.rs diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultSend.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestResultSend.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultSend.rs diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_A.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/A.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/message_A.rs diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TEST.rs similarity index 98% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/message_TEST.rs index 2b7c05e9..766478cd 100644 --- a/pilota-build/test_data/thrift_with_split/wrapper_arc/TEST.rs +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TEST.rs @@ -13,7 +13,7 @@ impl ::pilota::thrift::Message for Test { ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { #[allow(unused_imports)] use ::pilota::thrift::TOutputProtocolExt; - let struct_ident = ::pilota::thrift::TStructIdentifier { name: "TEST" }; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Test" }; __protocol.write_struct_begin(&struct_ident)?; __protocol.write_faststr_field(1, (&self.id).clone())?; @@ -150,7 +150,7 @@ impl ::pilota::thrift::Message for Test { })() { if let Some(field_id) = __pilota_decoding_field_id { err.prepend_msg(&format!( - "decode struct `TEST` field(#{}) failed, caused by: ", + "decode struct `Test` field(#{}) failed, caused by: ", field_id )); } @@ -276,7 +276,7 @@ impl ::pilota::thrift::Message for Test { { if let Some(field_id) = __pilota_decoding_field_id { err.prepend_msg(&format!( - "decode struct `TEST` field(#{}) failed, caused by: ", + "decode struct `Test` field(#{}) failed, caused by: ", field_id )); } @@ -315,7 +315,7 @@ impl ::pilota::thrift::Message for Test { fn size(&self, __protocol: &mut T) -> usize { #[allow(unused_imports)] use ::pilota::thrift::TLengthProtocolExt; - __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "TEST" }) + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Test" }) + __protocol.faststr_field_len(Some(1), &self.id) + __protocol.list_field_len( Some(2), diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsRecv.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsRecv.rs diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsSend.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TestServiceTestArgsSend.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsSend.rs diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/service_TestService.rs similarity index 100% rename from pilota-build/test_data/thrift_with_split/wrapper_arc/TestService.rs rename to pilota-build/test_data/thrift_with_split/wrapper_arc/service_TestService.rs From 7607f3d95a5d579da50b3df2bc3db52d7c500ab1 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Tue, 24 Sep 2024 11:37:06 +0200 Subject: [PATCH 04/10] Linter fix --- pilota-build/src/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index b1ac52da..506324dc 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -16,7 +16,6 @@ use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use traits::CodegenBackend; use self::workspace::Workspace; -use crate::rir::{Item, NodeKind}; use crate::{ db::RirDatabase, dedup::def_id_equal, @@ -26,6 +25,7 @@ use crate::{ context::{tls::CUR_ITEM, Mode}, rir, }, + rir::{Item, NodeKind}, symbol::{DefId, EnumRepr, FileId}, Context, Symbol, }; From 95fbd1c085f7fa1cc8d618a40b382028e7469917 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Wed, 25 Sep 2024 12:42:18 +0200 Subject: [PATCH 05/10] Add workspace tests --- pilota-build/src/codegen/mod.rs | 4 +- pilota-build/src/codegen/workspace.rs | 5 +- pilota-build/src/fmt.rs | 2 +- pilota-build/src/test/mod.rs | 99 +- .../thrift_workspace/input/article.thrift | 32 + .../thrift_workspace/input/author.thrift | 24 + .../thrift_workspace/input/cdn.thrift | 9 + .../thrift_workspace/input/common.thrift | 7 + .../thrift_workspace/input/image.thrift | 23 + .../thrift_workspace/output/Cargo.toml | 12 + .../output/article/Cargo.toml | 19 + .../output/article/src/gen.rs | 1378 +++++++++++++++++ .../output/article/src/lib.rs | 2 + .../thrift_workspace/output/author/Cargo.toml | 19 + .../thrift_workspace/output/author/src/gen.rs | 915 +++++++++++ .../thrift_workspace/output/author/src/lib.rs | 2 + .../thrift_workspace/output/common/Cargo.toml | 16 + .../thrift_workspace/output/common/src/gen.rs | 1025 ++++++++++++ .../thrift_workspace/output/common/src/lib.rs | 2 + .../thrift_workspace/output/image/Cargo.toml | 19 + .../thrift_workspace/output/image/src/gen.rs | 955 ++++++++++++ .../thrift_workspace/output/image/src/lib.rs | 2 + .../input/article.thrift | 32 + .../input/author.thrift | 24 + .../input/cdn.thrift | 9 + .../input/common.thrift | 7 + .../input/image.thrift | 23 + .../output/Cargo.toml | 12 + .../output/article/Cargo.toml | 19 + ...enum_ArticleServiceGetArticleResultRecv.rs | 144 ++ ...enum_ArticleServiceGetArticleResultSend.rs | 144 ++ .../output/article/src/enum_Status.rs | 87 ++ .../output/article/src/gen.rs | 32 + .../output/article/src/lib.rs | 2 + .../output/article/src/message_Article.rs | 342 ++++ ...essage_ArticleServiceGetArticleArgsRecv.rs | 148 ++ ...essage_ArticleServiceGetArticleArgsSend.rs | 148 ++ .../output/article/src/message_Author.rs | 1 + .../output/article/src/message_CDN.rs | 1 + .../output/article/src/message_CommonData.rs | 1 + .../article/src/message_GetArticleRequest.rs | 149 ++ .../article/src/message_GetArticleResponse.rs | 152 ++ .../output/article/src/message_Image.rs | 1 + .../article/src/service_ArticleService.rs | 2 + .../output/author/Cargo.toml | 19 + .../enum_AuthorServiceGetAuthorResultRecv.rs | 144 ++ .../enum_AuthorServiceGetAuthorResultSend.rs | 144 ++ .../output/author/src/gen.rs | 30 + .../output/author/src/lib.rs | 2 + .../output/author/src/message_Author.rs | 1 + .../message_AuthorServiceGetAuthorArgsRecv.rs | 151 ++ .../message_AuthorServiceGetAuthorArgsSend.rs | 151 ++ .../output/author/src/message_CDN.rs | 1 + .../output/author/src/message_CommonData.rs | 1 + .../author/src/message_GetAuthorRequest.rs | 149 ++ .../author/src/message_GetAuthorResponse.rs | 152 ++ .../output/author/src/message_Image.rs | 1 + .../author/src/service_AuthorService.rs | 2 + .../output/common/Cargo.toml | 16 + .../output/common/src/gen.rs | 22 + .../output/common/src/lib.rs | 2 + .../output/common/src/message_Author.rs | 257 +++ .../output/common/src/message_CDN.rs | 205 +++ .../output/common/src/message_CommonData.rs | 202 +++ .../output/common/src/message_Image.rs | 231 +++ .../output/image/Cargo.toml | 19 + .../enum_ImageServiceGetImageResultRecv.rs | 144 ++ .../enum_ImageServiceGetImageResultSend.rs | 144 ++ .../output/image/src/gen.rs | 26 + .../output/image/src/lib.rs | 2 + .../output/image/src/message_CDN.rs | 1 + .../output/image/src/message_CommonData.rs | 1 + .../image/src/message_GetImageRequest.rs | 149 ++ .../image/src/message_GetImageResponse.rs | 152 ++ .../output/image/src/message_Image.rs | 1 + .../message_ImageServiceGetImageArgsRecv.rs | 151 ++ .../message_ImageServiceGetImageArgsSend.rs | 151 ++ .../output/image/src/service_ImageService.rs | 2 + 78 files changed, 8870 insertions(+), 7 deletions(-) create mode 100644 pilota-build/test_data/thrift_workspace/input/article.thrift create mode 100644 pilota-build/test_data/thrift_workspace/input/author.thrift create mode 100644 pilota-build/test_data/thrift_workspace/input/cdn.thrift create mode 100644 pilota-build/test_data/thrift_workspace/input/common.thrift create mode 100644 pilota-build/test_data/thrift_workspace/input/image.thrift create mode 100644 pilota-build/test_data/thrift_workspace/output/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace/output/article/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace/output/article/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/article/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/author/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace/output/author/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/author/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/common/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace/output/common/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/common/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/image/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace/output/image/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace/output/image/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/input/article.thrift create mode 100644 pilota-build/test_data/thrift_workspace_with_split/input/author.thrift create mode 100644 pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift create mode 100644 pilota-build/test_data/thrift_workspace_with_split/input/common.thrift create mode 100644 pilota-build/test_data/thrift_workspace_with_split/input/image.thrift create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 506324dc..741767dd 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -507,10 +507,8 @@ where file.flush().unwrap(); fmt_file(full_path); - let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); - stream.push_str( - format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(), + format!("include!(\"{}\");\n", file_name).as_str(), ); } else { this.write_item(&mut stream, *def_id, &mut dup) diff --git a/pilota-build/src/codegen/workspace.rs b/pilota-build/src/codegen/workspace.rs index 72f929a9..0a59ac92 100644 --- a/pilota-build/src/codegen/workspace.rs +++ b/pilota-build/src/codegen/workspace.rs @@ -85,6 +85,7 @@ where None } }) + .sorted() .join(",\n"); let mut cargo_toml = toml::from_str::(&unsafe { @@ -184,6 +185,8 @@ where Command::new("cargo") .arg("init") .arg("--lib") + .arg("--vcs") + .arg("none") .current_dir(base_dir.as_ref()) .arg(&*info.name), )?; @@ -246,7 +249,7 @@ where def_id, kind: super::CodegenKind::RePub, })), - base_dir.as_ref(), + base_dir.as_ref().join(&*info.name).join("src").as_path(), ); if let Some(main_mod_path) = info.main_mod_path { gen_rs_stream.push_str(&format!( diff --git a/pilota-build/src/fmt.rs b/pilota-build/src/fmt.rs index 925e3eb6..61f061e1 100644 --- a/pilota-build/src/fmt.rs +++ b/pilota-build/src/fmt.rs @@ -24,8 +24,8 @@ pub fn fmt_file>(file: P) { Err(e) => eprintln!("{}", e), Ok(output) => { if !output.status.success() { + eprintln!("rustfmt failed to format {}", file.display()); std::io::stderr().write_all(&output.stderr).unwrap(); - exit(output.status.code().unwrap_or(1)) } } } diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index ff8bf1dd..f94f5443 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,7 +1,7 @@ #![cfg(test)] use std::{fs, path::Path}; - +use std::fs::File; use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService}; @@ -45,7 +45,14 @@ fn diff_dir(old: impl AsRef, new: impl AsRef) { if !corresponding_new_file.exists() { panic!("File {:?} does not exist in the new directory", file_name); } - diff_file(old_file, corresponding_new_file); + + if old_file.is_file() && corresponding_new_file.is_file() { + diff_file(old_file, corresponding_new_file); + } else if !old_file.is_file() && !corresponding_new_file.is_file() { + diff_dir(old_file, corresponding_new_file) + } else { + panic!("{} and {} are not both files or directories", old_file.to_str().unwrap(), corresponding_new_file.to_str().unwrap()); + } } } @@ -85,6 +92,41 @@ fn test_with_builder( } } +fn test_with_builder_workspace( + source: impl AsRef, + target: impl AsRef, + f: F, +) { + if std::env::var("UPDATE_TEST_DATA").as_deref() == Ok("1") { + fs::remove_dir(&target); + fs::create_dir_all(&target).unwrap(); + let cargo_toml_path = target.as_ref().join("Cargo.toml"); + File::create(cargo_toml_path).unwrap(); + + f(source.as_ref(), target.as_ref()); + } else { + let dir = tempdir().unwrap(); + let path = dir.path().join( + target + .as_ref() + .file_name() + .and_then(|s| s.to_str()) + .unwrap(), + ); + let mut base_dir_tmp = path.clone(); + base_dir_tmp.pop(); + base_dir_tmp.push(path.file_stem().unwrap()); + println!("{path:?}"); + + fs::create_dir_all(&path).unwrap(); + let cargo_toml_path = path.join("Cargo.toml"); + File::create(cargo_toml_path).unwrap(); + + f(source.as_ref(), &path); + diff_dir(target, &base_dir_tmp); + } +} + fn test_with_split_builder( source: impl AsRef, target: impl AsRef, @@ -125,6 +167,35 @@ fn test_thrift(source: impl AsRef, target: impl AsRef) { }); } +fn test_thrift_workspace(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { + let services: Vec = service_names.iter() + .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) + .collect(); + test_with_builder_workspace(input_dir, output_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .compile_with_config( + services, + crate::Output::Workspace(target.into()), + ) + }); +} + +fn test_thrift_workspace_with_split(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { + let services: Vec = service_names.iter() + .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) + .collect(); + test_with_builder_workspace(input_dir, output_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .split_generated_files(true) + .compile_with_config( + services, + crate::Output::Workspace(target.into()), + ) + }); +} + fn test_thrift_with_split( source: impl AsRef, target: impl AsRef, @@ -186,6 +257,30 @@ fn test_thrift_gen() { }); } +#[test] +fn test_thrift_workspace_gen() { + let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join("thrift_workspace"); + + let input_dir = test_data_dir.join("input"); + let output_dir = test_data_dir.join("output"); + + test_thrift_workspace(input_dir, output_dir, vec!["article", "author", "image"]); +} + +#[test] +fn test_thrift_workspace_with_split_gen() { + let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join("thrift_workspace_with_split"); + + let input_dir = test_data_dir.join("input"); + let output_dir = test_data_dir.join("output"); + + test_thrift_workspace_with_split(input_dir, output_dir, vec!["article", "author", "image"]); +} + #[test] fn test_thrift_gen_with_split() { let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) diff --git a/pilota-build/test_data/thrift_workspace/input/article.thrift b/pilota-build/test_data/thrift_workspace/input/article.thrift new file mode 100644 index 00000000..328bf5a5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/article.thrift @@ -0,0 +1,32 @@ +include "image.thrift" +include "author.thrift" +include "common.thrift" + +namespace rs article + +enum Status { + NORMAL = 0, + DELETED = 1, +} + +struct Article { + 1: required i64 id, + 2: required string title, + 3: required string content, + 4: required author.Author author, + 5: required Status status, + 6: required list images, + 7: required common.CommonData common_data, +} + +struct GetArticleRequest { + 1: required i64 id, +} + +struct GetArticleResponse { + 1: required Article article, +} + +service ArticleService { + GetArticleResponse GetArticle(1: GetArticleRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/author.thrift b/pilota-build/test_data/thrift_workspace/input/author.thrift new file mode 100644 index 00000000..9af3823e --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/author.thrift @@ -0,0 +1,24 @@ +include "image.thrift" +include "common.thrift" + +namespace rs author + +struct Author { + 1: required i64 id, + 2: required string username, + 3: required string email, + 4: required image.Image avatar, + 5: required common.CommonData common_data, +} + +struct GetAuthorRequest { + 1: required i64 id, +} + +struct GetAuthorResponse { + 1: required Author author, +} + +service AuthorService { + GetAuthorResponse GetAuthor(1: GetAuthorRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/cdn.thrift b/pilota-build/test_data/thrift_workspace/input/cdn.thrift new file mode 100644 index 00000000..c6847a3c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/cdn.thrift @@ -0,0 +1,9 @@ +include "common.thrift" + +namespace rs article.image.cdn + +struct CDN { + 1: required i64 id, + 2: required string url, + 3: required common.CommonData common_data, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/common.thrift b/pilota-build/test_data/thrift_workspace/input/common.thrift new file mode 100644 index 00000000..517116f1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/common.thrift @@ -0,0 +1,7 @@ +namespace rs common + +struct CommonData { + 1: required i64 id, + 2: required string name, + 3: required string description, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/image.thrift b/pilota-build/test_data/thrift_workspace/input/image.thrift new file mode 100644 index 00000000..b1d4ec86 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/image.thrift @@ -0,0 +1,23 @@ +include "common.thrift" +include "cdn.thrift" + +namespace rs article.image + +struct Image { + 1: required i64 id, + 2: required string url, + 3: required cdn.CDN cdn, + 4: required common.CommonData common_data, +} + +struct GetImageRequest { + 1: required i64 id, +} + +struct GetImageResponse { + 1: required Image image, +} + +service ImageService { + GetImageResponse GetImage(1: GetImageRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/output/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/Cargo.toml new file mode 100644 index 00000000..f88e4700 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +members = [ + "article", + "author", "common", + "image", +] + +[workspace.dependencies] +anyhow = "1" +pilota = "*" +volo = "*" +volo-thrift = "*" diff --git a/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml new file mode 100644 index 00000000..0ef53902 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "article" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs new file mode 100644 index 00000000..5b353c3d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs @@ -0,0 +1,1378 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq, Copy)] + #[repr(transparent)] + pub struct Status(i32); + + impl Status { + pub const NORMAL: Self = Self(0); + pub const DELETED: Self = Self(1); + + pub fn inner(&self) -> i32 { + self.0 + } + + pub fn to_string(&self) -> ::std::string::String { + match self { + Self(0) => ::std::string::String::from("NORMAL"), + Self(1) => ::std::string::String::from("DELETED"), + Self(val) => val.to_string(), + } + } + } + + impl ::std::convert::From for Status { + fn from(value: i32) -> Self { + Self(value) + } + } + + impl ::std::convert::From for i32 { + fn from(value: Status) -> i32 { + value.0 + } + } + + impl ::pilota::thrift::Message for Status { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_i32(self.inner())?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let value = __protocol.read_i32()?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err( + |err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, 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?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err( + |err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + }, + )?) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.i32_len(self.inner()) + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ArticleServiceGetArticleArgsRecv { + pub req: GetArticleRequest, + } + impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsRecv { + 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: "ArticleServiceGetArticleArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ArticleServiceGetArticleResultSend { + #[derivative(Default)] + Ok(GetArticleResponse), + } + + impl ::pilota::thrift::Message for ArticleServiceGetArticleResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + })?; + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + }) + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetArticleResponse { + pub article: Article, + } + impl ::pilota::thrift::Message for GetArticleResponse { + 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: "GetArticleResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.article, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => + { + var_1 = Some( +
::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + ), + ); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }) + __protocol.struct_field_len(Some(1), &self.article) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ArticleServiceGetArticleArgsSend { + pub req: GetArticleRequest, + } + impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsSend { + 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: "ArticleServiceGetArticleArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetArticleRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetArticleRequest { + 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: "GetArticleRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub trait ArticleService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ArticleServiceGetArticleResultRecv { + #[derivative(Default)] + Ok(GetArticleResponse), + } + + impl ::pilota::thrift::Message for ArticleServiceGetArticleResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + })?; + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + }) + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Article { + pub id: i64, + + pub title: ::pilota::FastStr, + + pub content: ::pilota::FastStr, + + pub author: ::common::author::Author, + + pub status: Status, + + pub images: ::std::vec::Vec<::common::article::image::Image>, + + pub common_data: ::common::common::CommonData, + } + impl ::pilota::thrift::Message for Article { + 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: "Article" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.title).clone())?; + __protocol.write_faststr_field(3, (&self.content).clone())?; + __protocol.write_struct_field(4, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_i32_field(5, (&self.status).inner())?; + __protocol.write_list_field( + 6, + ::pilota::thrift::TType::Struct, + &&self.images, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_struct_field( + 7, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::common::article::image::Image> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr() + .offset(i as isize) + .write(::pilota::thrift::Message::decode(__protocol)?); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + Some(7) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_7 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Article` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::decode_async(__protocol).await?); + + },Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = 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(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + }; + __protocol.read_list_end().await?; + val + }); + + },Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(<::common::common::CommonData as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Article` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + ), + ); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + ), + ); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + ), + ); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Article" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.title) + + __protocol.faststr_field_len(Some(3), &self.content) + + __protocol.struct_field_len(Some(4), &self.author) + + __protocol.i32_field_len(Some(5), (&self.status).inner()) + + __protocol.list_field_len( + Some(6), + ::pilota::thrift::TType::Struct, + &self.images, + |__protocol, el| __protocol.struct_len(el), + ) + + __protocol.struct_field_len(Some(7), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub mod image { + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod author { + pub use ::common::author::Author; + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use article::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml new file mode 100644 index 00000000..4933f648 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "author" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs new file mode 100644 index 00000000..d06fec3d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs @@ -0,0 +1,915 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod author { + + pub trait AuthorService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum AuthorServiceGetAuthorResultRecv { + #[derivative(Default)] + Ok(GetAuthorResponse), + } + + impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + })?; + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + }) + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct AuthorServiceGetAuthorArgsRecv { + pub req: GetAuthorRequest, + } + impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsRecv { + 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: "AuthorServiceGetAuthorArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum AuthorServiceGetAuthorResultSend { + #[derivative(Default)] + Ok(GetAuthorResponse), + } + + impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + })?; + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + }) + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetAuthorResponse { + pub author: ::common::author::Author, + } + impl ::pilota::thrift::Message for GetAuthorResponse { + 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: "GetAuthorResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + ), + ); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }) + __protocol.struct_field_len(Some(1), &self.author) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct AuthorServiceGetAuthorArgsSend { + pub req: GetAuthorRequest, + } + impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsSend { + 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: "AuthorServiceGetAuthorArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetAuthorRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetAuthorRequest { + 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: "GetAuthorRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub use ::common::author::Author; + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use author::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml new file mode 100644 index 00000000..206531f6 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml @@ -0,0 +1,16 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "common" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs new file mode 100644 index 00000000..b7fcf21f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs @@ -0,0 +1,1025 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Image { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub cdn: cdn::Cdn, + + pub common_data: super::super::common::CommonData, + } + impl ::pilota::thrift::Message for Image { + 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: "Image" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.cdn, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field( + 4, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(4) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Image` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Image` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Image" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.cdn) + + __protocol.struct_field_len(Some(4), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub mod cdn { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Cdn { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub common_data: super::super::super::common::CommonData, + } + impl ::pilota::thrift::Message for Cdn { + 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: "Cdn" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field( + 3, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_3 = + Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Cdn` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Cdn` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size( + &self, + __protocol: &mut T, + ) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Cdn" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } + } + } + + pub mod author { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Author { + pub id: i64, + + pub username: ::pilota::FastStr, + + pub email: ::pilota::FastStr, + + pub avatar: super::article::image::Image, + + pub common_data: super::common::CommonData, + } + impl ::pilota::thrift::Message for Author { + 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: "Author" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.username).clone())?; + __protocol.write_faststr_field(3, (&self.email).clone())?; + __protocol.write_struct_field(4, &self.avatar, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field( + 5, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Author` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Author` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + ), + ); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Author" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.username) + + __protocol.faststr_field_len(Some(3), &self.email) + + __protocol.struct_field_len(Some(4), &self.avatar) + + __protocol.struct_field_len(Some(5), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } + + pub mod common { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct CommonData { + pub id: i64, + + pub name: ::pilota::FastStr, + + pub description: ::pilota::FastStr, + } + impl ::pilota::thrift::Message for CommonData { + 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: "CommonData" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.name).clone())?; + __protocol.write_faststr_field(3, (&self.description).clone())?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr().await?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "CommonData" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.name) + + __protocol.faststr_field_len(Some(3), &self.description) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } +} diff --git a/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml new file mode 100644 index 00000000..ae1e8e17 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "image" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs new file mode 100644 index 00000000..c89387d2 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs @@ -0,0 +1,955 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ImageServiceGetImageArgsRecv { + pub req: GetImageRequest, + } + impl ::pilota::thrift::Message for ImageServiceGetImageArgsRecv { + 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: "ImageServiceGetImageArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ImageServiceGetImageResultSend { + #[derivative(Default)] + Ok(GetImageResponse), + } + + impl ::pilota::thrift::Message for ImageServiceGetImageResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + })?; + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.write_struct_field( + 0, + value, + ::pilota::thrift::TType::Struct, + )?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + }) + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetImageResponse { + pub image: ::common::article::image::Image, + } + impl ::pilota::thrift::Message for GetImageResponse { + 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: "GetImageResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field( + 1, + &self.image, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + ), + ); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + ), + ); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }) + __protocol.struct_field_len(Some(1), &self.image) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ImageServiceGetImageArgsSend { + pub req: GetImageRequest, + } + impl ::pilota::thrift::Message for ImageServiceGetImageArgsSend { + 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: "ImageServiceGetImageArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetImageRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetImageRequest { + 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: "GetImageRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageRequest` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub trait ImageService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ImageServiceGetImageResultRecv { + #[derivative(Default)] + Ok(GetImageResponse), + } + + impl ::pilota::thrift::Message for ImageServiceGetImageResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + })?; + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.write_struct_field( + 0, + value, + ::pilota::thrift::TType::Struct, + )?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + }) + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use article::image::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift new file mode 100644 index 00000000..328bf5a5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift @@ -0,0 +1,32 @@ +include "image.thrift" +include "author.thrift" +include "common.thrift" + +namespace rs article + +enum Status { + NORMAL = 0, + DELETED = 1, +} + +struct Article { + 1: required i64 id, + 2: required string title, + 3: required string content, + 4: required author.Author author, + 5: required Status status, + 6: required list images, + 7: required common.CommonData common_data, +} + +struct GetArticleRequest { + 1: required i64 id, +} + +struct GetArticleResponse { + 1: required Article article, +} + +service ArticleService { + GetArticleResponse GetArticle(1: GetArticleRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift new file mode 100644 index 00000000..9af3823e --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift @@ -0,0 +1,24 @@ +include "image.thrift" +include "common.thrift" + +namespace rs author + +struct Author { + 1: required i64 id, + 2: required string username, + 3: required string email, + 4: required image.Image avatar, + 5: required common.CommonData common_data, +} + +struct GetAuthorRequest { + 1: required i64 id, +} + +struct GetAuthorResponse { + 1: required Author author, +} + +service AuthorService { + GetAuthorResponse GetAuthor(1: GetAuthorRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift new file mode 100644 index 00000000..c6847a3c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift @@ -0,0 +1,9 @@ +include "common.thrift" + +namespace rs article.image.cdn + +struct CDN { + 1: required i64 id, + 2: required string url, + 3: required common.CommonData common_data, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift new file mode 100644 index 00000000..517116f1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift @@ -0,0 +1,7 @@ +namespace rs common + +struct CommonData { + 1: required i64 id, + 2: required string name, + 3: required string description, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift new file mode 100644 index 00000000..b1d4ec86 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift @@ -0,0 +1,23 @@ +include "common.thrift" +include "cdn.thrift" + +namespace rs article.image + +struct Image { + 1: required i64 id, + 2: required string url, + 3: required cdn.CDN cdn, + 4: required common.CommonData common_data, +} + +struct GetImageRequest { + 1: required i64 id, +} + +struct GetImageResponse { + 1: required Image image, +} + +service ImageService { + GetImageResponse GetImage(1: GetImageRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml new file mode 100644 index 00000000..cf98ef15 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +members = [ + "article", + "author", + "image", +] + +[workspace.dependencies] +anyhow = "1" +pilota = "*" +volo = "*" +volo-thrift = "*" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml new file mode 100644 index 00000000..0ef53902 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "article" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs new file mode 100644 index 00000000..f9bfba0b --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ArticleServiceGetArticleResultRecv { + #[derivative(Default)] + Ok(GetArticleResponse), +} + +impl ::pilota::thrift::Message for ArticleServiceGetArticleResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + })?; + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + }) + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs new file mode 100644 index 00000000..a84e3837 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ArticleServiceGetArticleResultSend { + #[derivative(Default)] + Ok(GetArticleResponse), +} + +impl ::pilota::thrift::Message for ArticleServiceGetArticleResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + })?; + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + }) + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs new file mode 100644 index 00000000..453a7996 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs @@ -0,0 +1,87 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq, Copy)] +#[repr(transparent)] +pub struct Status(i32); + +impl Status { + pub const NORMAL: Self = Self(0); + pub const DELETED: Self = Self(1); + + pub fn inner(&self) -> i32 { + self.0 + } + + pub fn to_string(&self) -> ::std::string::String { + match self { + Self(0) => ::std::string::String::from("NORMAL"), + Self(1) => ::std::string::String::from("DELETED"), + Self(val) => val.to_string(), + } + } +} + +impl ::std::convert::From for Status { + fn from(value: i32) -> Self { + Self(value) + } +} + +impl ::std::convert::From for i32 { + fn from(value: Status) -> i32 { + value.0 + } +} + +impl ::pilota::thrift::Message for Status { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_i32(self.inner())?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let value = __protocol.read_i32()?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, 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?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + })?) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.i32_len(self.inner()) + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs new file mode 100644 index 00000000..5ebac8bb --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs @@ -0,0 +1,32 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + include!("enum_Status.rs"); + include!("message_ArticleServiceGetArticleArgsRecv.rs"); + include!("enum_ArticleServiceGetArticleResultSend.rs"); + include!("message_GetArticleResponse.rs"); + include!("message_ArticleServiceGetArticleArgsSend.rs"); + include!("message_GetArticleRequest.rs"); + include!("service_ArticleService.rs"); + include!("enum_ArticleServiceGetArticleResultRecv.rs"); + include!("message_Article.rs"); + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use article::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs new file mode 100644 index 00000000..29ad8d68 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs @@ -0,0 +1,342 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Article { + pub id: i64, + + pub title: ::pilota::FastStr, + + pub content: ::pilota::FastStr, + + pub author: ::common::author::Author, + + pub status: Status, + + pub images: ::std::vec::Vec<::common::article::image::Image>, + + pub common_data: ::common::common::CommonData, +} +impl ::pilota::thrift::Message for Article { + 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: "Article" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.title).clone())?; + __protocol.write_faststr_field(3, (&self.content).clone())?; + __protocol.write_struct_field(4, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_i32_field(5, (&self.status).inner())?; + __protocol.write_list_field( + 6, + ::pilota::thrift::TType::Struct, + &&self.images, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_struct_field(7, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::common::article::image::Image> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr() + .offset(i as isize) + .write(::pilota::thrift::Message::decode(__protocol)?); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Article` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::decode_async(__protocol).await?); + + },Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = 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(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + }; + __protocol.read_list_end().await?; + val + }); + + },Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(<::common::common::CommonData as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Article` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Article" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.title) + + __protocol.faststr_field_len(Some(3), &self.content) + + __protocol.struct_field_len(Some(4), &self.author) + + __protocol.i32_field_len(Some(5), (&self.status).inner()) + + __protocol.list_field_len( + Some(6), + ::pilota::thrift::TType::Struct, + &self.images, + |__protocol, el| __protocol.struct_len(el), + ) + + __protocol.struct_field_len(Some(7), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs new file mode 100644 index 00000000..95339be0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs @@ -0,0 +1,148 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ArticleServiceGetArticleArgsRecv { + pub req: GetArticleRequest, +} +impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsRecv { + 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: "ArticleServiceGetArticleArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs new file mode 100644 index 00000000..c47c5388 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs @@ -0,0 +1,148 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ArticleServiceGetArticleArgsSend { + pub req: GetArticleRequest, +} +impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsSend { + 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: "ArticleServiceGetArticleArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs @@ -0,0 +1 @@ +pub use ::common::author::Author; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs new file mode 100644 index 00000000..f9892c38 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetArticleRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetArticleRequest { + 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: "GetArticleRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs new file mode 100644 index 00000000..9cc8d06f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetArticleResponse { + pub article: Article, +} +impl ::pilota::thrift::Message for GetArticleResponse { + 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: "GetArticleResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.article, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( +
::decode_async(__protocol) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }) + __protocol.struct_field_len(Some(1), &self.article) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs new file mode 100644 index 00000000..42e7df87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs @@ -0,0 +1,2 @@ + +pub trait ArticleService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml new file mode 100644 index 00000000..4933f648 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "author" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs new file mode 100644 index 00000000..81045cdb --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum AuthorServiceGetAuthorResultRecv { + #[derivative(Default)] + Ok(GetAuthorResponse), +} + +impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + })?; + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + }) + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs new file mode 100644 index 00000000..37419a87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum AuthorServiceGetAuthorResultSend { + #[derivative(Default)] + Ok(GetAuthorResponse), +} + +impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + })?; + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + }) + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs new file mode 100644 index 00000000..68bcd655 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs @@ -0,0 +1,30 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("service_AuthorService.rs"); + include!("enum_AuthorServiceGetAuthorResultRecv.rs"); + include!("message_AuthorServiceGetAuthorArgsRecv.rs"); + include!("enum_AuthorServiceGetAuthorResultSend.rs"); + include!("message_GetAuthorResponse.rs"); + include!("message_AuthorServiceGetAuthorArgsSend.rs"); + include!("message_GetAuthorRequest.rs"); + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use author::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs @@ -0,0 +1 @@ +pub use ::common::author::Author; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs new file mode 100644 index 00000000..3757735f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct AuthorServiceGetAuthorArgsRecv { + pub req: GetAuthorRequest, +} +impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsRecv { + 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: "AuthorServiceGetAuthorArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs new file mode 100644 index 00000000..f6eba41d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct AuthorServiceGetAuthorArgsSend { + pub req: GetAuthorRequest, +} +impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsSend { + 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: "AuthorServiceGetAuthorArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs new file mode 100644 index 00000000..354ce21c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetAuthorRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetAuthorRequest { + 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: "GetAuthorRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs new file mode 100644 index 00000000..ca4eb853 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetAuthorResponse { + pub author: ::common::author::Author, +} +impl ::pilota::thrift::Message for GetAuthorResponse { + 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: "GetAuthorResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }) + __protocol.struct_field_len(Some(1), &self.author) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs new file mode 100644 index 00000000..9cbd928f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs @@ -0,0 +1,2 @@ + +pub trait AuthorService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml new file mode 100644 index 00000000..206531f6 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml @@ -0,0 +1,16 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "common" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs new file mode 100644 index 00000000..26a817f0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs @@ -0,0 +1,22 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs new file mode 100644 index 00000000..a57b6372 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs @@ -0,0 +1,257 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Author { + pub id: i64, + + pub username: ::pilota::FastStr, + + pub email: ::pilota::FastStr, + + pub avatar: super::article::image::Image, + + pub common_data: super::common::CommonData, +} +impl ::pilota::thrift::Message for Author { + 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: "Author" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.username).clone())?; + __protocol.write_faststr_field(3, (&self.email).clone())?; + __protocol.write_struct_field(4, &self.avatar, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field(5, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Author` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Author` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Author" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.username) + + __protocol.faststr_field_len(Some(3), &self.email) + + __protocol.struct_field_len(Some(4), &self.avatar) + + __protocol.struct_field_len(Some(5), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs new file mode 100644 index 00000000..8ece535f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs @@ -0,0 +1,205 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Cdn { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub common_data: super::super::super::common::CommonData, +} +impl ::pilota::thrift::Message for Cdn { + 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: "Cdn" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Cdn` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Cdn` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Cdn" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs new file mode 100644 index 00000000..6aa0cb18 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs @@ -0,0 +1,202 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct CommonData { + pub id: i64, + + pub name: ::pilota::FastStr, + + pub description: ::pilota::FastStr, +} +impl ::pilota::thrift::Message for CommonData { + 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: "CommonData" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.name).clone())?; + __protocol.write_faststr_field(3, (&self.description).clone())?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "CommonData" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.name) + + __protocol.faststr_field_len(Some(3), &self.description) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs new file mode 100644 index 00000000..6ac83879 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs @@ -0,0 +1,231 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Image { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub cdn: cdn::Cdn, + + pub common_data: super::super::common::CommonData, +} +impl ::pilota::thrift::Message for Image { + 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: "Image" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.cdn, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field(4, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Image` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::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 var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Image` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Image" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.cdn) + + __protocol.struct_field_len(Some(4), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml new file mode 100644 index 00000000..ae1e8e17 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "image" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs new file mode 100644 index 00000000..b25d6dc0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ImageServiceGetImageResultRecv { + #[derivative(Default)] + Ok(GetImageResponse), +} + +impl ::pilota::thrift::Message for ImageServiceGetImageResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + })?; + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + }) + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs new file mode 100644 index 00000000..8caa6563 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ImageServiceGetImageResultSend { + #[derivative(Default)] + Ok(GetImageResponse), +} + +impl ::pilota::thrift::Message for ImageServiceGetImageResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + })?; + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + 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); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + 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 ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + }) + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs new file mode 100644 index 00000000..c0bb15b5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs @@ -0,0 +1,26 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_ImageServiceGetImageArgsRecv.rs"); + include!("enum_ImageServiceGetImageResultSend.rs"); + include!("message_GetImageResponse.rs"); + include!("message_ImageServiceGetImageArgsSend.rs"); + include!("message_GetImageRequest.rs"); + include!("service_ImageService.rs"); + include!("enum_ImageServiceGetImageResultRecv.rs"); + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use article::image::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs new file mode 100644 index 00000000..ab4b8bf1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetImageRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetImageRequest { + 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: "GetImageRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs new file mode 100644 index 00000000..e8eb80e9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetImageResponse { + pub image: ::common::article::image::Image, +} +impl ::pilota::thrift::Message for GetImageResponse { + 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: "GetImageResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.image, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + )); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + )); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }) + __protocol.struct_field_len(Some(1), &self.image) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs new file mode 100644 index 00000000..e6b39933 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ImageServiceGetImageArgsRecv { + pub req: GetImageRequest, +} +impl ::pilota::thrift::Message for ImageServiceGetImageArgsRecv { + 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: "ImageServiceGetImageArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs new file mode 100644 index 00000000..34d817a7 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ImageServiceGetImageArgsSend { + pub req: GetImageRequest, +} +impl ::pilota::thrift::Message for ImageServiceGetImageArgsSend { + 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: "ImageServiceGetImageArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::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 => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::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 var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::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 => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs new file mode 100644 index 00000000..ae17ff16 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs @@ -0,0 +1,2 @@ + +pub trait ImageService {} From 9506860a9f80f7f73f3a1408d72401da235f7ad5 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Thu, 10 Oct 2024 12:09:04 +0200 Subject: [PATCH 06/10] Fix tests --- pilota-build/src/codegen/mod.rs | 18 +++++++++++++++--- .../output/Cargo.toml | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 741767dd..09b73899 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -507,9 +507,21 @@ where file.flush().unwrap(); fmt_file(full_path); - stream.push_str( - format!("include!(\"{}\");\n", file_name).as_str(), - ); + match &*this.mode { + Mode::Workspace(_) => { + stream.push_str( + format!("include!(\"{}\");\n", file_name).as_str(), + ); + }, + + Mode::SingleFile { .. } => { + let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); + + stream.push_str( + format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(), + ); + } + } } else { this.write_item(&mut stream, *def_id, &mut dup) } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml index cf98ef15..f88e4700 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml +++ b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = [ "article", - "author", + "author", "common", "image", ] From e5aae1da82e67baa91f9e90730638bb957ef84d5 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Fri, 11 Oct 2024 18:22:13 +0200 Subject: [PATCH 07/10] Generate different mods in different directories --- pilota-build/src/codegen/mod.rs | 29 ++++++-------- pilota-build/src/test/mod.rs | 38 +++++++++++-------- ...enum_ArticleServiceGetArticleResultRecv.rs | 0 ...enum_ArticleServiceGetArticleResultSend.rs | 0 .../article/src/{ => article}/enum_Status.rs | 0 .../{ => article/image/cdn}/message_CDN.rs | 0 .../src/{ => article/image}/message_Image.rs | 0 .../src/{ => article}/message_Article.rs | 0 ...essage_ArticleServiceGetArticleArgsRecv.rs | 0 ...essage_ArticleServiceGetArticleArgsSend.rs | 0 .../message_GetArticleRequest.rs | 0 .../message_GetArticleResponse.rs | 0 .../{ => article}/service_ArticleService.rs | 0 .../src/{ => author}/message_Author.rs | 0 .../src/{ => common}/message_CommonData.rs | 0 .../output/article/src/gen.rs | 26 ++++++------- .../{ => article/image/cdn}/message_CDN.rs | 0 .../src/{ => article/image}/message_Image.rs | 0 .../enum_AuthorServiceGetAuthorResultRecv.rs | 0 .../enum_AuthorServiceGetAuthorResultSend.rs | 0 .../author/src/{ => author}/message_Author.rs | 0 .../message_AuthorServiceGetAuthorArgsRecv.rs | 0 .../message_AuthorServiceGetAuthorArgsSend.rs | 0 .../{ => author}/message_GetAuthorRequest.rs | 0 .../{ => author}/message_GetAuthorResponse.rs | 0 .../src/{ => author}/service_AuthorService.rs | 0 .../src/{ => common}/message_CommonData.rs | 0 .../output/author/src/gen.rs | 22 +++++------ .../{ => article/image/cdn}/message_CDN.rs | 0 .../src/{ => article/image}/message_Image.rs | 0 .../common/src/{ => author}/message_Author.rs | 0 .../src/{ => common}/message_CommonData.rs | 0 .../output/common/src/gen.rs | 8 ++-- .../{ => article/image/cdn}/message_CDN.rs | 0 .../enum_ImageServiceGetImageResultRecv.rs | 0 .../enum_ImageServiceGetImageResultSend.rs | 0 .../image}/message_GetImageRequest.rs | 0 .../image}/message_GetImageResponse.rs | 0 .../src/{ => article/image}/message_Image.rs | 0 .../message_ImageServiceGetImageArgsRecv.rs | 0 .../message_ImageServiceGetImageArgsSend.rs | 0 .../image}/service_ImageService.rs | 0 .../src/{ => common}/message_CommonData.rs | 0 .../output/image/src/gen.rs | 20 +++++----- 44 files changed, 72 insertions(+), 71 deletions(-) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/enum_ArticleServiceGetArticleResultRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/enum_ArticleServiceGetArticleResultSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/enum_Status.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article/image/cdn}/message_CDN.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article/image}/message_Image.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/message_Article.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/message_ArticleServiceGetArticleArgsRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/message_ArticleServiceGetArticleArgsSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/message_GetArticleRequest.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/message_GetArticleResponse.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => article}/service_ArticleService.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => author}/message_Author.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/article/src/{ => common}/message_CommonData.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => article/image/cdn}/message_CDN.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => article/image}/message_Image.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/enum_AuthorServiceGetAuthorResultRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/enum_AuthorServiceGetAuthorResultSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/message_Author.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/message_AuthorServiceGetAuthorArgsRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/message_AuthorServiceGetAuthorArgsSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/message_GetAuthorRequest.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/message_GetAuthorResponse.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => author}/service_AuthorService.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/author/src/{ => common}/message_CommonData.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/common/src/{ => article/image/cdn}/message_CDN.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/common/src/{ => article/image}/message_Image.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/common/src/{ => author}/message_Author.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/common/src/{ => common}/message_CommonData.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image/cdn}/message_CDN.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/enum_ImageServiceGetImageResultRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/enum_ImageServiceGetImageResultSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/message_GetImageRequest.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/message_GetImageResponse.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/message_Image.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/message_ImageServiceGetImageArgsRecv.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/message_ImageServiceGetImageArgsSend.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => article/image}/service_ImageService.rs (100%) rename pilota-build/test_data/thrift_workspace_with_split/output/image/src/{ => common}/message_CommonData.rs (100%) diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 09b73899..966f2fef 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -496,32 +496,25 @@ where NodeKind::Method(_) => "method", NodeKind::Arg(_) => "arg", }; + + let base_mod_name = p.iter().map(|s| s.to_string()).join("/"); + let mod_dir = base_dir.join(base_mod_name.clone()); + let file_name = format!("{}_{}.rs", name_prefix, node.name()); this.write_item(&mut item_stream, *def_id, &mut dup); - let full_path = base_dir.join(file_name.clone()); - std::fs::create_dir_all(base_dir).unwrap(); + let full_path = mod_dir.join(file_name.clone()); + std::fs::create_dir_all(mod_dir).unwrap(); + let mut file = std::io::BufWriter::new(std::fs::File::create(full_path.clone()).unwrap()); file.write_all(item_stream.as_bytes()).unwrap(); file.flush().unwrap(); fmt_file(full_path); - match &*this.mode { - Mode::Workspace(_) => { - stream.push_str( - format!("include!(\"{}\");\n", file_name).as_str(), - ); - }, - - Mode::SingleFile { .. } => { - let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); - - stream.push_str( - format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(), - ); - } - } + stream.push_str( + format!("include!(\"{}/{}\");\n", base_mod_name, file_name).as_str(), + ); } else { this.write_item(&mut stream, *def_id, &mut dup) } @@ -570,7 +563,7 @@ where self.write_items( &mut stream, self.codegen_items.iter().map(|def_id| (*def_id).into()), - base_dir.join(ns_name.to_string()).as_path(), + base_dir, ); stream = format! {r#"pub mod {ns_name} {{ diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index f94f5443..bd7746c7 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,7 +1,7 @@ #![cfg(test)] -use std::{fs, path::Path}; use std::fs::File; +use std::{fs, path::Path}; use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService}; @@ -45,13 +45,17 @@ fn diff_dir(old: impl AsRef, new: impl AsRef) { if !corresponding_new_file.exists() { panic!("File {:?} does not exist in the new directory", file_name); } - + if old_file.is_file() && corresponding_new_file.is_file() { diff_file(old_file, corresponding_new_file); } else if !old_file.is_file() && !corresponding_new_file.is_file() { diff_dir(old_file, corresponding_new_file) } else { - panic!("{} and {} are not both files or directories", old_file.to_str().unwrap(), corresponding_new_file.to_str().unwrap()); + panic!( + "{} and {} are not both files or directories", + old_file.to_str().unwrap(), + corresponding_new_file.to_str().unwrap() + ); } } } @@ -167,32 +171,36 @@ fn test_thrift(source: impl AsRef, target: impl AsRef) { }); } -fn test_thrift_workspace(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { - let services: Vec = service_names.iter() +fn test_thrift_workspace( + input_dir: impl AsRef, + output_dir: impl AsRef, + service_names: Vec<&str>, +) { + let services: Vec = service_names + .iter() .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) .collect(); test_with_builder_workspace(input_dir, output_dir, |source, target| { crate::Builder::thrift() .ignore_unused(false) - .compile_with_config( - services, - crate::Output::Workspace(target.into()), - ) + .compile_with_config(services, crate::Output::Workspace(target.into())); }); } -fn test_thrift_workspace_with_split(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { - let services: Vec = service_names.iter() +fn test_thrift_workspace_with_split( + input_dir: impl AsRef, + output_dir: impl AsRef, + service_names: Vec<&str>, +) { + let services: Vec = service_names + .iter() .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) .collect(); test_with_builder_workspace(input_dir, output_dir, |source, target| { crate::Builder::thrift() .ignore_unused(false) .split_generated_files(true) - .compile_with_config( - services, - crate::Output::Workspace(target.into()), - ) + .compile_with_config(services, crate::Output::Workspace(target.into())) }); } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_Status.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_Status.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/message_CDN.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/message_CDN.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/message_Image.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/message_Image.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_Article.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_Article.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleRequest.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleRequest.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleResponse.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleResponse.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/service_ArticleService.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/service_ArticleService.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/message_Author.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/message_Author.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/message_CommonData.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/message_CommonData.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs index 5ebac8bb..581d0021 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs @@ -2,31 +2,31 @@ pub mod gen { #![allow(warnings, clippy::all)] pub mod article { - include!("enum_Status.rs"); - include!("message_ArticleServiceGetArticleArgsRecv.rs"); - include!("enum_ArticleServiceGetArticleResultSend.rs"); - include!("message_GetArticleResponse.rs"); - include!("message_ArticleServiceGetArticleArgsSend.rs"); - include!("message_GetArticleRequest.rs"); - include!("service_ArticleService.rs"); - include!("enum_ArticleServiceGetArticleResultRecv.rs"); - include!("message_Article.rs"); + include!("article/enum_Status.rs"); + include!("article/message_ArticleServiceGetArticleArgsRecv.rs"); + include!("article/enum_ArticleServiceGetArticleResultSend.rs"); + include!("article/message_GetArticleResponse.rs"); + include!("article/message_ArticleServiceGetArticleArgsSend.rs"); + include!("article/message_GetArticleRequest.rs"); + include!("article/service_ArticleService.rs"); + include!("article/enum_ArticleServiceGetArticleResultRecv.rs"); + include!("article/message_Article.rs"); pub mod image { - include!("message_Image.rs"); + include!("article/image/message_Image.rs"); pub mod cdn { - include!("message_CDN.rs"); + include!("article/image/cdn/message_CDN.rs"); } } } pub mod author { - include!("message_Author.rs"); + include!("author/message_Author.rs"); } pub mod common { - include!("message_CommonData.rs"); + include!("common/message_CommonData.rs"); } pub use article::*; } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/message_CDN.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/message_CDN.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/message_Image.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/message_Image.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_Author.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_Author.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorRequest.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorRequest.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorResponse.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorResponse.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/service_AuthorService.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/service_AuthorService.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/message_CommonData.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/message_CommonData.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs index 68bcd655..b2420e3b 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs @@ -4,27 +4,27 @@ pub mod gen { pub mod article { pub mod image { - include!("message_Image.rs"); + include!("article/image/message_Image.rs"); pub mod cdn { - include!("message_CDN.rs"); + include!("article/image/cdn/message_CDN.rs"); } } } pub mod author { - include!("service_AuthorService.rs"); - include!("enum_AuthorServiceGetAuthorResultRecv.rs"); - include!("message_AuthorServiceGetAuthorArgsRecv.rs"); - include!("enum_AuthorServiceGetAuthorResultSend.rs"); - include!("message_GetAuthorResponse.rs"); - include!("message_AuthorServiceGetAuthorArgsSend.rs"); - include!("message_GetAuthorRequest.rs"); - include!("message_Author.rs"); + include!("author/service_AuthorService.rs"); + include!("author/enum_AuthorServiceGetAuthorResultRecv.rs"); + include!("author/message_AuthorServiceGetAuthorArgsRecv.rs"); + include!("author/enum_AuthorServiceGetAuthorResultSend.rs"); + include!("author/message_GetAuthorResponse.rs"); + include!("author/message_AuthorServiceGetAuthorArgsSend.rs"); + include!("author/message_GetAuthorRequest.rs"); + include!("author/message_Author.rs"); } pub mod common { - include!("message_CommonData.rs"); + include!("common/message_CommonData.rs"); } pub use author::*; } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/message_CDN.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/message_CDN.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/message_Image.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/message_Image.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/message_Author.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/message_Author.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/message_CommonData.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/message_CommonData.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs index 26a817f0..03d64769 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs @@ -4,19 +4,19 @@ pub mod gen { pub mod article { pub mod image { - include!("message_Image.rs"); + include!("article/image/message_Image.rs"); pub mod cdn { - include!("message_CDN.rs"); + include!("article/image/cdn/message_CDN.rs"); } } } pub mod author { - include!("message_Author.rs"); + include!("author/message_Author.rs"); } pub mod common { - include!("message_CommonData.rs"); + include!("common/message_CommonData.rs"); } } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/message_CDN.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/message_CDN.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageRequest.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageRequest.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageResponse.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageResponse.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_Image.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_Image.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsRecv.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsRecv.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsSend.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsSend.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/service_ImageService.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/service_ImageService.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/message_CommonData.rs similarity index 100% rename from pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs rename to pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/message_CommonData.rs diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs index c0bb15b5..b4dee346 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs @@ -4,23 +4,23 @@ pub mod gen { pub mod article { pub mod image { - include!("message_ImageServiceGetImageArgsRecv.rs"); - include!("enum_ImageServiceGetImageResultSend.rs"); - include!("message_GetImageResponse.rs"); - include!("message_ImageServiceGetImageArgsSend.rs"); - include!("message_GetImageRequest.rs"); - include!("service_ImageService.rs"); - include!("enum_ImageServiceGetImageResultRecv.rs"); - include!("message_Image.rs"); + include!("article/image/message_ImageServiceGetImageArgsRecv.rs"); + include!("article/image/enum_ImageServiceGetImageResultSend.rs"); + include!("article/image/message_GetImageResponse.rs"); + include!("article/image/message_ImageServiceGetImageArgsSend.rs"); + include!("article/image/message_GetImageRequest.rs"); + include!("article/image/service_ImageService.rs"); + include!("article/image/enum_ImageServiceGetImageResultRecv.rs"); + include!("article/image/message_Image.rs"); pub mod cdn { - include!("message_CDN.rs"); + include!("article/image/cdn/message_CDN.rs"); } } } pub mod common { - include!("message_CommonData.rs"); + include!("common/message_CommonData.rs"); } pub use article::image::*; } From 63df82eda1a43818a7b0428cc1aa81063e286374 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Sat, 12 Oct 2024 18:11:30 +0200 Subject: [PATCH 08/10] Add a check for successful `cargo build` when testing workspace mode --- pilota-build/src/test/mod.rs | 50 +++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index bd7746c7..33bca271 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -2,6 +2,7 @@ use std::fs::File; use std::{fs, path::Path}; +use std::process::Command; use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService}; @@ -60,6 +61,49 @@ fn diff_dir(old: impl AsRef, new: impl AsRef) { } } +fn check_cargo_build(target: impl AsRef) { + let tmp_dir = tempdir().unwrap(); + let tmp_target = tmp_dir.path().join(target.as_ref().file_name().unwrap()); + + fn copy_dir_recursively(src: impl AsRef, dst: impl AsRef) -> std::io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let path = entry.path(); + let dst_path = dst.as_ref().join(entry.file_name()); + if path.is_dir() { + copy_dir_recursively(path, dst_path)?; + } else { + fs::copy(path, dst_path)?; + } + } + Ok(()) + } + + // `cargo build` produces the `target` directory and the `Cargo.lock` file + // To not pollute the test data, copy the directory to a temporary one + copy_dir_recursively(&target, &tmp_target).unwrap(); + + println!("Running cargo build in {}", tmp_target.display()); + + let result = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned())) + .current_dir(&tmp_target) + .arg("build") + .output(); + + match result { + Ok(status) => { + if !status.status.success() { + eprintln!("{}", String::from_utf8_lossy(&status.stderr)); + panic!("cargo build returned non-zero exit code for {}. See above for more details", tmp_target.display()); + } + } + Err(_) => { + panic!("cargo build failed for {}", tmp_target.display()); + } + } +} + fn test_protobuf(source: impl AsRef, target: impl AsRef) { test_with_builder(source, target, |source, target| { crate::Builder::protobuf() @@ -108,6 +152,8 @@ fn test_with_builder_workspace( File::create(cargo_toml_path).unwrap(); f(source.as_ref(), target.as_ref()); + + check_cargo_build(target) } else { let dir = tempdir().unwrap(); let path = dir.path().join( @@ -127,7 +173,9 @@ fn test_with_builder_workspace( File::create(cargo_toml_path).unwrap(); f(source.as_ref(), &path); - diff_dir(target, &base_dir_tmp); + diff_dir(&target, &base_dir_tmp); + + check_cargo_build(target) } } From 1f74c61a6d625854150b0420927afed669ae7719 Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Sun, 13 Oct 2024 10:18:38 +0200 Subject: [PATCH 09/10] Generate `mod.rs` file for each mode when splitting --- pilota-build/src/codegen/mod.rs | 98 ++++++++++++------- pilota-build/src/test/mod.rs | 15 +-- .../thrift_with_split/wrapper_arc.rs | 8 +- .../thrift_with_split/wrapper_arc/mod.rs | 7 ++ .../article/src/article/image/cdn/mod.rs | 1 + .../output/article/src/article/image/mod.rs | 1 + .../output/article/src/article/mod.rs | 9 ++ .../output/article/src/author/mod.rs | 1 + .../output/article/src/common/mod.rs | 1 + .../output/article/src/gen.rs | 18 +--- .../author/src/article/image/cdn/mod.rs | 1 + .../output/author/src/article/image/mod.rs | 1 + .../output/author/src/author/mod.rs | 8 ++ .../output/author/src/common/mod.rs | 1 + .../output/author/src/gen.rs | 15 +-- .../common/src/article/image/cdn/mod.rs | 1 + .../output/common/src/article/image/mod.rs | 1 + .../output/common/src/author/mod.rs | 1 + .../output/common/src/common/mod.rs | 1 + .../output/common/src/gen.rs | 8 +- .../output/image/src/article/image/cdn/mod.rs | 1 + .../output/image/src/article/image/mod.rs | 8 ++ .../output/image/src/common/mod.rs | 1 + .../output/image/src/gen.rs | 13 +-- 24 files changed, 132 insertions(+), 88 deletions(-) create mode 100644 pilota-build/test_data/thrift_with_split/wrapper_arc/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/mod.rs create mode 100644 pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/mod.rs diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 966f2fef..c3280bf7 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -6,6 +6,7 @@ use std::{ }; use ahash::AHashMap; +use dashmap::mapref::one::RefMut; use dashmap::DashMap; use faststr::FastStr; use itertools::Itertools; @@ -478,44 +479,11 @@ where let _enter = span.enter(); let mut dup = AHashMap::default(); - for def_id in def_ids.iter() { - if this.split { - let mut item_stream = String::new(); - let node = this.db.node(def_id.def_id).unwrap(); - let name_prefix = match node.kind { - NodeKind::Item(ref item) => match item.as_ref() { - Item::Message(_) => "message", - Item::Enum(_) => "enum", - Item::Service(_) => "service", - Item::NewType(_) => "new_type", - Item::Const(_) => "const", - Item::Mod(_) => "mod", - }, - NodeKind::Variant(_) => "variant", - NodeKind::Field(_) => "field", - NodeKind::Method(_) => "method", - NodeKind::Arg(_) => "arg", - }; - - let base_mod_name = p.iter().map(|s| s.to_string()).join("/"); - let mod_dir = base_dir.join(base_mod_name.clone()); - - let file_name = format!("{}_{}.rs", name_prefix, node.name()); - this.write_item(&mut item_stream, *def_id, &mut dup); - let full_path = mod_dir.join(file_name.clone()); - std::fs::create_dir_all(mod_dir).unwrap(); - - let mut file = - std::io::BufWriter::new(std::fs::File::create(full_path.clone()).unwrap()); - file.write_all(item_stream.as_bytes()).unwrap(); - file.flush().unwrap(); - fmt_file(full_path); - - stream.push_str( - format!("include!(\"{}/{}\");\n", base_mod_name, file_name).as_str(), - ); - } else { + if this.split { + Self::write_split_mod(this, base_dir, p, def_ids, &mut stream, &mut dup); + } else { + for def_id in def_ids.iter() { this.write_item(&mut stream, *def_id, &mut dup) } } @@ -557,6 +525,62 @@ where write_stream(&mut pkgs, stream, &pkg_node); } + fn write_split_mod( + this: &mut Codegen, + base_dir: &Path, + p: &Arc<[FastStr]>, + def_ids: &Vec, + stream: &mut RefMut, String>, + mut dup: &mut AHashMap>, + ) { + let base_mod_name = p.iter().map(|s| s.to_string()).join("/"); + let mod_file_name = format!("{}/mod.rs", base_mod_name); + let mut mod_stream = String::new(); + + for def_id in def_ids.iter() { + let mut item_stream = String::new(); + let node = this.db.node(def_id.def_id).unwrap(); + let name_prefix = match node.kind { + NodeKind::Item(ref item) => match item.as_ref() { + Item::Message(_) => "message", + Item::Enum(_) => "enum", + Item::Service(_) => "service", + Item::NewType(_) => "new_type", + Item::Const(_) => "const", + Item::Mod(_) => "mod", + }, + NodeKind::Variant(_) => "variant", + NodeKind::Field(_) => "field", + NodeKind::Method(_) => "method", + NodeKind::Arg(_) => "arg", + }; + + let mod_dir = base_dir.join(base_mod_name.clone()); + + let file_name = format!("{}_{}.rs", name_prefix, node.name()); + this.write_item(&mut item_stream, *def_id, &mut dup); + + let full_path = mod_dir.join(file_name.clone()); + std::fs::create_dir_all(mod_dir).unwrap(); + + let mut file = + std::io::BufWriter::new(std::fs::File::create(full_path.clone()).unwrap()); + file.write_all(item_stream.as_bytes()).unwrap(); + file.flush().unwrap(); + fmt_file(full_path); + + mod_stream.push_str(format!("include!(\"{}\");\n", file_name).as_str()); + } + + let mod_path = base_dir.join(&mod_file_name); + let mut mod_file = std::io::BufWriter::new(std::fs::File::create(&mod_path).unwrap()); + mod_file.write_all(mod_stream.as_bytes()).unwrap(); + mod_file.flush().unwrap(); + fmt_file(&mod_path); + + stream.push_str(format!("include!(\"{}\");\n", mod_file_name).as_str()); + } + pub fn write_file(self, ns_name: Symbol, file_name: impl AsRef) { let base_dir = file_name.as_ref().parent().unwrap(); let mut stream = String::default(); diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index 33bca271..830ba38b 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,8 +1,8 @@ #![cfg(test)] use std::fs::File; -use std::{fs, path::Path}; use std::process::Command; +use std::{fs, path::Path}; use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService}; @@ -83,19 +83,22 @@ fn check_cargo_build(target: impl AsRef) { // `cargo build` produces the `target` directory and the `Cargo.lock` file // To not pollute the test data, copy the directory to a temporary one copy_dir_recursively(&target, &tmp_target).unwrap(); - + println!("Running cargo build in {}", tmp_target.display()); let result = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned())) .current_dir(&tmp_target) .arg("build") .output(); - + match result { Ok(status) => { if !status.status.success() { eprintln!("{}", String::from_utf8_lossy(&status.stderr)); - panic!("cargo build returned non-zero exit code for {}. See above for more details", tmp_target.display()); + panic!( + "cargo build returned non-zero exit code for {}. See above for more details", + tmp_target.display() + ); } } Err(_) => { @@ -152,7 +155,7 @@ fn test_with_builder_workspace( File::create(cargo_toml_path).unwrap(); f(source.as_ref(), target.as_ref()); - + check_cargo_build(target) } else { let dir = tempdir().unwrap(); @@ -174,7 +177,7 @@ fn test_with_builder_workspace( f(source.as_ref(), &path); diff_dir(&target, &base_dir_tmp); - + check_cargo_build(target) } } diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs index 2f17a7a4..90e1881d 100644 --- a/pilota-build/test_data/thrift_with_split/wrapper_arc.rs +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs @@ -2,12 +2,6 @@ pub mod wrapper_arc { #![allow(warnings, clippy::all)] pub mod wrapper_arc { - include!("wrapper_arc/message_A.rs"); - include!("wrapper_arc/service_TestService.rs"); - include!("wrapper_arc/enum_TestServiceTestResultRecv.rs"); - include!("wrapper_arc/message_TestServiceTestArgsRecv.rs"); - include!("wrapper_arc/enum_TestServiceTestResultSend.rs"); - include!("wrapper_arc/message_TEST.rs"); - include!("wrapper_arc/message_TestServiceTestArgsSend.rs"); + include!("wrapper_arc/mod.rs"); } } diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/mod.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/mod.rs new file mode 100644 index 00000000..ea61a8ce --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/mod.rs @@ -0,0 +1,7 @@ +include!("message_A.rs"); +include!("service_TestService.rs"); +include!("enum_TestServiceTestResultRecv.rs"); +include!("message_TestServiceTestArgsRecv.rs"); +include!("enum_TestServiceTestResultSend.rs"); +include!("message_TEST.rs"); +include!("message_TestServiceTestArgsSend.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/mod.rs new file mode 100644 index 00000000..bdf630b1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/mod.rs @@ -0,0 +1 @@ +include!("message_CDN.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/mod.rs new file mode 100644 index 00000000..fae6e988 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/mod.rs @@ -0,0 +1 @@ +include!("message_Image.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/mod.rs new file mode 100644 index 00000000..9d550212 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/mod.rs @@ -0,0 +1,9 @@ +include!("enum_Status.rs"); +include!("message_ArticleServiceGetArticleArgsRecv.rs"); +include!("enum_ArticleServiceGetArticleResultSend.rs"); +include!("message_GetArticleResponse.rs"); +include!("message_ArticleServiceGetArticleArgsSend.rs"); +include!("message_GetArticleRequest.rs"); +include!("service_ArticleService.rs"); +include!("enum_ArticleServiceGetArticleResultRecv.rs"); +include!("message_Article.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/mod.rs new file mode 100644 index 00000000..bc027b9a --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/mod.rs @@ -0,0 +1 @@ +include!("message_Author.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/mod.rs new file mode 100644 index 00000000..5e2006a4 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/mod.rs @@ -0,0 +1 @@ +include!("message_CommonData.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs index 581d0021..4ab5d758 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs @@ -2,31 +2,23 @@ pub mod gen { #![allow(warnings, clippy::all)] pub mod article { - include!("article/enum_Status.rs"); - include!("article/message_ArticleServiceGetArticleArgsRecv.rs"); - include!("article/enum_ArticleServiceGetArticleResultSend.rs"); - include!("article/message_GetArticleResponse.rs"); - include!("article/message_ArticleServiceGetArticleArgsSend.rs"); - include!("article/message_GetArticleRequest.rs"); - include!("article/service_ArticleService.rs"); - include!("article/enum_ArticleServiceGetArticleResultRecv.rs"); - include!("article/message_Article.rs"); + include!("article/mod.rs"); pub mod image { - include!("article/image/message_Image.rs"); + include!("article/image/mod.rs"); pub mod cdn { - include!("article/image/cdn/message_CDN.rs"); + include!("article/image/cdn/mod.rs"); } } } pub mod author { - include!("author/message_Author.rs"); + include!("author/mod.rs"); } pub mod common { - include!("common/message_CommonData.rs"); + include!("common/mod.rs"); } pub use article::*; } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/mod.rs new file mode 100644 index 00000000..bdf630b1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/mod.rs @@ -0,0 +1 @@ +include!("message_CDN.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/mod.rs new file mode 100644 index 00000000..fae6e988 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/mod.rs @@ -0,0 +1 @@ +include!("message_Image.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/mod.rs new file mode 100644 index 00000000..ee1cf56b --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/mod.rs @@ -0,0 +1,8 @@ +include!("service_AuthorService.rs"); +include!("enum_AuthorServiceGetAuthorResultRecv.rs"); +include!("message_AuthorServiceGetAuthorArgsRecv.rs"); +include!("enum_AuthorServiceGetAuthorResultSend.rs"); +include!("message_GetAuthorResponse.rs"); +include!("message_AuthorServiceGetAuthorArgsSend.rs"); +include!("message_GetAuthorRequest.rs"); +include!("message_Author.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/mod.rs new file mode 100644 index 00000000..5e2006a4 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/mod.rs @@ -0,0 +1 @@ +include!("message_CommonData.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs index b2420e3b..baf10c7e 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs @@ -4,27 +4,20 @@ pub mod gen { pub mod article { pub mod image { - include!("article/image/message_Image.rs"); + include!("article/image/mod.rs"); pub mod cdn { - include!("article/image/cdn/message_CDN.rs"); + include!("article/image/cdn/mod.rs"); } } } pub mod author { - include!("author/service_AuthorService.rs"); - include!("author/enum_AuthorServiceGetAuthorResultRecv.rs"); - include!("author/message_AuthorServiceGetAuthorArgsRecv.rs"); - include!("author/enum_AuthorServiceGetAuthorResultSend.rs"); - include!("author/message_GetAuthorResponse.rs"); - include!("author/message_AuthorServiceGetAuthorArgsSend.rs"); - include!("author/message_GetAuthorRequest.rs"); - include!("author/message_Author.rs"); + include!("author/mod.rs"); } pub mod common { - include!("common/message_CommonData.rs"); + include!("common/mod.rs"); } pub use author::*; } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/mod.rs new file mode 100644 index 00000000..bdf630b1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/mod.rs @@ -0,0 +1 @@ +include!("message_CDN.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/mod.rs new file mode 100644 index 00000000..fae6e988 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/mod.rs @@ -0,0 +1 @@ +include!("message_Image.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/mod.rs new file mode 100644 index 00000000..bc027b9a --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/mod.rs @@ -0,0 +1 @@ +include!("message_Author.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/mod.rs new file mode 100644 index 00000000..5e2006a4 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/mod.rs @@ -0,0 +1 @@ +include!("message_CommonData.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs index 03d64769..df776c89 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs @@ -4,19 +4,19 @@ pub mod gen { pub mod article { pub mod image { - include!("article/image/message_Image.rs"); + include!("article/image/mod.rs"); pub mod cdn { - include!("article/image/cdn/message_CDN.rs"); + include!("article/image/cdn/mod.rs"); } } } pub mod author { - include!("author/message_Author.rs"); + include!("author/mod.rs"); } pub mod common { - include!("common/message_CommonData.rs"); + include!("common/mod.rs"); } } diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/mod.rs new file mode 100644 index 00000000..bdf630b1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/mod.rs @@ -0,0 +1 @@ +include!("message_CDN.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/mod.rs new file mode 100644 index 00000000..875e4fb5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/mod.rs @@ -0,0 +1,8 @@ +include!("message_ImageServiceGetImageArgsRecv.rs"); +include!("enum_ImageServiceGetImageResultSend.rs"); +include!("message_GetImageResponse.rs"); +include!("message_ImageServiceGetImageArgsSend.rs"); +include!("message_GetImageRequest.rs"); +include!("service_ImageService.rs"); +include!("enum_ImageServiceGetImageResultRecv.rs"); +include!("message_Image.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/mod.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/mod.rs new file mode 100644 index 00000000..5e2006a4 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/mod.rs @@ -0,0 +1 @@ +include!("message_CommonData.rs"); diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs index b4dee346..ae7ab893 100644 --- a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs @@ -4,23 +4,16 @@ pub mod gen { pub mod article { pub mod image { - include!("article/image/message_ImageServiceGetImageArgsRecv.rs"); - include!("article/image/enum_ImageServiceGetImageResultSend.rs"); - include!("article/image/message_GetImageResponse.rs"); - include!("article/image/message_ImageServiceGetImageArgsSend.rs"); - include!("article/image/message_GetImageRequest.rs"); - include!("article/image/service_ImageService.rs"); - include!("article/image/enum_ImageServiceGetImageResultRecv.rs"); - include!("article/image/message_Image.rs"); + include!("article/image/mod.rs"); pub mod cdn { - include!("article/image/cdn/message_CDN.rs"); + include!("article/image/cdn/mod.rs"); } } } pub mod common { - include!("common/message_CommonData.rs"); + include!("common/mod.rs"); } pub use article::image::*; } From c5590beb3c1d7aa10bf05765753216f06192a77d Mon Sep 17 00:00:00 2001 From: "evgeny.bovykin" Date: Sun, 13 Oct 2024 16:40:03 +0200 Subject: [PATCH 10/10] Apply fmt fixes --- pilota-build/src/codegen/mod.rs | 3 +-- pilota-build/src/test/mod.rs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index c3280bf7..6cbd759c 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -6,8 +6,7 @@ use std::{ }; use ahash::AHashMap; -use dashmap::mapref::one::RefMut; -use dashmap::DashMap; +use dashmap::{mapref::one::RefMut, DashMap}; use faststr::FastStr; use itertools::Itertools; use normpath::PathExt; diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index 830ba38b..1022e24d 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,8 +1,7 @@ #![cfg(test)] -use std::fs::File; -use std::process::Command; -use std::{fs, path::Path}; +use std::{fs, fs::File, path::Path, process::Command}; + use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService};