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


##########
rust/fory-derive/src/object/util.rs:
##########
@@ -1117,109 +1115,151 @@ fn to_snake_case(name: &str) -> String {
     result
 }
 
-/// Computes the fingerprint string for a struct type used in schema 
versioning.
-///
-/// **Fingerprint Format:**
-///
-/// Each field contributes: `<field_name_or_id>,<type_id>,<ref>,<nullable>;`
-///
-/// Fields are sorted by field name (snake_case) lexicographically.
-///
-/// **Field Components:**
-/// - `field_name_or_id`: snake_case field name, or tag ID if `#[fory(id = 
N)]` is set
-/// - `type_id`: Fory TypeId as decimal string (e.g., "4" for INT32)
-/// - `ref`: "1" if reference tracking enabled, "0" otherwise
-/// - `nullable`: "1" if null flag is written, "0" otherwise
+/// Field metadata for fingerprint computation.
+struct FieldFingerprintInfo {
+    /// Field name (snake_case) or field ID as string
+    name_or_id: String,
+    /// Whether the field has explicit nullable=true/false set via 
#[fory(nullable)]
+    explicit_nullable: Option<bool>,
+    /// Whether reference tracking is enabled
+    ref_tracking: bool,
+    /// The field type for TypeId detection
+    field_type: Type,
+}
+
+/// Generates code to compute struct version hash at runtime.
 ///
-/// **Example fingerprint:** `"age,4,0,0;name,12,0,1;"`
+/// The generated code:
+/// 1. Uses `OnceLock` to cache the computed hash (computed only once)
+/// 2. For user-defined types (TypeId::UNKNOWN at macro time), uses 0 
(UNKNOWN) in fingerprint
+/// 3. Builds fingerprint string and computes MurmurHash3
 ///
-/// This format is consistent across Go, Java, Rust, and C++ implementations.
-pub(crate) fn compute_struct_fingerprint(fields: &[&Field]) -> String {
+/// **Fingerprint Format:** `<field_name_or_id>,<type_id>,<ref>,<nullable>;`
+/// Fields are sorted by name lexicographically.
+pub(crate) fn gen_struct_version_hash_ts(fields: &[&Field]) -> TokenStream {

Review Comment:
   Another way is generate a const function, this will be zero-cost. but I'm 
not sure whether it's feasible



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