diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 0e67582e..6cbd759c 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -6,7 +6,7 @@ use std::{ }; use ahash::AHashMap; -use dashmap::DashMap; +use dashmap::{mapref::one::RefMut, DashMap}; use faststr::FastStr; use itertools::Itertools; use normpath::PathExt; @@ -25,6 +25,7 @@ use crate::{ context::{tls::CUR_ITEM, Mode}, rir, }, + rir::{Item, NodeKind}, symbol::{DefId, EnumRepr, FileId}, Context, Symbol, }; @@ -447,8 +448,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, .. }| { @@ -473,8 +478,13 @@ 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 { + 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) + } } }); @@ -514,11 +524,69 @@ 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(); self.write_items( &mut stream, self.codegen_items.iter().map(|def_id| (*def_id).into()), + base_dir, ); 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..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,6 +249,7 @@ where def_id, kind: super::CodegenKind::RePub, })), + 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/lib.rs b/pilota-build/src/lib.rs index 2d015fec..76bf2c02 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 split_generated_files(mut self, split: bool) -> Self { + self.split = split; + 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..1022e24d 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, fs::File, path::Path, process::Command}; use tempfile::tempdir; @@ -19,6 +19,93 @@ 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); + } + + 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() + ); + } + } +} + +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() @@ -55,6 +142,74 @@ 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()); + + check_cargo_build(target) + } 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); + + check_cargo_build(target) + } +} + +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 +221,55 @@ 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, + gen_dir: impl AsRef, +) { + test_with_split_builder(source, target, gen_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .split_generated_files(true) + .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 +315,56 @@ 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")) + .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..90e1881d --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc.rs @@ -0,0 +1,7 @@ +pub mod wrapper_arc { + #![allow(warnings, clippy::all)] + + pub mod wrapper_arc { + include!("wrapper_arc/mod.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/enum_TestServiceTestResultRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultRecv.rs new file mode 100644 index 00000000..eb02d1a1 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_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/enum_TestServiceTestResultSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_TestServiceTestResultSend.rs new file mode 100644 index 00000000..97b0f8b5 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/enum_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() + } +} diff --git a/pilota-build/test_data/thrift_with_split/wrapper_arc/message_A.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_A.rs new file mode 100644 index 00000000..b0c48761 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_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/message_TEST.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TEST.rs new file mode 100644 index 00000000..766478cd --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_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/message_TestServiceTestArgsRecv.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsRecv.rs new file mode 100644 index 00000000..71a1d9b1 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_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/message_TestServiceTestArgsSend.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_TestServiceTestArgsSend.rs new file mode 100644 index 00000000..12e37b2a --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/message_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/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_with_split/wrapper_arc/service_TestService.rs b/pilota-build/test_data/thrift_with_split/wrapper_arc/service_TestService.rs new file mode 100644 index 00000000..bcfc2708 --- /dev/null +++ b/pilota-build/test_data/thrift_with_split/wrapper_arc/service_TestService.rs @@ -0,0 +1,2 @@ + +pub trait TestService {} 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..f88e4700 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/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_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/article/enum_ArticleServiceGetArticleResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultRecv.rs new file mode 100644 index 00000000..f9bfba0b --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/enum_ArticleServiceGetArticleResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_ArticleServiceGetArticleResultSend.rs new file mode 100644 index 00000000..a84e3837 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/enum_Status.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/enum_Status.rs new file mode 100644 index 00000000..453a7996 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/image/cdn/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/cdn/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/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/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/image/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/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/message_Article.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_Article.rs new file mode 100644 index 00000000..29ad8d68 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/message_ArticleServiceGetArticleArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsRecv.rs new file mode 100644 index 00000000..95339be0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/message_ArticleServiceGetArticleArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_ArticleServiceGetArticleArgsSend.rs new file mode 100644 index 00000000..c47c5388 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/message_GetArticleRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleRequest.rs new file mode 100644 index 00000000..f9892c38 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/article/message_GetArticleResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/message_GetArticleResponse.rs new file mode 100644 index 00000000..9cc8d06f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/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/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/article/service_ArticleService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/service_ArticleService.rs new file mode 100644 index 00000000..42e7df87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/article/service_ArticleService.rs @@ -0,0 +1,2 @@ + +pub trait ArticleService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/author/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/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/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/common/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/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 new file mode 100644 index 00000000..4ab5d758 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs @@ -0,0 +1,24 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + include!("article/mod.rs"); + + pub mod image { + include!("article/image/mod.rs"); + + pub mod cdn { + include!("article/image/cdn/mod.rs"); + } + } + } + + pub mod author { + include!("author/mod.rs"); + } + + pub mod common { + include!("common/mod.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/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/article/image/cdn/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/cdn/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/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/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/article/image/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/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/enum_AuthorServiceGetAuthorResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultRecv.rs new file mode 100644 index 00000000..81045cdb --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/enum_AuthorServiceGetAuthorResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/enum_AuthorServiceGetAuthorResultSend.rs new file mode 100644 index 00000000..37419a87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/message_AuthorServiceGetAuthorArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsRecv.rs new file mode 100644 index 00000000..3757735f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/message_AuthorServiceGetAuthorArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_AuthorServiceGetAuthorArgsSend.rs new file mode 100644 index 00000000..f6eba41d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/message_GetAuthorRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorRequest.rs new file mode 100644 index 00000000..354ce21c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/author/message_GetAuthorResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/message_GetAuthorResponse.rs new file mode 100644 index 00000000..ca4eb853 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/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/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/author/service_AuthorService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/service_AuthorService.rs new file mode 100644 index 00000000..9cbd928f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/author/service_AuthorService.rs @@ -0,0 +1,2 @@ + +pub trait AuthorService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/common/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/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 new file mode 100644 index 00000000..baf10c7e --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs @@ -0,0 +1,23 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("article/image/mod.rs"); + + pub mod cdn { + include!("article/image/cdn/mod.rs"); + } + } + } + + pub mod author { + include!("author/mod.rs"); + } + + pub mod common { + include!("common/mod.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/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/article/image/cdn/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/message_CDN.rs new file mode 100644 index 00000000..8ece535f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/cdn/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/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/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/message_Image.rs new file mode 100644 index 00000000..6ac83879 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/article/image/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/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/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/message_Author.rs new file mode 100644 index 00000000..a57b6372 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/author/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/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/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/message_CommonData.rs new file mode 100644 index 00000000..6aa0cb18 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/common/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/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 new file mode 100644 index 00000000..df776c89 --- /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!("article/image/mod.rs"); + + pub mod cdn { + include!("article/image/cdn/mod.rs"); + } + } + } + + pub mod author { + include!("author/mod.rs"); + } + + pub mod common { + include!("common/mod.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/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/article/image/cdn/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/cdn/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/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/enum_ImageServiceGetImageResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultRecv.rs new file mode 100644 index 00000000..b25d6dc0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/enum_ImageServiceGetImageResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/enum_ImageServiceGetImageResultSend.rs new file mode 100644 index 00000000..8caa6563 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/message_GetImageRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageRequest.rs new file mode 100644 index 00000000..ab4b8bf1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/message_GetImageResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_GetImageResponse.rs new file mode 100644 index 00000000..e8eb80e9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/message_ImageServiceGetImageArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsRecv.rs new file mode 100644 index 00000000..e6b39933 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/article/image/message_ImageServiceGetImageArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/message_ImageServiceGetImageArgsSend.rs new file mode 100644 index 00000000..34d817a7 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/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/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/article/image/service_ImageService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/service_ImageService.rs new file mode 100644 index 00000000..ae17ff16 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/article/image/service_ImageService.rs @@ -0,0 +1,2 @@ + +pub trait ImageService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/common/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/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 new file mode 100644 index 00000000..ae7ab893 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs @@ -0,0 +1,19 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("article/image/mod.rs"); + + pub mod cdn { + include!("article/image/cdn/mod.rs"); + } + } + } + + pub mod common { + include!("common/mod.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::*;