{-# OPTIONS_GHC -optc-D_LARGEFILE_SOURCE #-}
{-# OPTIONS_GHC -optc-D_LARGEFILE64_SOURCE #-}
{-# OPTIONS_GHC -optc-D_THREAD_SAFE #-}
{-# OPTIONS_GHC -optc-D_REENTRANT #-}
{-# OPTIONS_GHC -optc-DBUILD_DIR="build/debug" #-}
{-# OPTIONS_GHC -optc-DGHC_VERSION=90205 #-}
{-# OPTIONS_GHC -optc-D__APPLE__ #-}
{-# LINE 1 "Util/TimeVectorStorable.hsc" #-}
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module Util.TimeVectorStorable where
import qualified Data.Aeson as Aeson
import Foreign
import qualified Util.FFI as FFI
import qualified ForeignC as C
import qualified Util.Serialize as Serialize
import qualified Perform.RealTime as RealTime
data Sample y = Sample {
sx :: {-# UNPACK #-} !X
, sy :: !y
} deriving (Show, Eq)
type X = RealTime.RealTime
instance Storable (Sample Double) where
sizeOf _ = (16)
{-# LINE 33 "Util/TimeVectorStorable.hsc" #-}
alignment _ = alignment (0 :: C.CDouble)
poke sp (Sample time val) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) sp time
{-# LINE 36 "Util/TimeVectorStorable.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) sp (FFI.c_double val)
{-# LINE 37 "Util/TimeVectorStorable.hsc" #-}
peek sp = do
time <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) sp
{-# LINE 39 "Util/TimeVectorStorable.hsc" #-}
val <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) sp
{-# LINE 40 "Util/TimeVectorStorable.hsc" #-}
return $ Sample time (FFI.hs_double val)
instance C.CStorable (Sample Double) where
sizeOf = sizeOf
alignment = alignment
peek = peek
poke = poke
instance (Serialize.Serialize y) => Serialize.Serialize (Sample y) where
put (Sample a b) = Serialize.put a >> Serialize.put b
get = Serialize.get >>= \a -> Serialize.get >>= \b -> return $ Sample a b
instance Aeson.ToJSON (Sample Double) where
toJSON (Sample x y) = Aeson.toJSON (x, y)
instance Aeson.FromJSON (Sample Double) where
parseJSON = fmap (uncurry Sample) . Aeson.parseJSON