packages feed

bytes 0.9 → 0.10

raw patch · 4 files changed

+70/−23 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.10+----+* Changed all of the byte orders to big-endian by default *except* for `Word` and `Int`, which are variable sized.+ 0.9 ----- * Added proper support for `binary` 0.7.
bytes.cabal view
@@ -1,6 +1,6 @@ name:          bytes category:      Data, Serialization-version:       0.9+version:       0.10 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -62,6 +62,7 @@     ghc-options: -Werror    ghc-options: -Wall -fwarn-tabs -O2+  c-sources: cbits/i2d.c   hs-source-dirs: src  test-suite doctests
+ cbits/i2d.c view
@@ -0,0 +1,36 @@++unsigned long long doubleToWord64(double input) {+  union {+    double d;+    unsigned long long l;+  } u;+  u.d = input;+  return u.l;+}++double word64ToDouble(unsigned long long input) {+  union {+    double d;+    unsigned long long l;+  } u;+  u.l = input;+  return u.d;+}++unsigned long long floatToWord32(float input) {+  union {+    float f;+    unsigned long long l;+  } u;+  u.f = input;+  return u.l;+}++float word32ToDouble(unsigned long long input) {+  union {+    float f;+    unsigned long long l;+  } u;+  u.l = input;+  return u.f;+}
src/Data/Bytes/Serial.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}@@ -76,15 +77,15 @@ #endif  instance Serial Strict.ByteString where-  serialize bs = putWord32host (fromIntegral (Strict.length bs)) >> putByteString bs+  serialize bs = putWord32be (fromIntegral (Strict.length bs)) >> putByteString bs   deserialize = do-    n <- getWord32host+    n <- getWord32be     getByteString (fromIntegral n)  instance Serial Lazy.ByteString where-  serialize bs = putWord64host (fromIntegral (Lazy.length bs)) >> putLazyByteString bs+  serialize bs = putWord64be (fromIntegral (Lazy.length bs)) >> putLazyByteString bs   deserialize = do-    n <- getWord64host+    n <- getWord64be     getLazyByteString (fromIntegral n)  instance Serial SText.Text where@@ -117,33 +118,38 @@   unless (n >= required) $ fail "restore: Required more bytes"   return $ unsafePerformIO $ withForeignPtr fp $ \p -> peekByteOff p o +foreign import ccall floatToWord32 :: Float -> Word32+foreign import ccall word32ToFloat :: Word32 -> Float+foreign import ccall doubleToWord64 :: Double -> Word64+foreign import ccall word64ToDouble :: Word64 -> Double+ instance Serial Double where-  serialize = store-  deserialize = restore+  serialize = serialize . doubleToWord64+  deserialize = liftM word64ToDouble restore  instance Serial Float where-  serialize = store-  deserialize = restore+  serialize = serialize . floatToWord32+  deserialize = liftM word32ToFloat restore  instance Serial Char where-  serialize = putWord32host . fromIntegral . fromEnum-  deserialize = liftM (toEnum . fromIntegral) getWord32host+  serialize = putWord32be . fromIntegral . fromEnum+  deserialize = liftM (toEnum . fromIntegral) getWord32be  instance Serial Word where   serialize = putWordhost   deserialize = getWordhost  instance Serial Word64 where-  serialize = putWord64host-  deserialize = getWord64host+  serialize = putWord64be+  deserialize = getWord64be  instance Serial Word32 where-  serialize = putWord32host-  deserialize = getWord32host+  serialize = putWord32be+  deserialize = getWord32be  instance Serial Word16 where-  serialize = putWord16host-  deserialize = getWord16host+  serialize = putWord16be+  deserialize = getWord16be  instance Serial Word8 where   serialize = putWord8@@ -154,16 +160,16 @@   deserialize = liftM fromIntegral getWordhost  instance Serial Int64 where-  serialize = putWord64host . fromIntegral-  deserialize = liftM fromIntegral getWord64host+  serialize = putWord64be . fromIntegral+  deserialize = liftM fromIntegral getWord64be  instance Serial Int32 where-  serialize = putWord32host . fromIntegral-  deserialize = liftM fromIntegral getWord32host+  serialize = putWord32be . fromIntegral+  deserialize = liftM fromIntegral getWord32be  instance Serial Int16 where-  serialize = putWord16host . fromIntegral-  deserialize = liftM fromIntegral getWord16host+  serialize = putWord16be . fromIntegral+  deserialize = liftM fromIntegral getWord16be  instance Serial Int8 where   serialize = putWord8 . fromIntegral