diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index 506324dc..741767dd 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -507,10 +507,8 @@ where file.flush().unwrap(); fmt_file(full_path); - let base_dir_local_path = base_dir.iter().last().unwrap().to_str().unwrap(); - stream.push_str( - format!("include!(\"{}/{}\");\n", base_dir_local_path, file_name).as_str(), + format!("include!(\"{}\");\n", file_name).as_str(), ); } else { this.write_item(&mut stream, *def_id, &mut dup) diff --git a/pilota-build/src/codegen/workspace.rs b/pilota-build/src/codegen/workspace.rs index 72f929a9..0a59ac92 100644 --- a/pilota-build/src/codegen/workspace.rs +++ b/pilota-build/src/codegen/workspace.rs @@ -85,6 +85,7 @@ where None } }) + .sorted() .join(",\n"); let mut cargo_toml = toml::from_str::(&unsafe { @@ -184,6 +185,8 @@ where Command::new("cargo") .arg("init") .arg("--lib") + .arg("--vcs") + .arg("none") .current_dir(base_dir.as_ref()) .arg(&*info.name), )?; @@ -246,7 +249,7 @@ where def_id, kind: super::CodegenKind::RePub, })), - base_dir.as_ref(), + base_dir.as_ref().join(&*info.name).join("src").as_path(), ); if let Some(main_mod_path) = info.main_mod_path { gen_rs_stream.push_str(&format!( diff --git a/pilota-build/src/fmt.rs b/pilota-build/src/fmt.rs index 925e3eb6..61f061e1 100644 --- a/pilota-build/src/fmt.rs +++ b/pilota-build/src/fmt.rs @@ -24,8 +24,8 @@ pub fn fmt_file>(file: P) { Err(e) => eprintln!("{}", e), Ok(output) => { if !output.status.success() { + eprintln!("rustfmt failed to format {}", file.display()); std::io::stderr().write_all(&output.stderr).unwrap(); - exit(output.status.code().unwrap_or(1)) } } } diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index ff8bf1dd..f94f5443 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -1,7 +1,7 @@ #![cfg(test)] use std::{fs, path::Path}; - +use std::fs::File; use tempfile::tempdir; use crate::{plugin::SerdePlugin, IdlService}; @@ -45,7 +45,14 @@ fn diff_dir(old: impl AsRef, new: impl AsRef) { if !corresponding_new_file.exists() { panic!("File {:?} does not exist in the new directory", file_name); } - diff_file(old_file, corresponding_new_file); + + if old_file.is_file() && corresponding_new_file.is_file() { + diff_file(old_file, corresponding_new_file); + } else if !old_file.is_file() && !corresponding_new_file.is_file() { + diff_dir(old_file, corresponding_new_file) + } else { + panic!("{} and {} are not both files or directories", old_file.to_str().unwrap(), corresponding_new_file.to_str().unwrap()); + } } } @@ -85,6 +92,41 @@ fn test_with_builder( } } +fn test_with_builder_workspace( + source: impl AsRef, + target: impl AsRef, + f: F, +) { + if std::env::var("UPDATE_TEST_DATA").as_deref() == Ok("1") { + fs::remove_dir(&target); + fs::create_dir_all(&target).unwrap(); + let cargo_toml_path = target.as_ref().join("Cargo.toml"); + File::create(cargo_toml_path).unwrap(); + + f(source.as_ref(), target.as_ref()); + } else { + let dir = tempdir().unwrap(); + let path = dir.path().join( + target + .as_ref() + .file_name() + .and_then(|s| s.to_str()) + .unwrap(), + ); + let mut base_dir_tmp = path.clone(); + base_dir_tmp.pop(); + base_dir_tmp.push(path.file_stem().unwrap()); + println!("{path:?}"); + + fs::create_dir_all(&path).unwrap(); + let cargo_toml_path = path.join("Cargo.toml"); + File::create(cargo_toml_path).unwrap(); + + f(source.as_ref(), &path); + diff_dir(target, &base_dir_tmp); + } +} + fn test_with_split_builder( source: impl AsRef, target: impl AsRef, @@ -125,6 +167,35 @@ fn test_thrift(source: impl AsRef, target: impl AsRef) { }); } +fn test_thrift_workspace(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { + let services: Vec = service_names.iter() + .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) + .collect(); + test_with_builder_workspace(input_dir, output_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .compile_with_config( + services, + crate::Output::Workspace(target.into()), + ) + }); +} + +fn test_thrift_workspace_with_split(input_dir: impl AsRef, output_dir: impl AsRef, service_names: Vec<&str>) { + let services: Vec = service_names.iter() + .map(|name| IdlService::from_path(input_dir.as_ref().join(format!("{}.thrift", name)))) + .collect(); + test_with_builder_workspace(input_dir, output_dir, |source, target| { + crate::Builder::thrift() + .ignore_unused(false) + .split_generated_files(true) + .compile_with_config( + services, + crate::Output::Workspace(target.into()), + ) + }); +} + fn test_thrift_with_split( source: impl AsRef, target: impl AsRef, @@ -186,6 +257,30 @@ fn test_thrift_gen() { }); } +#[test] +fn test_thrift_workspace_gen() { + let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join("thrift_workspace"); + + let input_dir = test_data_dir.join("input"); + let output_dir = test_data_dir.join("output"); + + test_thrift_workspace(input_dir, output_dir, vec!["article", "author", "image"]); +} + +#[test] +fn test_thrift_workspace_with_split_gen() { + let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("test_data") + .join("thrift_workspace_with_split"); + + let input_dir = test_data_dir.join("input"); + let output_dir = test_data_dir.join("output"); + + test_thrift_workspace_with_split(input_dir, output_dir, vec!["article", "author", "image"]); +} + #[test] fn test_thrift_gen_with_split() { let test_data_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) diff --git a/pilota-build/test_data/thrift_workspace/input/article.thrift b/pilota-build/test_data/thrift_workspace/input/article.thrift new file mode 100644 index 00000000..328bf5a5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/article.thrift @@ -0,0 +1,32 @@ +include "image.thrift" +include "author.thrift" +include "common.thrift" + +namespace rs article + +enum Status { + NORMAL = 0, + DELETED = 1, +} + +struct Article { + 1: required i64 id, + 2: required string title, + 3: required string content, + 4: required author.Author author, + 5: required Status status, + 6: required list images, + 7: required common.CommonData common_data, +} + +struct GetArticleRequest { + 1: required i64 id, +} + +struct GetArticleResponse { + 1: required Article article, +} + +service ArticleService { + GetArticleResponse GetArticle(1: GetArticleRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/author.thrift b/pilota-build/test_data/thrift_workspace/input/author.thrift new file mode 100644 index 00000000..9af3823e --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/author.thrift @@ -0,0 +1,24 @@ +include "image.thrift" +include "common.thrift" + +namespace rs author + +struct Author { + 1: required i64 id, + 2: required string username, + 3: required string email, + 4: required image.Image avatar, + 5: required common.CommonData common_data, +} + +struct GetAuthorRequest { + 1: required i64 id, +} + +struct GetAuthorResponse { + 1: required Author author, +} + +service AuthorService { + GetAuthorResponse GetAuthor(1: GetAuthorRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/cdn.thrift b/pilota-build/test_data/thrift_workspace/input/cdn.thrift new file mode 100644 index 00000000..c6847a3c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/cdn.thrift @@ -0,0 +1,9 @@ +include "common.thrift" + +namespace rs article.image.cdn + +struct CDN { + 1: required i64 id, + 2: required string url, + 3: required common.CommonData common_data, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/common.thrift b/pilota-build/test_data/thrift_workspace/input/common.thrift new file mode 100644 index 00000000..517116f1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/common.thrift @@ -0,0 +1,7 @@ +namespace rs common + +struct CommonData { + 1: required i64 id, + 2: required string name, + 3: required string description, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/input/image.thrift b/pilota-build/test_data/thrift_workspace/input/image.thrift new file mode 100644 index 00000000..b1d4ec86 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/input/image.thrift @@ -0,0 +1,23 @@ +include "common.thrift" +include "cdn.thrift" + +namespace rs article.image + +struct Image { + 1: required i64 id, + 2: required string url, + 3: required cdn.CDN cdn, + 4: required common.CommonData common_data, +} + +struct GetImageRequest { + 1: required i64 id, +} + +struct GetImageResponse { + 1: required Image image, +} + +service ImageService { + GetImageResponse GetImage(1: GetImageRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace/output/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/Cargo.toml new file mode 100644 index 00000000..f88e4700 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +members = [ + "article", + "author", "common", + "image", +] + +[workspace.dependencies] +anyhow = "1" +pilota = "*" +volo = "*" +volo-thrift = "*" diff --git a/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml new file mode 100644 index 00000000..0ef53902 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "article" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs new file mode 100644 index 00000000..5b353c3d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/src/gen.rs @@ -0,0 +1,1378 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq, Copy)] + #[repr(transparent)] + pub struct Status(i32); + + impl Status { + pub const NORMAL: Self = Self(0); + pub const DELETED: Self = Self(1); + + pub fn inner(&self) -> i32 { + self.0 + } + + pub fn to_string(&self) -> ::std::string::String { + match self { + Self(0) => ::std::string::String::from("NORMAL"), + Self(1) => ::std::string::String::from("DELETED"), + Self(val) => val.to_string(), + } + } + } + + impl ::std::convert::From for Status { + fn from(value: i32) -> Self { + Self(value) + } + } + + impl ::std::convert::From for i32 { + fn from(value: Status) -> i32 { + value.0 + } + } + + impl ::pilota::thrift::Message for Status { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_i32(self.inner())?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let value = __protocol.read_i32()?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err( + |err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + }, + )?) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let value = __protocol.read_i32().await?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err( + |err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + }, + )?) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.i32_len(self.inner()) + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ArticleServiceGetArticleArgsRecv { + pub req: GetArticleRequest, + } + impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ArticleServiceGetArticleResultSend { + #[derivative(Default)] + Ok(GetArticleResponse), + } + + impl ::pilota::thrift::Message for ArticleServiceGetArticleResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + })?; + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + }) + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetArticleResponse { + pub article: Article, + } + impl ::pilota::thrift::Message for GetArticleResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.article, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_1 = Some( +
::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + ), + ); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }) + __protocol.struct_field_len(Some(1), &self.article) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ArticleServiceGetArticleArgsSend { + pub req: GetArticleRequest, + } + impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetArticleRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetArticleRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub trait ArticleService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ArticleServiceGetArticleResultRecv { + #[derivative(Default)] + Ok(GetArticleResponse), + } + + impl ::pilota::thrift::Message for ArticleServiceGetArticleResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + })?; + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + }) + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Article { + pub id: i64, + + pub title: ::pilota::FastStr, + + pub content: ::pilota::FastStr, + + pub author: ::common::author::Author, + + pub status: Status, + + pub images: ::std::vec::Vec<::common::article::image::Image>, + + pub common_data: ::common::common::CommonData, + } + impl ::pilota::thrift::Message for Article { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Article" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.title).clone())?; + __protocol.write_faststr_field(3, (&self.content).clone())?; + __protocol.write_struct_field(4, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_i32_field(5, (&self.status).inner())?; + __protocol.write_list_field( + 6, + ::pilota::thrift::TType::Struct, + &&self.images, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_struct_field( + 7, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::common::article::image::Image> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr() + .offset(i as isize) + .write(::pilota::thrift::Message::decode(__protocol)?); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + Some(7) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_7 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Article` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::decode_async(__protocol).await?); + + },Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some({ + let list_ident = __protocol.read_list_begin().await?; + let mut val = Vec::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.push(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + }; + __protocol.read_list_end().await?; + val + }); + + },Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(<::common::common::CommonData as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Article` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + ), + ); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + ), + ); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + ), + ); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Article" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.title) + + __protocol.faststr_field_len(Some(3), &self.content) + + __protocol.struct_field_len(Some(4), &self.author) + + __protocol.i32_field_len(Some(5), (&self.status).inner()) + + __protocol.list_field_len( + Some(6), + ::pilota::thrift::TType::Struct, + &self.images, + |__protocol, el| __protocol.struct_len(el), + ) + + __protocol.struct_field_len(Some(7), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub mod image { + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod author { + pub use ::common::author::Author; + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use article::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/article/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml new file mode 100644 index 00000000..4933f648 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "author" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs new file mode 100644 index 00000000..d06fec3d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/src/gen.rs @@ -0,0 +1,915 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod author { + + pub trait AuthorService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum AuthorServiceGetAuthorResultRecv { + #[derivative(Default)] + Ok(GetAuthorResponse), + } + + impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + })?; + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + }) + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct AuthorServiceGetAuthorArgsRecv { + pub req: GetAuthorRequest, + } + impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum AuthorServiceGetAuthorResultSend { + #[derivative(Default)] + Ok(GetAuthorResponse), + } + + impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + })?; + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + }) + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetAuthorResponse { + pub author: ::common::author::Author, + } + impl ::pilota::thrift::Message for GetAuthorResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + ), + ); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }) + __protocol.struct_field_len(Some(1), &self.author) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct AuthorServiceGetAuthorArgsSend { + pub req: GetAuthorRequest, + } + impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetAuthorRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetAuthorRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub use ::common::author::Author; + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use author::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/author/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml new file mode 100644 index 00000000..206531f6 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/Cargo.toml @@ -0,0 +1,16 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "common" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs new file mode 100644 index 00000000..b7fcf21f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/src/gen.rs @@ -0,0 +1,1025 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Image { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub cdn: cdn::Cdn, + + pub common_data: super::super::common::CommonData, + } + impl ::pilota::thrift::Message for Image { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Image" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.cdn, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field( + 4, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(4) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Image` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Image` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Image" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.cdn) + + __protocol.struct_field_len(Some(4), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub mod cdn { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Cdn { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub common_data: super::super::super::common::CommonData, + } + impl ::pilota::thrift::Message for Cdn { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> + { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Cdn" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field( + 3, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol + .field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_3 = + Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Cdn` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Cdn` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size( + &self, + __protocol: &mut T, + ) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Cdn" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } + } + } + + pub mod author { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct Author { + pub id: i64, + + pub username: ::pilota::FastStr, + + pub email: ::pilota::FastStr, + + pub avatar: super::article::image::Image, + + pub common_data: super::common::CommonData, + } + impl ::pilota::thrift::Message for Author { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Author" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.username).clone())?; + __protocol.write_faststr_field(3, (&self.email).clone())?; + __protocol.write_struct_field(4, &self.avatar, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field( + 5, + &self.common_data, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) + if field_ident.field_type == ::pilota::thrift::TType::Struct => + { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Author` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Author` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + ), + ); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + ), + ); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Author" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.username) + + __protocol.faststr_field_len(Some(3), &self.email) + + __protocol.struct_field_len(Some(4), &self.avatar) + + __protocol.struct_field_len(Some(5), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } + + pub mod common { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct CommonData { + pub id: i64, + + pub name: ::pilota::FastStr, + + pub description: ::pilota::FastStr, + } + impl ::pilota::thrift::Message for CommonData { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "CommonData" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.name).clone())?; + __protocol.write_faststr_field(3, (&self.description).clone())?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) + if field_ident.field_type == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + Some(2) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_2 = Some(__protocol.read_faststr().await?); + } + Some(3) + if field_ident.field_type + == ::pilota::thrift::TType::Binary => + { + var_3 = Some(__protocol.read_faststr().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + ), + ); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + ), + ); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol + .struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "CommonData" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.name) + + __protocol.faststr_field_len(Some(3), &self.description) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + } +} diff --git a/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/common/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml b/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml new file mode 100644 index 00000000..ae1e8e17 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "image" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs new file mode 100644 index 00000000..c89387d2 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/src/gen.rs @@ -0,0 +1,955 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ImageServiceGetImageArgsRecv { + pub req: GetImageRequest, + } + impl ::pilota::thrift::Message for ImageServiceGetImageArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ImageServiceGetImageResultSend { + #[derivative(Default)] + Ok(GetImageResponse), + } + + impl ::pilota::thrift::Message for ImageServiceGetImageResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + })?; + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.write_struct_field( + 0, + value, + ::pilota::thrift::TType::Struct, + )?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + }) + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetImageResponse { + pub image: ::common::article::image::Image, + } + impl ::pilota::thrift::Message for GetImageResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field( + 1, + &self.image, + ::pilota::thrift::TType::Struct, + )?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + ), + ); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + ), + ); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }) + __protocol.struct_field_len(Some(1), &self.image) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct ImageServiceGetImageArgsSend { + pub req: GetImageRequest, + } + impl ::pilota::thrift::Message for ImageServiceGetImageArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::Struct => + { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + ), + ); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + pub struct GetImageRequest { + pub id: i64, + } + impl ::pilota::thrift::Message for GetImageRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) + if field_ident.field_type + == ::pilota::thrift::TType::I64 => + { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageRequest` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + ), + ); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub trait ImageService {} + #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] + #[derivative(Default)] + #[derive(Clone, PartialEq)] + pub enum ImageServiceGetImageResultRecv { + #[derivative(Default)] + Ok(GetImageResponse), + } + + impl ::pilota::thrift::Message for ImageServiceGetImageResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + })?; + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.write_struct_field( + 0, + value, + ::pilota::thrift::TType::Struct, + )?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result + { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result< + Self, + ::pilota::thrift::ThriftException, + >, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::decode_async(__protocol).await?; + + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message" + )); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + }) + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } + } + pub use ::common::article::image::Image; + pub mod cdn { + pub use ::common::article::image::cdn::Cdn; + } + } + } + + pub mod common { + pub use ::common::common::CommonData; + } + pub use article::image::*; +} diff --git a/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs b/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace/output/image/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift new file mode 100644 index 00000000..328bf5a5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/article.thrift @@ -0,0 +1,32 @@ +include "image.thrift" +include "author.thrift" +include "common.thrift" + +namespace rs article + +enum Status { + NORMAL = 0, + DELETED = 1, +} + +struct Article { + 1: required i64 id, + 2: required string title, + 3: required string content, + 4: required author.Author author, + 5: required Status status, + 6: required list images, + 7: required common.CommonData common_data, +} + +struct GetArticleRequest { + 1: required i64 id, +} + +struct GetArticleResponse { + 1: required Article article, +} + +service ArticleService { + GetArticleResponse GetArticle(1: GetArticleRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift new file mode 100644 index 00000000..9af3823e --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/author.thrift @@ -0,0 +1,24 @@ +include "image.thrift" +include "common.thrift" + +namespace rs author + +struct Author { + 1: required i64 id, + 2: required string username, + 3: required string email, + 4: required image.Image avatar, + 5: required common.CommonData common_data, +} + +struct GetAuthorRequest { + 1: required i64 id, +} + +struct GetAuthorResponse { + 1: required Author author, +} + +service AuthorService { + GetAuthorResponse GetAuthor(1: GetAuthorRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift new file mode 100644 index 00000000..c6847a3c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/cdn.thrift @@ -0,0 +1,9 @@ +include "common.thrift" + +namespace rs article.image.cdn + +struct CDN { + 1: required i64 id, + 2: required string url, + 3: required common.CommonData common_data, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift new file mode 100644 index 00000000..517116f1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/common.thrift @@ -0,0 +1,7 @@ +namespace rs common + +struct CommonData { + 1: required i64 id, + 2: required string name, + 3: required string description, +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift b/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift new file mode 100644 index 00000000..b1d4ec86 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/input/image.thrift @@ -0,0 +1,23 @@ +include "common.thrift" +include "cdn.thrift" + +namespace rs article.image + +struct Image { + 1: required i64 id, + 2: required string url, + 3: required cdn.CDN cdn, + 4: required common.CommonData common_data, +} + +struct GetImageRequest { + 1: required i64 id, +} + +struct GetImageResponse { + 1: required Image image, +} + +service ImageService { + GetImageResponse GetImage(1: GetImageRequest req), +} \ No newline at end of file diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml new file mode 100644 index 00000000..cf98ef15 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] +members = [ + "article", + "author", + "image", +] + +[workspace.dependencies] +anyhow = "1" +pilota = "*" +volo = "*" +volo-thrift = "*" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml new file mode 100644 index 00000000..0ef53902 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "article" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs new file mode 100644 index 00000000..f9bfba0b --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ArticleServiceGetArticleResultRecv { + #[derivative(Default)] + Ok(GetArticleResponse), +} + +impl ::pilota::thrift::Message for ArticleServiceGetArticleResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + })?; + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ArticleServiceGetArticleResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultRecv", + }) + match self { + ArticleServiceGetArticleResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs new file mode 100644 index 00000000..a84e3837 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_ArticleServiceGetArticleResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ArticleServiceGetArticleResultSend { + #[derivative(Default)] + Ok(GetArticleResponse), +} + +impl ::pilota::thrift::Message for ArticleServiceGetArticleResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + })?; + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ArticleServiceGetArticleResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleResultSend", + }) + match self { + ArticleServiceGetArticleResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs new file mode 100644 index 00000000..453a7996 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/enum_Status.rs @@ -0,0 +1,87 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq, Copy)] +#[repr(transparent)] +pub struct Status(i32); + +impl Status { + pub const NORMAL: Self = Self(0); + pub const DELETED: Self = Self(1); + + pub fn inner(&self) -> i32 { + self.0 + } + + pub fn to_string(&self) -> ::std::string::String { + match self { + Self(0) => ::std::string::String::from("NORMAL"), + Self(1) => ::std::string::String::from("DELETED"), + Self(val) => val.to_string(), + } + } +} + +impl ::std::convert::From for Status { + fn from(value: i32) -> Self { + Self(value) + } +} + +impl ::std::convert::From for i32 { + fn from(value: Status) -> i32 { + value.0 + } +} + +impl ::pilota::thrift::Message for Status { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_i32(self.inner())?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let value = __protocol.read_i32()?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + })?) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let value = __protocol.read_i32().await?; + ::std::result::Result::Ok(::std::convert::TryFrom::try_from(value).map_err(|err| { + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + format!("invalid enum value for Status, value: {}", value), + ) + })?) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.i32_len(self.inner()) + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs new file mode 100644 index 00000000..5ebac8bb --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/gen.rs @@ -0,0 +1,32 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + include!("enum_Status.rs"); + include!("message_ArticleServiceGetArticleArgsRecv.rs"); + include!("enum_ArticleServiceGetArticleResultSend.rs"); + include!("message_GetArticleResponse.rs"); + include!("message_ArticleServiceGetArticleArgsSend.rs"); + include!("message_GetArticleRequest.rs"); + include!("service_ArticleService.rs"); + include!("enum_ArticleServiceGetArticleResultRecv.rs"); + include!("message_Article.rs"); + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use article::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs new file mode 100644 index 00000000..29ad8d68 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Article.rs @@ -0,0 +1,342 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Article { + pub id: i64, + + pub title: ::pilota::FastStr, + + pub content: ::pilota::FastStr, + + pub author: ::common::author::Author, + + pub status: Status, + + pub images: ::std::vec::Vec<::common::article::image::Image>, + + pub common_data: ::common::common::CommonData, +} +impl ::pilota::thrift::Message for Article { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Article" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.title).clone())?; + __protocol.write_faststr_field(3, (&self.content).clone())?; + __protocol.write_struct_field(4, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_i32_field(5, (&self.status).inner())?; + __protocol.write_list_field( + 6, + ::pilota::thrift::TType::Struct, + &&self.images, + |__protocol, val| { + __protocol.write_struct(val)?; + ::std::result::Result::Ok(()) + }, + )?; + __protocol.write_struct_field(7, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some(unsafe { + let list_ident = __protocol.read_list_begin()?; + let mut val: Vec<::common::article::image::Image> = + Vec::with_capacity(list_ident.size); + for i in 0..list_ident.size { + val.as_mut_ptr() + .offset(i as isize) + .write(::pilota::thrift::Message::decode(__protocol)?); + } + val.set_len(list_ident.size); + __protocol.read_list_end()?; + val + }); + } + Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Article` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + let mut var_6 = None; + let mut var_7 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::I32 => { + var_5 = Some(::decode_async(__protocol).await?); + + },Some(6) if field_ident.field_type == ::pilota::thrift::TType::List => { + var_6 = Some({ + let list_ident = __protocol.read_list_begin().await?; + let mut val = Vec::with_capacity(list_ident.size); + for _ in 0..list_ident.size { + val.push(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + }; + __protocol.read_list_end().await?; + val + }); + + },Some(7) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_7 = Some(<::common::common::CommonData as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Article` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field title is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field content is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field status is required".to_string(), + )); + }; + let Some(var_6) = var_6 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field images is required".to_string(), + )); + }; + let Some(var_7) = var_7 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + title: var_2, + content: var_3, + author: var_4, + status: var_5, + images: var_6, + common_data: var_7, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Article" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.title) + + __protocol.faststr_field_len(Some(3), &self.content) + + __protocol.struct_field_len(Some(4), &self.author) + + __protocol.i32_field_len(Some(5), (&self.status).inner()) + + __protocol.list_field_len( + Some(6), + ::pilota::thrift::TType::Struct, + &self.images, + |__protocol, el| __protocol.struct_len(el), + ) + + __protocol.struct_field_len(Some(7), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs new file mode 100644 index 00000000..95339be0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsRecv.rs @@ -0,0 +1,148 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ArticleServiceGetArticleArgsRecv { + pub req: GetArticleRequest, +} +impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs new file mode 100644 index 00000000..c47c5388 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_ArticleServiceGetArticleArgsSend.rs @@ -0,0 +1,148 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ArticleServiceGetArticleArgsSend { + pub req: GetArticleRequest, +} +impl ::pilota::thrift::Message for ArticleServiceGetArticleArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ArticleServiceGetArticleArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ArticleServiceGetArticleArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Author.rs @@ -0,0 +1 @@ +pub use ::common::author::Author; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs new file mode 100644 index 00000000..f9892c38 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetArticleRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetArticleRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs new file mode 100644 index 00000000..9cc8d06f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_GetArticleResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetArticleResponse { + pub article: Article, +} +impl ::pilota::thrift::Message for GetArticleResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.article, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( +
::decode_async(__protocol) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetArticleResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field article is required".to_string(), + )); + }; + + let data = Self { article: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetArticleResponse", + }) + __protocol.struct_field_len(Some(1), &self.article) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs new file mode 100644 index 00000000..42e7df87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/article/src/service_ArticleService.rs @@ -0,0 +1,2 @@ + +pub trait ArticleService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml new file mode 100644 index 00000000..4933f648 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "author" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs new file mode 100644 index 00000000..81045cdb --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum AuthorServiceGetAuthorResultRecv { + #[derivative(Default)] + Ok(GetAuthorResponse), +} + +impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + })?; + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(AuthorServiceGetAuthorResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultRecv", + }) + match self { + AuthorServiceGetAuthorResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs new file mode 100644 index 00000000..37419a87 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/enum_AuthorServiceGetAuthorResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum AuthorServiceGetAuthorResultSend { + #[derivative(Default)] + Ok(GetAuthorResponse), +} + +impl ::pilota::thrift::Message for AuthorServiceGetAuthorResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + })?; + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(AuthorServiceGetAuthorResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorResultSend", + }) + match self { + AuthorServiceGetAuthorResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs new file mode 100644 index 00000000..68bcd655 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/gen.rs @@ -0,0 +1,30 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("service_AuthorService.rs"); + include!("enum_AuthorServiceGetAuthorResultRecv.rs"); + include!("message_AuthorServiceGetAuthorArgsRecv.rs"); + include!("enum_AuthorServiceGetAuthorResultSend.rs"); + include!("message_GetAuthorResponse.rs"); + include!("message_AuthorServiceGetAuthorArgsSend.rs"); + include!("message_GetAuthorRequest.rs"); + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use author::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs new file mode 100644 index 00000000..979682c3 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Author.rs @@ -0,0 +1 @@ +pub use ::common::author::Author; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs new file mode 100644 index 00000000..3757735f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsRecv.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct AuthorServiceGetAuthorArgsRecv { + pub req: GetAuthorRequest, +} +impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs new file mode 100644 index 00000000..f6eba41d --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_AuthorServiceGetAuthorArgsSend.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct AuthorServiceGetAuthorArgsSend { + pub req: GetAuthorRequest, +} +impl ::pilota::thrift::Message for AuthorServiceGetAuthorArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `AuthorServiceGetAuthorArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "AuthorServiceGetAuthorArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs new file mode 100644 index 00000000..354ce21c --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetAuthorRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetAuthorRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs new file mode 100644 index 00000000..ca4eb853 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_GetAuthorResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetAuthorResponse { + pub author: ::common::author::Author, +} +impl ::pilota::thrift::Message for GetAuthorResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.author, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(<::common::author::Author as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetAuthorResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field author is required".to_string(), + )); + }; + + let data = Self { author: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetAuthorResponse", + }) + __protocol.struct_field_len(Some(1), &self.author) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs new file mode 100644 index 00000000..9cbd928f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/author/src/service_AuthorService.rs @@ -0,0 +1,2 @@ + +pub trait AuthorService {} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml new file mode 100644 index 00000000..206531f6 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/Cargo.toml @@ -0,0 +1,16 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "common" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs new file mode 100644 index 00000000..26a817f0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/gen.rs @@ -0,0 +1,22 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod author { + include!("message_Author.rs"); + } + + pub mod common { + include!("message_CommonData.rs"); + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs new file mode 100644 index 00000000..a57b6372 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Author.rs @@ -0,0 +1,257 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Author { + pub id: i64, + + pub username: ::pilota::FastStr, + + pub email: ::pilota::FastStr, + + pub avatar: super::article::image::Image, + + pub common_data: super::common::CommonData, +} +impl ::pilota::thrift::Message for Author { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Author" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.username).clone())?; + __protocol.write_faststr_field(3, (&self.email).clone())?; + __protocol.write_struct_field(4, &self.avatar, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field(5, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Author` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + let mut var_5 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + },Some(5) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_5 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Author` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field username is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field email is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field avatar is required".to_string(), + )); + }; + let Some(var_5) = var_5 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + username: var_2, + email: var_3, + avatar: var_4, + common_data: var_5, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Author" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.username) + + __protocol.faststr_field_len(Some(3), &self.email) + + __protocol.struct_field_len(Some(4), &self.avatar) + + __protocol.struct_field_len(Some(5), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs new file mode 100644 index 00000000..8ece535f --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CDN.rs @@ -0,0 +1,205 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Cdn { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub common_data: super::super::super::common::CommonData, +} +impl ::pilota::thrift::Message for Cdn { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Cdn" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Cdn` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Cdn` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + common_data: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Cdn" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs new file mode 100644 index 00000000..6aa0cb18 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_CommonData.rs @@ -0,0 +1,202 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct CommonData { + pub id: i64, + + pub name: ::pilota::FastStr, + + pub description: ::pilota::FastStr, +} +impl ::pilota::thrift::Message for CommonData { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "CommonData" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.name).clone())?; + __protocol.write_faststr_field(3, (&self.description).clone())?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_3 = Some(__protocol.read_faststr().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `CommonData` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field name is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field description is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + name: var_2, + description: var_3, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "CommonData" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.name) + + __protocol.faststr_field_len(Some(3), &self.description) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs new file mode 100644 index 00000000..6ac83879 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/common/src/message_Image.rs @@ -0,0 +1,231 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct Image { + pub id: i64, + + pub url: ::pilota::FastStr, + + pub cdn: cdn::Cdn, + + pub common_data: super::super::common::CommonData, +} +impl ::pilota::thrift::Message for Image { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { name: "Image" }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_faststr_field(2, (&self.url).clone())?; + __protocol.write_struct_field(3, &self.cdn, ::pilota::thrift::TType::Struct)?; + __protocol.write_struct_field(4, &self.common_data, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr()?); + } + Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `Image` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + let mut var_2 = None; + let mut var_3 = None; + let mut var_4 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + + },Some(2) if field_ident.field_type == ::pilota::thrift::TType::Binary => { + var_2 = Some(__protocol.read_faststr().await?); + + },Some(3) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_3 = Some(::decode_async(__protocol).await?); + + },Some(4) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_4 = Some(::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `Image` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + let Some(var_2) = var_2 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field url is required".to_string(), + )); + }; + let Some(var_3) = var_3 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field cdn is required".to_string(), + )); + }; + let Some(var_4) = var_4 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field common_data is required".to_string(), + )); + }; + + let data = Self { + id: var_1, + url: var_2, + cdn: var_3, + common_data: var_4, + }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Image" }) + + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.faststr_field_len(Some(2), &self.url) + + __protocol.struct_field_len(Some(3), &self.cdn) + + __protocol.struct_field_len(Some(4), &self.common_data) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml b/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml new file mode 100644 index 00000000..ae1e8e17 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/Cargo.toml @@ -0,0 +1,19 @@ +[dependencies.anyhow] +workspace = true + +[dependencies.common] +path = "../common" + +[dependencies.pilota] +workspace = true + +[dependencies.volo] +workspace = true + +[dependencies.volo-thrift] +workspace = true + +[package] +edition = "2021" +name = "image" +version = "0.1.0" diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs new file mode 100644 index 00000000..b25d6dc0 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultRecv.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ImageServiceGetImageResultRecv { + #[derivative(Default)] + Ok(GetImageResponse), +} + +impl ::pilota::thrift::Message for ImageServiceGetImageResultRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + })?; + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ImageServiceGetImageResultRecv::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultRecv", + }) + match self { + ImageServiceGetImageResultRecv::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs new file mode 100644 index 00000000..8caa6563 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/enum_ImageServiceGetImageResultSend.rs @@ -0,0 +1,144 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] +#[derivative(Default)] +#[derive(Clone, PartialEq)] +pub enum ImageServiceGetImageResultSend { + #[derivative(Default)] + Ok(GetImageResponse), +} + +impl ::pilota::thrift::Message for ImageServiceGetImageResultSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + __protocol.write_struct_begin(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + })?; + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.write_struct_field(0, value, ::pilota::thrift::TType::Struct)?; + } + } + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + let mut ret = None; + __protocol.read_struct_begin()?; + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = ::pilota::thrift::Message::decode(__protocol)?; + __protocol.struct_len(&field_ident); + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + } + __protocol.read_field_end()?; + __protocol.read_struct_end()?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut ret = None; + __protocol.read_struct_begin().await?; + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + match field_ident.id { + Some(0) => { + if ret.is_none() { + let field_ident = + ::decode_async( + __protocol, + ) + .await?; + + ret = Some(ImageServiceGetImageResultSend::Ok(field_ident)); + } else { + return ::std::result::Result::Err( + ::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received multiple fields for union from remote Message", + ), + ); + } + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + } + __protocol.read_field_end().await?; + __protocol.read_struct_end().await?; + if let Some(ret) = ret { + ::std::result::Result::Ok(ret) + } else { + ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "received empty union from remote Message", + )) + } + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageResultSend", + }) + match self { + ImageServiceGetImageResultSend::Ok(ref value) => { + __protocol.struct_field_len(Some(0), value) + } + } + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs new file mode 100644 index 00000000..c0bb15b5 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/gen.rs @@ -0,0 +1,26 @@ +pub mod gen { + #![allow(warnings, clippy::all)] + + pub mod article { + + pub mod image { + include!("message_ImageServiceGetImageArgsRecv.rs"); + include!("enum_ImageServiceGetImageResultSend.rs"); + include!("message_GetImageResponse.rs"); + include!("message_ImageServiceGetImageArgsSend.rs"); + include!("message_GetImageRequest.rs"); + include!("service_ImageService.rs"); + include!("enum_ImageServiceGetImageResultRecv.rs"); + include!("message_Image.rs"); + + pub mod cdn { + include!("message_CDN.rs"); + } + } + } + + pub mod common { + include!("message_CommonData.rs"); + } + pub use article::image::*; +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs new file mode 100644 index 00000000..3a85e855 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/lib.rs @@ -0,0 +1,2 @@ +include!("gen.rs"); +pub use gen::*; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs new file mode 100644 index 00000000..0f1acce9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CDN.rs @@ -0,0 +1 @@ +pub use ::common::article::image::cdn::Cdn; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs new file mode 100644 index 00000000..501acfed --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_CommonData.rs @@ -0,0 +1 @@ +pub use ::common::common::CommonData; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs new file mode 100644 index 00000000..ab4b8bf1 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageRequest.rs @@ -0,0 +1,149 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetImageRequest { + pub id: i64, +} +impl ::pilota::thrift::Message for GetImageRequest { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_i64_field(1, *&self.id)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64()?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::I64 => { + var_1 = Some(__protocol.read_i64().await?); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageRequest` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field id is required".to_string(), + )); + }; + + let data = Self { id: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageRequest", + }) + __protocol.i64_field_len(Some(1), *&self.id) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs new file mode 100644 index 00000000..e8eb80e9 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_GetImageResponse.rs @@ -0,0 +1,152 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct GetImageResponse { + pub image: ::common::article::image::Image, +} +impl ::pilota::thrift::Message for GetImageResponse { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.image, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `GetImageResponse` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + )); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + + + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + + break; + } else { + + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(<::common::article::image::Image as ::pilota::thrift::Message>::decode_async(__protocol).await?); + + }, + _ => { + __protocol.skip(field_ident.field_type).await?; + + }, + } + + __protocol.read_field_end().await?; + + + }; + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + }.await { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `GetImageResponse` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field image is required".to_string(), + )); + }; + + let data = Self { image: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "GetImageResponse", + }) + __protocol.struct_field_len(Some(1), &self.image) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs new file mode 100644 index 00000000..3e028164 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_Image.rs @@ -0,0 +1 @@ +pub use ::common::article::image::Image; diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs new file mode 100644 index 00000000..e6b39933 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsRecv.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ImageServiceGetImageArgsRecv { + pub req: GetImageRequest, +} +impl ::pilota::thrift::Message for ImageServiceGetImageArgsRecv { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsRecv` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsRecv", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs new file mode 100644 index 00000000..34d817a7 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/message_ImageServiceGetImageArgsSend.rs @@ -0,0 +1,151 @@ +#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] +pub struct ImageServiceGetImageArgsSend { + pub req: GetImageRequest, +} +impl ::pilota::thrift::Message for ImageServiceGetImageArgsSend { + fn encode( + &self, + __protocol: &mut T, + ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { + #[allow(unused_imports)] + use ::pilota::thrift::TOutputProtocolExt; + let struct_ident = ::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }; + + __protocol.write_struct_begin(&struct_ident)?; + __protocol.write_struct_field(1, &self.req, ::pilota::thrift::TType::Struct)?; + __protocol.write_field_stop()?; + __protocol.write_struct_end()?; + ::std::result::Result::Ok(()) + } + + fn decode( + __protocol: &mut T, + ) -> ::std::result::Result { + #[allow(unused_imports)] + use ::pilota::{thrift::TLengthProtocolExt, Buf}; + + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin()?; + if let ::std::result::Result::Err(mut err) = (|| { + loop { + let field_ident = __protocol.read_field_begin()?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + __protocol.field_stop_len(); + break; + } else { + __protocol.field_begin_len(field_ident.field_type, field_ident.id); + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); + } + _ => { + __protocol.skip(field_ident.field_type)?; + } + } + + __protocol.read_field_end()?; + __protocol.field_end_len(); + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + })() { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!( + "decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", + field_id + )); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end()?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + } + + fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>( + __protocol: &'a mut T, + ) -> ::std::pin::Pin< + ::std::boxed::Box< + dyn ::std::future::Future< + Output = ::std::result::Result, + > + Send + + 'a, + >, + > { + ::std::boxed::Box::pin(async move { + let mut var_1 = None; + + let mut __pilota_decoding_field_id = None; + + __protocol.read_struct_begin().await?; + if let ::std::result::Result::Err(mut err) = async { + loop { + let field_ident = __protocol.read_field_begin().await?; + if field_ident.field_type == ::pilota::thrift::TType::Stop { + break; + } else { + } + __pilota_decoding_field_id = field_ident.id; + match field_ident.id { + Some(1) if field_ident.field_type == ::pilota::thrift::TType::Struct => { + var_1 = Some( + ::decode_async( + __protocol, + ) + .await?, + ); + } + _ => { + __protocol.skip(field_ident.field_type).await?; + } + } + + __protocol.read_field_end().await?; + } + ::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(()) + } + .await + { + if let Some(field_id) = __pilota_decoding_field_id { + err.prepend_msg(&format!("decode struct `ImageServiceGetImageArgsSend` field(#{}) failed, caused by: ", field_id)); + } + return ::std::result::Result::Err(err); + }; + __protocol.read_struct_end().await?; + + let Some(var_1) = var_1 else { + return ::std::result::Result::Err(::pilota::thrift::new_protocol_exception( + ::pilota::thrift::ProtocolExceptionKind::InvalidData, + "field req is required".to_string(), + )); + }; + + let data = Self { req: var_1 }; + ::std::result::Result::Ok(data) + }) + } + + fn size(&self, __protocol: &mut T) -> usize { + #[allow(unused_imports)] + use ::pilota::thrift::TLengthProtocolExt; + __protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { + name: "ImageServiceGetImageArgsSend", + }) + __protocol.struct_field_len(Some(1), &self.req) + + __protocol.field_stop_len() + + __protocol.struct_end_len() + } +} diff --git a/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs new file mode 100644 index 00000000..ae17ff16 --- /dev/null +++ b/pilota-build/test_data/thrift_workspace_with_split/output/image/src/service_ImageService.rs @@ -0,0 +1,2 @@ + +pub trait ImageService {}