Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Charon.Class.Serial
Description
Provides the Serial
class.
Synopsis
- class Serial a where
- type DecodeExtra a
- encode :: a -> Either String ByteString
- decode :: DecodeExtra a -> ByteString -> Either String a
- encodeThrowM :: (HasCallStack, MonadThrow m, Serial a) => a -> m ByteString
- decodeUnit :: (DecodeExtra a ~ (), Serial a) => ByteString -> Either String a
- decodeUnitThrowM :: (DecodeExtra a ~ (), HasCallStack, MonadThrow m, Serial a) => ByteString -> m a
Class
Class for (de)serializing data. This differs from the Serialise class in that Serialise is specifically used for the Cbor backend, whereas this is meant as a general interface.
For instance, the Cbor PathData implements Serial in terms of its Serialise (binary) instance. We then use the common Serial interface when (en|de)coding to/from a file.
Thus this interface is primarily intended for the various PathDatas to implement. Less commonly, however, there are some types that implement Serial as a general to/from ByteString, e.g. Timestampe implements it, which is used by the Fdo backend.
Methods
encode :: a -> Either String ByteString Source #
Encode to bytestring.
decode :: DecodeExtra a -> ByteString -> Either String a Source #
Decode from a bytestring.
Instances
Encoding
encodeThrowM :: (HasCallStack, MonadThrow m, Serial a) => a -> m ByteString Source #
Encodes the value, throwing an exception for any failures.
Decoding
decodeUnit :: (DecodeExtra a ~ (), Serial a) => ByteString -> Either String a Source #
Convenience function for when decoding takes no extra data.
decodeUnitThrowM :: (DecodeExtra a ~ (), HasCallStack, MonadThrow m, Serial a) => ByteString -> m a Source #
Convenience function for when decodeThrowM
takes no extra data.