charon-0.1: Template
Safe HaskellSafe-Inferred
LanguageGHC2021

Charon.Class.Serial

Description

Provides the Serial class.

Synopsis

Class

class Serial a where Source #

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.

Associated Types

type DecodeExtra a Source #

Extra data used for decoding.

Methods

encode :: a -> Either String ByteString Source #

Encode to bytestring.

decode :: DecodeExtra a -> ByteString -> Either String a Source #

Decode from a bytestring.

Instances

Instances details
Serial PathData Source # 
Instance details

Defined in Charon.Backend.Cbor.PathData

Associated Types

type DecodeExtra PathData Source #

Serial DirectorySizes Source # 
Instance details

Defined in Charon.Backend.Fdo.DirectorySizes

Associated Types

type DecodeExtra DirectorySizes Source #

Serial DirectorySizesEntry Source # 
Instance details

Defined in Charon.Backend.Fdo.DirectorySizes

Serial PathData Source # 
Instance details

Defined in Charon.Backend.Fdo.PathData

Associated Types

type DecodeExtra PathData Source #

Serial PathData Source # 
Instance details

Defined in Charon.Backend.Json.PathData

Associated Types

type DecodeExtra PathData Source #

Serial Timestamp Source # 
Instance details

Defined in Charon.Data.Timestamp

Associated Types

type DecodeExtra Timestamp Source #

Serial (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Associated Types

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.