-- | Optimised decode function for OSC packets.moduleSound.OpenSoundControl.Coding.Decode.Binary(getPacket,decodePacket,decodePacket_strict)whereimportControl.ApplicativeimportData.Binary.GetimportqualifiedData.Binary.IEEE754asIimportqualifiedData.ByteStringasSimportqualifiedData.ByteString.LazyasLimportqualifiedData.ByteString.Lazy.Char8asCimportData.Int(Int32)importData.Word(Word32)importSound.OpenSoundControl.Coding.ByteimportSound.OpenSoundControl.TimeimportSound.OpenSoundControl.Type-- | Isolate an action to operating within a fixed block of bytes. The action-- is required to consume all the bytes that it is isolated to.isolate::Word32->Geta->Getaisolatenm=dos<-get_bytesnlet(a,s',_)=runGetStatems0ifL.nulls'thenreturnaelsefail"isolate: not all bytes consumed"-- | Get a 32 biut integer in big-endian byte order.getInt32be::GetInt32getInt32be=fromIntegral<$>getWord32be-- | Get an aligned OSC string.get_string::GetStringget_string=dos<-getLazyByteStringNulskip(fromIntegral(align(L.lengths+1)))return$C.unpacks-- | Get binary data prefixed by byte count.get_bytes::Word32->GetL.ByteStringget_bytesn=dob<-getLazyByteString(fromIntegraln)ifn/=fromIntegral(L.lengthb)thenfail"get_bytes: end of stream"elseskip(fromIntegral(alignn))returnb-- | Get an OSC datum.get_datum::Datum_Type->GetDatumget_datumty=casetyof'i'->Int<$>fromIntegral<$>getInt32be'f'->Float<$>realToFrac<$>I.getFloat32be'd'->Double<$>I.getFloat64be's'->String<$>get_string'b'->Blob<$>(get_bytes=<<getWord32be)'t'->TimeStamp<$>NTPi<$>getWord64be'm'->dob0<-getWord8b1<-getWord8b2<-getWord8b3<-getWord8return$Midi(b0,b1,b2,b3)_->fail("get_datum: illegal type "++showty)-- | Get an OSC 'Message'.get_message::GetMessageget_message=docmd<-get_stringdsc<-get_stringcasedscof(',':tags)->doarg<-mapMget_datumtagsreturn$Messagecmdarg_->fail"get_message: invalid type descriptor string"-- | Get a sequence of OSC 'Message's, each one headed by its length.get_message_seq::Get[Message]get_message_seq=dob<-isEmptyifbthenreturn[]elsedop<-flipisolateget_message=<<getWord32beps<-get_message_seqreturn(p:ps)get_bundle::GetBundleget_bundle=doskip(fromIntegral(L.lengthbundleHeader))t<-NTPi<$>getWord64beps<-get_message_seqreturn$Bundletps-- | Get an OSC 'Packet'.getPacket::GetPacketgetPacket=doh<-uncheckedLookAhead(L.lengthbundleHeader)ifh==bundleHeaderthenfmapPacket_Bundleget_bundleelsefmapPacket_Messageget_message-- | Decode an OSC packet from a lazy ByteString.---- > let b = L.pack [47,103,95,102,114,101,101,0,44,105,0,0,0,0,0,0]-- > in decodeOSC b == Message "/g_free" [Int 0]decodePacket::L.ByteString->Packet{-# INLINE decodePacket #-}decodePacket=runGetgetPacket-- | Decode an OSC packet from a strict ByteString.decodePacket_strict::S.ByteString->Packet{-# INLINE decodePacket_strict #-}decodePacket_strict=runGetgetPacket.L.fromChunks.(:[])