-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Type class for sequence of bytes
--   
--   Abstract class to manipulate sequence of bytes
--   
--   The use case of this class is abstracting manipulation of types that
--   are just wrapping a bytestring with stronger and more meaniful name.
--   
--   Usual definition of those types are of the form: newtype MyType =
--   MyType ByteString
@package byteable
@version 0.1.1


module Data.Byteable

-- | Class of things that can generate sequence of bytes
class Byteable a where byteableLength = length . toBytes withBytePtr a f = withForeignPtr fptr $ \ ptr -> f (ptr `plusPtr` off) where (fptr, off, _) = toForeignPtr $ toBytes a
toBytes :: Byteable a => a -> ByteString
byteableLength :: Byteable a => a -> Int
withBytePtr :: Byteable a => a -> (Ptr Word8 -> IO b) -> IO b

-- | A constant time equality test for 2 byteable objects.
--   
--   If objects are of 2 different sizes, the function will abort early
--   without comparing any bytes.
--   
--   compared to == , this function will go over all the bytes present
--   before yielding a result even when knowing the overall result early in
--   the processing.
constEqBytes :: Byteable a => a -> a -> Bool
instance Byteable ByteString
