diff --git a/pilota-build/test_data/thrift/separator.rs b/pilota-build/test_data/thrift/separator.rs deleted file mode 100644 index 68d1256..0000000 --- a/pilota-build/test_data/thrift/separator.rs +++ /dev/null @@ -1,1001 +0,0 @@ -pub mod separator { - #![allow(warnings, clippy::all)] - - pub mod separator { - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] - pub struct MyInt32(pub i32); - - impl ::std::ops::Deref for MyInt32 { - type Target = i32; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl From for MyInt32 { - fn from(v: i32) -> Self { - Self(v) - } - } - - impl ::pilota::thrift::Message for MyInt32 { - fn encode( - &self, - __protocol: &mut T, - ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { - #[allow(unused_imports)] - use ::pilota::thrift::TOutputProtocolExt; - __protocol.write_i32(*(&**self))?; - ::std::result::Result::Ok(()) - } - - fn decode( - __protocol: &mut T, - ) -> ::std::result::Result { - #[allow(unused_imports)] - use ::pilota::{thrift::TLengthProtocolExt, Buf}; - ::std::result::Result::Ok(MyInt32(__protocol.read_i32()?)) - } - - 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 { - ::std::result::Result::Ok(MyInt32(__protocol.read_i32().await?)) - }) - } - - fn size(&self, __protocol: &mut T) -> usize { - #[allow(unused_imports)] - use ::pilota::thrift::TLengthProtocolExt; - __protocol.i32_len(*&**self) - } - } - pub trait Service {} - #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] - #[derivative(Default)] - #[derive(Clone, PartialEq)] - pub enum ServiceTestEpisodeResultRecv { - #[derivative(Default)] - Ok(MyStruct), - } - - impl ::pilota::thrift::Message for ServiceTestEpisodeResultRecv { - 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: "ServiceTestEpisodeResultRecv", - })?; - match self { - ServiceTestEpisodeResultRecv::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(ServiceTestEpisodeResultRecv::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(ServiceTestEpisodeResultRecv::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: "ServiceTestEpisodeResultRecv", - }) + match self { - ServiceTestEpisodeResultRecv::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 TypedefTestStruct { - pub field_my_int32: ::std::option::Option, - - pub field_my_string: ::std::option::Option, - - pub field_int32: ::std::option::Option, - - pub field_string: ::std::option::Option<::pilota::FastStr>, - } - impl ::pilota::thrift::Message for TypedefTestStruct { - 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: "TypedefTestStruct", - }; - - __protocol.write_struct_begin(&struct_ident)?; - if let Some(value) = self.field_my_int32.as_ref() { - __protocol.write_struct_field(1, value, ::pilota::thrift::TType::I32)?; - } - if let Some(value) = self.field_my_string.as_ref() { - __protocol.write_struct_field(2, value, ::pilota::thrift::TType::Binary)?; - } - if let Some(value) = self.field_int32.as_ref() { - __protocol.write_i32_field(3, *value)?; - } - if let Some(value) = self.field_string.as_ref() { - __protocol.write_faststr_field(4, (value).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 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::I32 => { - var_1 = Some(::pilota::thrift::Message::decode(__protocol)?); - } - Some(2) - if field_ident.field_type == ::pilota::thrift::TType::Binary => - { - var_2 = Some(::pilota::thrift::Message::decode(__protocol)?); - } - Some(3) if field_ident.field_type == ::pilota::thrift::TType::I32 => { - var_3 = Some(__protocol.read_i32()?); - } - Some(4) - if field_ident.field_type == ::pilota::thrift::TType::Binary => - { - var_4 = 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 `TypedefTestStruct` field(#{}) failed, caused by: ", - field_id - )); - } - return ::std::result::Result::Err(err); - }; - __protocol.read_struct_end()?; - - let data = Self { - field_my_int32: var_1, - field_my_string: var_2, - field_int32: var_3, - field_string: 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::I32 => - { - var_1 = Some( - ::decode_async( - __protocol, - ) - .await?, - ); - } - Some(2) - if field_ident.field_type - == ::pilota::thrift::TType::Binary => - { - var_2 = Some( - ::decode_async( - __protocol, - ) - .await?, - ); - } - Some(3) - if field_ident.field_type == ::pilota::thrift::TType::I32 => - { - var_3 = Some(__protocol.read_i32().await?); - } - Some(4) - if field_ident.field_type - == ::pilota::thrift::TType::Binary => - { - var_4 = 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 `TypedefTestStruct` field(#{}) failed, caused by: ", - field_id - )); - } - return ::std::result::Result::Err(err); - }; - __protocol.read_struct_end().await?; - - let data = Self { - field_my_int32: var_1, - field_my_string: var_2, - field_int32: var_3, - field_string: 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: "TypedefTestStruct", - }) + self - .field_my_int32 - .as_ref() - .map_or(0, |value| __protocol.struct_field_len(Some(1), value)) - + self - .field_my_string - .as_ref() - .map_or(0, |value| __protocol.struct_field_len(Some(2), value)) - + self - .field_int32 - .as_ref() - .map_or(0, |value| __protocol.i32_field_len(Some(3), *value)) - + self - .field_string - .as_ref() - .map_or(0, |value| __protocol.faststr_field_len(Some(4), value)) - + __protocol.field_stop_len() - + __protocol.struct_end_len() - } - } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] - pub struct ServiceTestEpisodeArgsRecv { - pub arg: MyStruct, - } - impl ::pilota::thrift::Message for ServiceTestEpisodeArgsRecv { - 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: "ServiceTestEpisodeArgsRecv", - }; - - __protocol.write_struct_begin(&struct_ident)?; - __protocol.write_struct_field(1, &self.arg, ::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 `ServiceTestEpisodeArgsRecv` 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 arg is required".to_string(), - )); - }; - - let data = Self { arg: 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 `ServiceTestEpisodeArgsRecv` 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 arg is required".to_string(), - ), - ); - }; - - let data = Self { arg: 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: "ServiceTestEpisodeArgsRecv", - }) + __protocol.struct_field_len(Some(1), &self.arg) - + __protocol.field_stop_len() - + __protocol.struct_end_len() - } - } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] - #[derivative(Default)] - #[derive(Clone, PartialEq)] - pub enum ServiceTestEpisodeResultSend { - #[derivative(Default)] - Ok(MyStruct), - } - - impl ::pilota::thrift::Message for ServiceTestEpisodeResultSend { - 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: "ServiceTestEpisodeResultSend", - })?; - match self { - ServiceTestEpisodeResultSend::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(ServiceTestEpisodeResultSend::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(ServiceTestEpisodeResultSend::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: "ServiceTestEpisodeResultSend", - }) + match self { - ServiceTestEpisodeResultSend::Ok(ref value) => { - __protocol.struct_field_len(Some(0), value) - } - } + __protocol.field_stop_len() - + __protocol.struct_end_len() - } - } - pub const TEST_LIST: [&'static str; 2] = ["hello", "world"]; - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] - pub struct MyString(pub ::pilota::FastStr); - - impl ::std::ops::Deref for MyString { - type Target = ::pilota::FastStr; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl From<::pilota::FastStr> for MyString { - fn from(v: ::pilota::FastStr) -> Self { - Self(v) - } - } - - impl ::pilota::thrift::Message for MyString { - fn encode( - &self, - __protocol: &mut T, - ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { - #[allow(unused_imports)] - use ::pilota::thrift::TOutputProtocolExt; - __protocol.write_faststr((&**self).clone())?; - ::std::result::Result::Ok(()) - } - - fn decode( - __protocol: &mut T, - ) -> ::std::result::Result { - #[allow(unused_imports)] - use ::pilota::{thrift::TLengthProtocolExt, Buf}; - ::std::result::Result::Ok(MyString(__protocol.read_faststr()?)) - } - - 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 { - ::std::result::Result::Ok(MyString(__protocol.read_faststr().await?)) - }) - } - - fn size(&self, __protocol: &mut T) -> usize { - #[allow(unused_imports)] - use ::pilota::thrift::TLengthProtocolExt; - __protocol.faststr_len(&**self) - } - } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] - pub struct ServiceTestEpisodeArgsSend { - pub arg: MyStruct, - } - impl ::pilota::thrift::Message for ServiceTestEpisodeArgsSend { - 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: "ServiceTestEpisodeArgsSend", - }; - - __protocol.write_struct_begin(&struct_ident)?; - __protocol.write_struct_field(1, &self.arg, ::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 `ServiceTestEpisodeArgsSend` 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 arg is required".to_string(), - )); - }; - - let data = Self { arg: 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 `ServiceTestEpisodeArgsSend` 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 arg is required".to_string(), - ), - ); - }; - - let data = Self { arg: 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: "ServiceTestEpisodeArgsSend", - }) + __protocol.struct_field_len(Some(1), &self.arg) - + __protocol.field_stop_len() - + __protocol.struct_end_len() - } - } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] - pub struct MyStruct(pub TypedefTestStruct); - - impl ::std::ops::Deref for MyStruct { - type Target = TypedefTestStruct; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl From for MyStruct { - fn from(v: TypedefTestStruct) -> Self { - Self(v) - } - } - - impl ::pilota::thrift::Message for MyStruct { - fn encode( - &self, - __protocol: &mut T, - ) -> ::std::result::Result<(), ::pilota::thrift::ThriftException> { - #[allow(unused_imports)] - use ::pilota::thrift::TOutputProtocolExt; - __protocol.write_struct((&**self))?; - ::std::result::Result::Ok(()) - } - - fn decode( - __protocol: &mut T, - ) -> ::std::result::Result { - #[allow(unused_imports)] - use ::pilota::{thrift::TLengthProtocolExt, Buf}; - ::std::result::Result::Ok(MyStruct(::pilota::thrift::Message::decode(__protocol)?)) - } - - 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 { - ::std::result::Result::Ok(MyStruct( - ::decode_async(__protocol) - .await?, - )) - }) - } - - fn size(&self, __protocol: &mut T) -> usize { - #[allow(unused_imports)] - use ::pilota::thrift::TLengthProtocolExt; - __protocol.struct_len(&**self) - } - } - } -} diff --git a/pilota-build/test_data/thrift/separator.thrift b/pilota-build/test_data/thrift/separator.thrift deleted file mode 100644 index e3a0c06..0000000 --- a/pilota-build/test_data/thrift/separator.thrift +++ /dev/null @@ -1,20 +0,0 @@ -typedef i32 MyInt32 -typedef string MyString; - -struct TypedefTestStruct { - 1: MyInt32 field_MyInt32; - 2: MyString field_MyString; - 3: i32 field_Int32; - 4: string field_String; -}; - -typedef TypedefTestStruct MyStruct, - -const list TEST_LIST = [ - "hello", - "world", -]; - -service Service { - MyStruct testEpisode(1:MyStruct arg) -}, \ No newline at end of file diff --git a/pilota-thrift-parser/src/parser/thrift.rs b/pilota-thrift-parser/src/parser/thrift.rs index 8389dc4..edbf6b9 100644 --- a/pilota-thrift-parser/src/parser/thrift.rs +++ b/pilota-thrift-parser/src/parser/thrift.rs @@ -152,4 +152,31 @@ mod tests { "#; let (_remain, _res) = File::parse(body).unwrap(); } + + #[test] + fn test_separator() { + let body = r#"typedef i32 MyInt32 +typedef string MyString; + +struct TypedefTestStruct { + 1: MyInt32 field_MyInt32; + 2: MyString field_MyString; + 3: i32 field_Int32; + 4: string field_String; +}; + +typedef TypedefTestStruct MyStruct, + +const list TEST_LIST = [ + "hello", + "world", +]; + +service Service { + MyStruct testEpisode(1:MyStruct arg) +},"#; + let (remain, res) = File::parse(body).unwrap(); + assert!(remain.is_empty()); + assert_eq!(res.items.len(), 6); + } }