packages feed

zoom-cache 0.1.0.1 → 0.1.0.2

raw patch · 2 files changed

+129/−2 lines, 2 files

Files

+ Data/ZoomCache/Binary.hs view
@@ -0,0 +1,126 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE RecordWildCards #-}+{-# OPTIONS -Wall #-}+----------------------------------------------------------------------+-- |+-- Module      : Data.ZoomCache.Write+-- Copyright   : Conrad Parker+-- License     : BSD3-style (see LICENSE)+--+-- Maintainer  : Conrad Parker <conrad@metadecks.org>+-- Stability   : unstable+-- Portability : unknown+--+-- Blaze-builder utility functions for writing ZoomCache files.+----------------------------------------------------------------------++module Data.ZoomCache.Binary (+    -- * Builders+      encInt+    , encDbl+    , fromRational64+    , fromGlobal+    , fromTrackType+    , fromDataRateType+    , fromTrackNo+    , fromSummary++    -- * Helpers+    , toWord64+) where++import Blaze.ByteString.Builder hiding (flush)+import qualified Data.ByteString.Lazy as L+import qualified Data.ByteString.Lazy.Char8 as LC+import Data.Monoid+import Data.Ratio+import Data.Word+import Unsafe.Coerce (unsafeCoerce)++import Data.ZoomCache.Common+import Data.ZoomCache.Summary++----------------------------------------------------------------------+-- Builders for local types++fromGlobal :: Global -> Builder+fromGlobal Global{..} = mconcat+    [ fromLazyByteString globalHeader+    , mconcat $+        [ fromVersion version+        , encInt noTracks+        , fromRational64 presentationTime+        , fromRational64 baseTime+        ]+    , fromLazyByteString $ LC.pack (replicate 20 '\0') -- UTCTime+    ]++fromVersion :: Version -> Builder+fromVersion (Version vMaj vMin) = mconcat+    [ fromInt16be . fromIntegral $ vMaj+    , fromInt16be . fromIntegral $ vMin+    ]++fromTrackType :: TrackType -> Builder+fromTrackType ZDouble = fromInt16be 0+fromTrackType ZInt    = fromInt16be 1++fromDataRateType :: DataRateType -> Builder+fromDataRateType ConstantDR = fromInt16be 0+fromDataRateType VariableDR = fromInt16be 1++fromTrackNo :: TrackNo -> Builder+fromTrackNo = fromInt32be . fromIntegral++fromSummary :: Summary -> Builder+fromSummary s@SummaryDouble{..} = mconcat [ fromSummaryHeader s, l, d]+    where+        d = mconcat $ map encDbl+            [ summaryDoubleEntry+            , summaryDoubleExit+            , summaryDoubleMin+            , summaryDoubleMax+            , summaryAvg+            , summaryRMS+            ]+        l = encInt . L.length . toLazyByteString $ d+fromSummary s@SummaryInt{..} = mconcat [ fromSummaryHeader s, l, d]+    where+        d = mconcat $ map encInt+            [ summaryIntEntry+            , summaryIntExit+            , summaryIntMin+            , summaryIntMax+            ] ++ map encDbl+            [ summaryAvg+            , summaryRMS+            ]+        l = encInt . L.length . toLazyByteString $ d++fromSummaryHeader :: Summary -> Builder+fromSummaryHeader s = mconcat+    [ fromLazyByteString summaryHeader+    , encInt . summaryTrack $ s+    , encInt . summaryLevel $ s+    , encInt . unTS . summaryEntryTime $ s+    , encInt . unTS . summaryExitTime $ s+    ]++----------------------------------------------------------------------+-- Binary data helpers+    +fromRational64 :: Rational -> Builder+fromRational64 r = mconcat+    [ fromInt64be . fromIntegral . numerator $ r+    , fromInt64be . fromIntegral . denominator $ r+    ]++encInt :: forall a . (Integral a) => a -> Builder+encInt = fromInt32be . fromIntegral++encDbl :: Double -> Builder+encDbl = fromWord64be . toWord64++toWord64 :: Double -> Word64+toWord64 = unsafeCoerce+
zoom-cache.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.1.0.1+Version:             0.1.0.2  -- A short (one-line) description of the package. Synopsis:            A streamable, seekable, zoomable cache file format@@ -49,7 +49,8 @@  Library   -- Modules exported by the library.-  Exposed-modules:     Data.ZoomCache.Common+  Exposed-modules:     Data.ZoomCache.Binary+                       Data.ZoomCache.Common                        Data.ZoomCache.Packet                        Data.ZoomCache.Pretty                        Data.ZoomCache.Read