on fe55cd4 help sign in
vty/src/Data/Marshalling.hs
29 lines 867 B history raw
1-- Copyright 2009 Corey O'Connor
2module Data.Marshalling ( module Data.Marshalling
3 , module Data.Word
4 , module Foreign.Ptr
5 , module Foreign.ForeignPtr
6 , module Foreign.Marshal
7 )
8 where
10import Control.Monad ( foldM )
11import Control.Monad.Trans
13import Data.Word
15import Foreign.Ptr
16import Foreign.ForeignPtr
17import Foreign.Marshal
18import Foreign.Storable
20type OutputBuffer = Ptr Word8
22string_to_bytes :: String -> [Word8]
23string_to_bytes str = map (toEnum . fromEnum) str
25serialize_bytes :: MonadIO m => [Word8] -> OutputBuffer -> m OutputBuffer
26serialize_bytes bytes out_ptr = foldM ( \ptr b -> liftIO (poke ptr b) >> return ( ptr `plusPtr` 1 ) )
27 out_ptr
28 bytes