| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Binary.DerivingVia
Description
This module defines some types to be used with DerivingVia when deriving Binary instances.
Synopsis
- newtype Alternatively a = Alternatively {
- getAlt :: a
Documentation
newtype Alternatively a Source #
Try to deserialize each constructor of a in order.
For sum types, stock Binary writes (and expects to read) an integer denoting the index of the constructor.
This isn't always what's needed. In the following example, the constructor is uniquely identified by the marker byte,
and its index in the Haskell ADT is irrelevant:
data JfifSegment = App0Segment (MatchByte "app0 segment" 0xdb, JfifApp0) | DqtSegment (MatchByte "dqt segment" 0xdb, QuantTable) | SofSegment (MatchByte "sof segment" 0xc0, SofInfo) | DhtSegment (MatchByte "dht segment" 0xc4, HuffmanTable) | DriSegment (MatchByte "dri segment" 0xdd, RestartInterval) | SosSegment (MatchByte "sos segment" 0xda, SosImage) | UnknownSegment RawSegment deriving Generic deriving Binary via Alternatively JfifSegment
Constructors
| Alternatively | |
Fields
| |
Instances
| (Generic a, GAltBinary (Rep a)) => Binary (Alternatively a) Source # | |
Defined in Data.Binary.DerivingVia Methods put :: Alternatively a -> Put # get :: Get (Alternatively a) # putList :: [Alternatively a] -> Put # | |