Serialization of Integer fails for -1
- Dominant language
- Haskell
- Stars
- 23
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
There are issues with this library and the default encoding of negative `Integer`.
Encoding with the `cereal` library:
```
λ :m + Data.Serialize Data.ByteString.Base16
λ let bs = encode (-1 :: Integer)
λ encodeBase16 bs
"00ffffffff"
λ decode bs :: Either String Integer
Right (-1)
```
Encoding with the `bytes` library:
```
λ let bs = runPutS $ serialize (-1 :: Integer)
λ encodeBase16 bs
"ff"
λ runGetS deserialize bs :: Either String Integer
Left "too few bytes\nFrom:\tdemandInput\n\n"
λ let bl = runPutL $ serialize (-1 :: Integer)
λ Data.ByteString.Lazy.Base16.encodeBase16 bl
"ff"
λ runGetL deserialize bl :: Integer
*** Exception: Data.Binary.Get.runGet at position 1: not enough bytes
CallStack (from HasCallStack):
error, called at libraries/binary/src/Data/Binary/Get.hs:351:5 in binary-0.8.8.0:Data.Binary.Get
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.