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