{-# OPTIONS_HADDOCK hide #-}
module Database.Tds.Message.Header ( Header (..)
) where
import Data.Word (Word8(..),Word16(..),Word32(..),Word64(..))
import Data.Int (Int8(..),Int16(..),Int32(..),Int64(..))
import Data.Binary (Put(..),Get(..),Binary(..))
import qualified Data.Binary.Put as Put
import qualified Data.Binary.Get as Get
type Type = Word8
type Status = Word8
type Length = Int
type SPID = Word16
type PacketID = Word8
type Window = Word8
data Header = Header !Type !Status !Length !SPID !PacketID !Window
putHeader :: Header -> Put
putHeader (Header pt st len spid pcid win) = do
Put.putWord8 pt
Put.putWord8 st
Put.putWord16be $ fromIntegral $ len
Put.putWord16be spid
Put.putWord8 pcid
Put.putWord8 win
getHeader :: Get Header
getHeader = do
pt <- Get.getWord8
st <- Get.getWord8
len <- Get.getWord16be
spid <- Get.getWord16be
pcid <- Get.getWord8
win <- Get.getWord8
return $ Header pt st (fromIntegral len) spid pcid win
instance Binary Header where
put = putHeader
get = getHeader