{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module Flat.Instances.Array
()
where
import qualified Data.Array as A
import qualified Data.Array.Unboxed as U
import Data.Array.IArray
import Flat.Class
import Flat.Decoder
import Flat.Encoder
import Flat.Instances.Base ( )
import Flat.Instances.Mono
instance (Flat i, Flat e, Ix i) => Flat (A.Array i e) where
size :: Array i e -> NumBits -> NumBits
size = Array i e -> NumBits -> NumBits
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i, Flat e, Flat i) =>
a i e -> NumBits -> NumBits
sizeIArray
encode :: Array i e -> Encoding
encode = Array i e -> Encoding
forall i (a :: * -> * -> *) e.
(Ix i, IArray a e, Flat i, Flat e) =>
a i e -> Encoding
encodeIArray
decode :: Get (Array i e)
decode = Get (Array i e)
forall i (a :: * -> * -> *) e.
(Ix i, IArray a e, Flat i, Flat e) =>
Get (a i e)
decodeIArray
instance (Flat i, Flat e, Ix i, IArray U.UArray e) => Flat (U.UArray i e) where
size :: UArray i e -> NumBits -> NumBits
size = UArray i e -> NumBits -> NumBits
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i, Flat e, Flat i) =>
a i e -> NumBits -> NumBits
sizeIArray
encode :: UArray i e -> Encoding
encode = UArray i e -> Encoding
forall i (a :: * -> * -> *) e.
(Ix i, IArray a e, Flat i, Flat e) =>
a i e -> Encoding
encodeIArray
decode :: Get (UArray i e)
decode = Get (UArray i e)
forall i (a :: * -> * -> *) e.
(Ix i, IArray a e, Flat i, Flat e) =>
Get (a i e)
decodeIArray
sizeIArray :: (IArray a e, Ix i, Flat e, Flat i) => a i e -> NumBits -> NumBits
sizeIArray :: a i e -> NumBits -> NumBits
sizeIArray a i e
arr = ([e] -> NumBits -> NumBits
forall mono.
(IsSequence mono, Flat (Element mono)) =>
mono -> NumBits -> NumBits
sizeSequence ([e] -> NumBits -> NumBits)
-> (a i e -> [e]) -> a i e -> NumBits -> NumBits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a i e -> [e]
forall (a :: * -> * -> *) e i. (IArray a e, Ix i) => a i e -> [e]
elems (a i e -> NumBits -> NumBits) -> a i e -> NumBits -> NumBits
forall a b. (a -> b) -> a -> b
$ a i e
arr) (NumBits -> NumBits) -> (NumBits -> NumBits) -> NumBits -> NumBits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (i, i) -> NumBits -> NumBits
forall a. Flat a => a -> NumBits -> NumBits
size (a i e -> (i, i)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> (i, i)
bounds a i e
arr)
encodeIArray :: (Ix i, IArray a e, Flat i, Flat e) => a i e -> Encoding
encodeIArray :: a i e -> Encoding
encodeIArray a i e
arr = (i, i) -> Encoding
forall a. Flat a => a -> Encoding
encode (a i e -> (i, i)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> (i, i)
bounds a i e
arr) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [e] -> Encoding
forall mono.
(Flat (Element mono), MonoFoldable mono) =>
mono -> Encoding
encodeSequence (a i e -> [e]
forall (a :: * -> * -> *) e i. (IArray a e, Ix i) => a i e -> [e]
elems a i e
arr)
decodeIArray :: (Ix i, IArray a e, Flat i, Flat e) => Get (a i e)
decodeIArray :: Get (a i e)
decodeIArray = (i, i) -> [e] -> a i e
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
(i, i) -> [e] -> a i e
listArray ((i, i) -> [e] -> a i e) -> Get (i, i) -> Get ([e] -> a i e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (i, i)
forall a. Flat a => Get a
decode Get ([e] -> a i e) -> Get [e] -> Get (a i e)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [e]
forall b. (Flat (Element b), IsSequence b) => Get b
decodeSequence
{-# INLINE sizeIArray #-}
{-# INLINE encodeIArray #-}
{-# INLINE decodeIArray #-}