kaori-seasons commented on code in PR #2819:
URL: https://github.com/apache/fory/pull/2819#discussion_r2468139381


##########
rust/fory-core/src/serializer/core.rs:
##########
@@ -1217,6 +1230,70 @@ pub trait Serializer: 'static {
         std::mem::size_of::<Self>()
     }
 
+    /// Indicate whether this type should be treated as a reference type in 
cross-language (xlang) serialization.
+    ///
+    /// In cross-language scenarios, type systems differ between languages. 
For example:
+    /// - In Java: `String`, `List`, `Map` are reference types (need RefFlag)
+    /// - In Rust: `String`, `Vec`, `HashMap` are value types (by default, no 
RefFlag)
+    ///
+    /// This method bridges the gap by allowing Rust types to declare their 
cross-language reference semantics.
+    ///
+    /// # Returns
+    ///
+    /// - `true` if this type should be treated as a reference type in xlang 
mode
+    ///   (will write RefFlag during serialization)
+    /// - `false` if this type should be treated as a value type in xlang mode
+    ///   (will not write RefFlag, default)
+    ///
+    /// # Type Mapping Guidelines
+    ///
+    /// | Rust Type | Java Type | Should Return |
+    /// |-----------|-----------|---------------|
+    /// | `i32`, `f64`, `bool` | `int`, `double`, `boolean` | `false` |
+    /// | `Option<i32>` | `Integer` | `false` (Option handles null) |
+    /// | `String` | `String` | `true` |
+    /// | `Vec<T>` | `List<T>` | `true` |
+    /// | `HashMap<K,V>` | `Map<K,V>` | `true` |
+    /// | User struct | Java object | `true` |
+    ///
+    /// # Default Implementation
+    ///
+    /// Returns `false` for all types. Override for types that correspond to 
reference types in other languages.
+    ///
+    /// # Examples
+    ///
+    /// ```rust,ignore
+    /// // String should be treated as reference type in Java
+    /// impl Serializer for String {
+    ///     fn fory_is_xlang_ref_type() -> bool {
+    ///         true
+    ///     }
+    /// }
+    ///
+    /// // i32 is primitive in Java (int)
+    /// impl Serializer for i32 {
+    ///     fn fory_is_xlang_ref_type() -> bool {
+    ///         false  // default
+    ///     }
+    /// }
+    /// ```
+    ///
+    /// # Implementation Notes
+    ///
+    /// - Only affects behavior when `context.is_xlang()` is true
+    /// - Used in [`fory_write`] to determine RefFlag behavior
+    /// - Fory implements this for all built-in types
+    /// - User types should override this for proper xlang interop
+    ///
+    /// [`fory_write`]: Serializer::fory_write
+    #[inline(always)]
+    fn fory_is_xlang_ref_type() -> bool

Review Comment:
   > Remove this method, all rust types are xlang serializable
   
   Hello, I'm thinking about whether it's possible to use the TypeId 
enumeration to distinguish types. 
   For example, 
   ```
   pub enum TypeId {
   STRING, // Reference type
   LIST, // Reference type
   MAP, // Reference type
   INT32_ARRAY,
   // ...
   }
   ```
   
   Then, in fory_write(), automatically determine the type based on 
fory_static_type_id().
   
   Example:
   ```
   if write_ref_info {
       let is_ref_type = matches!(
           Self::fory_static_type_id(),
           TypeId::STRING | TypeId::LIST | TypeId::MAP | TypeId::SET
       );
       
       if context.is_xlang() && is_ref_type {
           context.writer.write_i8(RefFlag::RefValue as i8);
       }
   }
   ```
   
   This requires maintaining a large match expression.
   
   Do you have any suggestions?



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