Safe Haskell | None |
---|---|
Language | Haskell98 |
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, Vector v a) => v a -> Write
- writeStorableVector :: (Storable a, 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 BytesMonoid Source #
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 Int Source #
Returns the bytes that will be written when the write action is performed.
write :: EndianStore a => a -> Write Source #
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 -> Write Source #
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, Vector v a) => v a -> Write Source #
The vector version of write
.
writeStorableVector :: (Storable a, Vector v a) => v a -> Write Source #
The vector version of writeStorable
.
writeBytes :: LengthUnit n => Word8 -> n -> Write Source #
The combinator writeBytes n b
writes b
as the next n
consecutive bytes.
writeByteString :: ByteString -> Write Source #
Writes a strict bytestring.
skipWrite :: LengthUnit u => u -> Write Source #
A write action that just skips over the given bytes.