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

   ### Question
   
   According to Fory's [xlang 
spec](https://github.com/apache/fory/blob/main/docs/specification/xlang_serialization_spec.md#duration),
 the `seconds` field of a Duration is:                    
   > encoded as a signed varint64. Can be positive or negative.
   
   However, Fory's Rust implementation uses `std::time::Duration`, which is 
**unsigned** and therefore cannot represent negative durations.
   
   https://doc.rust-lang.org/src/core/time.rs.html#82
   
   The deserialization code in `rust/fory-core/src/serializer/datetime.rs` 
currently does:
   
   `let secs = context.reader.read_varint64()? as u64;`
   
   `read_varint64()` correctly decodes the ZigZag-encoded wire bytes back to an 
i64. However, the u64 cast is only a bitwise reinterpretation which doesn't 
check the sign. A value of `-1i64` becomes `u64::MAX`, resulting in a Duration 
of approximately 584 billion years.
   
   Also, the `nanos` field is allowed to be negative in the spec, but Rust's 
Nanosecond type is also unsigned.
   
   Maybe we should replace Rust's `std::time::Duration` to `chrono::Duration`, 
whose `seconds` and `nanos` are all signed: 
https://docs.rs/chrono/latest/src/chrono/time_delta.rs.html#64


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