urlyy commented on PR #2724:
URL: https://github.com/apache/fory/pull/2724#issuecomment-3382113992
now read_compatible is like:
```
fn fory_read_compatible(
context: &mut fory_core::resolver::context::ReadContext,
) -> Result<Self, fory_core::error::Error> {
let remote_type_id = context.reader.read_varuint32();
let meta_index = context.reader.read_varuint32();
let meta = context.get_meta(meta_index as usize);
let fields = {
let meta = context.get_meta(meta_index as usize);
meta.get_field_infos().clone()
};
let mut _c1: Option<Vec<i16>> = None;
let mut _c2: Option<Vec<String>> = None;
let mut _c3: Option<String> = None;
let mut _c4: Option<HashMap<String, String>> = None;
let local_type_def = context
.get_fory()
.get_type_resolver()
.get_type_info(std::any::TypeId::of::<Self>())
.get_type_def();
let high_bytes = &local_type_def[..8];
let local_type_hash =
i64::from_le_bytes(high_bytes.try_into().unwrap());
if meta.get_hash() == local_type_hash {
// fast_path
let field_names = <Self as
fory_core::serializer::StructSerializer>::fory_get_sorted_field_names(
context.get_fory(),
);
let field_name = 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 = 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)?,
);
}
....
} else {
// normal compatible logic
for field in fields.iter() {
....
}
}
```
--
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]