raaz-0.0.2: The raaz cryptographic library.

Safe HaskellNone

Raaz.Core.Write

Description

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.

Synopsis

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. Writes 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 write a gives a write action that stores a value a. 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 writeStorable a gives a write action that stores a value a 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.