packages feed

ptr 0.15.2 → 0.15.3

raw patch · 6 files changed

+57/−13 lines, 6 files

Files

library/Ptr/IO.hs view
@@ -4,6 +4,7 @@  import Ptr.Prelude import qualified Data.ByteString.Internal as A+import qualified Data.ByteString.Short.Internal as B import qualified Ptr.UncheckedShifting as D  @@ -105,6 +106,18 @@ peekBytes ptr amount =   {-# SCC "peekBytes" #-}    A.create amount $ \destPtr -> A.memcpy destPtr ptr amount++{-# INLINE peekShortByteString #-}+peekShortByteString :: Ptr Word8 -> Int -> IO ShortByteString+peekShortByteString ptr amount =+  B.createFromPtr ptr amount++{-# INLINE peekNullTerminatedShortByteString #-}+peekNullTerminatedShortByteString :: Ptr Word8 -> (Int -> IO ShortByteString -> IO a) -> IO a+peekNullTerminatedShortByteString ptr cont =+  do+    !length <- fromIntegral <$> A.c_strlen (castPtr ptr)+    cont length (B.createFromPtr ptr length)  {-# INLINE pokeStorable #-} pokeStorable :: Storable a => Ptr Word8 -> a -> IO ()
library/Ptr/Parse.hs view
@@ -4,6 +4,7 @@ import Ptr.Prelude hiding (peek, take) import qualified Ptr.PokeAndPeek as A import qualified Data.ByteString.Char8 as B+import qualified Data.ByteString.Short.Internal as E import qualified Ptr.Prelude as C import qualified Ptr.IO as D @@ -52,6 +53,17 @@ fail message =   Parse $ \ _ _ _ failWithMessage _ -> failWithMessage message +{-# INLINE io #-}+io :: Int -> (Ptr Word8 -> IO output) -> Parse output+io !requiredAmount ptrIO =+  {-# SCC "io" #-} +  Parse $ \ !availableAmount !ptr failWithEOI failWithMessage succeed ->+  if availableAmount >= requiredAmount+    then do+      !result <- ptrIO ptr+      succeed result (availableAmount - requiredAmount) (plusPtr ptr requiredAmount)+    else failWithEOI (requiredAmount - availableAmount)+ {-# INLINE pokeAndPeek #-} pokeAndPeek :: A.PokeAndPeek input output -> Parse output pokeAndPeek (A.PokeAndPeek requiredAmount _ ptrIO) =@@ -86,31 +98,31 @@ word8 :: Parse Word8 word8 =   {-# SCC "word8" #-} -  pokeAndPeek A.word8+  io 1 D.peekWord8  {-# INLINE beWord16 #-} beWord16 :: Parse Word16 beWord16 =   {-# SCC "beWord16" #-} -  pokeAndPeek A.beWord16+  io 2 D.peekBEWord16  {-# INLINE beWord32 #-} beWord32 :: Parse Word32 beWord32 =   {-# SCC "beWord32" #-} -  pokeAndPeek A.beWord32+  io 4 D.peekBEWord32  {-# INLINE beWord64 #-} beWord64 :: Parse Word64 beWord64 =   {-# SCC "beWord64" #-} -  pokeAndPeek A.beWord64+  io 8 D.peekBEWord64  {-# INLINE bytes #-} bytes :: Int -> Parse ByteString bytes amount =   {-# SCC "bytes" #-} -  pokeAndPeek (A.bytes amount)+  io amount (\ ptr -> D.peekBytes ptr amount)  {-# INLINE allBytes #-} allBytes :: Parse ByteString@@ -130,6 +142,18 @@       consumedAmount -> if consumedAmount <= availableAmount         then succeed bytes (availableAmount - consumedAmount) (plusPtr ptr consumedAmount)         else failWithEOI (consumedAmount - availableAmount)++{-# INLINE nullTerminatedShortByteString #-}+nullTerminatedShortByteString :: Parse ShortByteString+nullTerminatedShortByteString =+  {-# SCC "nullTerminatedShortByteString" #-}+  Parse $ \ !availableAmount !ptr failWithEOI failWithMessage succeed ->+  D.peekNullTerminatedShortByteString ptr $ \ length create ->+  if length <= availableAmount+    then do+      result <- create+      succeed result (availableAmount - length) (plusPtr ptr length)+    else failWithEOI (length - availableAmount)  {-# INLINE bytesWhile #-} bytesWhile :: (Word8 -> Bool) -> Parse ByteString
library/Ptr/Peek.hs view
@@ -4,10 +4,11 @@ import Ptr.Prelude hiding (take) import qualified Ptr.PokeAndPeek as B import qualified Ptr.Parse as C+import qualified Ptr.IO as A   data Peek output =-  Peek !Int !(Ptr Word8 -> IO output)+  Peek {-# UNPACK #-} !Int !(Ptr Word8 -> IO output)  instance Functor Peek where   {-# INLINE fmap #-}@@ -30,31 +31,31 @@ word8 :: Peek Word8 word8 =   {-# SCC "word8" #-} -  pokeAndPeek B.word8+  Peek 1 A.peekWord8  {-# INLINE beWord16 #-} beWord16 :: Peek Word16 beWord16 =   {-# SCC "beWord16" #-} -  pokeAndPeek B.beWord16+  Peek 2 A.peekBEWord16  {-# INLINE beWord32 #-} beWord32 :: Peek Word32 beWord32 =   {-# SCC "beWord32" #-} -  pokeAndPeek B.beWord32+  Peek 4 A.peekBEWord32  {-# INLINE beWord64 #-} beWord64 :: Peek Word64 beWord64 =   {-# SCC "beWord64" #-} -  pokeAndPeek B.beWord64+  Peek 8 A.peekBEWord64  {-# INLINE bytes #-} bytes :: Int -> Peek ByteString-bytes amount =+bytes !amount =   {-# SCC "bytes" #-} -  pokeAndPeek (B.bytes amount)+  Peek amount (\ ptr -> A.peekBytes ptr amount)  {-# INLINE pokeAndPeek #-} pokeAndPeek :: B.PokeAndPeek input output -> Peek output
library/Ptr/PokeAndPeek.hs view
@@ -54,24 +54,29 @@ {-# INLINE word8 #-} word8 :: InvPokeAndPeek Word8 word8 =+  {-# SCC "word8" #-}    PokeAndPeek 1 A.pokeWord8 A.peekWord8  {-# INLINE beWord16 #-} beWord16 :: InvPokeAndPeek Word16 beWord16 =+  {-# SCC "beWord16" #-}    PokeAndPeek 2 A.pokeBEWord16 A.peekBEWord16  {-# INLINE beWord32 #-} beWord32 :: InvPokeAndPeek Word32 beWord32 =+  {-# SCC "beWord32" #-}    PokeAndPeek 4 A.pokeBEWord32 A.peekBEWord32  {-# INLINE beWord64 #-} beWord64 :: InvPokeAndPeek Word64 beWord64 =+  {-# SCC "beWord64" #-}    PokeAndPeek 8 A.pokeBEWord64 A.peekBEWord64  {-# INLINE bytes #-} bytes :: Int -> InvPokeAndPeek ByteString bytes amount =+  {-# SCC "bytes" #-}    PokeAndPeek amount (\ptr -> A.pokeBytesTrimming ptr amount) (\ptr -> A.peekBytes ptr amount)
library/Ptr/Prelude.hs view
@@ -49,6 +49,7 @@ -- bytestring ------------------------- import Data.ByteString as Exports (ByteString)+import Data.ByteString.Short as Exports (ShortByteString)  -- text -------------------------
ptr.cabal view
@@ -1,7 +1,7 @@ name:   ptr version:-  0.15.2+  0.15.3 category:   Ptr, Data synopsis: