urlyy commented on code in PR #2815:
URL: https://github.com/apache/fory/pull/2815#discussion_r2454498912
##########
rust/fory-core/src/resolver/type_resolver.rs:
##########
@@ -816,4 +875,51 @@ impl TypeResolver {
pub(crate) fn set_compatible(&mut self, compatible: bool) {
self.compatible = compatible;
}
+
+ pub fn get_actual_type_id<T: 'static + Serializer + ForyDefault>(&self) ->
Result<u32, Error> {
+ let rs_type_id = std::any::TypeId::of::<T>();
+ if let Some(type_id) = self.actual_type_id_map.get(&rs_type_id) {
+ Ok(*type_id)
+ } else {
+ T::fory_get_type_id(self)
+ }
+ }
+
+ pub fn build(&self) -> Self {
+ Self {
+ type_info_map_by_id: self.type_info_map_by_id.clone(),
+ type_info_map: self.type_info_map.clone(),
+ type_info_map_by_name: self.type_info_map_by_name.clone(),
+ type_info_map_by_ms_name: self.type_info_map_by_ms_name.clone(),
+ type_id_index: self.type_id_index.clone(),
+ compatible: self.compatible,
+ actual_type_id_map: Default::default(),
+ registry: Default::default(),
+ once: Once::new(),
+ finalize_result: Default::default(),
+ }
+ }
+
+ pub(crate) fn finalize_registration(&mut self) -> Result<(), Error> {
Review Comment:
Fory::serialize里做了get_or_init,里面不能返回Err,所以拆成两部分,build()的clone操作放在get_or_init里面防止多次调用,finalize_registration是返回Result,通过once保证只调用一次写。
--
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]