{-# LANGUAGE OverloadedStrings #-}

module Network.HPACK.Huffman.Decode (
    -- * Huffman decoding
    decodeH,
    decodeHuffman,
    HuffmanDecoder,
    decH,
    GCBuffer,
) where

import Control.Exception (throwIO)
import Data.Array (Array, listArray)
import Data.Array.Base (unsafeAt)
import qualified Data.ByteString as BS
import Network.ByteOrder

import Imports
import Network.HPACK.Huffman.Bit
import Network.HPACK.Huffman.Params
import Network.HPACK.Huffman.Table
import Network.HPACK.Huffman.Tree
import Network.HPACK.Types (DecodeError (..))

----------------------------------------------------------------

-- | Huffman decoding.
type HuffmanDecoder = ReadBuffer -> Int -> IO ByteString

----------------------------------------------------------------

data Pin
    = EndOfString
    | Forward {-# UNPACK #-} Word8 -- node no.
    | GoBack
        {-# UNPACK #-} Word8 -- node no.
        {-# UNPACK #-} Word8 -- a decoded value
    | GoBack2
        {-# UNPACK #-} Word8 -- node no.
        {-# UNPACK #-} Word8 -- a decoded value
        {-# UNPACK #-} Word8 -- a decoded value
    deriving (Int -> Pin -> ShowS
[Pin] -> ShowS
Pin -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pin] -> ShowS
$cshowList :: [Pin] -> ShowS
show :: Pin -> String
$cshow :: Pin -> String
showsPrec :: Int -> Pin -> ShowS
$cshowsPrec :: Int -> Pin -> ShowS
Show)

data WayStep = WayStep (Maybe Int) (Array Word8 Pin)
type Way256 = Array Word8 WayStep

next :: WayStep -> Word8 -> Pin
next :: WayStep -> Word8 -> Pin
next (WayStep Maybe Int
_ Array Word8 Pin
a16) Word8
w = Array Word8 Pin
a16 forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
`unsafeAt` forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w

----------------------------------------------------------------

-- | Huffman decoding.
decodeH
    :: GCBuffer
    -- ^ A working space
    -> BufferSize
    -> ReadBuffer
    -- ^ A read buffer which contains the target
    -> Int
    -- ^ The target length
    -> IO ByteString
decodeH :: GCBuffer -> Int -> ReadBuffer -> Int -> IO ByteString
decodeH GCBuffer
gcbuf Int
bufsiz ReadBuffer
rbuf Int
len = forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr GCBuffer
gcbuf forall a b. (a -> b) -> a -> b
$ \Ptr Word8
buf -> do
    WriteBuffer
wbuf <- Ptr Word8 -> Int -> IO WriteBuffer
newWriteBuffer Ptr Word8
buf Int
bufsiz
    WriteBuffer -> ReadBuffer -> Int -> IO ()
decH WriteBuffer
wbuf ReadBuffer
rbuf Int
len
    WriteBuffer -> IO ByteString
toByteString WriteBuffer
wbuf

-- | Low devel Huffman decoding in a write buffer.
decH :: WriteBuffer -> ReadBuffer -> Int -> IO ()
decH :: WriteBuffer -> ReadBuffer -> Int -> IO ()
decH WriteBuffer
wbuf ReadBuffer
rbuf Int
len = forall {t}. (Eq t, Num t) => t -> WayStep -> IO ()
go Int
len (Way256
way256 forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
`unsafeAt` Int
0)
  where
    go :: t -> WayStep -> IO ()
go t
0 WayStep
way0 = case WayStep
way0 of
        WayStep Maybe Int
Nothing Array Word8 Pin
_ -> forall e a. Exception e => e -> IO a
throwIO DecodeError
IllegalEos
        WayStep (Just Int
i) Array Word8 Pin
_
            | Int
i forall a. Ord a => a -> a -> Bool
<= Int
8 -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
            | Bool
otherwise -> forall e a. Exception e => e -> IO a
throwIO DecodeError
TooLongEos
    go t
n WayStep
way0 = do
        Word8
w <- forall a. Readable a => a -> IO Word8
read8 ReadBuffer
rbuf
        WayStep
way <- WayStep -> Word8 -> IO WayStep
doit WayStep
way0 Word8
w
        t -> WayStep -> IO ()
go (t
n forall a. Num a => a -> a -> a
- t
1) WayStep
way
    doit :: WayStep -> Word8 -> IO WayStep
doit WayStep
way Word8
w = case WayStep -> Word8 -> Pin
next WayStep
way Word8
w of
        Pin
EndOfString -> forall e a. Exception e => e -> IO a
throwIO DecodeError
EosInTheMiddle
        Forward Word8
n -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Way256
way256 forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
`unsafeAt` forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
n
        GoBack Word8
n Word8
v -> do
            WriteBuffer -> Word8 -> IO ()
write8 WriteBuffer
wbuf Word8
v
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Way256
way256 forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
`unsafeAt` forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
n
        GoBack2 Word8
n Word8
v1 Word8
v2 -> do
            WriteBuffer -> Word8 -> IO ()
write8 WriteBuffer
wbuf Word8
v1
            WriteBuffer -> Word8 -> IO ()
write8 WriteBuffer
wbuf Word8
v2
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Way256
way256 forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
`unsafeAt` forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
n

-- | Huffman decoding with a temporary buffer whose size is 4096.
decodeHuffman :: ByteString -> IO ByteString
decodeHuffman :: ByteString -> IO ByteString
decodeHuffman ByteString
bs = Int -> (WriteBuffer -> IO ()) -> IO ByteString
withWriteBuffer Int
4096 forall a b. (a -> b) -> a -> b
$ \WriteBuffer
wbuf ->
    forall a. ByteString -> (ReadBuffer -> IO a) -> IO a
withReadBuffer ByteString
bs forall a b. (a -> b) -> a -> b
$ \ReadBuffer
rbuf -> WriteBuffer -> ReadBuffer -> Int -> IO ()
decH WriteBuffer
wbuf ReadBuffer
rbuf forall a b. (a -> b) -> a -> b
$ ByteString -> Int
BS.length ByteString
bs

----------------------------------------------------------------

{-# NOINLINE way256 #-}
way256 :: Way256
way256 :: Way256
way256 = HTree -> Way256
construct forall a b. (a -> b) -> a -> b
$ [Bits] -> HTree
toHTree [Bits]
huffmanTable

construct :: HTree -> Way256
construct :: HTree -> Way256
construct HTree
decoder = forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Word8
0, Word8
255) forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map HTree -> WayStep
to16ways forall a b. (a -> b) -> a -> b
$ HTree -> [HTree]
flatten HTree
decoder
  where
    to16ways :: HTree -> WayStep
to16ways HTree
x = Maybe Int -> Array Word8 Pin -> WayStep
WayStep Maybe Int
ei Array Word8 Pin
a16
      where
        ei :: Maybe Int
ei = HTree -> Maybe Int
eosInfo HTree
x
        a16 :: Array Word8 Pin
a16 = forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (Word8
0, Word8
255) forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (HTree -> HTree -> Chara -> Bits -> Pin
step HTree
decoder HTree
x Chara
Non) [Bits]
bits8s

data Chara
    = Non
    | One Word8
    | Two Word8 Word8

{- FOURMOLU_DISABLE -}
inc :: Chara -> Word8 -> Chara
inc :: Chara -> Word8 -> Chara
inc Chara
Non Word8
w     = Word8 -> Chara
One Word8
w
inc (One Word8
v) Word8
w = Word8 -> Word8 -> Chara
Two Word8
v Word8
w
inc Chara
_       Word8
_ = forall a. HasCallStack => String -> a
error String
"inc"

step :: HTree -> HTree -> Chara -> [B] -> Pin
step :: HTree -> HTree -> Chara -> Bits -> Pin
step HTree
root (Tip Maybe Int
_ Int
v)     Chara
x  Bits
bss
  | Int
v forall a. Eq a => a -> a -> Bool
== Int
idxEos                     = Pin
EndOfString
  | Bool
otherwise                       = let w :: Word8
w = forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
v
                                          x' :: Chara
x' = Chara -> Word8 -> Chara
inc Chara
x Word8
w
                                      in HTree -> HTree -> Chara -> Bits -> Pin
step HTree
root HTree
root Chara
x' Bits
bss
step HTree
_    (Bin Maybe Int
_ Int
n HTree
_ HTree
_) Chara
Non       [] = Word8 -> Pin
Forward (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
step HTree
_    (Bin Maybe Int
_ Int
n HTree
_ HTree
_) (One Word8
w)   [] = Word8 -> Word8 -> Pin
GoBack (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) Word8
w
step HTree
_    (Bin Maybe Int
_ Int
n HTree
_ HTree
_) (Two Word8
w Word8
z) [] = Word8 -> Word8 -> Word8 -> Pin
GoBack2 (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) Word8
w Word8
z
step HTree
root (Bin Maybe Int
_ Int
_ HTree
l HTree
_) Chara
mx    (B
F:Bits
bs) = HTree -> HTree -> Chara -> Bits -> Pin
step HTree
root HTree
l Chara
mx Bits
bs
step HTree
root (Bin Maybe Int
_ Int
_ HTree
_ HTree
r) Chara
mx    (B
T:Bits
bs) = HTree -> HTree -> Chara -> Bits -> Pin
step HTree
root HTree
r Chara
mx Bits
bs

bits8s :: [[B]]
bits8s :: [Bits]
bits8s = [
    [B
F,B
F,B
F,B
F,B
F,B
F,B
F,B
F]
  , [B
F,B
F,B
F,B
F,B
F,B
F,B
F,B
T]
  , [B
F,B
F,B
F,B
F,B
F,B
F,B
T,B
F]
  , [B
F,B
F,B
F,B
F,B
F,B
F,B
T,B
T]
  , [B
F,B
F,B
F,B
F,B
F,B
T,B
F,B
F]
  , [B
F,B
F,B
F,B
F,B
F,B
T,B
F,B
T]
  , [B
F,B
F,B
F,B
F,B
F,B
T,B
T,B
F]
  , [B
F,B
F,B
F,B
F,B
F,B
T,B
T,B
T]
  , [B
F,B
F,B
F,B
F,B
T,B
F,B
F,B
F]
  , [B
F,B
F,B
F,B
F,B
T,B
F,B
F,B
T]
  , [B
F,B
F,B
F,B
F,B
T,B
F,B
T,B
F]
  , [B
F,B
F,B
F,B
F,B
T,B
F,B
T,B
T]
  , [B
F,B
F,B
F,B
F,B
T,B
T,B
F,B
F]
  , [B
F,B
F,B
F,B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