composewell / streamly

High performance, concurrent functional programming abstractions
https://streamly.composewell.com
Other
867 stars 66 forks source link

Throw a specific exception in deserialize failure #2614

Open harendra-kumar opened 12 months ago

harendra-kumar commented 12 months ago

Currently we just call error:

        if (next <= sz)
        then Unbox.peekByteIndex off arr >>= \val -> pure (next, val)
        else error
            $ "deserialize: accessing array at offset = "
                ++ show (next - 1)
                ++ " max valid offset = " ++ show (sz - 1)
harendra-kumar commented 4 months ago

When we are deserializing we can throw DeserializeUnderflow and when serializing SerializeOverflow. SerializeOverflow can be useful to re-allocate only if we overflow.

harendra-kumar commented 4 months ago

Should we do the same for Unbox as well?

adithyaov commented 3 months ago

Currently, we seldom bound-check. Should we bound check on every deserializeAt and at every serializeAt?