1. Aleksey Khudyakov
  2. binary-combinators

Commits

Aleksey Khudyakov  committed 5727846

Use functions from patched binary

  • Participants
  • Parent commits a2223ec
  • Branches default

Comments (0)

Files changed (2)

File Data/Binary/Combinators.hs

View file
 import Data.Binary
 import Data.Binary.Get
 import Data.Binary.Put
-import Data.Binary.IEEE754
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Internal as B
 import Data.Int
 
 -- | Put number as double precition (64bit) IEEE floating point number
 putAsFloat  :: Real a => a -> Put
-putAsFloat  = putFloat32le . realToFrac
+putAsFloat  = putFloatIEEEhost . realToFrac
 {-# INLINE putAsFloat #-}
 -- | Put number as double precition (64bit) IEEE floating point number
 putAsDouble :: Real a => a -> Put
-putAsDouble = putFloat64le . realToFrac
+putAsDouble = putDoubleIEEEhost . realToFrac
 {-# INLINE putAsDouble #-}
 
--- Get storable data
-getStorable :: Storable a => Get a
-getStorable = {-# SCC "getStorable" #-} do 
-  bs <- getByteString 4
-  let (fp,o,_) = B.toForeignPtr bs
-  return $ B.inlinePerformIO $ withForeignPtr fp $ \p -> peek (castPtr $ plusPtr p o)
-{-# INLINE getStorable #-}
-
 -- | Get number as double precition (64bit) IEEE floating point number
 -- realToFrac <$> getFloat32le
 getAsFloat  :: Fractional a => Get a
-getAsFloat = {-# SCC "getAsFloat" #-} realToFrac <$> (getStorable :: Get Float)
+getAsFloat = {-# SCC "getAsFloat" #-} realToFrac <$> getFloatIEEEhost
 {-# INLINE getAsFloat #-}
 -- | Get number as double precition (64bit) IEEE floating point number
 getAsDouble :: Fractional a => Get a
-getAsDouble = {-# SCC "getAsDouble" #-} realToFrac <$> (getStorable :: Get Double)
+getAsDouble = {-# SCC "getAsDouble" #-} realToFrac <$> getDoubleIEEEhost
 {-# INLINE getAsDouble #-}
 
 ----------------------------------------------------------------

File binary-combinators.cabal

View file
 Author:		Alexey Khudyakov
 Homepage:	
 Category:	Data
-Synopsis:	Combinators to create Binary instances.
+Synopsis:	Combinators to create Binary instances. Unfortunately it require patched binary.
 Build-Type:     Simple
 
 Library
                    haskell98,
                    bytestring,
                    binary,
-                   data-binary-ieee754,
                    zlib
   Exposed-modules: Data.Binary.Combinators
                    Data.Binary.Stream