{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans      #-}
{-|
 This module provides a conversion function between a
 'Flake' and a strict 'ByteString'.  The 'ByteString'
 is the series of bytes that make up the 'Flake', with
 the lower bytes being in the lower indecies.
-}

module Data.Snowchecked.Encoding.ByteString
	( module Data.Snowchecked.Encoding.Class
	) where

import           Data.ByteString
import           Data.ByteString.Lazy                      (fromStrict,
                                                            toStrict)
import           Data.Snowchecked.Encoding.ByteString.Lazy
import           Data.Snowchecked.Encoding.Class

instance IsFlake ByteString where
	fromFlake :: Flake -> ByteString
fromFlake = ByteString -> ByteString
toStrict (ByteString -> ByteString)
-> (Flake -> ByteString) -> Flake -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flake -> ByteString
forall a. IsFlake a => Flake -> a
fromFlake
	{-# INLINE fromFlake #-}

	parseFish :: SnowcheckedConfig -> ByteString -> m Flakeish
parseFish SnowcheckedConfig
cfg ByteString
bs = SnowcheckedConfig -> ByteString -> m Flakeish
forall a (m :: * -> *).
(IsFlake a, MonadFail m) =>
SnowcheckedConfig -> a -> m Flakeish
parseFish SnowcheckedConfig
cfg (ByteString -> m Flakeish) -> ByteString -> m Flakeish
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
fromStrict ByteString
bs
	{-# INLINE parseFish #-}