[Haskell-cafe] Data.ByteString.Lazy.ByteString vs Data.ByteString.Lazy.Internal.ByteString
Daniel Fischer
daniel.is.fischer at googlemail.com
Mon Mar 14 06:18:04 CET 2011
On Monday 14 March 2011 05:45:04, C K Kashyap wrote:
> Thanks Brandon,
>
> data Endian = Big | Little
> data Size = Eight | Sixteen | ThirtyTwo | SixtyFour
> type EncTuple = (Int,Size,Endian)
>
> My requirement is to write encode :: [EncTuple] -> ByteString
Looks like a job for Data.Binary.
> I'd like to use it with just the libraries that are part of the platform
I don't know whether binary is in the platform, though (but I expect it to
be).
> - and I am not a fan of using the internal stuff :)
> I'd appreciate it very much if you could give me a sample.
instance Binary Endian where
put Big = putWord8 0
put Little = putWord8 1
get = do
w <- getWord8
case w of
0 -> return Big
1 -> return Little
_ -> error ("Bad Endian tag: " ++ show w)
instance Binary Size where
put Eight = putWord8 8
put Sixteen = putWord8 16
...
get = do
w <- getWord8
case w of
8 -> return 8
...
putAux Eight _ i = putWord8 (fromIntegral i)
putAux Sixteen Big i = putWord16be (fromIntegral i)
...
More information about the Haskell-Cafe
mailing list