{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module HiFileParser
    ( Interface(..)
    , List(..)
    , Dictionary(..)
    , Module(..)
    , Usage(..)
    , Dependencies(..)
    , getInterface
    , fromFile
    ) where

{- HLINT ignore "Reduce duplication" -}

import           Control.Monad                 (replicateM, replicateM_)
import           Data.Binary                   (Get, Word32)
import           Data.Binary.Get               (Decoder (..), bytesRead,
                                                getByteString, getInt64be,
                                                getWord32be, getWord64be,
                                                getWord8, lookAhead,
                                                runGetIncremental, skip)
import           Data.Bool                     (bool)
import           Data.ByteString.Lazy.Internal (defaultChunkSize)
import           Data.Char                     (chr)
import           Data.Functor                  (void, ($>))
import           Data.List                     (find)
import           Data.Maybe                    (catMaybes)
import           Data.Semigroup                ((<>))
import qualified Data.Vector                   as V
import           GHC.IO.IOMode                 (IOMode (..))
import           Numeric                       (showHex)
import           RIO.ByteString                as B (ByteString, hGetSome, null)
import           RIO                           (Generic, NFData)
import           System.IO                     (withBinaryFile)

type IsBoot = Bool

type ModuleName = ByteString

newtype List a = List
    { List a -> [a]
unList :: [a]
    } deriving newtype (Int -> List a -> ShowS
[List a] -> ShowS
List a -> String
(Int -> List a -> ShowS)
-> (List a -> String) -> ([List a] -> ShowS) -> Show (List a)
forall a. Show a => Int -> List a -> ShowS
forall a. Show a => [List a] -> ShowS
forall a. Show a => List a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [List a] -> ShowS
$cshowList :: forall a. Show a => [List a] -> ShowS
show :: List a -> String
$cshow :: forall a. Show a => List a -> String
showsPrec :: Int -> List a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> List a -> ShowS
Show, List a -> ()
(List a -> ()) -> NFData (List a)
forall a. NFData a => List a -> ()
forall a. (a -> ()) -> NFData a
rnf :: List a -> ()
$crnf :: forall a. NFData a => List a -> ()
NFData)

newtype Dictionary = Dictionary
    { Dictionary -> Vector ByteString
unDictionary :: V.Vector ByteString
    } deriving newtype (Int -> Dictionary -> ShowS
[Dictionary] -> ShowS
Dictionary -> String
(Int -> Dictionary -> ShowS)
-> (Dictionary -> String)
-> ([Dictionary] -> ShowS)
-> Show Dictionary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Dictionary] -> ShowS
$cshowList :: [Dictionary] -> ShowS
show :: Dictionary -> String
$cshow :: Dictionary -> String
showsPrec :: Int -> Dictionary -> ShowS
$cshowsPrec :: Int -> Dictionary -> ShowS
Show, Dictionary -> ()
(Dictionary -> ()) -> NFData Dictionary
forall a. (a -> ()) -> NFData a
rnf :: Dictionary -> ()
$crnf :: Dictionary -> ()
NFData)

newtype Module = Module
    { Module -> ByteString
unModule :: ModuleName
    } deriving newtype (Int -> Module -> ShowS
[Module] -> ShowS
Module -> String
(Int -> Module -> ShowS)
-> (Module -> String) -> ([Module] -> ShowS) -> Show Module
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Module] -> ShowS
$cshowList :: [Module] -> ShowS
show :: Module -> String
$cshow :: Module -> String
showsPrec :: Int -> Module -> ShowS
$cshowsPrec :: Int -> Module -> ShowS
Show, Module -> ()
(Module -> ()) -> NFData Module
forall a. (a -> ()) -> NFData a
rnf :: Module -> ()
$crnf :: Module -> ()
NFData)

