module Text.Damn.Packet.Internal (
Packet(..),
Arguments,
pktCommandL,
pktParameterL,
pktArgsL,
pktBodyL
) where
import Control.Applicative
import Control.DeepSeq
import Data.ByteString
import Data.Data
import Data.Map (Map)
import Data.Text
type Arguments = Map Text Text
lens :: Functor f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t
lens sa sbt afb s = sbt s <$> afb (sa s)
--p=propertyName
--ts=timestamp
data Packet = Packet { pktCommand :: Text
, pktParameter :: Maybe Text
, pktArgs :: Arguments
, pktBody :: Maybe ByteString
} deriving (Eq, Data, Show, Typeable)
instance NFData Packet where
rnf (Packet a b c d) = rnf a `seq`
rnf b `seq`
rnf c `seq`
rnf d `seq`
()
pktCommandL :: Functor f
=> (Text -> f Text)
-> Packet -> f Packet
pktCommandL = lens pktCommand (\pk b -> pk { pktCommand = b })
pktParameterL :: Functor f
=> (Maybe Text -> f (Maybe Text))
-> Packet -> f Packet
pktParameterL = lens pktParameter (\pk b -> pk { pktParameter = b })
pktArgsL :: Functor f
=> (Arguments -> f Arguments)
-> Packet -> f Packet
pktArgsL = lens pktArgs (\pk b -> pk { pktArgs = b })
pktBodyL :: Functor f
=> (Maybe ByteString -> f (Maybe ByteString))
-> Packet -> f Packet
pktBodyL = lens pktBody (\pk b -> pk { pktBody = b })