-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A streamable, seekable, zoomable cache file format -- -- zoom-cache is a fairly simple data file format for storing and -- summarizing streams of time-series data. The purpose of this format is -- to make it easy to quickly generate plots; zooming refers to -- being able to render a window of data, and being able to quickly -- change the bounds of the window: to move around and to zoom in and -- out. -- -- This library provides a monadic writing and an iteratee reading -- interface for zoom-cache files. -- -- What's neat about this format and library? Glad you asked! -- --
-- 0 1 2 3 -- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Identifier | 0-3 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 4-7 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Version major (int16) | Version minor (int16) | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | No. tracks (int32) | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Presentationtime numerator (int64) | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Presentationtime denominator (int64) | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Basetime numerator (int64) | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Basetime denominator (int64) | 40-43 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 44-47 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | UTC | 48-51 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 52-55 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 56-59 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 60-63 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 64-67 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ --globalHeader :: ByteString -- | The major version encoded by this library versionMajor :: Int -- | The minor version encoded by this library versionMinor :: Int -- | Track header: -- --
-- 0 1 2 3 -- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Identifier | 0-3 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 4-7 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Track no. (int32) | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Codec identifier | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Flag: 0=CBR, 1=VBR | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Datarate numerator (int64) | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Datarate denominator (int64) | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Length of name in bytes (int32) | 40-43 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Name (UTF-8) ... | 44- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Datarate: numerator 0 indicates variable bitrate (all data values are -- timestamped) trackHeader :: ByteString trackTypeDouble :: ByteString trackTypeInt :: ByteString -- | Raw Data Packet header: -- --
-- 0 1 2 3 -- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Identifier | 0-3 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 4-7 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Track no. (int32) | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry Timestamp (int64) | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit TImestamp (int64) | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Count of data points COUNT (int32) | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Payload length in bytes (remainder of packet) (int32) | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Data ... | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 40- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Timestamps ... | TS- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Timestamps block is only present if VBR (datarate numerator is 0) -- -- TS = 28 + (COUNT * sizeof(Type)) packetHeader :: ByteString -- | Summary Data Packet header: -- --
-- 0 1 2 3 -- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Identifier | 0-3 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 4-7 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Track no. (int32) | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Level (int32) | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry Timestamp (int64) | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit Timestamp (int64) | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Summary length in bytes (int32) | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Summary Data ... | 36- ---- -- Some default encodings of Summary Data are provided in modules -- Data.ZoomCache.Double and Data.ZoomCache.Int. summaryHeader :: ByteString -- | Iteratee reading of ZoomCache files. module Data.Iteratee.ZoomCache.Utils -- | Read 2 bytes as a big-endian Int. readInt16be :: (Functor m, MonadIO m) => Iteratee [Word8] m Int -- | Read 4 bytes as a big-endian Int. readInt32be :: (Functor m, MonadIO m) => Iteratee [Word8] m Int -- | Read 8 bytes as a big-endian Integer readInt64be :: (Functor m, MonadIO m, Integral a) => Iteratee [Word8] m a -- | Read 8 bytes as a big-endian Double readDouble64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Double -- | Read 16 bytes as a big-endian Rational, encoded as an 8 byte big -- endian numerator followed by an 8 byte big endian denominator. readRational64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Rational -- | Types used throughout zoom-cache module Data.ZoomCache.Common data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 data TrackType ZDouble :: TrackType ZInt :: TrackType -- | Constant or Variable datarate. For constant datarate, timestamps are -- implied as incrementing by 1/datarate For variable datarate, explicit -- timestamps are attached to each datum, encoded as a separate block of -- timestamps in the Raw Data packet. data DataRateType ConstantDR :: DataRateType VariableDR :: DataRateType type TrackNo = Int data Global Global :: Version -> Int -> Rational -> Rational -> Maybe Int -> Global version :: Global -> Version noTracks :: Global -> Int presentationTime :: Global -> Rational baseTime :: Global -> Rational baseUTC :: Global -> Maybe Int -- | Global and track headers for a zoom-cache file data CacheFile CacheFile :: Global -> IntMap TrackSpec -> CacheFile cfGlobal :: CacheFile -> Global cfSpecs :: CacheFile -> IntMap TrackSpec -- | Create an empty CacheFile using the given Global mkCacheFile :: Global -> CacheFile -- | Determine whether all tracks of a CacheFile are specified fiFull :: CacheFile -> Bool data Version Version :: !Int -> !Int -> Version -- | A map of all track numbers to their TrackSpec type TrackMap = IntMap TrackSpec -- | A specification of the type and name of each track data TrackSpec TrackSpec :: !TrackType -> !DataRateType -> {-# UNPACK #-} !Rational -> !ByteString -> TrackSpec specType :: TrackSpec -> !TrackType specDRType :: TrackSpec -> !DataRateType specRate :: TrackSpec -> {-# UNPACK #-} !Rational specName :: TrackSpec -> !ByteString instance Eq TimeStamp instance Ord TimeStamp instance Show TimeStamp instance Eq Version instance Show Version instance Show Global instance Eq TrackType instance Show TrackType instance Show DataRateType instance Show TrackSpec -- | ZoomCache packet and summary types and interfaces module Data.ZoomCache.Types -- | A codec instance must specify a SummaryData type, and implement -- all methods of this class. class ZoomReadable a where { data family SummaryData a :: *; } readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String -- | A codec instance must additionally specify a SummaryWork type class ZoomWritable a where { data family SummaryWork a :: *; } fromRaw :: ZoomWritable a => a -> Builder fromSummaryData :: ZoomWritable a => SummaryData a -> Builder initSummaryWork :: ZoomWritable a => TimeStamp -> SummaryWork a updateSummaryData :: ZoomWritable a => Int -> TimeStamp -> a -> SummaryWork a -> SummaryWork a toSummaryData :: ZoomWritable a => Double -> SummaryWork a -> SummaryData a appendSummaryData :: ZoomWritable a => Double -> SummaryData a -> Double -> SummaryData a -> SummaryData a data ZoomRaw ZoomRaw :: [a] -> ZoomRaw data ZoomSummary ZoomSummary :: (Summary a) -> ZoomSummary data ZoomWork ZoomWork :: IntMap (Summary a -> Summary a) -> Maybe (SummaryWork a) -> ZoomWork levels :: ZoomWork -> IntMap (Summary a -> Summary a) currWork :: ZoomWork -> Maybe (SummaryWork a) data Packet Packet :: TrackNo -> TimeStamp -> TimeStamp -> Int -> ZoomRaw -> [TimeStamp] -> Packet packetTrack :: Packet -> TrackNo packetEntryTime :: Packet -> TimeStamp packetExitTime :: Packet -> TimeStamp packetCount :: Packet -> Int packetData :: Packet -> ZoomRaw packetTimeStamps :: Packet -> [TimeStamp] -- | A recorded block of summary data data Summary a Summary :: TrackNo -> Int -> TimeStamp -> TimeStamp -> SummaryData a -> Summary a summaryTrack :: Summary a -> TrackNo summaryLevel :: Summary a -> Int summaryEntryTime :: Summary a -> TimeStamp summaryExitTime :: Summary a -> TimeStamp summaryData :: Summary a -> SummaryData a -- | The duration covered by a summary, in units of 1 / the track's -- datarate summaryDuration :: Summary a -> Int64 -- | Pretty-printing of zoom-cache types module Data.ZoomCache.Pretty -- | Pretty-print a Global prettyGlobal :: Global -> String -- | Pretty-print a TrackSpec prettyTrackSpec :: TrackNo -> TrackSpec -> String -- | Pretty-print a TimeStamp, given a datarate prettyTimeStamp :: Rational -> TimeStamp -> String -- | Pretty-print a Summary, given a datarate prettySummary :: ZoomReadable a => Rational -> Summary a -> String -- | Blaze-builder utility functions for writing ZoomCache files. module Blaze.ByteString.Builder.ZoomCache -- | Serialize a TimeStamp in 64bit big endian format. fromTimeStamp :: TimeStamp -> Builder -- | Serialize a Double in big-endian IEEE 754-2008 binary64 format -- (IEEE 754-1985 double format). fromDouble :: Double -> Builder -- | Serialize an Integral in 32bit big endian format. fromIntegral32be :: Integral a => a -> Builder -- | Serialize a Rational as a sequence of two 64bit big endian -- format integers. fromRational64 :: Rational -> Builder -- | Writing of ZoomCache files. module Data.ZoomCache.Write -- | The ZoomWrite class provides write, a method to write a Haskell -- value to an open ZoomCache file. class ZoomWrite t write :: ZoomWrite t => TrackNo -> t -> ZoomW () writeData :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> a -> ZoomW () writeDataVBR :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> (TimeStamp, a) -> ZoomW () -- | A StateT IO monad for writing a ZoomCache file type ZoomW = StateT ZoomWHandle IO -- | Run a ZoomW () action on a given file handle, using the -- specified TrackMap specification withFileWrite :: TrackMap -> Bool -> ZoomW () -> FilePath -> IO () -- | Force a flush of ZoomCache summary blocks to disk. It is not usually -- necessary to call this function as summary blocks are transparently -- written at regular intervals. flush :: ZoomW () data ZoomWHandle -- | Open a new ZoomCache file for writing, using a specified -- TrackMap. openWrite :: TrackMap -> Bool -> FilePath -> IO ZoomWHandle -- | Query the maximum number of data points to buffer for a given track -- before forcing a flush of all buffered data and summaries. watermark :: TrackNo -> ZoomW (Maybe Int) -- | Set the maximum number of data points to buffer for a given track -- before forcing a flush of all buffered data and summaries. setWatermark :: TrackNo -> Int -> ZoomW () -- | Create a track map for a stream of a given type, as track no. 1 oneTrack :: TrackType -> DataRateType -> Rational -> ByteString -> TrackMap -- | This module re-exports the required interfaces and some useful -- functions for developing zoom-cache codecs. -- -- To implement a codec, specify SummaryData and -- SummaryWork types, and implement the methods of the -- ZoomReadable and ZoomWritable classes. -- -- For sample implementations, read the source of the provided instances -- Data.ZoomCache.Int and Data.ZoomCache.Double. module Data.ZoomCache.Codec -- | A codec instance must specify a SummaryData type, and implement -- all methods of this class. class ZoomReadable a where { data family SummaryData a :: *; } readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String -- | A codec instance must additionally specify a SummaryWork type class ZoomWritable a where { data family SummaryWork a :: *; } fromRaw :: ZoomWritable a => a -> Builder fromSummaryData :: ZoomWritable a => SummaryData a -> Builder initSummaryWork :: ZoomWritable a => TimeStamp -> SummaryWork a updateSummaryData :: ZoomWritable a => Int -> TimeStamp -> a -> SummaryWork a -> SummaryWork a toSummaryData :: ZoomWritable a => Double -> SummaryWork a -> SummaryData a appendSummaryData :: ZoomWritable a => Double -> SummaryData a -> Double -> SummaryData a -> SummaryData a -- | The ZoomWrite class provides write, a method to write a Haskell -- value to an open ZoomCache file. class ZoomWrite t write :: ZoomWrite t => TrackNo -> t -> ZoomW () -- | Read 2 bytes as a big-endian Int. readInt16be :: (Functor m, MonadIO m) => Iteratee [Word8] m Int -- | Read 4 bytes as a big-endian Int. readInt32be :: (Functor m, MonadIO m) => Iteratee [Word8] m Int -- | Read 8 bytes as a big-endian Integer readInt64be :: (Functor m, MonadIO m, Integral a) => Iteratee [Word8] m a -- | Read 8 bytes as a big-endian Double readDouble64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Double -- | Read 16 bytes as a big-endian Rational, encoded as an 8 byte big -- endian numerator followed by an 8 byte big endian denominator. readRational64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Rational writeData :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> a -> ZoomW () writeDataVBR :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> (TimeStamp, a) -> ZoomW () -- | Serialize a Rational as a sequence of two 64bit big endian -- format integers. fromRational64 :: Rational -> Builder -- | Serialize an Integral in 32bit big endian format. fromIntegral32be :: Integral a => a -> Builder -- | Serialize a Double in big-endian IEEE 754-2008 binary64 format -- (IEEE 754-1985 double format). fromDouble :: Double -> Builder data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 -- | Default codec implementation for values of type Double. This module -- implements the interfaces documented in Data.ZoomCache.Codec. -- View the module source for enlightenment. -- -- The table below describes the encoding of SummaryData for Double. -- --
-- | ... | -35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry (double) | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 40-43 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit (double) | 44-47 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 48-51 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Min (double) | 52-55 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 56-59 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Max (double) | 60-63 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 64-67 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Avg (double) | 68-71 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 72-75 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | RMS (double) | 76-79 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 80-83 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Field encoding formats: -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) module Data.ZoomCache.Double instance ZoomWritable Double instance ZoomWrite (TimeStamp, Double) instance ZoomWrite Double instance ZoomReadable Double -- | Default codec implementation for values of type Int. This module -- implements the interfaces documented in Data.ZoomCache.Codec. -- View the module source for enlightenment. -- -- The table below describes the encoding of SummaryData for Int. -- --
-- | ... | -35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry (int32) | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit (int32) | 40-43 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Min (int32) | 44-47 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Max (int32) | 48-51 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Avg (double) | 52-55 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 56-59 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | RMS (double) | 60-63 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 64-67 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Field encoding formats: -- -- int32: 32bit big endian -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) module Data.ZoomCache.Int instance ZoomWritable Int instance ZoomWrite (TimeStamp, Int) instance ZoomWrite Int instance ZoomReadable Int -- | Iteratee reading of ZoomCache files. module Data.Iteratee.ZoomCache data Stream StreamPacket :: CacheFile -> TrackNo -> Packet -> Stream strmFile :: Stream -> CacheFile strmTrack :: Stream -> TrackNo strmPacket :: Stream -> Packet StreamSummary :: CacheFile -> TrackNo -> ZoomSummary -> Stream strmFile :: Stream -> CacheFile strmTrack :: Stream -> TrackNo strmSummary :: Stream -> ZoomSummary StreamNull :: Stream -- | Parse only the global and track headers of a zoom-cache file, -- returning a CacheFile iterHeaders :: (Functor m, MonadIO m) => Iteratee [Word8] m CacheFile -- | An enumeratee of a zoom-cache file, from the global header onwards. -- The global and track headers will be transparently read, and the -- CacheFile visible in the Stream elements. enumCacheFile :: (Functor m, MonadIO m) => Enumeratee [Word8] Stream m a -- | An enumeratee of zoom-cache data, after global and track headers have -- been read, or if the CacheFile has been acquired elsewhere. enumStream :: (Functor m, MonadIO m) => CacheFile -> Enumeratee [Word8] Stream m a -- | Map a monadic Stream processing function over an entire -- zoom-cache file. mapStream :: (Functor m, MonadIO m) => (Stream -> m ()) -> Iteratee [Word8] m () -- | Map a monadic Packet processing function over an entire -- zoom-cache file. mapPackets :: (Functor m, MonadIO m) => (Packet -> m ()) -> Iteratee [Word8] m () -- | Map a monadic Summary processing function over an entire -- zoom-cache file. mapSummaries :: (Functor m, MonadIO m) => (ZoomSummary -> m ()) -> Iteratee [Word8] m () instance NullPoint Stream instance Nullable Stream -- | API for implementing ZoomCache applications module Data.ZoomCache data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 type TrackNo = Int data TrackType ZDouble :: TrackType ZInt :: TrackType -- | Constant or Variable datarate. For constant datarate, timestamps are -- implied as incrementing by 1/datarate For variable datarate, explicit -- timestamps are attached to each datum, encoded as a separate block of -- timestamps in the Raw Data packet. data DataRateType ConstantDR :: DataRateType VariableDR :: DataRateType -- | Global and track headers for a zoom-cache file data CacheFile CacheFile :: Global -> IntMap TrackSpec -> CacheFile cfGlobal :: CacheFile -> Global cfSpecs :: CacheFile -> IntMap TrackSpec -- | A codec instance must specify a SummaryData type, and implement -- all methods of this class. class ZoomReadable a readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String data ZoomRaw ZoomRaw :: [a] -> ZoomRaw data ZoomSummary ZoomSummary :: (Summary a) -> ZoomSummary data Packet Packet :: TrackNo -> TimeStamp -> TimeStamp -> Int -> ZoomRaw -> [TimeStamp] -> Packet packetTrack :: Packet -> TrackNo packetEntryTime :: Packet -> TimeStamp packetExitTime :: Packet -> TimeStamp packetCount :: Packet -> Int packetData :: Packet -> ZoomRaw packetTimeStamps :: Packet -> [TimeStamp] -- | A recorded block of summary data data Summary a Summary :: TrackNo -> Int -> TimeStamp -> TimeStamp -> SummaryData a -> Summary a summaryTrack :: Summary a -> TrackNo summaryLevel :: Summary a -> Int summaryEntryTime :: Summary a -> TimeStamp summaryExitTime :: Summary a -> TimeStamp summaryData :: Summary a -> SummaryData a -- | A map of all track numbers to their TrackSpec type TrackMap = IntMap TrackSpec -- | A specification of the type and name of each track data TrackSpec TrackSpec :: !TrackType -> !DataRateType -> {-# UNPACK #-} !Rational -> !ByteString -> TrackSpec specType :: TrackSpec -> !TrackType specDRType :: TrackSpec -> !DataRateType specRate :: TrackSpec -> {-# UNPACK #-} !Rational specName :: TrackSpec -> !ByteString -- | The ZoomWrite class provides write, a method to write a Haskell -- value to an open ZoomCache file. class ZoomWrite t write :: ZoomWrite t => TrackNo -> t -> ZoomW () -- | A StateT IO monad for writing a ZoomCache file type ZoomW = StateT ZoomWHandle IO -- | Run a ZoomW () action on a given file handle, using the -- specified TrackMap specification withFileWrite :: TrackMap -> Bool -> ZoomW () -> FilePath -> IO () -- | Force a flush of ZoomCache summary blocks to disk. It is not usually -- necessary to call this function as summary blocks are transparently -- written at regular intervals. flush :: ZoomW () -- | Query the maximum number of data points to buffer for a given track -- before forcing a flush of all buffered data and summaries. watermark :: TrackNo -> ZoomW (Maybe Int) -- | Set the maximum number of data points to buffer for a given track -- before forcing a flush of all buffered data and summaries. setWatermark :: TrackNo -> Int -> ZoomW () -- | Create a track map for a stream of a given type, as track no. 1 oneTrack :: TrackType -> DataRateType -> Rational -> ByteString -> TrackMap -- | Reading of ZoomCache files. module Data.ZoomCache.Dump zoomDumpFile :: TrackNo -> FilePath -> IO () zoomDumpSummary :: TrackNo -> FilePath -> IO () zoomDumpSummaryLevel :: TrackNo -> Int -> FilePath -> IO () zoomInfoFile :: FilePath -> IO ()