Safe Haskell | None |
---|
Provides convenience functions for manipulating dAmn packets.
- data Packet = Packet {}
- type Arguments = Map Text Text
- pktSubpacket :: Packet -> Result Packet
- pktSubpacket' :: Packet -> Maybe Packet
- pktCommandL :: Functor f => (Text -> f Text) -> Packet -> f Packet
- pktParameterL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f Packet
- pktArgsL :: Functor f => (Arguments -> f Arguments) -> Packet -> f Packet
- pktBodyL :: Functor f => (Maybe ByteString -> f (Maybe ByteString)) -> Packet -> f Packet
- pktSubpacketL :: Functor f => (Maybe Packet -> f (Maybe Packet)) -> Packet -> f Packet
- parse :: ByteString -> Result Packet
- parse' :: ByteString -> Maybe Packet
- render :: Packet -> ByteString
The Packet datatype
Represents a dAmn packet.
Packets are comprised of a command, which is mandatory, and three other optional elements: a "parameter", an argument list, and a body. Any combination of the latter three (or none of them) is valid, so the parser is fairly lenient.
A packet with all four elements will look something like this:
property chat:SomeChatroom p=propertyName by=name of setter ts=timestamp value of property
Parsing this results in the packet:
Packet
{pktCommand
= "property" ,pktParameter
=Just
"chat:SomeChatroom" ,pktArgs
=fromList
[("p","propertyName"),("by","name of setter"),("ts","timestamp")] ,pktBody
=Just
"value of property" }
Packet | |
|
Subpackets
pktSubpacket :: Packet -> Result PacketSource
Due to the way dAmn packets are designed, it's not possible to unambiguously determine whether a packet has a subpacket or just a body. Thus you will need to request a subpacket yourself.
pktSubpacket' :: Packet -> Maybe PacketSource
Use when you don't care about the reason for parse failure.
Packet lenses
pktCommandL :: Functor f => (Text -> f Text) -> Packet -> f PacketSource
A lens on pktCommand
.
pktParameterL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f PacketSource
A lens on pktParameter
.
pktBodyL :: Functor f => (Maybe ByteString -> f (Maybe ByteString)) -> Packet -> f PacketSource
A lens on pktBody
.
pktSubpacketL :: Functor f => (Maybe Packet -> f (Maybe Packet)) -> Packet -> f PacketSource
A lens on pktSubpacket'
.
Parsing
parse :: ByteString -> Result PacketSource
Parse some text, providing a packet or the reason for parse failure.
parse' :: ByteString -> Maybe PacketSource
Parse some text, discarding any failure message.
Rendering packets
render :: Packet -> ByteStringSource
render
converts a packet back into the dAmn text format.
This is used by pktSubpacketL
to fulfill the lens laws, but you might
find it useful if you want to write packets to dAmn.