BaldDemian opened a new issue, #3787:
URL: https://github.com/apache/fory/issues/3787

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/issues) 
and found no similar issues.
   
   
   ### Version
   
   Latest Fory
   
   ### Component(s)
   
   C++
   
   ### Minimal reproduce step
   
   Consider this FDL:
   
   ```
   package repro.temporal_key;
   
   message Holder {
       map<duration, string> values = 1;
   }
   ```
   
   ### What did you expect to see?
   
   The generated code should compile.
   
   ### What did you see instead?
   
   The generated code fails to compile.
   
   ### Anything Else?
   
   ## Root Cause
   
   This bug is introduced by PR https://github.com/apache/fory/pull/3745. In 
this PR, we generate `unordered_map` for IDL's `map` type to match the 
behaviors of other languages. 
   
   But in C++, the key type of an `unordered_map` must be hashable.
   
   Fory documents `duration` and `timestamp` as valid IDL `map` key types. 
Currently, Fory maps `duration` to `fory::serialization::Duration` and 
timestamp to `fory::serialization::Timestamp`. But these two types are just 
aliases for standard library types:
   
   
https://github.com/apache/fory/blob/6c6ba3fb4172a71811c57664ae2a892f04208b5b/cpp/fory/serialization/temporal_serializers.h#L29-L38
   
   In C++17, these standard library types do not provide usable `std::hash` 
specializations, so `std::unordered_map<fory::serialization::Duration, ...>` 
and `std::unordered_map<fory::serialization::Timestamp, ...>` fail to compile.
   
   `date` does not hit the same problem because Fory maps it to a Fory-owned 
`Date` type instead of a standard library alias.
   
   ## Proposed Fix
   
   Replace `fory::serialization::Duration` and `fory::serialization::Timestamp` 
from standard-library aliases with Fory-owned wrapper types. 
   
   Duration should store a normalized seconds/nanoseconds representation or 
total nanoseconds, and Timestamp should store seconds/nanoseconds since the 
Unix epoch. 
   These wrapper types should provide equality, ordering, and hash methods, so 
they can be used directly as `unordered_map` keys.
   
   The serializers can keep the existing wire format unchanged by reading from 
and writing to the wrapper fields using the same seconds/nanoseconds encoding.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


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