Skip to content

Commit

Permalink
add workspace split generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
liujie.roger committed Oct 28, 2024
1 parent 9186d60 commit 6706960
Show file tree
Hide file tree
Showing 67 changed files with 5,776 additions and 15 deletions.
46 changes: 31 additions & 15 deletions tests/code-generation-workspace-split/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
[package]
name = "code-generation-workspace-split"
edition = "2021"
version = "0.0.0"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
bench = false
name = "gen"
test = false

[dependencies.pilota-build]
branch = "main"
git = "https://github.com/cloudwego/pilota"

[dependencies.volo-build]
workspace = true

[package]
edition = "2021"
name = "code-generation-workspace-split"
publish = false
version = "0.0.0"

[workspace]
members = []
members = [
"common",
"rpc_article",
"rpc_author",
"rpc_image",
]

[workspace.dependencies]
anyhow = "1"
async-trait = "0.1"
lazy_static = "1"
serde = "1"

pilota = "*"
volo = "*"
volo-build = "*"
volo-thrift = "*"
[workspace.dependencies.pilota]
branch = "main"
git = "https://github.com/cloudwego/pilota"

[dependencies.volo-build]
workspace = true
[workspace.dependencies.volo]
path = "../../volo"

[workspace.dependencies.volo-build]
path = "../../volo-build"

[workspace.dependencies.volo-thrift]
path = "../../volo-thrift"
28 changes: 28 additions & 0 deletions tests/code-generation-workspace-split/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[dependencies.anyhow]
workspace = true

[dependencies.async-trait]
workspace = true

[dependencies.lazy_static]
workspace = true

[dependencies.pilota]
workspace = true

[dependencies.serde]
workspace = true

[dependencies.volo]
workspace = true

[dependencies.volo-build]
workspace = true

[dependencies.volo-thrift]
workspace = true

[package]
edition = "2021"
name = "common"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
#[derive(
PartialOrd,
Hash,
Eq,
Ord,
Debug,
Default,
::pilota::serde::Serialize,
::pilota::serde::Deserialize,
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<T: ::pilota::thrift::TOutputProtocol>(
&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<T: ::pilota::thrift::TInputProtocol>(
__protocol: &mut T,
) -> ::std::result::Result<Self, ::pilota::thrift::ThriftException> {
#[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(<super::super::super::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 `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<T: ::pilota::thrift::TLengthProtocol>(&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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!("message_CDN.rs");
Loading

0 comments on commit 6706960

Please sign in to comment.