Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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.
type DecodeExtra a Source #
Extra data used for decoding.
encode :: a -> Either String ByteString Source #
Encode to bytestring.
decode :: DecodeExtra a -> ByteString -> Either String a Source #
Decode from a bytestring.
Instances
Serial PathData Source # | |
Defined in Charon.Backend.Cbor.PathData type DecodeExtra PathData Source # | |
Serial DirectorySizes Source # | |
Defined in Charon.Backend.Fdo.DirectorySizes type DecodeExtra DirectorySizes Source # | |
Serial DirectorySizesEntry Source # | |
Serial PathData Source # | |
Defined in Charon.Backend.Fdo.PathData type DecodeExtra PathData Source # | |
Serial PathData Source # | |
Defined in Charon.Backend.Json.PathData type DecodeExtra PathData Source # | |
Serial Timestamp Source # | |
Defined in Charon.Data.Timestamp type DecodeExtra Timestamp Source # | |
Serial (PathI i) Source # | |
Defined in Charon.Data.Paths type DecodeExtra (PathI i) Source # |
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.