Source

fixed-vector / fixed-vector-cereal / Data / Vector / Fixed / Instances / Cereal.hs

{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Module with cereal instances for data types defined in fixed
--   vector
module Data.Vector.Fixed.Instances.Cereal where

import           Data.Vector.Fixed             (Arity)
import qualified Data.Vector.Fixed           as F
import qualified Data.Vector.Fixed.Boxed     as B
import qualified Data.Vector.Fixed.Unboxed   as U
import qualified Data.Vector.Fixed.Primitive as P
import qualified Data.Vector.Fixed.Storable  as S
import           Data.Serialize                (Serialize(..))


instance (Arity n, Serialize a) => Serialize (B.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, P.Prim a, Serialize a) => Serialize (P.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, S.Storable a, Serialize a) => Serialize (S.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (U.Unbox n a, Serialize a) => Serialize (U.Vec n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Arity n, Serialize a) => Serialize (F.VecList n a) where
  put = F.mapM_ put
  get = F.replicateM get

instance (Serialize a) => Serialize (F.Only a) where
  put (F.Only a) = put a
  get = F.Only `fmap` get

instance Serialize (F.Empty a) where
  put _ = return ()
  get = return F.Empty
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.