chaokunyang commented on code in PR #2492:
URL: https://github.com/apache/fory/pull/2492#discussion_r2298180861


##########
rust/fory-core/src/resolver/type_resolver.rs:
##########
@@ -69,19 +71,75 @@ impl ClassInfo {
     }
 }
 
-#[derive(Default)]
-pub struct ClassResolver {
+pub struct TypeResolver {
     serialize_map: HashMap<u32, Harness>,
     type_id_map: HashMap<TypeId, u32>,
-    class_info_map: HashMap<TypeId, ClassInfo>,
+    type_info_map: HashMap<TypeId, TypeInfo>,
+}
+macro_rules! register_harness {
+    ($ty:ty, $id:expr, $map:expr) => {{
+        fn serializer(this: &dyn std::any::Any, context: &mut WriteContext) {
+            let this = this.downcast_ref::<$ty>();
+            match this {
+                Some(v) => <$ty>::serialize(v, context),
+                None => todo!(""),
+            }
+        }
+
+        fn deserializer(context: &mut ReadContext) -> Result<Box<dyn 
std::any::Any>, Error> {
+            match <$ty>::deserialize(context) {
+                Ok(v) => Ok(Box::new(v)),
+                Err(e) => Err(e),
+            }
+        }
+
+        $map.insert($id as u32, Harness::new(serializer, deserializer));
+    }};
+}
+
+impl Default for TypeResolver {
+    fn default() -> Self {
+        let mut serialize_map = HashMap::new();
+
+        register_harness!(bool, FieldType::BOOL, serialize_map);
+        register_harness!(i8, FieldType::INT8, serialize_map);
+        register_harness!(i16, FieldType::INT16, serialize_map);
+        register_harness!(i32, FieldType::INT32, serialize_map);
+        register_harness!(i64, FieldType::INT64, serialize_map);
+        register_harness!(f32, FieldType::FLOAT32, serialize_map);
+        register_harness!(f64, FieldType::FLOAT64, serialize_map);
+
+        // register_harness!(u8, FieldType::BINARY, serialize_map);

Review Comment:
   delete those if they not needed anymore



-- 
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]

Reply via email to