module Sound.OSC.Coding where
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.Char8 as C
import Sound.OSC.Type
import qualified Sound.OSC.Coding.Decode.Binary as Binary
import qualified Sound.OSC.Coding.Encode.Builder as Builder
class Coding a where
encodePacket :: Packet -> a
decodePacket :: a -> Packet
instance Coding S.ByteString where
encodePacket = Builder.encodePacket_strict
decodePacket = Binary.decodePacket_strict
instance Coding B.ByteString where
encodePacket = Builder.encodePacket
decodePacket = Binary.decodePacket
instance Coding String where
encodePacket = C.unpack . encodePacket
decodePacket = decodePacket . C.pack
type Coder = (Packet -> B.ByteString,B.ByteString -> Packet)
encodeMessage :: Coding c => Message -> c
encodeMessage = encodePacket . Packet_Message
encodeBundle :: Coding c => Bundle -> c
encodeBundle = encodePacket . Packet_Bundle
decodeMessage :: Coding c => c -> Maybe Message
decodeMessage = packet_to_message . decodePacket
decodeBundle :: Coding c => c -> Bundle
decodeBundle = packet_to_bundle . decodePacket