{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
module Network.HTTP2.Frame.Types where
import Data.Ix
import Network.Control (WindowSize)
import Text.Read
import qualified Text.Read.Lex as L
import Imports
frameHeaderLength :: Int
= StreamId
9
newtype ErrorCode = ErrorCode Word32 deriving (ErrorCode -> ErrorCode -> Bool
(ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool) -> Eq ErrorCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ErrorCode -> ErrorCode -> Bool
== :: ErrorCode -> ErrorCode -> Bool
$c/= :: ErrorCode -> ErrorCode -> Bool
/= :: ErrorCode -> ErrorCode -> Bool
Eq, Eq ErrorCode
Eq ErrorCode =>
(ErrorCode -> ErrorCode -> Ordering)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> ErrorCode)
-> (ErrorCode -> ErrorCode -> ErrorCode)
-> Ord ErrorCode
ErrorCode -> ErrorCode -> Bool
ErrorCode -> ErrorCode -> Ordering
ErrorCode -> ErrorCode -> ErrorCode
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ErrorCode -> ErrorCode -> Ordering
compare :: ErrorCode -> ErrorCode -> Ordering
$c< :: ErrorCode -> ErrorCode -> Bool
< :: ErrorCode -> ErrorCode -> Bool
$c<= :: ErrorCode -> ErrorCode -> Bool
<= :: ErrorCode -> ErrorCode -> Bool
$c> :: ErrorCode -> ErrorCode -> Bool
> :: ErrorCode -> ErrorCode -> Bool
$c>= :: ErrorCode -> ErrorCode -> Bool
>= :: ErrorCode -> ErrorCode -> Bool
$cmax :: ErrorCode -> ErrorCode -> ErrorCode
max :: ErrorCode -> ErrorCode -> ErrorCode
$cmin :: ErrorCode -> ErrorCode -> ErrorCode
min :: ErrorCode -> ErrorCode -> ErrorCode
Ord, ReadPrec [ErrorCode]
ReadPrec ErrorCode
StreamId -> ReadS ErrorCode
ReadS [ErrorCode]
(StreamId -> ReadS ErrorCode)
-> ReadS [ErrorCode]
-> ReadPrec ErrorCode
-> ReadPrec [ErrorCode]
-> Read ErrorCode
forall a.
(StreamId -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: StreamId -> ReadS ErrorCode
readsPrec :: StreamId -> ReadS ErrorCode
$creadList :: ReadS [ErrorCode]
readList :: ReadS [ErrorCode]
$creadPrec :: ReadPrec ErrorCode
readPrec :: ReadPrec ErrorCode
$creadListPrec :: ReadPrec [ErrorCode]
readListPrec :: ReadPrec [ErrorCode]
Read)
fromErrorCode :: ErrorCode -> Word32
fromErrorCode :: ErrorCode -> Word32
fromErrorCode (ErrorCode Word32
w) = Word32
w
toErrorCode :: Word32 -> ErrorCode
toErrorCode :: Word32 -> ErrorCode
toErrorCode = Word32 -> ErrorCode
ErrorCode
pattern NoError :: ErrorCode
pattern $mNoError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bNoError :: ErrorCode
NoError = ErrorCode 0x0
pattern ProtocolError :: ErrorCode
pattern $mProtocolError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bProtocolError :: ErrorCode
ProtocolError = ErrorCode 0x1
pattern InternalError :: ErrorCode
pattern $mInternalError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bInternalError :: ErrorCode
InternalError = ErrorCode 0x2
pattern FlowControlError :: ErrorCode
pattern $mFlowControlError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bFlowControlError :: ErrorCode
FlowControlError = ErrorCode 0x3
pattern SettingsTimeout :: ErrorCode
pattern $mSettingsTimeout :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bSettingsTimeout :: ErrorCode
SettingsTimeout = ErrorCode 0x4
pattern StreamClosed :: ErrorCode
pattern $mStreamClosed :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bStreamClosed :: ErrorCode
StreamClosed = ErrorCode 0x5
pattern FrameSizeError :: ErrorCode
pattern $mFrameSizeError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameSizeError :: ErrorCode
FrameSizeError = ErrorCode 0x6
pattern RefusedStream :: ErrorCode
pattern $mRefusedStream :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bRefusedStream :: ErrorCode
RefusedStream = ErrorCode 0x7
pattern Cancel :: ErrorCode
pattern $mCancel :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bCancel :: ErrorCode
Cancel = ErrorCode 0x8
pattern CompressionError :: ErrorCode
pattern $mCompressionError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bCompressionError :: ErrorCode
CompressionError = ErrorCode 0x9
pattern ConnectError :: ErrorCode
pattern $mConnectError :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bConnectError :: ErrorCode
ConnectError = ErrorCode 0xa
pattern EnhanceYourCalm :: ErrorCode
pattern $mEnhanceYourCalm :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bEnhanceYourCalm :: ErrorCode
EnhanceYourCalm = ErrorCode 0xb
pattern InadequateSecurity :: ErrorCode
pattern $mInadequateSecurity :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bInadequateSecurity :: ErrorCode
InadequateSecurity = ErrorCode 0xc
pattern HTTP11Required :: ErrorCode
pattern $mHTTP11Required :: forall {r}. ErrorCode -> ((# #) -> r) -> ((# #) -> r) -> r
$bHTTP11Required :: ErrorCode
HTTP11Required = ErrorCode 0xd
instance Show ErrorCode where
show :: ErrorCode -> String
show ErrorCode
NoError = String
"NoError"
show ErrorCode
ProtocolError = String
"ProtocolError"
show ErrorCode
InternalError = String
"InternalError"
show ErrorCode
FlowControlError = String
"FlowControlError"
show ErrorCode
SettingsTimeout = String
"SettingsTimeout"
show ErrorCode
StreamClosed = String
"StreamClosed"
show ErrorCode
FrameSizeError = String
"FrameSizeError"
show ErrorCode
RefusedStream = String
"RefusedStream"
show ErrorCode
Cancel = String
"Cancel"
show ErrorCode
CompressionError = String
"CompressionError"
show ErrorCode
ConnectError = String
"ConnectError"
show ErrorCode
EnhanceYourCalm = String
"EnhanceYourCalm"
show ErrorCode
InadequateSecurity = String
"InadequateSecurity"
show ErrorCode
HTTP11Required = String
"HTTP11Required"
show (ErrorCode Word32
x) = String
"ErrorCode " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word32 -> String
forall a. Show a => a -> String
show Word32
x
newtype SettingsKey = SettingsKey Word16 deriving (SettingsKey -> SettingsKey -> Bool
(SettingsKey -> SettingsKey -> Bool)
-> (SettingsKey -> SettingsKey -> Bool) -> Eq SettingsKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SettingsKey -> SettingsKey -> Bool
== :: SettingsKey -> SettingsKey -> Bool
$c/= :: SettingsKey -> SettingsKey -> Bool
/= :: SettingsKey -> SettingsKey -> Bool
Eq, Eq SettingsKey
Eq SettingsKey =>
(SettingsKey -> SettingsKey -> Ordering)
-> (SettingsKey -> SettingsKey -> Bool)
-> (SettingsKey -> SettingsKey -> Bool)
-> (SettingsKey -> SettingsKey -> Bool)
-> (SettingsKey -> SettingsKey -> Bool)
-> (SettingsKey -> SettingsKey -> SettingsKey)
-> (SettingsKey -> SettingsKey -> SettingsKey)
-> Ord SettingsKey
SettingsKey -> SettingsKey -> Bool
SettingsKey -> SettingsKey -> Ordering
SettingsKey -> SettingsKey -> SettingsKey
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SettingsKey -> SettingsKey -> Ordering
compare :: SettingsKey -> SettingsKey -> Ordering
$c< :: SettingsKey -> SettingsKey -> Bool
< :: SettingsKey -> SettingsKey -> Bool
$c<= :: SettingsKey -> SettingsKey -> Bool
<= :: SettingsKey -> SettingsKey -> Bool
$c> :: SettingsKey -> SettingsKey -> Bool
> :: SettingsKey -> SettingsKey -> Bool
$c>= :: SettingsKey -> SettingsKey -> Bool
>= :: SettingsKey -> SettingsKey -> Bool
$cmax :: SettingsKey -> SettingsKey -> SettingsKey
max :: SettingsKey -> SettingsKey -> SettingsKey
$cmin :: SettingsKey -> SettingsKey -> SettingsKey
min :: SettingsKey -> SettingsKey -> SettingsKey
Ord)
fromSettingsKey :: SettingsKey -> Word16
fromSettingsKey :: SettingsKey -> Word16
fromSettingsKey (SettingsKey Word16
x) = Word16
x
toSettingsKey :: Word16 -> SettingsKey
toSettingsKey :: Word16 -> SettingsKey
toSettingsKey = Word16 -> SettingsKey
SettingsKey
minSettingsKey :: SettingsKey
minSettingsKey :: SettingsKey
minSettingsKey = Word16 -> SettingsKey
SettingsKey Word16
1
maxSettingsKey :: SettingsKey
maxSettingsKey :: SettingsKey
maxSettingsKey = Word16 -> SettingsKey
SettingsKey Word16
6
pattern SettingsHeaderTableSize :: SettingsKey
pattern = SettingsKey 1
pattern SettingsEnablePush :: SettingsKey
pattern $mSettingsEnablePush :: forall {r}. SettingsKey -> ((# #) -> r) -> ((# #) -> r) -> r
$bSettingsEnablePush :: SettingsKey
SettingsEnablePush = SettingsKey 2
pattern SettingsMaxConcurrentStreams :: SettingsKey
pattern $mSettingsMaxConcurrentStreams :: forall {r}. SettingsKey -> ((# #) -> r) -> ((# #) -> r) -> r
$bSettingsMaxConcurrentStreams :: SettingsKey
SettingsMaxConcurrentStreams = SettingsKey 3
pattern SettingsInitialWindowSize :: SettingsKey
pattern $mSettingsInitialWindowSize :: forall {r}. SettingsKey -> ((# #) -> r) -> ((# #) -> r) -> r
$bSettingsInitialWindowSize :: SettingsKey
SettingsInitialWindowSize = SettingsKey 4
pattern SettingsMaxFrameSize :: SettingsKey
pattern $mSettingsMaxFrameSize :: forall {r}. SettingsKey -> ((# #) -> r) -> ((# #) -> r) -> r
$bSettingsMaxFrameSize :: SettingsKey
SettingsMaxFrameSize = SettingsKey 5
pattern SettingsMaxHeaderListSize :: SettingsKey
pattern = SettingsKey 6
instance Show SettingsKey where
show :: SettingsKey -> String
show SettingsKey
SettingsHeaderTableSize = String
"SettingsHeaderTableSize"
show SettingsKey
SettingsEnablePush = String
"SettingsEnablePush"
show SettingsKey
SettingsMaxConcurrentStreams = String
"SettingsMaxConcurrentStreams"
show SettingsKey
SettingsInitialWindowSize = String
"SettingsInitialWindowSize"
show SettingsKey
SettingsMaxFrameSize = String
"SettingsMaxFrameSize"
show SettingsKey
SettingsMaxHeaderListSize = String
"SettingsMaxHeaderListSize"
show (SettingsKey Word16
x) = String
"SettingsKey " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word16 -> String
forall a. Show a => a -> String
show Word16
x
instance Read SettingsKey where
readListPrec :: ReadPrec [SettingsKey]
readListPrec = ReadPrec [SettingsKey]
forall a. Read a => ReadPrec [a]
readListPrecDefault
readPrec :: ReadPrec SettingsKey
readPrec = do
Ident String
idnt <- ReadPrec Lexeme
lexP
String -> ReadPrec SettingsKey
forall {a}. (Eq a, IsString a) => a -> ReadPrec SettingsKey
readSK String
idnt
where
readSK :: a -> ReadPrec SettingsKey
readSK a
"SettingsHeaderTableSize" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsHeaderTableSize
readSK a
"SettingsEnablePush" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsEnablePush
readSK a
"SettingsMaxConcurrentStreams" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsMaxConcurrentStreams
readSK a
"SettingsInitialWindowSize" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsInitialWindowSize
readSK a
"SettingsMaxFrameSize" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsMaxFrameSize
readSK a
"SettingsMaxHeaderListSize" = SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return SettingsKey
SettingsMaxHeaderListSize
readSK a
"SettingsKey" = do
Number Number
ftyp <- ReadPrec Lexeme
lexP
SettingsKey -> ReadPrec SettingsKey
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (SettingsKey -> ReadPrec SettingsKey)
-> SettingsKey -> ReadPrec SettingsKey
forall a b. (a -> b) -> a -> b
$ Word16 -> SettingsKey
SettingsKey (Word16 -> SettingsKey) -> Word16 -> SettingsKey
forall a b. (a -> b) -> a -> b
$ Integer -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Word16) -> Integer -> Word16
forall a b. (a -> b) -> a -> b
$ Maybe Integer -> Integer
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Integer -> Integer) -> Maybe Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Number -> Maybe Integer
L.numberToInteger Number
ftyp
readSK a
_ = String -> ReadPrec SettingsKey
forall a. HasCallStack => String -> a
error String
"Read for SettingsKey"
type SettingsValue = Int
type SettingsList = [(SettingsKey, SettingsValue)]
defaultWindowSize :: WindowSize
defaultWindowSize :: StreamId
defaultWindowSize = StreamId
65535
maxWindowSize :: WindowSize
maxWindowSize :: StreamId
maxWindowSize = StreamId
2147483647
isWindowOverflow :: WindowSize -> Bool
isWindowOverflow :: StreamId -> Bool
isWindowOverflow StreamId
w = StreamId -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
testBit StreamId
w StreamId
31
recommendedConcurrency :: Int
recommendedConcurrency :: StreamId
recommendedConcurrency = StreamId
100
type Weight = Int
data Priority = Priority
{ Priority -> Bool
exclusive :: Bool
, Priority -> StreamId
streamDependency :: StreamId
, Priority -> StreamId
weight :: Weight
}
deriving (StreamId -> Priority -> ShowS
[Priority] -> ShowS
Priority -> String
(StreamId -> Priority -> ShowS)
-> (Priority -> String) -> ([Priority] -> ShowS) -> Show Priority
forall a.
(StreamId -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: StreamId -> Priority -> ShowS
showsPrec :: StreamId -> Priority -> ShowS
$cshow :: Priority -> String
show :: Priority -> String
$cshowList :: [Priority] -> ShowS
showList :: [Priority] -> ShowS
Show, ReadPrec [Priority]
ReadPrec Priority
StreamId -> ReadS Priority
ReadS [Priority]
(StreamId -> ReadS Priority)
-> ReadS [Priority]
-> ReadPrec Priority
-> ReadPrec [Priority]
-> Read Priority
forall a.
(StreamId -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: StreamId -> ReadS Priority
readsPrec :: StreamId -> ReadS Priority
$creadList :: ReadS [Priority]
readList :: ReadS [Priority]
$creadPrec :: ReadPrec Priority
readPrec :: ReadPrec Priority
$creadListPrec :: ReadPrec [Priority]
readListPrec :: ReadPrec [Priority]
Read, Priority -> Priority -> Bool
(Priority -> Priority -> Bool)
-> (Priority -> Priority -> Bool) -> Eq Priority
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Priority -> Priority -> Bool
== :: Priority -> Priority -> Bool
$c/= :: Priority -> Priority -> Bool
/= :: Priority -> Priority -> Bool
Eq)
newtype FrameType = FrameType Word8 deriving (FrameType -> FrameType -> Bool
(FrameType -> FrameType -> Bool)
-> (FrameType -> FrameType -> Bool) -> Eq FrameType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FrameType -> FrameType -> Bool
== :: FrameType -> FrameType -> Bool
$c/= :: FrameType -> FrameType -> Bool
/= :: FrameType -> FrameType -> Bool
Eq, Eq FrameType
Eq FrameType =>
(FrameType -> FrameType -> Ordering)
-> (FrameType -> FrameType -> Bool)
-> (FrameType -> FrameType -> Bool)
-> (FrameType -> FrameType -> Bool)
-> (FrameType -> FrameType -> Bool)
-> (FrameType -> FrameType -> FrameType)
-> (FrameType -> FrameType -> FrameType)
-> Ord FrameType
FrameType -> FrameType -> Bool
FrameType -> FrameType -> Ordering
FrameType -> FrameType -> FrameType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FrameType -> FrameType -> Ordering
compare :: FrameType -> FrameType -> Ordering
$c< :: FrameType -> FrameType -> Bool
< :: FrameType -> FrameType -> Bool
$c<= :: FrameType -> FrameType -> Bool
<= :: FrameType -> FrameType -> Bool
$c> :: FrameType -> FrameType -> Bool
> :: FrameType -> FrameType -> Bool
$c>= :: FrameType -> FrameType -> Bool
>= :: FrameType -> FrameType -> Bool
$cmax :: FrameType -> FrameType -> FrameType
max :: FrameType -> FrameType -> FrameType
$cmin :: FrameType -> FrameType -> FrameType
min :: FrameType -> FrameType -> FrameType
Ord, Ord FrameType
Ord FrameType =>
((FrameType, FrameType) -> [FrameType])
-> ((FrameType, FrameType) -> FrameType -> StreamId)
-> ((FrameType, FrameType) -> FrameType -> StreamId)
-> ((FrameType, FrameType) -> FrameType -> Bool)
-> ((FrameType, FrameType) -> StreamId)
-> ((FrameType, FrameType) -> StreamId)
-> Ix FrameType
(FrameType, FrameType) -> StreamId
(FrameType, FrameType) -> [FrameType]
(FrameType, FrameType) -> FrameType -> Bool
(FrameType, FrameType) -> FrameType -> StreamId
forall a.
Ord a =>
((a, a) -> [a])
-> ((a, a) -> a -> StreamId)
-> ((a, a) -> a -> StreamId)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> StreamId)
-> ((a, a) -> StreamId)
-> Ix a
$crange :: (FrameType, FrameType) -> [FrameType]
range :: (FrameType, FrameType) -> [FrameType]
$cindex :: (FrameType, FrameType) -> FrameType -> StreamId
index :: (FrameType, FrameType) -> FrameType -> StreamId
$cunsafeIndex :: (FrameType, FrameType) -> FrameType -> StreamId
unsafeIndex :: (FrameType, FrameType) -> FrameType -> StreamId
$cinRange :: (FrameType, FrameType) -> FrameType -> Bool
inRange :: (FrameType, FrameType) -> FrameType -> Bool
$crangeSize :: (FrameType, FrameType) -> StreamId
rangeSize :: (FrameType, FrameType) -> StreamId
$cunsafeRangeSize :: (FrameType, FrameType) -> StreamId
unsafeRangeSize :: (FrameType, FrameType) -> StreamId
Ix)
fromFrameType :: FrameType -> Word8
fromFrameType :: FrameType -> FrameFlags
fromFrameType (FrameType FrameFlags
x) = FrameFlags
x
toFrameType :: Word8 -> FrameType
toFrameType :: FrameFlags -> FrameType
toFrameType = FrameFlags -> FrameType
FrameType
minFrameType :: FrameType
minFrameType :: FrameType
minFrameType = FrameFlags -> FrameType
FrameType FrameFlags
0
maxFrameType :: FrameType
maxFrameType :: FrameType
maxFrameType = FrameFlags -> FrameType
FrameType FrameFlags
9
pattern FrameData :: FrameType
pattern $mFrameData :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameData :: FrameType
FrameData = FrameType 0
pattern FrameHeaders :: FrameType
pattern = FrameType 1
pattern FramePriority :: FrameType
pattern $mFramePriority :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFramePriority :: FrameType
FramePriority = FrameType 2
pattern FrameRSTStream :: FrameType
pattern $mFrameRSTStream :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameRSTStream :: FrameType
FrameRSTStream = FrameType 3
pattern FrameSettings :: FrameType
pattern $mFrameSettings :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameSettings :: FrameType
FrameSettings = FrameType 4
pattern FramePushPromise :: FrameType
pattern $mFramePushPromise :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFramePushPromise :: FrameType
FramePushPromise = FrameType 5
pattern FramePing :: FrameType
pattern $mFramePing :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFramePing :: FrameType
FramePing = FrameType 6
pattern FrameGoAway :: FrameType
pattern $mFrameGoAway :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameGoAway :: FrameType
FrameGoAway = FrameType 7
pattern FrameWindowUpdate :: FrameType
pattern $mFrameWindowUpdate :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameWindowUpdate :: FrameType
FrameWindowUpdate = FrameType 8
pattern FrameContinuation :: FrameType
pattern $mFrameContinuation :: forall {r}. FrameType -> ((# #) -> r) -> ((# #) -> r) -> r
$bFrameContinuation :: FrameType
FrameContinuation = FrameType 9
instance Show FrameType where
show :: FrameType -> String
show FrameType
FrameData = String
"FrameData"
show FrameType
FrameHeaders = String
"FrameHeaders"
show FrameType
FramePriority = String
"FramePriority"
show FrameType
FrameRSTStream = String
"FrameRSTStream"
show FrameType
FrameSettings = String
"FrameSettings"
show FrameType
FramePushPromise = String
"FramePushPromise"
show FrameType
FramePing = String
"FramePing"
show FrameType
FrameGoAway = String
"FrameGoAway"
show FrameType
FrameWindowUpdate = String
"FrameWindowUpdate"
show FrameType
FrameContinuation = String
"FrameContinuation"
show (FrameType FrameFlags
x) = String
"FrameType " String -> ShowS
forall a. [a] -> [a] -> [a]
++ FrameFlags -> String
forall a. Show a => a -> String
show FrameFlags
x
instance Read FrameType where
readListPrec :: ReadPrec [FrameType]
readListPrec = ReadPrec [FrameType]
forall a. Read a => ReadPrec [a]
readListPrecDefault
readPrec :: ReadPrec FrameType
readPrec = do
Ident String
idnt <- ReadPrec Lexeme
lexP
String -> ReadPrec FrameType
forall {a}. (Eq a, IsString a) => a -> ReadPrec FrameType
readFT String
idnt
where
readFT :: a -> ReadPrec FrameType
readFT a
"FrameData" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameData
readFT a
"FrameHeaders" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameHeaders
readFT a
"FramePriority" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FramePriority
readFT a
"FrameRSTStream" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameRSTStream
readFT a
"FrameSettings" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameSettings
readFT a
"FramePushPromise" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FramePushPromise
readFT a
"FramePing" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FramePing
readFT a
"FrameGoAway" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameGoAway
readFT a
"FrameWindowUpdate" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameWindowUpdate
readFT a
"FrameContinuation" = FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return FrameType
FrameContinuation
readFT a
"FrameType" = do
Number Number
ftyp <- ReadPrec Lexeme
lexP
FrameType -> ReadPrec FrameType
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (FrameType -> ReadPrec FrameType)
-> FrameType -> ReadPrec FrameType
forall a b. (a -> b) -> a -> b
$ FrameFlags -> FrameType
FrameType (FrameFlags -> FrameType) -> FrameFlags -> FrameType
forall a b. (a -> b) -> a -> b
$ Integer -> FrameFlags
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> FrameFlags) -> Integer -> FrameFlags
forall a b. (a -> b) -> a -> b
$ Maybe Integer -> Integer
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Integer -> Integer) -> Maybe Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Number -> Maybe Integer
L.numberToInteger Number
ftyp
readFT a
_ = String -> ReadPrec FrameType
forall a. HasCallStack => String -> a
error String
"Read for FrameType"
maxPayloadLength :: Int
maxPayloadLength :: StreamId
maxPayloadLength = StreamId
2 StreamId -> StreamId -> StreamId
forall a b. (Num a, Integral b) => a -> b -> a
^ (StreamId
24 :: Int) StreamId -> StreamId -> StreamId
forall a. Num a => a -> a -> a
- StreamId
1
defaultPayloadLength :: Int
defaultPayloadLength :: StreamId
defaultPayloadLength = StreamId
2 StreamId -> StreamId -> StreamId
forall a b. (Num a, Integral b) => a -> b -> a
^ (StreamId
14 :: Int)
type FrameFlags = Word8
defaultFlags :: FrameFlags
defaultFlags :: FrameFlags
defaultFlags = FrameFlags
0
testEndStream :: FrameFlags -> Bool
testEndStream :: FrameFlags -> Bool
testEndStream FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
0
testAck :: FrameFlags -> Bool
testAck :: FrameFlags -> Bool
testAck FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
0
testEndHeader :: FrameFlags -> Bool
FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
2
testPadded :: FrameFlags -> Bool
testPadded :: FrameFlags -> Bool
testPadded FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
3
testPriority :: FrameFlags -> Bool
testPriority :: FrameFlags -> Bool
testPriority FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
5
setEndStream :: FrameFlags -> FrameFlags
setEndStream :: FrameFlags -> FrameFlags
setEndStream FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> FrameFlags
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
0
setAck :: FrameFlags -> FrameFlags
setAck :: FrameFlags -> FrameFlags
setAck FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> FrameFlags
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
0
setEndHeader :: FrameFlags -> FrameFlags
FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> FrameFlags
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
2
setPadded :: FrameFlags -> FrameFlags
setPadded :: FrameFlags -> FrameFlags
setPadded FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> FrameFlags
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
3
setPriority :: FrameFlags -> FrameFlags
setPriority :: FrameFlags -> FrameFlags
setPriority FrameFlags
x = FrameFlags
x FrameFlags -> StreamId -> FrameFlags
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
5
type StreamId = Int
isControl :: StreamId -> Bool
isControl :: StreamId -> Bool
isControl StreamId
0 = Bool
True
isControl StreamId
_ = Bool
False
isClientInitiated :: StreamId -> Bool
isClientInitiated :: StreamId -> Bool
isClientInitiated = StreamId -> Bool
forall a. Integral a => a -> Bool
odd
isServerInitiated :: StreamId -> Bool
isServerInitiated :: StreamId -> Bool
isServerInitiated StreamId
0 = Bool
False
isServerInitiated StreamId
n = StreamId -> Bool
forall a. Integral a => a -> Bool
even StreamId
n
testExclusive :: StreamId -> Bool
testExclusive :: StreamId -> Bool
testExclusive StreamId
n = StreamId
n StreamId -> StreamId -> Bool
forall a. Bits a => a -> StreamId -> Bool
`testBit` StreamId
31
setExclusive :: StreamId -> StreamId
setExclusive :: StreamId -> StreamId
setExclusive StreamId
n = StreamId
n StreamId -> StreamId -> StreamId
forall a. Bits a => a -> StreamId -> a
`setBit` StreamId
31
clearExclusive :: StreamId -> StreamId
clearExclusive :: StreamId -> StreamId
clearExclusive StreamId
n = StreamId
n StreamId -> StreamId -> StreamId
forall a. Bits a => a -> StreamId -> a
`clearBit` StreamId
31
type = ByteString
type Padding = ByteString
data Frame = Frame
{ :: FrameHeader
, Frame -> FramePayload
framePayload :: FramePayload
}
deriving (StreamId -> Frame -> ShowS
[Frame] -> ShowS
Frame -> String
(StreamId -> Frame -> ShowS)
-> (Frame -> String) -> ([Frame] -> ShowS) -> Show Frame
forall a.
(StreamId -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: StreamId -> Frame -> ShowS
showsPrec :: StreamId -> Frame -> ShowS
$cshow :: Frame -> String
show :: Frame -> String
$cshowList :: [Frame] -> ShowS
showList :: [Frame] -> ShowS
Show, ReadPrec [Frame]
ReadPrec Frame
StreamId -> ReadS Frame
ReadS [Frame]
(StreamId -> ReadS Frame)
-> ReadS [Frame]
-> ReadPrec Frame
-> ReadPrec [Frame]
-> Read Frame
forall a.
(StreamId -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: StreamId -> ReadS Frame
readsPrec :: StreamId -> ReadS Frame
$creadList :: ReadS [Frame]
readList :: ReadS [Frame]
$creadPrec :: ReadPrec Frame
readPrec :: ReadPrec Frame
$creadListPrec :: ReadPrec [Frame]
readListPrec :: ReadPrec [Frame]
Read, Frame -> Frame -> Bool
(Frame -> Frame -> Bool) -> (Frame -> Frame -> Bool) -> Eq Frame
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Frame -> Frame -> Bool
== :: Frame -> Frame -> Bool
$c/= :: Frame -> Frame -> Bool
/= :: Frame -> Frame -> Bool
Eq)
data =
{ FrameHeader -> StreamId
payloadLength :: Int
, FrameHeader -> FrameFlags
flags :: FrameFlags
, FrameHeader -> StreamId
streamId :: StreamId
}
deriving (StreamId -> FrameHeader -> ShowS
[FrameHeader] -> ShowS
FrameHeader -> String
(StreamId -> FrameHeader -> ShowS)
-> (FrameHeader -> String)
-> ([FrameHeader] -> ShowS)
-> Show FrameHeader
forall a.
(StreamId -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: StreamId -> FrameHeader -> ShowS
showsPrec :: StreamId -> FrameHeader -> ShowS
$cshow :: FrameHeader -> String
show :: FrameHeader -> String
$cshowList :: [FrameHeader] -> ShowS
showList :: [FrameHeader] -> ShowS
Show, ReadPrec [FrameHeader]
ReadPrec FrameHeader
StreamId -> ReadS FrameHeader
ReadS [FrameHeader]
(StreamId -> ReadS FrameHeader)
-> ReadS [FrameHeader]
-> ReadPrec FrameHeader
-> ReadPrec [FrameHeader]
-> Read FrameHeader
forall a.
(StreamId -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: StreamId -> ReadS FrameHeader
readsPrec :: StreamId -> ReadS FrameHeader
$creadList :: ReadS [FrameHeader]
readList :: ReadS [FrameHeader]
$creadPrec :: ReadPrec FrameHeader
readPrec :: ReadPrec FrameHeader
$creadListPrec :: ReadPrec [FrameHeader]
readListPrec :: ReadPrec [FrameHeader]
Read, FrameHeader -> FrameHeader -> Bool
(FrameHeader -> FrameHeader -> Bool)
-> (FrameHeader -> FrameHeader -> Bool) -> Eq FrameHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FrameHeader -> FrameHeader -> Bool
== :: FrameHeader -> FrameHeader -> Bool
$c/= :: FrameHeader -> FrameHeader -> Bool
/= :: FrameHeader -> FrameHeader -> Bool
Eq)
data FramePayload
= DataFrame ByteString
| (Maybe Priority) HeaderBlockFragment
| PriorityFrame Priority
| RSTStreamFrame ErrorCode
| SettingsFrame SettingsList
| PushPromiseFrame StreamId HeaderBlockFragment
| PingFrame ByteString
| GoAwayFrame StreamId ErrorCode ByteString
| WindowUpdateFrame WindowSize
| ContinuationFrame HeaderBlockFragment
| UnknownFrame FrameType ByteString
deriving (StreamId -> FramePayload -> ShowS
[FramePayload] -> ShowS
FramePayload -> String
(StreamId -> FramePayload -> ShowS)
-> (FramePayload -> String)
-> ([FramePayload] -> ShowS)
-> Show FramePayload
forall a.
(StreamId -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: StreamId -> FramePayload -> ShowS
showsPrec :: StreamId -> FramePayload -> ShowS
$cshow :: FramePayload -> String
show :: FramePayload -> String
$cshowList :: [FramePayload] -> ShowS
showList :: [FramePayload] -> ShowS
Show, ReadPrec [FramePayload]
ReadPrec FramePayload
StreamId -> ReadS FramePayload
ReadS [FramePayload]
(StreamId -> ReadS FramePayload)
-> ReadS [FramePayload]
-> ReadPrec FramePayload
-> ReadPrec [FramePayload]
-> Read FramePayload
forall a.
(StreamId -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: StreamId -> ReadS FramePayload
readsPrec :: StreamId -> ReadS FramePayload
$creadList :: ReadS [FramePayload]
readList :: ReadS [FramePayload]
$creadPrec :: ReadPrec FramePayload
readPrec :: ReadPrec FramePayload
$creadListPrec :: ReadPrec [FramePayload]
readListPrec :: ReadPrec [FramePayload]
Read, FramePayload -> FramePayload -> Bool
(FramePayload -> FramePayload -> Bool)
-> (FramePayload -> FramePayload -> Bool) -> Eq FramePayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FramePayload -> FramePayload -> Bool
== :: FramePayload -> FramePayload -> Bool
$c/= :: FramePayload -> FramePayload -> Bool
/= :: FramePayload -> FramePayload -> Bool
Eq)
framePayloadToFrameType :: FramePayload -> FrameType
framePayloadToFrameType :: FramePayload -> FrameType
framePayloadToFrameType DataFrame{} = FrameType
FrameData
framePayloadToFrameType HeadersFrame{} = FrameType
FrameHeaders
framePayloadToFrameType PriorityFrame{} = FrameType
FramePriority
framePayloadToFrameType RSTStreamFrame{} = FrameType
FrameRSTStream
framePayloadToFrameType SettingsFrame{} = FrameType
FrameSettings
framePayloadToFrameType PushPromiseFrame{} = FrameType
FramePushPromise
framePayloadToFrameType PingFrame{} = FrameType
FramePing
framePayloadToFrameType GoAwayFrame{} = FrameType
FrameGoAway
framePayloadToFrameType WindowUpdateFrame{} = FrameType
FrameWindowUpdate
framePayloadToFrameType ContinuationFrame{} = FrameType
FrameContinuation
framePayloadToFrameType (UnknownFrame FrameType
ft ByteString
_) = FrameType
ft
isPaddingDefined :: FramePayload -> Bool
isPaddingDefined :: FramePayload -> Bool
isPaddingDefined DataFrame{} = Bool
True
isPaddingDefined HeadersFrame{} = Bool
True
isPaddingDefined PriorityFrame{} = Bool
False
isPaddingDefined RSTStreamFrame{} = Bool
False
isPaddingDefined SettingsFrame{} = Bool
False
isPaddingDefined PushPromiseFrame{} = Bool
True
isPaddingDefined PingFrame{} = Bool
False
isPaddingDefined GoAwayFrame{} = Bool
False
isPaddingDefined WindowUpdateFrame{} = Bool
False
isPaddingDefined ContinuationFrame{} = Bool
False
isPaddingDefined UnknownFrame{} = Bool
False
type ErrorCodeId = ErrorCode
type SettingsKeyId = SettingsKey
type FrameTypeId = FrameType