newtype Usage = Usage
    { Usage -> String
unUsage :: FilePath
    } deriving newtype (Int -> Usage -> ShowS
[Usage] -> ShowS
Usage -> String
(Int -> Usage -> ShowS)
-> (Usage -> String) -> ([Usage] -> ShowS) -> Show Usage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Usage] -> ShowS
$cshowList :: [Usage] -> ShowS
show :: Usage -> String
$cshow :: Usage -> String
showsPrec :: Int -> Usage -> ShowS
$cshowsPrec :: Int -> Usage -> ShowS
Show, Usage -> ()
(Usage -> ()) -> NFData Usage
forall a. (a -> ()) -> NFData a
rnf :: Usage -> ()
$crnf :: Usage -> ()
NFData)

data Dependencies = Dependencies
    { Dependencies -> List (ByteString, IsBoot)
dmods    :: List (ModuleName, IsBoot)
    , Dependencies -> List (ByteString, IsBoot)
dpkgs    :: List (ModuleName, Bool)
    , Dependencies -> List Module
dorphs   :: List Module
    , Dependencies -> List Module
dfinsts  :: List Module
    , Dependencies -> List ByteString
dplugins :: List ModuleName
    } deriving (Int -> Dependencies -> ShowS
[Dependencies] -> ShowS
Dependencies -> String
(Int -> Dependencies -> ShowS)
-> (Dependencies -> String)
-> ([Dependencies] -> ShowS)
-> Show Dependencies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Dependencies] -> ShowS
$cshowList :: [Dependencies] -> ShowS
show :: Dependencies -> String
$cshow :: Dependencies -> String
showsPrec :: Int -> Dependencies -> ShowS
$cshowsPrec :: Int -> Dependencies -> ShowS
Show, (forall x. Dependencies -> Rep Dependencies x)
-> (forall x. Rep Dependencies x -> Dependencies)
-> Generic Dependencies
forall x. Rep Dependencies x -> Dependencies
forall x. Dependencies -> Rep Dependencies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Dependencies x -> Dependencies
$cfrom :: forall x. Dependencies -> Rep Dependencies x
Generic)
instance NFData Dependencies

data Interface = Interface
    { Interface -> Dependencies
deps  :: Dependencies
    , Interface -> List Usage
usage :: List Usage
    } deriving (Int -> Interface -> ShowS
[Interface] -> ShowS
Interface -> String
(Int -> Interface -> ShowS)
-> (Interface -> String)
-> ([Interface] -> ShowS)
-> Show Interface
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Interface] -> ShowS
$cshowList :: [Interface] -> ShowS
show :: Interface -> String
$cshow :: Interface -> String
showsPrec :: Int -> Interface -> ShowS
$cshowsPrec :: Int -> Interface -> ShowS
Show, (forall x. Interface -> Rep Interface x)
-> (forall x. Rep Interface x -> Interface) -> Generic Interface
forall x. Rep Interface x -> Interface
forall x. Interface -> Rep Interface x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Interface x -> Interface
$cfrom :: forall x. Interface -> Rep Interface x
Generic)
instance NFData Interface

-- | Read a block prefixed with its length
withBlockPrefix :: Get a -> Get a
withBlockPrefix :: Get a -> Get a
withBlockPrefix Get a
f = Get Word32
getWord32be Get Word32 -> Get a -> Get a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get a
f

getBool :: Get Bool
getBool :: Get IsBoot
getBool = Int -> IsBoot
forall a. Enum a => Int -> a
toEnum (Int -> IsBoot) -> (Word8 -> Int) -> Word8 -> IsBoot
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8 -> IsBoot) -> Get Word8 -> Get IsBoot
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
getWord8

getString :: Get String
getString :: Get String
getString = (Word32 -> Char) -> [Word32] -> String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Char
chr (Int -> Char) -> (Word32 -> Int) -> Word32 -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) ([Word32] -> String)
-> (List Word32 -> [Word32]) -> List Word32 -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List Word32 -> [Word32]
forall a. List a -> [a]
unList (List Word32 -> String) -> Get (List Word32) -> Get String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word32 -> Get (List Word32)
forall a. Get a -> Get (List a)
getList Get Word32
getWord32be

