    module Network.PublicSuffixList.Serialize (getDataStructure, putDataStructure) where

    import qualified Data.ByteString      as BS
    import qualified Data.ByteString.UTF8 as U8
    import           Data.Functor
    import           Data.Serialize.Get hiding (getTreeOf)
    import           Data.Serialize.Put
    import qualified Data.Text            as T

    import Network.PublicSuffixList.Types

    getTreeOf :: Ord k => Get k -> Get (Tree k)
    getTreeOf :: Get k -> Get (Tree k)
    getTreeOf p :: Get k
    p = Map k (Tree k) -> Tree k
    forall e. Map e (Tree e) -> Tree e
    Node (Map k (Tree k) -> Tree k) -> Get (Map k (Tree k)) -> Get (Tree k)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Get k -> Get (Tree k) -> Get (Map k (Tree k))
    forall k a. Ord k => Get k -> Get a -> Get (Map k a)
    getMapOf Get k
    p (Get k -> Get (Tree k)
    forall k. Ord k => Get k -> Get (Tree k)
    getTreeOf Get k
    p)

    getText :: Get T.Text
    getText :: Get Text
    getText = (String -> Text
    T.pack (String -> Text) -> ([Word8] -> String) -> [Word8] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> String
    U8.toString (ByteString -> String)
    -> ([Word8] -> ByteString) -> [Word8] -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Word8] -> ByteString
    BS.pack) ([Word8] -> Text) -> Get [Word8] -> Get Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Get Word8 -> Get [Word8]
    forall a. Get a -> Get [a]
    getListOf Get Word8
    getWord8

    getDataStructure :: Get DataStructure
    getDataStructure :: Get DataStructure
    getDataStructure = Get (Tree Text) -> Get (Tree Text) -> Get DataStructure
    forall a b. Get a -> Get b -> Get (a, b)
    getTwoOf (Get Text -> Get (Tree Text)
    forall k. Ord k => Get k -> Get (Tree k)
    getTreeOf Get Text
    getText) (Get Text -> Get (Tree Text)
    forall k. Ord k => Get k -> Get (Tree k)
    getTreeOf Get Text
    getText)

    putTree :: Ord k => Putter k -> Putter (Tree k)
    putTree :: Putter k -> Putter (Tree k)
    putTree p :: Putter k
    p = Putter k -> Putter (Tree k) -> Putter (Map k (Tree k))
    forall k a. Putter k -> Putter a -> Putter (Map k a)
    putMapOf Putter k
    p (Putter k -> Putter (Tree k)
    forall k. Ord k => Putter k -> Putter (Tree k)
    putTree Putter k
    p) Putter (Map k (Tree k))
    -> (Tree k -> Map k (Tree k)) -> Putter (Tree k)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Tree k -> Map k (Tree k)
    forall e. Tree e -> Map e (Tree e)
    children

    putText :: Putter T.Text
    putText :: Putter Text
    putText = Putter Word8 -> Putter [Word8]
    forall a. Putter a -> Putter [a]
    putListOf Putter Word8
    putWord8 Putter [Word8] -> (Text -> [Word8]) -> Putter Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> [Word8]
    BS.unpack (ByteString -> [Word8]) -> (Text -> ByteString) -> Text -> [Word8]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ByteString
    U8.fromString (String -> ByteString) -> (Text -> String) -> Text -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> String
    T.unpack

    putDataStructure :: Putter DataStructure
    putDataStructure :: Putter DataStructure
    putDataStructure = Putter (Tree Text) -> Putter (Tree Text) -> Putter DataStructure
    forall a b. Putter a -> Putter b -> Putter (a, b)
    putTwoOf (Putter Text -> Putter (Tree Text)
    forall k. Ord k => Putter k -> Putter (Tree k)
    putTree Putter Text
    putText) (Putter Text -> Putter (Tree Text)
    forall k. Ord k => Putter k -> Putter (Tree k)
    putTree Putter Text
    putText)