byteable 0.1.0 → 0.1.1
raw patch · 2 files changed
+17/−3 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Byteable: byteableLength :: Byteable a => a -> Int
+ Data.Byteable: withBytePtr :: Byteable a => a -> (Ptr Word8 -> IO b) -> IO b
- Data.Byteable: class Byteable a
+ Data.Byteable: class Byteable a where byteableLength = length . toBytes withBytePtr a f = withForeignPtr fptr $ \ ptr -> f (ptr `plusPtr` off) where (fptr, off, _) = toForeignPtr $ toBytes a
Files
- Data/Byteable.hs +15/−1
- byteable.cabal +2/−2
Data/Byteable.hs view
@@ -10,13 +10,27 @@ , constEqBytes ) where +import Foreign.Ptr (Ptr, plusPtr)+import Foreign.ForeignPtr (withForeignPtr) import Data.ByteString (ByteString) import Data.List (foldl')+import Data.Word (Word8) import qualified Data.ByteString as B (length, zipWith)+import qualified Data.ByteString.Internal as B (toForeignPtr) -- | Class of things that can generate sequence of bytes class Byteable a where- toBytes :: a -> ByteString+ -- | Convert a byteable type to a bytestring+ toBytes :: a -> ByteString++ -- | Return the size of the byteable .+ byteableLength :: a -> Int+ byteableLength = B.length . toBytes++ -- | Provide a way to look at the data of a byteable type with a ptr.+ withBytePtr :: a -> (Ptr Word8 -> IO b) -> IO b+ withBytePtr a f = withForeignPtr fptr $ \ptr -> f (ptr `plusPtr` off)+ where (fptr, off, _) = B.toForeignPtr $ toBytes a instance Byteable ByteString where toBytes bs = bs
byteable.cabal view
@@ -1,5 +1,5 @@ Name: byteable-Version: 0.1.0+Version: 0.1.1 Synopsis: Type class for sequence of bytes Description: Abstract class to manipulate sequence of bytes@@ -8,7 +8,7 @@ types that are just wrapping a bytestring with stronger and more meaniful name. .- Usual definition is of the form: newtype MyType = MyType ByteString+ Usual definition of those types are of the form: newtype MyType = MyType ByteString License: BSD3 License-file: LICENSE Copyright: Vincent Hanquez <vincent@snarc.org>