getMaybe :: Get a -> Get (Maybe a)
getMaybe :: Get a -> Get (Maybe a)
getMaybe Get a
f = Get (Maybe a) -> Get (Maybe a) -> IsBoot -> Get (Maybe a)
forall a. a -> a -> IsBoot -> a
bool (Maybe a -> Get (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing) (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Get a -> Get (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get a
f) (IsBoot -> Get (Maybe a)) -> Get IsBoot -> Get (Maybe a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get IsBoot
getBool

getList :: Get a -> Get (List a)
getList :: Get a -> Get (List a)
getList Get a
f = do
    Word8
i <- Get Word8
getWord8
    Word32
l <-
        if Word8
i Word8 -> Word8 -> IsBoot
forall a. Eq a => a -> a -> IsBoot
== Word8
0xff
            then Get Word32
getWord32be
            else Word32 -> Get Word32
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i :: Word32)
    [a] -> List a
forall a. [a] -> List a
List ([a] -> List a) -> Get [a] -> Get (List a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Get a -> Get [a]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
l) Get a
f

getTuple :: Get a -> Get b -> Get (a, b)
getTuple :: Get a -> Get b -> Get (a, b)
getTuple Get a
f Get b
g = (,) (a -> b -> (a, b)) -> Get a -> Get (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get a
f Get (b -> (a, b)) -> Get b -> Get (a, b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get b
g

getByteStringSized :: Get ByteString
getByteStringSized :: Get ByteString
getByteStringSized = do
    Int64
size <- Get Int64
getInt64be
    Int -> Get ByteString
getByteString (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
size)

getDictionary :: Int -> Get Dictionary
getDictionary :: Int -> Get Dictionary
getDictionary Int
ptr = do
    Int64
offset <- Get Int64
bytesRead
    Int -> Get ()
skip (Int -> Get ()) -> Int -> Get ()
forall a b. (a -> b) -> a -> b
$ Int
ptr Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
offset
    Int
size <- Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int) -> Get Int64 -> Get Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int64
getInt64be
    Vector ByteString -> Dictionary
Dictionary (Vector ByteString -> Dictionary)
-> Get (Vector ByteString) -> Get Dictionary
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Get ByteString -> Get (Vector ByteString)
forall (m :: * -> *) a. Monad m => Int -> m a -> m (Vector a)
V.replicateM Int
size Get ByteString
getByteStringSized

getCachedBS :: Dictionary -> Get ByteString
getCachedBS :: Dictionary -> Get ByteString
getCachedBS Dictionary
d = Word32 -> Get ByteString
forall a (f :: * -> *).
(Integral a, MonadFail f, Show a) =>
a -> f ByteString
go (Word32 -> Get ByteString) -> Get Word32 -> Get ByteString
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get Word32
getWord32be
  where
    go :: a -> f ByteString
go a
i =
        case Dictionary -> Vector ByteString
unDictionary Dictionary
d Vector ByteString -> Int -> Maybe ByteString
forall a. Vector a -> Int -> Maybe a
V.!? a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i of
            Just ByteString
bs -> ByteString -> f ByteString
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
bs
            Maybe ByteString
Nothing -> String -> f ByteString
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> f ByteString) -> String -> f ByteString
forall a b. (a -> b) -> a -> b
$ String
"Invalid dictionary index: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
i

getFP :: Get ()
getFP :: Get ()
getFP = Get Word64 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get Word64 -> Get ()) -> Get Word64 -> Get ()
forall a b. (a -> b) -> a -> b
$ Get Word64
getWord64be Get Word64 -> Get Word64 -> Get Word64
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get Word64
getWord64be

getInterface721 :: Dictionary -> Get Interface
getInterface721 :: Dictionary -> Get Interface
getInterface721 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
2 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get Module -> Get Module
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface741 :: Dictionary -> Get Interface
getInterface741 :: Dictionary -> Get Interface
getInterface741 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
3 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get Module -> Get Module
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get Word64 -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get Word64
getWord64be Get (Maybe Usage) -> Get Word64 -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get Word64
getWord64be
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface761 :: Dictionary -> Get Interface
getInterface761 :: Dictionary -> Get Interface
getInterface761 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
3 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get Module -> Get Module
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get Word64 -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get Word64
getWord64be Get (Maybe Usage) -> Get Word64 -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get Word64
getWord64be
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface781 :: Dictionary -> Get Interface
getInterface781 :: Dictionary -> Get Interface
getInterface781 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
3 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get Module -> Get Module
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get () -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get ()
getFP
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface801 :: Dictionary -> Get Interface
getInterface801 :: Dictionary -> Get Interface
getInterface801 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get Word8 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word8
getWord8
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
3 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get Module -> Get Module
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get () -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get ()
getFP
                Word8
3 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface821 :: Dictionary -> Get Interface
getInterface821 :: Dictionary -> Get Interface
getInterface821 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get (Maybe Module) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (Maybe Module) -> Get ()) -> Get (Maybe Module) -> Get ()
forall a b. (a -> b) -> a -> b
$ Get Module -> Get (Maybe Module)
forall a. Get a -> Get (Maybe a)
getMaybe Get Module
getModule
    Get Word8 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word8
getWord8
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
3 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = do
        Word8
idType <- Get Word8
getWord8
        case Word8
idType of
            Word8
0 -> Get ByteString -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get ByteString -> Get ()) -> Get ByteString -> Get ()
forall a b. (a -> b) -> a -> b
$ Dictionary -> Get ByteString
getCachedBS Dictionary
d
            Word8
_ ->
                Get (List (ByteString, Module)) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (List (ByteString, Module)) -> Get ())
-> Get (List (ByteString, Module)) -> Get ()
forall a b. (a -> b) -> a -> b
$
                Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString
-> Get (List (ByteString, Module))
-> Get (List (ByteString, Module))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get (ByteString, Module) -> Get (List (ByteString, Module))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get Module -> Get (ByteString, Module)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get Module
getModule)
        ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get () -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get ()
getFP
                Word8
3 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface841 :: Dictionary -> Get Interface
getInterface841 :: Dictionary -> Get Interface
getInterface841 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get (Maybe Module) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (Maybe Module) -> Get ()) -> Get (Maybe Module) -> Get ()
forall a b. (a -> b) -> a -> b
$ Get Module -> Get (Maybe Module)
forall a. Get a -> Get (Maybe a)
getMaybe Get Module
getModule
    Get Word8 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word8
getWord8
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
5 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = do
        Word8
idType <- Get Word8
getWord8
        case Word8
idType of
            Word8
0 -> Get ByteString -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get ByteString -> Get ()) -> Get ByteString -> Get ()
forall a b. (a -> b) -> a -> b
$ Dictionary -> Get ByteString
getCachedBS Dictionary
d
            Word8
_ ->
                Get (List (ByteString, Module)) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (List (ByteString, Module)) -> Get ())
-> Get (List (ByteString, Module)) -> Get ()
forall a b. (a -> b) -> a -> b
$
                Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString
-> Get (List (ByteString, Module))
-> Get (List (ByteString, Module))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get (ByteString, Module) -> Get (List (ByteString, Module))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get Module -> Get (ByteString, Module)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get Module
getModule)
        ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        List ByteString -> Get (List ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ByteString] -> List ByteString
forall a. [a] -> List a
List [])
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get () -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get ()
getFP
                Word8
3 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface861 :: Dictionary -> Get Interface
getInterface861 :: Dictionary -> Get Interface
getInterface861 Dictionary
d = do
    Get Module -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Module
getModule
    Get (Maybe Module) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (Maybe Module) -> Get ()) -> Get (Maybe Module) -> Get ()
