haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Binary.Buffer

Contents

Description

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

Documentation

newtype Buffer Source #

A buffer

Constructors

Buffer ByteString 
Instances
Eq Buffer Source # 
Instance details

Defined in Haskus.Binary.Buffer

Methods

(==) :: Buffer -> Buffer -> Bool #

(/=) :: Buffer -> Buffer -> Bool #

Ord Buffer Source # 
Instance details

Defined in Haskus.Binary.Buffer

Show Buffer Source # 
Instance details

Defined in Haskus.Binary.Buffer

Bitwise Buffer Source # 
Instance details

Defined in Haskus.Binary.Buffer

IndexableBits Buffer Source # 
Instance details

Defined in Haskus.Binary.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

bufferDrop :: Word -> Buffer -> Buffer Source #

Drop some bytes O(1)

bufferSplitOn :: Word8 -> Buffer -> [Buffer] Source #

Split on the given Byte values

bufferTake :: Word -> Buffer -> Buffer Source #

Take some bytes O(1)

bufferTakeWhile :: (Word8 -> Bool) -> Buffer -> Buffer Source #

Take some bytes O(n)

bufferTakeAtMost :: Word -> Buffer -> Buffer Source #

Take some bytes O(1)

bufferZipWith :: (Word8 -> Word8 -> Word8) -> Buffer -> Buffer -> Buffer Source #

Zip two buffers with the given function

bufferDup :: Buffer -> IO Buffer Source #

Duplicate a buffer

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

bufferPoke :: Ptr a -> Buffer -> IO () Source #

Poke a buffer

Packing / Unpacking

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

bufferPackPtr :: MonadIO m => Word -> Ptr () -> m Buffer Source #

Pack from a pointer (copy)

Unsafe

bufferUnsafeDrop :: Word -> Buffer -> Buffer Source #

Unsafe drop (don't check the size)

bufferUnsafeTake :: Word -> Buffer -> Buffer Source #

Unsafe take (don't check the size)

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)

bufferUnsafeIndex :: Buffer -> Word -> Word8 Source #

Unsafe index (don't check the size)

bufferUnsafeMapMemory :: MonadIO m => Word -> Ptr () -> m Buffer Source #

Map memory

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)

IO

bufferWriteFile :: MonadIO m => FilePath -> Buffer -> m () Source #

Write file