Safe Haskell | None |
---|---|
Language | Haskell2010 |
A memory buffer with a fixed address
A buffer is a strict ByteString but with:
- a better interface: use Word instead of Int for sizes
- a better name: "string" is misleading
- some additional primitives
Synopsis
- newtype Buffer = Buffer ByteString
- withBufferPtr :: Buffer -> (Ptr b -> IO a) -> IO a
- bufferSize :: Buffer -> Word
- isBufferEmpty :: Buffer -> Bool
- emptyBuffer :: Buffer
- bufferZero :: Word -> Buffer
- bufferMap :: (Word8 -> Word8) -> Buffer -> Buffer
- bufferReverse :: Buffer -> Buffer
- bufferDrop :: Word -> Buffer -> Buffer
- bufferTail :: Buffer -> Buffer
- bufferAppend :: Buffer -> Buffer -> Buffer
- bufferCons :: Word8 -> Buffer -> Buffer
- bufferSnoc :: Buffer -> Word8 -> Buffer
- bufferInit :: Buffer -> Buffer
- bufferSplitOn :: Word8 -> Buffer -> [Buffer]
- bufferHead :: Buffer -> Word8
- bufferIndex :: Buffer -> Word -> Word8
- bufferTake :: Word -> Buffer -> Buffer
- bufferTakeWhile :: (Word8 -> Bool) -> Buffer -> Buffer
- bufferTakeAtMost :: Word -> Buffer -> Buffer
- bufferZipWith :: (Word8 -> Word8 -> Word8) -> Buffer -> Buffer -> Buffer
- bufferDup :: Buffer -> IO Buffer
- bufferPeekStorable :: forall a. Storable a => Buffer -> a
- bufferPeekStorableAt :: forall a. Storable a => Buffer -> Word -> a
- bufferPopStorable :: forall a. Storable a => Buffer -> (Buffer, a)
- bufferPoke :: Ptr a -> Buffer -> IO ()
- bufferPackByteString :: ByteString -> Buffer
- bufferPackByteList :: [Word8] -> Buffer
- bufferPackStorable :: forall a. Storable a => a -> Buffer
- bufferPackStorableList :: forall a. Storable a => [a] -> Buffer
- bufferPackPtr :: MonadIO m => Word -> Ptr () -> m Buffer
- bufferUnpackByteList :: Buffer -> [Word8]
- bufferUnpackByteString :: Buffer -> ByteString
- bufferUnsafeDrop :: Word -> Buffer -> Buffer
- bufferUnsafeTake :: Word -> Buffer -> Buffer
- bufferUnsafeTail :: Buffer -> Buffer
- bufferUnsafeHead :: Buffer -> Word8
- bufferUnsafeLast :: Buffer -> Word8
- bufferUnsafeInit :: Buffer -> Buffer
- bufferUnsafeIndex :: Buffer -> Word -> Word8
- bufferUnsafeMapMemory :: MonadIO m => Word -> Ptr () -> m Buffer
- bufferUnsafeUsePtr :: MonadInIO m => Buffer -> (Ptr () -> Word -> m a) -> m a
- bufferUnsafePackPtr :: MonadIO m => Word -> Ptr a -> m Buffer
- bufferReadFile :: MonadIO m => FilePath -> m Buffer
- bufferWriteFile :: MonadIO m => FilePath -> Buffer -> m ()
Documentation
A buffer
withBufferPtr :: Buffer -> (Ptr b -> IO a) -> IO a Source #
Unsafe: be careful if you modify the buffer contents or you may break referential transparency
bufferSize :: Buffer -> Word Source #
Buffer size
isBufferEmpty :: Buffer -> Bool Source #
Test if the buffer is empty
emptyBuffer :: Buffer Source #
Empty buffer
bufferZero :: Word -> Buffer Source #
Buffer filled with zero
bufferReverse :: Buffer -> Buffer Source #
Reverse
bufferTail :: Buffer -> Buffer Source #
Tail
bufferInit :: Buffer -> Buffer Source #
Init
bufferHead :: Buffer -> Word8 Source #
Head
bufferZipWith :: (Word8 -> Word8 -> Word8) -> Buffer -> Buffer -> Buffer Source #
Zip two buffers with the given function
Peek / Poke
bufferPeekStorable :: forall a. Storable a => Buffer -> a Source #
Peek a storable
bufferPeekStorableAt :: forall a. Storable a => Buffer -> Word -> a Source #
Peek a storable at the given offset
bufferPopStorable :: forall a. Storable a => Buffer -> (Buffer, a) Source #
Pop a Storable and return the new buffer
Packing / Unpacking
bufferPackByteString :: ByteString -> Buffer Source #
Pack a ByteString
bufferPackByteList :: [Word8] -> Buffer Source #
Pack a list of bytes
bufferPackStorable :: forall a. Storable a => a -> Buffer Source #
Pack a Storable
bufferPackStorableList :: forall a. Storable a => [a] -> Buffer Source #
Pack a list of Storable
bufferUnpackByteList :: Buffer -> [Word8] Source #
Unpack
bufferUnpackByteString :: Buffer -> ByteString Source #
Unpack
Unsafe
bufferUnsafeTail :: Buffer -> Buffer Source #
Unsafe tail (don't check the size)
bufferUnsafeHead :: Buffer -> Word8 Source #
Unsafe head (don't check the size)
bufferUnsafeLast :: Buffer -> Word8 Source #
Unsafe last (don't check the size)
bufferUnsafeInit :: Buffer -> Buffer Source #
Unsafe init (don't check the size)
bufferUnsafeUsePtr :: MonadInIO m => Buffer -> (Ptr () -> Word -> m a) -> m a Source #
Use buffer pointer
bufferUnsafePackPtr :: MonadIO m => Word -> Ptr a -> m Buffer Source #
Pack from a pointer (add finalizer)