network-byte-order 0.1.2.1 → 0.1.3.0
raw patch · 2 files changed
+31/−9 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.ByteOrder: read64 :: Readable a => a -> IO Word64
+ Network.ByteOrder: write64 :: WriteBuffer -> Word64 -> IO ()
Files
- Network/ByteOrder.hs +30/−8
- network-byte-order.cabal +1/−1
Network/ByteOrder.hs view
@@ -45,6 +45,7 @@ , read16 , read24 , read32+ , read64 , extractByteString , extractShortByteString -- *Writing to buffer@@ -56,6 +57,7 @@ , write16 , write24 , write32+ , write64 , copyByteString , copyShortByteString , shiftLastN@@ -375,11 +377,11 @@ write8 :: WriteBuffer -> Word8 -> IO () write8 WriteBuffer{..} w = do ptr <- readIORef offset- if ptr >= limit then+ let ptr' = ptr `plusPtr` 1+ if ptr' > limit then throwIO BufferOverrun else do poke ptr w- let ptr' = ptr `plusPtr` 1 writeIORef offset ptr' {-# INLINE write16 #-}@@ -391,11 +393,11 @@ write16 :: WriteBuffer -> Word16 -> IO () write16 WriteBuffer{..} w = do ptr <- readIORef offset- if ptr `plusPtr` 1 >= limit then+ let ptr' = ptr `plusPtr` 2+ if ptr' > limit then throwIO BufferOverrun else do poke16 w ptr 0- let ptr' = ptr `plusPtr` 2 writeIORef offset ptr' {-# INLINE write24 #-}@@ -407,11 +409,11 @@ write24 :: WriteBuffer -> Word32 -> IO () write24 WriteBuffer{..} w = do ptr <- readIORef offset- if ptr `plusPtr` 2 >= limit then+ let ptr' = ptr `plusPtr` 3+ if ptr' > limit then throwIO BufferOverrun else do poke24 w ptr 0- let ptr' = ptr `plusPtr` 3 writeIORef offset ptr' {-# INLINE write32 #-}@@ -423,13 +425,26 @@ write32 :: WriteBuffer -> Word32 -> IO () write32 WriteBuffer{..} w = do ptr <- readIORef offset- if ptr `plusPtr` 3 >= limit then+ let ptr' = ptr `plusPtr` 4+ if ptr' > limit then throwIO BufferOverrun else do poke32 w ptr 0- let ptr' = ptr `plusPtr` 4 writeIORef offset ptr' +{-# INLINE write64 #-}+-- | Write four bytes and ff one byte.+-- If buffer overrun occurs, 'BufferOverrun' is thrown.+write64 :: WriteBuffer -> Word64 -> IO ()+write64 WriteBuffer{..} w = do+ ptr <- readIORef offset+ let ptr' = ptr `plusPtr` 8+ if ptr' > limit then+ throwIO BufferOverrun+ else do+ poke64 w ptr 0+ writeIORef offset ptr'+ {-# INLINE shiftLastN #-} -- | Shifting the N-bytes area just before the current pointer (the 3rd argument). -- If the second argument is positive, shift it to right.@@ -701,6 +716,13 @@ w32 <- withCurrentOffSet rbuf (`peek32` 0) ff rbuf 4 return w32++-- | Reading four bytes as 'Word64' and ff four bytes.+read64 :: Readable a => a -> IO Word64+read64 rbuf = do+ w64 <- withCurrentOffSet rbuf (`peek64` 0)+ ff rbuf 8+ return w64 -- | Buffer overrun exception. data BufferOverrun = BufferOverrun -- ^ The buffer size is not enough
network-byte-order.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: network-byte-order-version: 0.1.2.1+version: 0.1.3.0 synopsis: Network byte order utilities description: Peek and poke functions for network byte order. license: BSD3