1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
module Main where
import Data.Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Maybe (fromJust)
import System.Environment (getArgs)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import HPACKEncode
import JSON
main :: IO ()
main = do
args <- getArgs
(arg1, arg2, desc) <- case args of
[a, b, c] -> return (a, b, c)
_ -> do
hPutStrLn stderr "hpack-encode on/off naive|linear <desc>"
exitFailure
let huffman
| arg1 == "on" = True
| otherwise = False
algo
| arg2 == "naive" = Naive
| arg2 == "static" = Static
| otherwise = Linear
stgy = EncodeStrategy algo huffman
hpackEncode stgy desc
hpackEncode :: EncodeStrategy -> String -> IO ()
hpackEncode stgy desc = do
bs <- BL.getContents
let tc = fromJust (decode bs :: Maybe Test)
hexs <- run False stgy tc
let cs = cases tc
cs' = zipWith update cs hexs
tc' =
tc
{ description = desc
, cases = cs'
}
BL.putStrLn $ encodePretty tc'
where
update c hex = c{wire = hex}
|