forall a b. (a -> b) -> a -> b
$ Get Module -> Get (Maybe Module)
forall a. Get a -> Get (Maybe a)
getMaybe Get Module
getModule
    Get Word8 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word8
getWord8
    Int -> Get () -> Get ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
6 Get ()
getFP
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Get IsBoot -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get IsBoot
getBool
    Dependencies -> List Usage -> Interface
Interface (Dependencies -> List Usage -> Interface)
-> Get Dependencies -> Get (List Usage -> Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Dependencies
getDependencies Get (List Usage -> Interface) -> Get (List Usage) -> Get Interface
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (List Usage)
getUsage
  where
    getModule :: Get Module
getModule = do
        Word8
idType <- Get Word8
getWord8
        case Word8
idType of
            Word8
0 -> Get ByteString -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get ByteString -> Get ()) -> Get ByteString -> Get ()
forall a b. (a -> b) -> a -> b
$ Dictionary -> Get ByteString
getCachedBS Dictionary
d
            Word8
_ ->
                Get (List (ByteString, Module)) -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Get (List (ByteString, Module)) -> Get ())
-> Get (List (ByteString, Module)) -> Get ()
forall a b. (a -> b) -> a -> b
$
                Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString
-> Get (List (ByteString, Module))
-> Get (List (ByteString, Module))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get (ByteString, Module) -> Get (List (ByteString, Module))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get Module -> Get (ByteString, Module)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get Module
getModule)
        ByteString -> Module
Module (ByteString -> Module) -> Get ByteString -> Get Module
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dictionary -> Get ByteString
getCachedBS Dictionary
d
    getDependencies :: Get Dependencies
getDependencies =
        Get Dependencies -> Get Dependencies
forall a. Get a -> Get a
withBlockPrefix (Get Dependencies -> Get Dependencies)
-> Get Dependencies -> Get Dependencies
forall a b. (a -> b) -> a -> b
$
        List (ByteString, IsBoot)
-> List (ByteString, IsBoot)
-> List Module
-> List Module
-> List ByteString
-> Dependencies
Dependencies (List (ByteString, IsBoot)
 -> List (ByteString, IsBoot)
 -> List Module
 -> List Module
 -> List ByteString
 -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List (ByteString, IsBoot)
      -> List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get
  (List (ByteString, IsBoot)
   -> List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List (ByteString, IsBoot))
-> Get
     (List Module -> List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get (ByteString, IsBoot) -> Get (List (ByteString, IsBoot))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get IsBoot -> Get (ByteString, IsBoot)
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get IsBoot
getBool) Get (List Module -> List Module -> List ByteString -> Dependencies)
-> Get (List Module)
-> Get (List Module -> List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List Module -> List ByteString -> Dependencies)
-> Get (List Module) -> Get (List ByteString -> Dependencies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get Module -> Get (List Module)
forall a. Get a -> Get (List a)
getList Get Module
getModule Get (List ByteString -> Dependencies)
-> Get (List ByteString) -> Get Dependencies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
        Get ByteString -> Get (List ByteString)
forall a. Get a -> Get (List a)
getList (Dictionary -> Get ByteString
getCachedBS Dictionary
d)
    getUsage :: Get (List Usage)
getUsage = Get (List Usage) -> Get (List Usage)
forall a. Get a -> Get a
withBlockPrefix (Get (List Usage) -> Get (List Usage))
-> Get (List Usage) -> Get (List Usage)
forall a b. (a -> b) -> a -> b
$ [Usage] -> List Usage
forall a. [a] -> List a
List ([Usage] -> List Usage)
-> (List (Maybe Usage) -> [Usage])
-> List (Maybe Usage)
-> List Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe Usage] -> [Usage]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe Usage] -> [Usage])
-> (List (Maybe Usage) -> [Maybe Usage])
-> List (Maybe Usage)
-> [Usage]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List (Maybe Usage) -> [Maybe Usage]
forall a. List a -> [a]
unList (List (Maybe Usage) -> List Usage)
-> Get (List (Maybe Usage)) -> Get (List Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe Usage) -> Get (List (Maybe Usage))
forall a. Get a -> Get (List a)
getList Get (Maybe Usage)
go
      where
        go :: Get (Maybe Usage)
        go :: Get (Maybe Usage)
