haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Binary.Serialize.Buffer

Contents

Description

Serializer into a mutable buffer

>>> let w = do putWord8 0x01 ; putWord32BE 0x23456789 ; putWord32BE 0xAABBCCDD
>>> b <- newBuffer 10
>>> void $ runBufferPut b 0 overflowBufferFail w
>>> xs <- forM [0..4] (bufferReadWord8IO b)
>>> xs == [0x01,0x23,0x45,0x67,0x89]
True
>>> b <- newBuffer 2 -- small buffer
>>> (_,b',_) <- runBufferPut b 0 overflowBufferDouble w
>>> xs <- forM [0..4] (bufferReadWord8IO b')
>>> xs == [0x01,0x23,0x45,0x67,0x89]
True
>>> bufferSizeIO b'
16
Synopsis

Put

newtype BufferPutT b m a Source #

A Put monad than fails when there is not enough space in the target buffer

Constructors

BufferPutT (StateT (BufferPutState m b) m a) 
Instances
Monad m => Monad (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

(>>=) :: BufferPutT b m a -> (a -> BufferPutT b m b0) -> BufferPutT b m b0 #

(>>) :: BufferPutT b m a -> BufferPutT b m b0 -> BufferPutT b m b0 #

return :: a -> BufferPutT b m a #

fail :: String -> BufferPutT b m a #

Functor m => Functor (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

fmap :: (a -> b0) -> BufferPutT b m a -> BufferPutT b m b0 #

(<$) :: a -> BufferPutT b m b0 -> BufferPutT b m a #

MonadFix m => MonadFix (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

mfix :: (a -> BufferPutT b m a) -> BufferPutT b m a #

MonadFail m => MonadFail (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

fail :: String -> BufferPutT b m a #

Monad m => Applicative (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

pure :: a -> BufferPutT b m a #

(<*>) :: BufferPutT b m (a -> b0) -> BufferPutT b m a -> BufferPutT b m b0 #

liftA2 :: (a -> b0 -> c) -> BufferPutT b m a -> BufferPutT b m b0 -> BufferPutT b m c #

(*>) :: BufferPutT b m a -> BufferPutT b m b0 -> BufferPutT b m b0 #

(<*) :: BufferPutT b m a -> BufferPutT b m b0 -> BufferPutT b m a #

MonadIO m => MonadIO (BufferPutT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

liftIO :: IO a -> BufferPutT b m a #

MonadIO m => PutMonad (BufferPutT (Buffer Mutable pin gc heap) m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

putWord8 :: Word8 -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord16 :: Word16 -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord32 :: Word32 -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord64 :: Word64 -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord8s :: [Word8] -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord16s :: [Word16] -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord32s :: [Word32] -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putWord64s :: [Word64] -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

putBuffer :: BufferSize (Buffer Immutable pin0 gc0 heap0) => Buffer Immutable pin0 gc0 heap0 -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

preAllocateAtLeast :: Word -> BufferPutT (Buffer Mutable pin gc heap) m () Source #

getPutOffset :: Monad m => BufferPutT b m Word Source #

Get current offset

getPutBuffer :: Monad m => BufferPutT b m b Source #

Get buffer

setPutOffset :: Monad m => Word -> BufferPutT b m () Source #

Get current offset

runBufferPut :: Monad m => b -> Word -> OverflowStrategy m b -> BufferPutT b m a -> m (a, b, Word) Source #

Run a buffer put

liftBufferPut :: Monad m => m a -> BufferPutT b m a Source #

Lift into BufferPutT

Get

newtype BufferGetT b m a Source #

A Get monad over a Buffer

Constructors

BufferGetT (StateT (BufferGetState m b) m a) 
Instances
Monad m => Monad (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

(>>=) :: BufferGetT b m a -> (a -> BufferGetT b m b0) -> BufferGetT b m b0 #

(>>) :: BufferGetT b m a -> BufferGetT b m b0 -> BufferGetT b m b0 #

return :: a -> BufferGetT b m a #

fail :: String -> BufferGetT b m a #

Functor m => Functor (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

fmap :: (a -> b0) -> BufferGetT b m a -> BufferGetT b m b0 #

(<$) :: a -> BufferGetT b m b0 -> BufferGetT b m a #

MonadFix m => MonadFix (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

mfix :: (a -> BufferGetT b m a) -> BufferGetT b m a #

MonadFail m => MonadFail (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

fail :: String -> BufferGetT b m a #

Monad m => Applicative (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

pure :: a -> BufferGetT b m a #

(<*>) :: BufferGetT b m (a -> b0) -> BufferGetT b m a -> BufferGetT b m b0 #

liftA2 :: (a -> b0 -> c) -> BufferGetT b m a -> BufferGetT b m b0 -> BufferGetT b m c #

(*>) :: BufferGetT b m a -> BufferGetT b m b0 -> BufferGetT b m b0 #

(<*) :: BufferGetT b m a -> BufferGetT b m b0 -> BufferGetT b m a #

MonadIO m => MonadIO (BufferGetT b m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

liftIO :: IO a -> BufferGetT b m a #

MonadIO m => GetMonad (BufferGetT (Buffer mut pin gc heap) m) Source # 
Instance details

Defined in Haskus.Binary.Serialize.Buffer

Methods

getWord8 :: BufferGetT (Buffer mut pin gc heap) m Word8 Source #

getWord16 :: BufferGetT (Buffer mut pin gc heap) m Word16 Source #

getWord32 :: BufferGetT (Buffer mut pin gc heap) m Word32 Source #

getWord64 :: BufferGetT (Buffer mut pin gc heap) m Word64 Source #

getWord8s :: Word -> BufferGetT (Buffer mut pin gc heap) m [Word8] Source #

getWord16s :: Word -> BufferGetT (Buffer mut pin gc heap) m [Word16] Source #

getWord32s :: Word -> BufferGetT (Buffer mut pin gc heap) m [Word32] Source #

getWord64s :: Word -> BufferGetT (Buffer mut pin gc heap) m [Word64] Source #

getBuffer :: Word -> BufferGetT (Buffer mut pin gc heap) m BufferI Source #

getBufferInto :: Word -> Buffer Mutable pin0 gc0 heap0 -> Maybe Word -> BufferGetT (Buffer mut pin gc heap) m () Source #

getSkipBytes :: Word -> BufferGetT (Buffer mut pin gc heap) m () Source #

getGetOffset :: Monad m => BufferGetT b m Word Source #

Get current offset

getGetBuffer :: Monad m => BufferGetT b m b Source #

Get buffer

setGetOffset :: Monad m => Word -> BufferGetT b m () Source #

Get current offset

runBufferGet :: Monad m => b -> Word -> OverflowStrategy m b -> BufferGetT b m a -> m (a, b, Word) Source #

Run a buffer get

liftBufferGet :: Monad m => m a -> BufferGetT b m a Source #

Lift into BufferGetT

Buffer overflow

newtype OverflowStrategy m b Source #

Action to perform when the buffer isn't large enough to contain the required data (extend the buffer, flush the data, etc.)

The returned buffer and offset replace the current ones.

Constructors

OverflowStrategy (BufferOverflow b -> m (b, Word)) 

data BufferOverflow b Source #

Buffer extension information

Constructors

BufferOverflow 

Fields

getPutOverflowStrategy :: Monad m => BufferPutT b m (OverflowStrategy m b) Source #

Get extend strategy

getGetOverflowStrategy :: Monad m => BufferGetT b m (OverflowStrategy m b) Source #

Get extend strategy

overflowBufferFail :: MonadFail m => OverflowStrategy m b Source #

Buffer overflow strategy: fails when there isn't enough space left

overflowBufferDouble :: MonadIO m => OverflowStrategy m BufferM Source #

Buffer extend strategy: double the buffer size each time and copy the original contents in it

overflowBufferDoublePinned :: MonadIO m => Maybe Word -> OverflowStrategy m BufferMP Source #

Buffer extend strategy: double the buffer size each time and copy the original contents in it

overflowBufferAdd :: MonadIO m => Word -> OverflowStrategy m BufferM Source #

Buffer extend strategy: add the given size each time and copy the original contents in it

overflowBufferAddPinned :: MonadIO m => Maybe Word -> Word -> OverflowStrategy m BufferMP Source #

Buffer extend strategy: add the given size each time and copy the original contents in it