module Codec.Goat.ValueFrame.Types
( ValueFrame(..)
) where
import Data.Bits.Floating
import Data.List
import Data.Serialize
import Data.Word
import qualified Data.ByteString as B
import Codec.Goat.Util
data ValueFrame = ValueFrame (Maybe Word32) Word32 B.ByteString
deriving (Eq)
instance Show ValueFrame where
show (ValueFrame Nothing _ _ ) = "ValueFrame EMPTY"
show (ValueFrame (Just x) len bs) = unwords
[ "ValueFrame"
, "first=" ++ show (coerceToFloat x :: Float)
, genericTake len $ map (bool '1' '0') (unpackBits bs) ]
instance Serialize ValueFrame where
put (ValueFrame x len bs) = do
putMaybeOf putWord32be x
putWord32be len
aiPutByteString bs
get = do
x <- getMaybeOf getWord32be
len <- getWord32be
bs <- aiGetByteString
return $ ValueFrame x len bs