go = do
            Word8
usageType <- Get Word8
getWord8
            case Word8
usageType of
                Word8
0 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
1 ->
                    Dictionary -> Get ByteString
getCachedBS Dictionary
d Get ByteString -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Get (Maybe ()) -> Get (Maybe ())
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get () -> Get (Maybe ())
forall a. Get a -> Get (Maybe a)
getMaybe Get ()
getFP Get (Maybe ())
-> Get (List (ByteString, ())) -> Get (List (ByteString, ()))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get (ByteString, ()) -> Get (List (ByteString, ()))
forall a. Get a -> Get (List a)
getList (Get ByteString -> Get () -> Get (ByteString, ())
forall a b. Get a -> Get b -> Get (a, b)
getTuple (Get Word8
getWord8 Get Word8 -> Get ByteString -> Get ByteString
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Dictionary -> Get ByteString
getCachedBS Dictionary
d) Get ()
getFP) Get (List (ByteString, ())) -> Get IsBoot -> Get IsBoot
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                    Get IsBoot
getBool Get IsBoot -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
2 -> Usage -> Maybe Usage
forall a. a -> Maybe a
Just (Usage -> Maybe Usage)
-> (String -> Usage) -> String -> Maybe Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Usage
Usage (String -> Maybe Usage) -> Get String -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
getString Get (Maybe Usage) -> Get () -> Get (Maybe Usage)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Get ()
getFP
                Word8
3 -> Get Module
getModule Get Module -> Get () -> Get ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Get ()
getFP Get () -> Maybe Usage -> Get (Maybe Usage)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe Usage
forall a. Maybe a
Nothing
                Word8
_ -> String -> Get (Maybe Usage)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Maybe Usage)) -> String -> Get (Maybe Usage)
forall a b. (a -> b) -> a -> b
$ String
"Invalid usageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word8 -> String
forall a. Show a => a -> String
show Word8
usageType

getInterface :: Get Interface
getInterface :: Get Interface
getInterface = do
    Word32
magic <- Get Word32
getWord32be
    case Word32
magic of
        -- x32
        Word32
0x1face      -> Get Word32 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word32
getWord32be
        -- x64
        Word32
0x1face64    -> Get Word64 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word64
getWord64be
        Word32
invalidMagic -> String -> Get ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ String
"Invalid magic: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
invalidMagic String
""
    -- ghc version
    String
version <- Get String
getString
    -- way
    Get String -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get String
getString
    -- dict_ptr
    Word32
dictPtr <- Get Word32
getWord32be
    -- dict
    Dictionary
dict <- Get Dictionary -> Get Dictionary
forall a. Get a -> Get a
lookAhead (Get Dictionary -> Get Dictionary)
-> Get Dictionary -> Get Dictionary
forall a b. (a -> b) -> a -> b
$ Int -> Get Dictionary
getDictionary (Int -> Get Dictionary) -> Int -> Get Dictionary
forall a b. (a -> b) -> a -> b
$ Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
dictPtr
    -- symtable_ptr
    Get Word32 -> Get ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Get Word32
getWord32be
    let versions :: [(String, Dictionary -> Get Interface)]
versions =
            [ (String
"8061", Dictionary -> Get Interface
getInterface861)
            , (String
"8041", Dictionary -> Get Interface
getInterface841)
            , (String
"8021", Dictionary -> Get Interface
getInterface821)
            , (String
"8001", Dictionary -> Get Interface
getInterface801)
            , (String
"7081", Dictionary -> Get Interface
getInterface781)
            , (String
"7061", Dictionary -> Get Interface
getInterface761)
            , (String
"7041", Dictionary -> Get Interface
getInterface741)
            , (String
"7021", Dictionary -> Get Interface
getInterface721)
            ]
    case (String, Dictionary -> Get Interface)
