-- 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! -- -- -- -- When developing applications that read or write zoom-cache files, it -- should be sufficient to import only the module Data.ZoomCache. @package zoom-cache @version 0.7.0.0 -- | The minimum and maximum positive, finite floats. module Data.ZoomCache.Numeric.FloatMinMax -- | The minimum positive, denormalized float. floatMin :: RealFloat a => a -- | The maximum denormalized float. floatMaxDenorm :: RealFloat a => a -- | The minimum positive, normalized float. floatMinNorm :: RealFloat a => a -- | The maximum finite float. floatMax :: RealFloat a => a -- | Delta encoding and decoding of numeric values. module Data.ZoomCache.Numeric.Delta -- | Delta encode a list of numbers -- --
--   > deltaEncode [1,2,3,2,4]
--   [1,1,1,-1,2]
--   
deltaEncode :: Num a => [a] -> [a] -- | Delta-decode a list of numbers -- --
--   > deltaDecode [1,1,1,-1,2]
--   [1,2,3,2,4]
--   
deltaDecode :: Num a => [a] -> [a] -- | zoom-cache format specification -- -- Field encoding formats: -- -- int16: 16bit big endian -- -- int32: 32bit big endian -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) module Data.ZoomCache.Format -- | Global 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
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | 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
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Reserved                                                |z|d|v| 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-
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- v : Variable data rate flag. 0=CBR, 1=VBR d : Delta -- encode flag. 0=Raw values 1=delta encoded values z : Zlib -- encode flag. 0=uncompressed 1=zlib compressed -- -- Datarate: numerator 0 indicates variable bitrate (all data values are -- timestamped) 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. (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.Numeric.Double and -- Data.ZoomCache.Numeric.Int. summaryHeader :: ByteString -- | Iteratee reading of ZoomCache files. module Data.Iteratee.ZoomCache.Utils -- | Read 1 byte as a signed Integral readInt8 :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 2 bytes as a big-endian signed Integral readInt16be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 4 bytes as a big-endian signed Integral readInt32be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 8 bytes as a big-endian signed Integral readInt64be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 1 byte as an unsigned Integral readWord8 :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 2 bytes as a big-endian unsigned Integral readWord16be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 4 bytes as a big-endian unsigned Integral readWord32be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 8 bytes as a big-endian unsigned Integral readWord64be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read a variable-length-coded Integer. For details of the -- variable-length coding format, see Data.ZoomCache.Numeric.Int. readIntegerVLC :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s m Integer -- | Read 4 bytes as a big-endian Float readFloat32be :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s m Float -- | Read 8 bytes as a big-endian Double readDouble64be :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s 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 :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s m Rational -- | Types used throughout zoom-cache module Data.ZoomCache.Common data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 data TimeStampDiff TSDiff :: {-# UNPACK #-} !Int64 -> TimeStampDiff unTSDiff :: TimeStampDiff -> {-# UNPACK #-} !Int64 -- |
--   timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)
--   
timeStampDiff :: TimeStamp -> TimeStamp -> TimeStampDiff -- | 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 data Version Version :: !Int -> !Int -> Version instance Eq TimeStamp instance Ord TimeStamp instance Show TimeStamp instance Eq TimeStampDiff instance Ord TimeStampDiff instance Show TimeStampDiff instance Eq Version instance Show Version instance Show Global instance Eq DataRateType instance Show DataRateType -- | ZoomCache packet and summary types and interfaces module Data.ZoomCache.Types data Codec Codec :: a -> Codec -- | 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 :: !Codec -> !Bool -> !Bool -> !DataRateType -> {-# UNPACK #-} !Rational -> !ByteString -> TrackSpec specType :: TrackSpec -> !Codec specDeltaEncode :: TrackSpec -> !Bool specZlibCompress :: TrackSpec -> !Bool specDRType :: TrackSpec -> !DataRateType specRate :: TrackSpec -> {-# UNPACK #-} !Rational specName :: TrackSpec -> !ByteString -- | Identify the tracktype corresponding to a given Codec Identifier. When -- parsing a zoom-cache file, the zoom-cache library will try each of a -- given list [IdentifyTrack]. -- -- The standard zoom-cache instances are provided in -- standardIdentifiers. -- -- When developing your own codecs it is not necessary to build a -- composite IdentifyTrack functions; it is sufficient to -- generate one for each new codec type. A library of related zoom-cache -- codecs should export its own [IdentifyTrack] functions, -- usually called something like mylibIdentifiers. -- -- These can be generated with identifyCodec. type IdentifyCodec = ByteString -> Maybe Codec -- | A codec instance must specify a SummaryData type, and implement -- all methods of this class. class Typeable a => ZoomReadable a where { data family SummaryData a :: *; { deltaDecodeRaw = id } } trackIdentifier :: ZoomReadable a => a -> ByteString readRaw :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m a readSummary :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String deltaDecodeRaw :: ZoomReadable a => [a] -> [a] -- | A codec instance must additionally specify a SummaryWork type class ZoomReadable a => ZoomWritable a where { data family SummaryWork a :: *; { deltaEncodeRaw _ = id } } fromRaw :: ZoomWritable a => a -> Builder fromSummaryData :: ZoomWritable a => SummaryData a -> Builder initSummaryWork :: ZoomWritable a => TimeStamp -> SummaryWork a updateSummaryData :: ZoomWritable a => TimeStamp -> a -> SummaryWork a -> SummaryWork a toSummaryData :: ZoomWritable a => TimeStampDiff -> SummaryWork a -> SummaryData a appendSummaryData :: ZoomWritable a => TimeStampDiff -> SummaryData a -> TimeStampDiff -> SummaryData a -> SummaryData a deltaEncodeRaw :: ZoomWritable a => SummaryWork a -> a -> 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 :: {-# UNPACK #-} !TrackNo -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !Int -> !ZoomRaw -> ![TimeStamp] -> Packet packetTrack :: Packet -> {-# UNPACK #-} !TrackNo packetEntryTime :: Packet -> {-# UNPACK #-} !TimeStamp packetExitTime :: Packet -> {-# UNPACK #-} !TimeStamp packetCount :: Packet -> {-# UNPACK #-} !Int packetData :: Packet -> !ZoomRaw packetTimeStamps :: Packet -> ![TimeStamp] -- | A recorded block of summary data data Summary a Summary :: {-# UNPACK #-} !TrackNo -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !TimeStamp -> !SummaryData a -> Summary a summaryTrack :: Summary a -> {-# UNPACK #-} !TrackNo summaryLevel :: Summary a -> {-# UNPACK #-} !Int summaryEntryTime :: Summary a -> {-# UNPACK #-} !TimeStamp summaryExitTime :: Summary a -> {-# UNPACK #-} !TimeStamp summaryData :: Summary a -> !SummaryData a -- | The duration covered by a summary, in units of 1 / the track's -- datarate summaryDuration :: Summary a -> TimeStampDiff -- | 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 instance Typeable1 Summary instance Show TrackSpec instance Show Codec -- | 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, Monad m) => [IdentifyCodec] -> Iteratee ByteString 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) => [IdentifyCodec] -> Enumeratee ByteString 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 ByteString Stream m a -- | Map a monadic Stream processing function over an entire -- zoom-cache file. mapStream :: (Functor m, MonadIO m) => [IdentifyCodec] -> (Stream -> m ()) -> Iteratee ByteString m () -- | Map a monadic Packet processing function over an entire -- zoom-cache file. mapPackets :: (Functor m, MonadIO m) => [IdentifyCodec] -> (Packet -> m ()) -> Iteratee ByteString m () -- | Map a monadic Summary processing function over an entire -- zoom-cache file. mapSummaries :: (Functor m, MonadIO m) => [IdentifyCodec] -> (ZoomSummary -> m ()) -> Iteratee ByteString m () instance NullPoint Stream instance Nullable Stream -- | Identifiers for track types of ZoomCache files. module Data.ZoomCache.Identify -- | Generate an IdentifyTrack function for a given type. identifyCodec :: ZoomReadable a => a -> IdentifyCodec -- | 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 Float in big-endian IEEE 754-2008 binary32 format -- (IEEE 754-1985 single format). fromFloat :: Float -> 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 an Integer in variable-length-coding format For -- details of the variable-length coding format, see -- Data.ZoomCache.Numeric.Int. fromIntegerVLC :: Integer -> 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 closeWrite :: ZoomWHandle -> IO () -- | 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 () mkTrackSpec :: ZoomReadable a => a -> Bool -> Bool -> DataRateType -> Rational -> ByteString -> TrackSpec -- | Create a track map for a stream of a given type, as track no. 1 oneTrack :: ZoomReadable a => a -> Bool -> Bool -> 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.Numeric.Int and -- Data.ZoomCache.Numeric.Double. module Data.ZoomCache.Codec -- | A codec instance must specify a SummaryData type, and implement -- all methods of this class. class Typeable a => ZoomReadable a where { data family SummaryData a :: *; { deltaDecodeRaw = id } } trackIdentifier :: ZoomReadable a => a -> ByteString readRaw :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m a readSummary :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String deltaDecodeRaw :: ZoomReadable a => [a] -> [a] -- | A codec instance must additionally specify a SummaryWork type class ZoomReadable a => ZoomWritable a where { data family SummaryWork a :: *; { deltaEncodeRaw _ = id } } fromRaw :: ZoomWritable a => a -> Builder fromSummaryData :: ZoomWritable a => SummaryData a -> Builder initSummaryWork :: ZoomWritable a => TimeStamp -> SummaryWork a updateSummaryData :: ZoomWritable a => TimeStamp -> a -> SummaryWork a -> SummaryWork a toSummaryData :: ZoomWritable a => TimeStampDiff -> SummaryWork a -> SummaryData a appendSummaryData :: ZoomWritable a => TimeStampDiff -> SummaryData a -> TimeStampDiff -> SummaryData a -> SummaryData a deltaEncodeRaw :: ZoomWritable a => SummaryWork a -> a -> 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 () -- | Generate an IdentifyTrack function for a given type. identifyCodec :: ZoomReadable a => a -> IdentifyCodec -- | Read 1 byte as a signed Integral readInt8 :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 2 bytes as a big-endian signed Integral readInt16be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 4 bytes as a big-endian signed Integral readInt32be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 8 bytes as a big-endian signed Integral readInt64be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 1 byte as an unsigned Integral readWord8 :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 2 bytes as a big-endian unsigned Integral readWord16be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 4 bytes as a big-endian unsigned Integral readWord32be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read 8 bytes as a big-endian unsigned Integral readWord64be :: (Nullable s, ListLike s Word8, Functor m, Monad m, Integral a) => Iteratee s m a -- | Read a variable-length-coded Integer. For details of the -- variable-length coding format, see Data.ZoomCache.Numeric.Int. readIntegerVLC :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s m Integer -- | Read 4 bytes as a big-endian Float readFloat32be :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s m Float -- | Read 8 bytes as a big-endian Double readDouble64be :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s 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 :: (Nullable s, ListLike s Word8, Functor m, Monad m) => Iteratee s 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 an Integer in variable-length-coding format For -- details of the variable-length coding format, see -- Data.ZoomCache.Numeric.Int. fromIntegerVLC :: Integer -> Builder -- | Serialize a Float in big-endian IEEE 754-2008 binary32 format -- (IEEE 754-1985 single format). fromFloat :: Float -> Builder -- | Serialize a Double in big-endian IEEE 754-2008 binary64 format -- (IEEE 754-1985 double format). fromDouble :: Double -> Builder data Codec data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 data TimeStampDiff TSDiff :: {-# UNPACK #-} !Int64 -> TimeStampDiff unTSDiff :: TimeStampDiff -> {-# UNPACK #-} !Int64 -- |
--   timeStampDiff (TS t1) (TS t2) = TSDiff (t1 - t2)
--   
timeStampDiff :: TimeStamp -> TimeStamp -> TimeStampDiff -- | Default codec implementation for values of type Bool. Elements of type -- Bool are useful for recording observations of binary events. -- -- This module implements the interfaces documented in -- Data.ZoomCache.Codec. -- -- The table below describes the encoding of SummaryData for Bool. -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Expected value (double)                                       | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | ...                                                           | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- Field encoding formats: -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) module Data.ZoomCache.Bool instance ZoomWritable Bool instance ZoomWrite (TimeStamp, Bool) instance ZoomWrite Bool instance ZoomReadable Bool -- | Default codec implementation for values of type (). Elements of type -- () are useful for marking events, and variable rate tracks written -- with type (TimeStamp, ()) are useful for recording times of events. -- -- This module implements the interfaces documented in -- Data.ZoomCache.Codec. -- -- As elements of type () contain no unique information it is sufficient -- to record only a count of elements which occur within each packet. -- -- No raw data is encoded for tracks of type () as the raw data packet -- header already includes a count of elements. This is implemented by -- specifying const mempty) as the Builder and (return ()) -- as the reader. -- -- The table below describes the encoding of SummaryData for (). -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Count (int32)                                                 | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- Field encoding formats: -- -- int32: 32bit big endian module Data.ZoomCache.Unit instance ZoomWritable () instance ZoomWrite (TimeStamp, ()) instance ZoomWrite () instance ZoomReadable () module Data.ZoomCache.Numeric.Types class (Ord a, Real a, ZoomReadable a, ZoomWritable a) => ZoomNum a numEntry :: ZoomNum a => SummaryData a -> a numExit :: ZoomNum a => SummaryData a -> a numMin :: ZoomNum a => SummaryData a -> a numMax :: ZoomNum a => SummaryData a -> a numAvg :: ZoomNum a => SummaryData a -> Double numRMS :: ZoomNum a => SummaryData a -> Double numWorkTime :: ZoomNum a => SummaryWork a -> TimeStamp numWorkEntry :: ZoomNum a => SummaryWork a -> Maybe a numWorkExit :: ZoomNum a => SummaryWork a -> a numWorkMin :: ZoomNum a => SummaryWork a -> a numWorkMax :: ZoomNum a => SummaryWork a -> a numWorkSum :: ZoomNum a => SummaryWork a -> Double numWorkSumSq :: ZoomNum a => SummaryWork a -> Double numMkSummary :: ZoomNum a => a -> a -> a -> a -> Double -> Double -> SummaryData a numMkSummaryWork :: ZoomNum a => TimeStamp -> Maybe a -> a -> a -> a -> Double -> Double -> SummaryWork a module Data.ZoomCache.Numeric.Internal readSummaryNum :: (Functor m, Monad m, ZoomNum a) => Iteratee ByteString m (SummaryData a) fromSummaryNum :: ZoomNum a => SummaryData a -> Builder initSummaryNumBounded :: (Bounded a, ZoomNum a) => TimeStamp -> SummaryWork a mkSummaryNum :: ZoomNum a => TimeStampDiff -> SummaryWork a -> SummaryData a appendSummaryNum :: ZoomNum a => TimeStampDiff -> SummaryData a -> TimeStampDiff -> SummaryData a -> SummaryData a updateSummaryNum :: ZoomNum a => TimeStamp -> a -> SummaryWork a -> SummaryWork a deltaDecodeNum :: ZoomNum a => [a] -> [a] deltaEncodeNum :: ZoomNum a => SummaryWork a -> a -> a -- | Default codec implementation for values of type Float and 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 Float. -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (float)                                                 | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Exit (float)                                                  | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (float)                                                   | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Max (float)                                                   | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (float)                                                   | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (float)                                                   | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- 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: -- -- float: big-endian IEEE 754-2008 binary32 (IEEE 754-1985 -- single) double: big-endian IEEE 754-2008 binary64 (IEEE -- 754-1985 double) module Data.ZoomCache.Numeric.IEEE754 instance ZoomNum Double instance ZoomWritable Double instance ZoomWrite (TimeStamp, Double) instance ZoomWrite Double instance ZoomReadable Double instance ZoomNum Float instance ZoomWritable Float instance ZoomWrite (TimeStamp, Float) instance ZoomWrite Float instance ZoomReadable Float -- | 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 Int8: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (int8)  | Exit (int8)   | Min (int8)    | Max (int8)    | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Int16: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (int16)                 | Exit (int16)                  | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (int16)                   | Max (int16)                   | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Int32: -- --
--   | ...                                                           |   -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
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Int64: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (int64)                                                 | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Exit (int64)                                                  | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (int64)                                                   | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Max (int64)                                                   | 60-63
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 64-67
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 68-71
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 72-75
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 76-79
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 80-83
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- SummaryData for Int and Integer is encoded as the following sequence: -- --
--   Entry (intVLC)
--   Exit (intVLC)
--   Min (intVLC)
--   Max (intVLC)
--   Avg (double)
--   RMS (double)
--   
-- -- Field encoding formats: -- -- int8: 8bit signed integer -- -- int16: 16bit big endian signed integer -- -- int32: 32bit big endian signed integer -- -- int64: 32bit big endian signed integer -- -- intVLC: Variable-length-coded signed integer -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) -- -- Variable-length coding format: -- -- zoom-cache includes a simple variable-length coding scheme for signed -- integers. When decoding, single bytes are read at a time. If the high -- bit is set, the next byte is also read. The lower 7 bits of each byte -- contain data. Decoding continues by reading single bytes until a byte -- is read with the high bit zero. -- -- The first byte of a variable-length coded integer contain a sign bit -- and the lowest 6 bits of the value. This byte is encoded as: -- --
--    0 1 2 3 4 5 6 7
--   +-+-+-+-+-+-+-+-+
--   |s| d[0]-d[5] |c|
--   +-+-+-+-+-+-+-+-+
--   
-- -- Subsequent bytes encode bits 6-12, 13-19, ... of the value: -- --
--    0 1 2 3 4 5 6 7
--   +-+-+-+-+-+-+-+-+
--   | d[n]-d[n+6] |c|
--   +-+-+-+-+-+-+-+-+
--   
-- -- where n = 6, 13, 20, ... -- -- s: sign, 1 = negative, 0 = non-negative -- -- c: continue flag, 1 = continue reading next byte, 0 = stop module Data.ZoomCache.Numeric.Int instance ZoomNum Integer instance ZoomWritable Integer instance ZoomWrite (TimeStamp, Integer) instance ZoomWrite Integer instance ZoomReadable Integer instance ZoomNum Int64 instance ZoomWritable Int64 instance ZoomWrite (TimeStamp, Int64) instance ZoomWrite Int64 instance ZoomReadable Int64 instance ZoomNum Int32 instance ZoomWritable Int32 instance ZoomWrite (TimeStamp, Int32) instance ZoomWrite Int32 instance ZoomReadable Int32 instance ZoomNum Int16 instance ZoomWritable Int16 instance ZoomWrite (TimeStamp, Int16) instance ZoomWrite Int16 instance ZoomReadable Int16 instance ZoomNum Int8 instance ZoomWritable Int8 instance ZoomWrite (TimeStamp, Int8) instance ZoomWrite Int8 instance ZoomReadable Int8 instance ZoomNum Int instance ZoomWritable Int instance ZoomWrite (TimeStamp, Int) instance ZoomWrite Int instance ZoomReadable Int -- | Default codec implementation for values of type Word. 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 Word8: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (word8) | Exit (word8)  | Min (word8)   | Max (word8)   | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Word16: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (word16)                | Exit (word16)                 | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (word16)                  | Max (word16)                  | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Word32: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (word32)                                                | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Exit (word32)                                                 | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (word32)                                                  | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Max (word32)                                                  | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 60-63
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 64-67
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- The table below describes the encoding of SummaryData for Word64: -- --
--   | ...                                                           |   -35
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Entry (word64)                                                | 36-39
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 40-43
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Exit (word64)                                                 | 44-47
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 48-51
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Min (word64)                                                  | 52-55
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 56-59
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Max (word64)                                                  | 60-63
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 64-67
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | Avg (double)                                                  | 68-71
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 72-75
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   | RMS (double)                                                  | 76-79
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   |                                                               | 80-83
--   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--   
-- -- SummaryData for Word is encoded as the following sequence, in which -- the variable-length coded sign bit is always zero: -- --
--   Entry (intVLC)
--   Exit (intVLC)
--   Min (intVLC)
--   Max (intVLC)
--   Avg (double)
--   RMS (double)
--   
-- -- Field encoding formats: -- -- word8: 8bit unsigned integer -- -- word16: 16bit big endian unsigned integer -- -- word32: 32bit big endian unsigned integer -- -- word64: 32bit big endian unsigned integer -- -- intVLC: Variable-length-coded signed integer -- -- double: big-endian IEEE 754-2008 binary64 (IEEE 754-1985 -- double) -- -- For details of the variable-length coding format, see -- Data.ZoomCache.Numeric.Int. module Data.ZoomCache.Numeric.Word instance ZoomNum Word64 instance ZoomWritable Word64 instance ZoomWrite (TimeStamp, Word64) instance ZoomWrite Word64 instance ZoomReadable Word64 instance ZoomNum Word32 instance ZoomWritable Word32 instance ZoomWrite (TimeStamp, Word32) instance ZoomWrite Word32 instance ZoomReadable Word32 instance ZoomNum Word16 instance ZoomWritable Word16 instance ZoomWrite (TimeStamp, Word16) instance ZoomWrite Word16 instance ZoomReadable Word16 instance ZoomNum Word8 instance ZoomWritable Word8 instance ZoomWrite (TimeStamp, Word8) instance ZoomWrite Word8 instance ZoomReadable Word8 instance ZoomNum Word instance ZoomWritable Word instance ZoomWrite (TimeStamp, Word) instance ZoomWrite Word instance ZoomReadable Word -- | API for implementing ZoomCache applications module Data.ZoomCache data TimeStamp TS :: {-# UNPACK #-} !Int64 -> TimeStamp unTS :: TimeStamp -> {-# UNPACK #-} !Int64 type TrackNo = Int data Codec Codec :: a -> Codec -- | Identify the tracktype corresponding to a given Codec Identifier. When -- parsing a zoom-cache file, the zoom-cache library will try each of a -- given list [IdentifyTrack]. -- -- The standard zoom-cache instances are provided in -- standardIdentifiers. -- -- When developing your own codecs it is not necessary to build a -- composite IdentifyTrack functions; it is sufficient to -- generate one for each new codec type. A library of related zoom-cache -- codecs should export its own [IdentifyTrack] functions, -- usually called something like mylibIdentifiers. -- -- These can be generated with identifyCodec. type IdentifyCodec = ByteString -> Maybe Codec -- | 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 Typeable a => ZoomReadable a trackIdentifier :: ZoomReadable a => a -> ByteString readRaw :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m a readSummary :: (ZoomReadable a, Functor m, Monad m) => Iteratee ByteString m (SummaryData a) prettyRaw :: ZoomReadable a => a -> String prettySummaryData :: ZoomReadable a => SummaryData a -> String deltaDecodeRaw :: ZoomReadable a => [a] -> [a] data ZoomRaw ZoomRaw :: [a] -> ZoomRaw data ZoomSummary ZoomSummary :: (Summary a) -> ZoomSummary data Packet Packet :: {-# UNPACK #-} !TrackNo -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !Int -> !ZoomRaw -> ![TimeStamp] -> Packet packetTrack :: Packet -> {-# UNPACK #-} !TrackNo packetEntryTime :: Packet -> {-# UNPACK #-} !TimeStamp packetExitTime :: Packet -> {-# UNPACK #-} !TimeStamp packetCount :: Packet -> {-# UNPACK #-} !Int packetData :: Packet -> !ZoomRaw packetTimeStamps :: Packet -> ![TimeStamp] -- | A recorded block of summary data data Summary a Summary :: {-# UNPACK #-} !TrackNo -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !TimeStamp -> {-# UNPACK #-} !TimeStamp -> !SummaryData a -> Summary a summaryTrack :: Summary a -> {-# UNPACK #-} !TrackNo summaryLevel :: Summary a -> {-# UNPACK #-} !Int summaryEntryTime :: Summary a -> {-# UNPACK #-} !TimeStamp summaryExitTime :: Summary a -> {-# UNPACK #-} !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 :: !Codec -> !Bool -> !Bool -> !DataRateType -> {-# UNPACK #-} !Rational -> !ByteString -> TrackSpec specType :: TrackSpec -> !Codec specDeltaEncode :: TrackSpec -> !Bool specZlibCompress :: TrackSpec -> !Bool 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 () data ZoomWHandle -- | Open a new ZoomCache file for writing, using a specified -- TrackMap. openWrite :: TrackMap -> Bool -> FilePath -> IO ZoomWHandle closeWrite :: ZoomWHandle -> IO () -- | 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 () mkTrackSpec :: ZoomReadable a => a -> Bool -> Bool -> DataRateType -> Rational -> ByteString -> TrackSpec -- | Create a track map for a stream of a given type, as track no. 1 oneTrack :: ZoomReadable a => a -> Bool -> Bool -> DataRateType -> Rational -> ByteString -> TrackMap -- | IdentifyTrack functions provided for standard codecs provided -- by the zoom-cache library. standardIdentifiers :: [IdentifyCodec] -- | Reading of ZoomCache files. module Data.ZoomCache.Dump zoomDumpFile :: [IdentifyCodec] -> TrackNo -> FilePath -> IO () zoomDumpSummary :: [IdentifyCodec] -> TrackNo -> FilePath -> IO () zoomDumpSummaryLevel :: [IdentifyCodec] -> TrackNo -> Int -> FilePath -> IO () zoomInfoFile :: [IdentifyCodec] -> FilePath -> IO ()