mirage / checkseum

MIT License
15 stars 13 forks source link

Confusion in how to (de)serialize Checkseum.Crc32.t #73

Closed reynir closed 1 year ago

reynir commented 1 year ago

I am using Checkseum.Crc32, and I serialized using Optint.to_int32 and deserialized using Optint.of_int32, and my code didn't work. First I used Optint.pp to print the two checksums and indeed they were different:

crc -1407441036
crc' 2887526260

Then later I switched to using Printf.printf "Back checksum: %ld vs %ld" (Optint.to_int32 crc) (Optint.to_int32 crc'): and got Bad CRC -1407441036 vs -1407441036 which is confusing. Then I dug into the checkseum tests and discovered they were using Optint.unsigned_of_int32.

I suggest perhaps Checkseum.S.{of,to}_int32 to the interface so others don't make the same mistake.

dinosaure commented 1 year ago

Then I dug into the checkseum tests and discovered they were using Optint.unsigned_of_int32.

Yes, the bit sign matters along cast for the optint point-of-view. And indeed, we probably should add {of,to}_int32 as you said.