on 207c508 help sign in
vty/src/Data/Marshalling.hs
30 lines 845 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.Storable
21type OutputBuffer = Ptr Word8
23string_to_bytes :: String -> [Word8]
24string_to_bytes str = map (toEnum . fromEnum) str
26serialize_bytes :: MonadIO m => [Word8] -> OutputBuffer -> m OutputBuffer
27serialize_bytes bytes !out_ptr = do
28 liftIO $! pokeArray out_ptr bytes
29 return $! out_ptr `plusPtr` ( length bytes )