-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TlvEncoder Date encoding for dates in a distant future (exceeding MAX_INT) #1630
Fix TlvEncoder Date encoding for dates in a distant future (exceeding MAX_INT) #1630
Conversation
…s 4-byte integer. Added unit test
Thx for the contribution 🙏 Looking at LWM2M-v1.1.1@core§Table: C.-2 Data Type Mapping
Does it means that leshan/leshan-lwm2m-core/src/main/java/org/eclipse/leshan/core/tlv/TlvEncoder.java Lines 64 to 81 in f9137bb
|
@sbernard31 Hmmm... I guess you're right. We can encode integers in 1, 2, 4 or 8 bytes. That would be the most optimal. I will change the code and add unit tests. |
…ending on value. Added unit tests to cover all encoding cases.
@sbernard31 done - I think I covered all of the edge cases in the unit tests. |
This is now integrated in Thx @jakubsobolewskisag 🙏 |
If encoded date is in distant future (number of seconds since 1970 exceeds MAX_INT), TlvEncoder breaks because it always tries to encode dates as 4-byte integers. This fix checks whether number of seconds exceeds MAX_INT, and if it does the value is encoded in 8-bytes. Otherwise, previous behavior will be used (4-bytes).