on 6fd33eb help sign in
vty/src/Data/Marshalling.hs
31 lines 874 B history raw
1{-# LANGUAGE BangPatterns #-}
2-- Copyright 2009 Corey O'Connor
3module Data.Marshalling ( module Data.Marshalling
4 , module Data.Word
5 , module Foreign.Ptr
6 , module Foreign.ForeignPtr
7 , module Foreign.Marshal
8 , module Foreign.Storable
9 )
10 where
12import Control.Monad.Trans
14import Data.Word
16import Foreign.Ptr
17import Foreign.ForeignPtr
18import Foreign.Marshal
19import Foreign.Marshal.Array
20import Foreign.Storable
22type OutputBuffer = Ptr Word8
24string_to_bytes :: String -> [Word8]
25string_to_bytes str = map (toEnum . fromEnum) str
27serialize_bytes :: MonadIO m => [Word8] -> OutputBuffer -> m OutputBuffer
28serialize_bytes bytes !out_ptr = do
29 liftIO $! pokeArray out_ptr bytes
30 return $! out_ptr `plusPtr` ( length bytes )