Skip to content

Commit

Permalink
fix(pilota-build): use absolute path for generated Vec (#296)
Browse files Browse the repository at this point in the history
Signed-off-by: Millione <[email protected]>
  • Loading branch information
Millione authored Jan 8, 2025
1 parent 34df6a0 commit 29dc691
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pilota-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pilota-build"
version = "0.11.28"
version = "0.11.29"
edition = "2021"
description = "Compile thrift and protobuf idl into rust code at compile-time."
documentation = "https://docs.rs/pilota-build"
Expand Down
4 changes: 2 additions & 2 deletions pilota-build/src/codegen/thrift/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl ThriftBackend {
format! {
r#"unsafe {{
let list_ident = {read_list_begin};
let mut val: Vec<{ty_rust_name}> = Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<{ty_rust_name}> = ::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {{
val.as_mut_ptr().offset(i as isize).write({read_el});
}};
Expand All @@ -411,7 +411,7 @@ impl ThriftBackend {
format! {
r#"{{
let list_ident = {read_list_begin};
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {{
val.push({read_el});
}};
Expand Down
157 changes: 95 additions & 62 deletions pilota-build/test_data/thrift/apache.rs

Large diffs are not rendered by default.

131 changes: 125 additions & 6 deletions pilota-build/test_data/thrift/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ pub mod btree {
for _ in 0..map_ident.size {
val.insert(__protocol.read_i32()?, unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<::std::sync::Arc<A>> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<::std::sync::Arc<A>> =
::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr().offset(i as isize).write(
::std::sync::Arc::new(
Expand Down Expand Up @@ -433,12 +433,12 @@ pub mod btree {
val.insert(
unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<
let mut val: ::std::vec::Vec<
::std::collections::BTreeMap<
::std::collections::BTreeSet<i32>,
i32,
>,
> = Vec::with_capacity(list_ident.size);
> = ::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr().offset(i as isize).write({
let map_ident = __protocol.read_map_begin()?;
Expand Down Expand Up @@ -560,7 +560,7 @@ pub mod btree {
for _ in 0..map_ident.size {
val.insert(__protocol.read_i32().await?, {
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push(::std::sync::Arc::new(<A as ::pilota::thrift::Message>::decode_async(__protocol).await?));
};
Expand Down Expand Up @@ -588,7 +588,7 @@ pub mod btree {
for _ in 0..map_ident.size {
val.insert({
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push({
let map_ident = __protocol.read_map_begin().await?;
Expand Down Expand Up @@ -736,6 +736,125 @@ pub mod btree {
+ __protocol.struct_end_len()
}
}
#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)]
pub struct Vec {}
impl ::pilota::thrift::Message for Vec {
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: "Vec" };

__protocol.write_struct_begin(&struct_ident)?;

__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 __pilota_decoding_field_id = None;

__protocol.read_struct_begin()?;
if let ::std::result::Result::Err(mut err) = (|| {
loop {
let field_ident = __protocol.read_field_begin()?;
if field_ident.field_type == ::pilota::thrift::TType::Stop {
__protocol.field_stop_len();
break;
} else {
__protocol.field_begin_len(field_ident.field_type, field_ident.id);
}
__pilota_decoding_field_id = field_ident.id;
match field_ident.id {
_ => {
__protocol.skip(field_ident.field_type)?;
}
}

__protocol.read_field_end()?;
__protocol.field_end_len();
}
::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(())
})() {
if let Some(field_id) = __pilota_decoding_field_id {
err.prepend_msg(&format!(
"decode struct `Vec` field(#{}) failed, caused by: ",
field_id
));
}
return ::std::result::Result::Err(err);
};
__protocol.read_struct_end()?;

let data = Self {};
::std::result::Result::Ok(data)
}

fn decode_async<'a, T: ::pilota::thrift::TAsyncInputProtocol>(
__protocol: &'a mut T,
) -> ::std::pin::Pin<
::std::boxed::Box<
dyn ::std::future::Future<
Output = ::std::result::Result<Self, ::pilota::thrift::ThriftException>,
> + Send
+ 'a,
>,
> {
::std::boxed::Box::pin(async move {
let mut __pilota_decoding_field_id = None;

__protocol.read_struct_begin().await?;
if let ::std::result::Result::Err(mut err) = async {
loop {
let field_ident = __protocol.read_field_begin().await?;
if field_ident.field_type == ::pilota::thrift::TType::Stop {
break;
} else {
}
__pilota_decoding_field_id = field_ident.id;
match field_ident.id {
_ => {
__protocol.skip(field_ident.field_type).await?;
}
}

__protocol.read_field_end().await?;
}
::std::result::Result::Ok::<_, ::pilota::thrift::ThriftException>(())
}
.await
{
if let Some(field_id) = __pilota_decoding_field_id {
err.prepend_msg(&format!(
"decode struct `Vec` field(#{}) failed, caused by: ",
field_id
));
}
return ::std::result::Result::Err(err);
};
__protocol.read_struct_end().await?;

let data = Self {};
::std::result::Result::Ok(data)
})
}

fn size<T: ::pilota::thrift::TLengthProtocol>(&self, __protocol: &mut T) -> usize {
#[allow(unused_imports)]
use ::pilota::thrift::TLengthProtocolExt;
__protocol.struct_begin_len(&::pilota::thrift::TStructIdentifier { name: "Vec" })
+ __protocol.field_stop_len()
+ __protocol.struct_end_len()
}
}
pub static TEST_MAP_LIST: ::std::sync::LazyLock<
::std::collections::BTreeMap<i32, ::std::vec::Vec<&'static str>>,
> = ::std::sync::LazyLock::new(|| {
Expand Down
6 changes: 5 additions & 1 deletion pilota-build/test_data/thrift/btree.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ const map<Index, string> TEST_MAP = {
Index.B: "world",
}(pilota.rust_type = "btree")

typedef map<set<i32>, string> TypeA(pilota.rust_type = "btree")
typedef map<set<i32>, string> TypeA(pilota.rust_type = "btree")

struct Vec {

}
12 changes: 6 additions & 6 deletions pilota-build/test_data/thrift/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ pub mod normal {
Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_3 = Some(unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<SubMessage> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<SubMessage> =
::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr()
.offset(i as isize)
Expand Down Expand Up @@ -519,7 +519,7 @@ pub mod normal {
},Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_3 = Some({
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push(<SubMessage as ::pilota::thrift::Message>::decode_async(__protocol).await?);
};
Expand Down Expand Up @@ -2299,8 +2299,8 @@ pub mod normal {
Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_3 = Some(unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<SubMessage> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<SubMessage> =
::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr()
.offset(i as isize)
Expand Down Expand Up @@ -2379,7 +2379,7 @@ pub mod normal {
},Some(3) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_3 = Some({
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push(<SubMessage as ::pilota::thrift::Message>::decode_async(__protocol).await?);
};
Expand Down
19 changes: 10 additions & 9 deletions pilota-build/test_data/thrift/wrapper_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,14 @@ pub mod wrapper_arc {
Some(2) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_2 = Some(unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<::std::vec::Vec<::std::sync::Arc<A>>> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<
::std::vec::Vec<::std::sync::Arc<A>>,
> = ::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr().offset(i as isize).write(unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<::std::sync::Arc<A>> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<::std::sync::Arc<A>> =
::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr().offset(i as isize).write(
::std::sync::Arc::new(
Expand All @@ -695,8 +696,8 @@ pub mod wrapper_arc {
for _ in 0..map_ident.size {
val.insert(__protocol.read_i32()?, unsafe {
let list_ident = __protocol.read_list_begin()?;
let mut val: Vec<::std::sync::Arc<A>> =
Vec::with_capacity(list_ident.size);
let mut val: ::std::vec::Vec<::std::sync::Arc<A>> =
::std::vec::Vec::with_capacity(list_ident.size);
for i in 0..list_ident.size {
val.as_mut_ptr().offset(i as isize).write(
::std::sync::Arc::new(
Expand Down Expand Up @@ -799,11 +800,11 @@ pub mod wrapper_arc {
},Some(2) if field_ident.field_type == ::pilota::thrift::TType::List => {
var_2 = Some({
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push({
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push(::std::sync::Arc::new(<A as ::pilota::thrift::Message>::decode_async(__protocol).await?));
};
Expand All @@ -822,7 +823,7 @@ pub mod wrapper_arc {
for _ in 0..map_ident.size {
val.insert(__protocol.read_i32().await?, {
let list_ident = __protocol.read_list_begin().await?;
let mut val = Vec::with_capacity(list_ident.size);
let mut val = ::std::vec::Vec::with_capacity(list_ident.size);
for _ in 0..list_ident.size {
val.push(::std::sync::Arc::new(<A as ::pilota::thrift::Message>::decode_async(__protocol).await?));
};
Expand Down
Loading

0 comments on commit 29dc691

Please sign in to comment.