Commits

Bryan O'Sullivan committed 475280d Merge

Merge pull request #38 from snoyberg/master

binary 0.5 support

  • Participants
  • Parent commits e12b968, e413e99

Comments (0)

Files changed (4)

File Criterion/Analysis/Types.hs

     , SampleAnalysis(..)
     ) where
 
+import Control.Applicative ((<$>), (<*>))
 import Control.DeepSeq (NFData(rnf))
-import Data.Binary (Binary)
+import Data.Binary (Binary (..), putWord8, getWord8)
 import Data.Data (Data, Typeable)
 import Data.Int (Int64)
 import Data.Monoid (Monoid(..))
     -- ^ More than 3 times the IQR above the third quartile.
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Outliers
+instance Binary Outliers where
+    put (Outliers v w x y z) = put v >> put w >> put x >> put y >> put z
+    get = Outliers <$> get <*> get <*> get <*> get <*> get
 instance NFData Outliers
 
 -- | A description of the extent to which outliers in the sample data
                                 -- are useless).
                      deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
 
-instance Binary OutlierEffect
+instance Binary OutlierEffect where
+    put Unaffected = putWord8 0
+    put Slight     = putWord8 1
+    put Moderate   = putWord8 2
+    put Severe     = putWord8 3
+    get = do
+        i <- getWord8
+        case i of
+            0 -> return Unaffected
+            1 -> return Slight
+            2 -> return Moderate
+            3 -> return Severe
+            _ -> fail $ "get for OutlierEffect: unexpected " ++ show i
 instance NFData OutlierEffect
 
 instance Monoid Outliers where
     -- ^ Quantitative description of effect (a fraction between 0 and 1).
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary OutlierVariance
+instance Binary OutlierVariance where
+    put (OutlierVariance x y z) = put x >> put y >> put z
+    get = OutlierVariance <$> get <*> get <*> get
 
 instance NFData OutlierVariance where
     rnf OutlierVariance{..} = rnf ovEffect `seq` rnf ovDesc `seq` rnf ovFraction
     , anOutlierVar :: OutlierVariance
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary SampleAnalysis
+instance Binary SampleAnalysis where
+    put (SampleAnalysis x y z) = put x >> put y >> put z
+    get = SampleAnalysis <$> get <*> get <*> get
 
 instance NFData SampleAnalysis where
     rnf SampleAnalysis{..} =

File Criterion/IO.hs

 {-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE CPP #-}
 -- |
 -- Module      : Criterion.IO
 -- Copyright   : (c) 2009, 2010 Bryan O'Sullivan
 
 import Criterion.Types (Result(..))
 import Data.Binary (Binary(..), encode)
+#if MIN_VERSION_binary(0, 6, 3)
 import Data.Binary.Get (runGetOrFail)
+#else
+import Data.Binary.Get (runGetState)
+#endif
 import Data.Binary.Put (putByteString, putWord16be, runPut)
 import Data.Version (Version(..))
 import Paths_criterion (version)
 writeResults :: FilePath -> [Result] -> IO ()
 writeResults path rs = withFile path WriteMode (flip hPutResults rs)
 
+#if MIN_VERSION_binary(0, 6, 3)
 readAll :: Binary a => Handle -> IO [a]
 readAll handle = do
   let go bs
                          Left (_, _, err) -> fail err
                          Right (bs', _, a) -> (a:) `fmap` go bs'
   go =<< L.hGetContents handle
+#else
+readAll :: Binary a => Handle -> IO [a]
+readAll handle = do
+  let go i bs
+         | L.null bs = return []
+         | otherwise =
+            let (a, bs', i') = runGetState get bs i
+             in (a:) `fmap` go i' bs'
+  go 0 =<< L.hGetContents handle
+#endif

File Criterion/Types.hs

     , Payload(..)
     ) where
 
+import Control.Applicative ((<$>), (<*>))
 import Control.DeepSeq (NFData, rnf)
 import Control.Exception (evaluate)
 import Criterion.Analysis.Types (Outliers(..), SampleAnalysis(..))
-import Data.Binary (Binary)
+import Data.Binary (Binary (..))
 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Statistics.Types (Sample)
     , outliers       :: Outliers
     } deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Payload
+instance Binary Payload where
+    put (Payload x y z) = put x >> put y >> put z
+    get = Payload <$> get <*> get <*> get
 
 data Result = Single String Payload
               deriving (Eq, Read, Show, Typeable, Data, Generic)
 
-instance Binary Result
+instance Binary Result where
+    put (Single x y) = put x >> put y
+    get = Single <$> get <*> get

File criterion.cabal

   build-depends:
     aeson >= 0.3.2.12,
     base < 5,
-    binary >= 0.6.3.0,
+    binary >= 0.5.1.0,
     bytestring >= 0.9 && < 1.0,
     cassava >= 0.3.0.0,
     containers,