-- 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 | Version minor | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | No. tracks | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Presentationtime numerator | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Presentationtime denominator | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Basetime numerator | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Basetime denominator | 40-43 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 44-47 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | UTC | 48-51 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 52-55 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 56-59 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 60-63 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 64-67 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Magic identifier at the beginning of a zoom-cache file. 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. | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Type | Flag: 0=CBR, 1=VBR | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Datarate numerator | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Datarate denominator | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Length of name in bytes | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Name (UTF-8) ... | 36- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Type: 0 64 bit IEEE754 floating point (Double) 1 32 bit signed integer -- (Int32) -- -- Datarate: numerator 0 indicates variable bitrate (all data values are -- timestamped) -- -- Identifier for track headers trackHeader :: 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. | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry Timestamp | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit TImestamp | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Payload length in bytes (remainder of packet) | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Count of data points COUNT | 32-35 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Data ... | 36-39 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 40- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Timestamps ... | TS- -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Timestamps block is only present if VBR (datarate numerator is 0) -- -- TS = 28 + (COUNT * sizeof(Type)) -- -- Identifier for packet headers packetHeader :: ByteString -- | Summary Data Packet header (IEEE754 floating point): -- --
-- 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. | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Level | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry Timestamp | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit Timestamp | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Summary length in bytes | 32-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 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Summary Data Packet header (signed 32-bit integer) -- --
-- 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. | 8-11 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Level | 12-15 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Entry Timestamp | 16-19 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 20-23 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Exit Timestamp | 24-27 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | ... | 28-31 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -- | Summary length in bytes | 32-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 -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ---- -- Identifier for summary headers summaryHeader :: ByteString -- | Iteratee reading of ZoomCache files. module Data.Iteratee.ZoomCache.Utils zReadInt16 :: (Functor m, MonadIO m) => Iteratee [Word8] m Int zReadInt32 :: (Functor m, MonadIO m) => Iteratee [Word8] m Int zReadInt64 :: (Functor m, MonadIO m) => Iteratee [Word8] m Integer zReadFloat64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Double readRational64 :: (Functor m, MonadIO m) => Iteratee [Word8] m Rational -- | Types used throughout zoom-cache module Data.ZoomCache.Common data TimeStamp TS :: !Integer -> TimeStamp unTS :: TimeStamp -> !Integer 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 -> Rational -> ByteString -> TrackSpec specType :: TrackSpec -> TrackType specDRType :: TrackSpec -> DataRateType specRate :: TrackSpec -> 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 class ZoomReadable a where { data family RawData a :: *; data family SummaryData a :: *; } readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a fromList :: ZoomReadable a => [a] -> RawData a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRawData :: ZoomReadable a => RawData a -> [String] prettySummaryData :: ZoomReadable a => SummaryData a -> String 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 toSummaryData :: ZoomWritable a => Double -> SummaryWork a -> SummaryData a updateSummaryData :: ZoomWritable a => Int -> TimeStamp -> a -> SummaryWork a -> SummaryWork a appendSummaryData :: ZoomWritable a => Double -> SummaryData a -> Double -> SummaryData a -> SummaryData a data ZoomRaw ZoomRaw :: (RawData 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 -> Integer -- | 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 -- | Interface for implementing ZoomCache codec instances. This module -- re-exports the interfaces required for developing zoom-cache codecs. -- -- For sample implementations, read the source of the provided instances -- Data.ZoomCache.Int and Data.ZoomCache.Double. module Data.ZoomCache.Codec class ZoomReadable a where { data family RawData a :: *; data family SummaryData a :: *; } readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a fromList :: ZoomReadable a => [a] -> RawData a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRawData :: ZoomReadable a => RawData a -> [String] prettySummaryData :: ZoomReadable a => SummaryData a -> String 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 toSummaryData :: ZoomWritable a => Double -> SummaryWork a -> SummaryData a updateSummaryData :: ZoomWritable a => Int -> TimeStamp -> a -> SummaryWork a -> SummaryWork 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 () data TimeStamp TS :: !Integer -> TimeStamp unTS :: TimeStamp -> !Integer zReadInt16 :: (Functor m, MonadIO m) => Iteratee [Word8] m Int zReadInt32 :: (Functor m, MonadIO m) => Iteratee [Word8] m Int zReadInt64 :: (Functor m, MonadIO m) => Iteratee [Word8] m Integer zReadFloat64be :: (Functor m, MonadIO m) => Iteratee [Word8] m Double readRational64 :: (Functor m, MonadIO m) => Iteratee [Word8] m Rational -- | 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 writeData :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> a -> ZoomW () writeDataVBR :: (Typeable a, ZoomWrite a, ZoomWritable a) => TrackNo -> (TimeStamp, a) -> ZoomW () -- | Default codec implementation for values of type Double. This module -- implements the interfaces documented in Data.ZoomCache.Codec. -- View the module source for enlightenment. 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. 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 :: !Integer -> TimeStamp unTS :: TimeStamp -> !Integer 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 class ZoomReadable a readRaw :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m a fromList :: ZoomReadable a => [a] -> RawData a readSummary :: (ZoomReadable a, Functor m, MonadIO m) => Iteratee [Word8] m (SummaryData a) prettyRawData :: ZoomReadable a => RawData a -> [String] prettySummaryData :: ZoomReadable a => SummaryData a -> String data ZoomRaw ZoomRaw :: (RawData 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 -> Rational -> ByteString -> TrackSpec specType :: TrackSpec -> TrackType specDRType :: TrackSpec -> DataRateType specRate :: TrackSpec -> 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 ()