Safe Haskell | None |
---|
Module to write stuff to buffers. As opposed to similar functions exposed in Raaz.Core.Write.Unsafe, the writes exposed here are safe as necessary range checks are done on the buffer before writing stuff to it.
- type Write = SemiR WriteAction BytesMonoid
- bytesToWrite :: Write -> BYTES Int
- unsafeWrite :: Write -> Pointer -> IO ()
- write :: EndianStore a => a -> Write
- writeStorable :: Storable a => a -> Write
- writeVector :: (EndianStore a, G.Vector v a) => v a -> Write
- writeStorableVector :: (Storable a, G.Vector v a) => v a -> Write
- writeBytes :: LengthUnit n => Word8 -> n -> Write
- writeByteString :: ByteString -> Write
- skipWrite :: LengthUnit u => u -> Write
Documentation
type Write = SemiR WriteAction BytesMonoidSource
A write is an action which when executed using runWrite
writes
bytes to the input buffer. It is similar to the Write
type
exposed from the Raaz.Write.Unsafe module except that it keeps
track of the total bytes that would be written to the buffer if the
action is run. The runWrite
action will raise an error if the
buffer it is provided with is of size smaller. Write
s are monoid
and hence can be concatnated using the <>
operator.
bytesToWrite :: Write -> BYTES IntSource
Returns the bytes that will be written when the write action is performed.
unsafeWrite :: Write -> Pointer -> IO ()Source
Perform the write action without any checks.
write :: EndianStore a => a -> WriteSource
The expression
gives a write action that stores a
value write
aa
. One needs the type of the value a
to be an instance of
EndianStore
. Proper endian conversion is done irrespective of
what the machine endianness is. The man use of this write is to
serialize data for the consumption of the outside world.
writeStorable :: Storable a => a -> WriteSource
The expression
gives a write action that
stores a value writeStorable
aa
in machine endian. The type of the value a
has
to be an instance of Storable
. This should be used when we want
to talk with C functions and not when talking to the outside world
(otherwise this could lead to endian confusion). To take care of
endianness use the write
combinator.
writeVector :: (EndianStore a, G.Vector v a) => v a -> WriteSource
The vector version of write
.
writeStorableVector :: (Storable a, G.Vector v a) => v a -> WriteSource
The vector version of writeStorable
.
writeBytes :: LengthUnit n => Word8 -> n -> WriteSource
The combinator writeBytes n b
writes b
as the next n
consecutive bytes.
writeByteString :: ByteString -> WriteSource
Writes a strict bytestring.
skipWrite :: LengthUnit u => u -> WriteSource
A write action that just skips over the given bytes.