{-# LANGUAGE OverloadedStrings #-}
module Network.HPACK.Table.Entry (
Size
, Entry(..)
, Header
, HeaderName
, HeaderValue
, Index
, toEntry
, toEntryToken
, entrySize
, entryTokenHeader
, entryToken
, entryHeaderName
, entryHeaderValue
, dummyEntry
, maxNumbers
) where
import qualified Data.ByteString as BS
import Network.HPACK.Token
import Network.HPACK.Types
type Size = Int
data Entry = Entry Size Token HeaderValue deriving Int -> Entry -> ShowS
[Entry] -> ShowS
Entry -> String
(Int -> Entry -> ShowS)
-> (Entry -> String) -> ([Entry] -> ShowS) -> Show Entry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entry] -> ShowS
$cshowList :: [Entry] -> ShowS
show :: Entry -> String
$cshow :: Entry -> String
showsPrec :: Int -> Entry -> ShowS
$cshowsPrec :: Int -> Entry -> ShowS
Show
headerSizeMagicNumber :: Size
= Int
32
headerSize :: Header -> Size
(HeaderName
k,HeaderName
v) = HeaderName -> Int
BS.length HeaderName
k
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ HeaderName -> Int
BS.length HeaderName
v
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
headerSizeMagicNumber
headerSize' :: Token -> HeaderValue -> Size
Token
t HeaderName
v = HeaderName -> Int
BS.length (Token -> HeaderName
tokenFoldedKey Token
t)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ HeaderName -> Int
BS.length HeaderName
v
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
headerSizeMagicNumber
toEntry :: Header -> Entry
toEntry :: Header -> Entry
toEntry kv :: Header
kv@(HeaderName
k,HeaderName
v) = Int -> Token -> HeaderName -> Entry
Entry Int
siz Token
t HeaderName
v
where
t :: Token
t = HeaderName -> Token
toToken HeaderName
k
siz :: Int
siz = Header -> Int
headerSize Header
kv
toEntryToken :: Token -> HeaderValue -> Entry
toEntryToken :: Token -> HeaderName -> Entry
toEntryToken Token
t HeaderName
v = Int -> Token -> HeaderName -> Entry
Entry Int
siz Token
t HeaderName
v
where
siz :: Int
siz = Token -> HeaderName -> Int
headerSize' Token
t HeaderName
v
entrySize :: Entry -> Size
entrySize :: Entry -> Int
entrySize (Entry Int
siz Token
_ HeaderName
_) = Int
siz
entryTokenHeader :: Entry -> TokenHeader
(Entry Int
_ Token
t HeaderName
v) = (Token
t, HeaderName
v)
entryToken :: Entry -> Token
entryToken :: Entry -> Token
entryToken (Entry Int
_ Token
t HeaderName
_) = Token
t
entryHeaderName :: Entry -> HeaderName
(Entry Int
_ Token
t HeaderName
_) = Token -> HeaderName
tokenFoldedKey Token
t
entryHeaderValue :: Entry -> HeaderValue
(Entry Int
_ Token
_ HeaderName
v) = HeaderName
v
dummyEntry :: Entry
dummyEntry :: Entry
dummyEntry = Int -> Token -> HeaderName -> Entry
Entry Int
0 Token
tokenMax HeaderName
"dummyValue"
maxNumbers :: Size -> Int
maxNumbers :: Int -> Int
maxNumbers Int
siz = Int
siz Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
headerSizeMagicNumber