-> Dictionary -> Get Interface
forall a b. (a, b) -> b
snd ((String, Dictionary -> Get Interface)
 -> Dictionary -> Get Interface)
-> Maybe (String, Dictionary -> Get Interface)
-> Maybe (Dictionary -> Get Interface)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((String, Dictionary -> Get Interface) -> IsBoot)
-> [(String, Dictionary -> Get Interface)]
-> Maybe (String, Dictionary -> Get Interface)
forall (t :: * -> *) a.
Foldable t =>
(a -> IsBoot) -> t a -> Maybe a
find ((String
version String -> String -> IsBoot
forall a. Ord a => a -> a -> IsBoot
>=) (String -> IsBoot)
-> ((String, Dictionary -> Get Interface) -> String)
-> (String, Dictionary -> Get Interface)
-> IsBoot
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, Dictionary -> Get Interface) -> String
forall a b. (a, b) -> a
fst) [(String, Dictionary -> Get Interface)]
versions of
        Just Dictionary -> Get Interface
f  -> Dictionary -> Get Interface
f Dictionary
dict
        Maybe (Dictionary -> Get Interface)
Nothing -> String -> Get Interface
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get Interface) -> String -> Get Interface
forall a b. (a -> b) -> a -> b
$ String
"Unsupported version: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
version

fromFile :: FilePath -> IO (Either String Interface)
fromFile :: String -> IO (Either String Interface)
fromFile String
fp = String
-> IOMode
-> (Handle -> IO (Either String Interface))
-> IO (Either String Interface)
forall r. String -> IOMode -> (Handle -> IO r) -> IO r
withBinaryFile String
fp IOMode
ReadMode Handle -> IO (Either String Interface)
forall (f :: * -> *).
MonadIO f =>
Handle -> f (Either String Interface)
go
  where
    go :: Handle -> f (Either String Interface)
go Handle
h =
      let feed :: Decoder b -> f (Either String b)
feed (Done ByteString
_ Int64
_ b
iface) = Either String b -> f (Either String b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either String b -> f (Either String b))
-> Either String b -> f (Either String b)
forall a b. (a -> b) -> a -> b
$ b -> Either String b
forall a b. b -> Either a b
Right b
iface
          feed (Fail ByteString
_ Int64
_ String
msg) = Either String b -> f (Either String b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either String b -> f (Either String b))
-> Either String b -> f (Either String b)
forall a b. (a -> b) -> a -> b
$ String -> Either String b
forall a b. a -> Either a b
Left String
msg
          feed (Partial Maybe ByteString -> Decoder b
k) = do
            ByteString
chunk <- Handle -> Int -> f ByteString
forall (m :: * -> *). MonadIO m => Handle -> Int -> m ByteString
hGetSome Handle
h Int
defaultChunkSize
            Decoder b -> f (Either String b)
feed (Decoder b -> f (Either String b))
-> Decoder b -> f (Either String b)
forall a b. (a -> b) -> a -> b
$ Maybe ByteString -> Decoder b
k (Maybe ByteString -> Decoder b) -> Maybe ByteString -> Decoder b
forall a b. (a -> b) -> a -> b
$ if ByteString -> IsBoot
B.null ByteString
chunk then Maybe ByteString
forall a. Maybe a
Nothing else ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
chunk
      in Decoder Interface -> f (Either String Interface)
forall (f :: * -> *) b.
MonadIO f =>
Decoder b -> f (Either String b)
feed (Decoder Interface -> f (Either String Interface))
-> Decoder Interface -> f (Either String Interface)
forall a b. (a -> b) -> a -> b
$ Get Interface -> Decoder Interface
forall a. Get a -> Decoder a
runGetIncremental Get Interface
getInterface