{-# 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 (Size -> Entry -> ShowS
[Entry] -> ShowS
Entry -> String
forall a.
(Size -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entry] -> ShowS
$cshowList :: [Entry] -> ShowS
show :: Entry -> String
$cshow :: Entry -> String
showsPrec :: Size -> Entry -> ShowS
$cshowsPrec :: Size -> Entry -> ShowS
Show)
headerSizeMagicNumber :: Size
= Size
32
headerSize :: Header -> Size
(HeaderValue
k, HeaderValue
v) =
HeaderValue -> Size
BS.length HeaderValue
k
forall a. Num a => a -> a -> a
+ HeaderValue -> Size
BS.length HeaderValue
v
forall a. Num a => a -> a -> a
+ Size
headerSizeMagicNumber
headerSize' :: Token -> HeaderValue -> Size
Token
t HeaderValue
v =
HeaderValue -> Size
BS.length (Token -> HeaderValue
tokenFoldedKey Token
t)
forall a. Num a => a -> a -> a
+ HeaderValue -> Size
BS.length HeaderValue
v
forall a. Num a => a -> a -> a
+ Size
headerSizeMagicNumber
toEntry :: Header -> Entry
toEntry :: Header -> Entry
toEntry kv :: Header
kv@(HeaderValue
k, HeaderValue
v) = Size -> Token -> HeaderValue -> Entry
Entry Size
siz Token
t HeaderValue
v
where
t :: Token
t = HeaderValue -> Token
toToken HeaderValue
k
siz :: Size
siz = Header -> Size
headerSize Header
kv
toEntryToken :: Token -> HeaderValue -> Entry
toEntryToken :: Token -> HeaderValue -> Entry
toEntryToken Token
t HeaderValue
v = Size -> Token -> HeaderValue -> Entry
Entry Size
siz Token
t HeaderValue
v
where
siz :: Size
siz = Token -> HeaderValue -> Size
headerSize' Token
t HeaderValue
v
entrySize :: Entry -> Size
entrySize :: Entry -> Size
entrySize (Entry Size
siz Token
_ HeaderValue
_) = Size
siz
entryTokenHeader :: Entry -> TokenHeader
(Entry Size
_ Token
t HeaderValue
v) = (Token
t, HeaderValue
v)
entryToken :: Entry -> Token
entryToken :: Entry -> Token
entryToken (Entry Size
_ Token
t HeaderValue
_) = Token
t
entryHeaderName :: Entry -> HeaderName
(Entry Size
_ Token
t HeaderValue
_) = Token -> HeaderValue
tokenFoldedKey Token
t
entryHeaderValue :: Entry -> HeaderValue
(Entry Size
_ Token
_ HeaderValue
v) = HeaderValue
v
dummyEntry :: Entry
dummyEntry :: Entry
dummyEntry = Size -> Token -> HeaderValue -> Entry
Entry Size
0 Token
tokenMax HeaderValue
"dummyValue"
maxNumbers :: Size -> Int
maxNumbers :: Size -> Size
maxNumbers Size
siz = Size
siz forall a. Integral a => a -> a -> a
`div` Size
headerSizeMagicNumber