Port of Data.Binary with tighter data types and parameterised error messages