urlyy commented on PR #2724:
URL: https://github.com/apache/fory/pull/2724#issuecomment-3381580541
Notice: `fory_read_data` is only called by `fory_read`, and `fory_read` is
only called in `consistent` mode.
here is a demo:
```rust
use std::collections::HashMap;
use fory_core::fory::Fory;
use fory_derive::ForyObject;
// RUSTFLAGS="-Awarnings" cargo expand -p fory-tests --test test_unroll
#[test]
fn complex_struct() {
#[derive(ForyObject, Debug, PartialEq)]
struct Person {
c1: Vec<i16>,
c2: Vec<String>,
c3: String,
c4: HashMap<String, String>,
}
let mut fory = Fory::default();
fory.register::<Person>(102);
let person = Person::default();
let bytes = fory.serialize(&person);
fory.deserialize::<Person>(bytes.as_slice()).unwrap();
}
```
expanded code in fory_read_data:
```rust
let sorted_field_names = <Self as
fory_core::serializer::StructSerializer>::fory_get_sorted_field_names(
context.get_fory(),
);
let field_name = sorted_field_names.get(0).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
_c1 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<i16>,
>(context, true, skip_ref_flag, false)?,
);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
_c2 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<String>,
>(context, true, skip_ref_flag, false)?,
);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
_c3 = Some(
fory_core::serializer::read_ref_info_data::<
String,
>(context, true, skip_ref_flag, false)?,
);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
_c4 = Some(
fory_core::serializer::read_ref_info_data::<
HashMap<String, String>,
>(context, true, skip_ref_flag, false)?,
);
}
_ => ::core::panicking::panic("internal error: entered unreachable code"),
}
let field_name = sorted_field_names.get(1).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
_c1 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<i16>,
>(context, true, skip_ref_flag, false)?,
);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
_c2 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<String>,
>(context, true, skip_ref_flag, false)?,
);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
_c3 = Some(
fory_core::serializer::read_ref_info_data::<
String,
>(context, true, skip_ref_flag, false)?,
);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
_c4 = Some(
fory_core::serializer::read_ref_info_data::<
HashMap<String, String>,
>(context, true, skip_ref_flag, false)?,
);
}
_ => ::core::panicking::panic("internal error: entered unreachable code"),
}
let field_name = sorted_field_names.get(2).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
_c1 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<i16>,
>(context, true, skip_ref_flag, false)?,
);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
_c2 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<String>,
>(context, true, skip_ref_flag, false)?,
);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
_c3 = Some(
fory_core::serializer::read_ref_info_data::<
String,
>(context, true, skip_ref_flag, false)?,
);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
_c4 = Some(
fory_core::serializer::read_ref_info_data::<
HashMap<String, String>,
>(context, true, skip_ref_flag, false)?,
);
}
_ => ::core::panicking::panic("internal error: entered unreachable code"),
}
let field_name = sorted_field_names.get(3).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
_c1 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<i16>,
>(context, true, skip_ref_flag, false)?,
);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
_c2 = Some(
fory_core::serializer::read_ref_info_data::<
Vec<String>,
>(context, true, skip_ref_flag, false)?,
);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
_c3 = Some(
fory_core::serializer::read_ref_info_data::<
String,
>(context, true, skip_ref_flag, false)?,
);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
_c4 = Some(
fory_core::serializer::read_ref_info_data::<
HashMap<String, String>,
>(context, true, skip_ref_flag, false)?,
);
}
_ => ::core::panicking::panic("internal error: entered unreachable code"),
}
Ok(Self {
c1: _c1.unwrap_or_default(),
c2: _c2.unwrap_or_default(),
c3: _c3.unwrap_or_default(),
c4: _c4.unwrap_or_default(),
})
```
expanded code in fory_write_data:
```rust
let sorted_field_names = <Self as
fory_core::serializer::StructSerializer>::fory_get_sorted_field_names(
context.get_fory(),
);
let field_name = sorted_field_names.get(0).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<i16>,
>(&self.c1, context, true, skip_ref_flag, false);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<String>,
>(&self.c2, context, true, skip_ref_flag, false);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
String,
>(&self.c3, context, true, skip_ref_flag, false);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
HashMap<String, String>,
>(&self.c4, context, true, skip_ref_flag, false);
}
_ => ::core::panicking::panic("internal error: entered unreachable
code"),
}
let field_name = sorted_field_names.get(1).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<i16>,
>(&self.c1, context, true, skip_ref_flag, false);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<String>,
>(&self.c2, context, true, skip_ref_flag, false);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
String,
>(&self.c3, context, true, skip_ref_flag, false);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
HashMap<String, String>,
>(&self.c4, context, true, skip_ref_flag, false);
}
_ => ::core::panicking::panic("internal error: entered unreachable
code"),
}
let field_name = sorted_field_names.get(2).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<i16>,
>(&self.c1, context, true, skip_ref_flag, false);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<String>,
>(&self.c2, context, true, skip_ref_flag, false);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
String,
>(&self.c3, context, true, skip_ref_flag, false);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
HashMap<String, String>,
>(&self.c4, context, true, skip_ref_flag, false);
}
_ => ::core::panicking::panic("internal error: entered unreachable
code"),
}
let field_name = sorted_field_names.get(3).unwrap();
match field_name.as_str() {
"c1" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<i16>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<i16>,
>(&self.c1, context, true, skip_ref_flag, false);
}
"c2" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
Vec<String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
Vec<String>,
>(&self.c2, context, true, skip_ref_flag, false);
}
"c3" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
String,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
String,
>(&self.c3, context, true, skip_ref_flag, false);
}
"c4" => {
let skip_ref_flag = fory_core::serializer::get_skip_ref_flag::<
HashMap<String, String>,
>(context.get_fory());
fory_core::serializer::write_ref_info_data::<
HashMap<String, String>,
>(&self.c4, context, true, skip_ref_flag, false);
}
_ => ::core::panicking::panic("internal error: entered unreachable
code"),
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]