packages feed

pinch 0.3.1.0 → 0.3.2.0

raw patch · 9 files changed

+112/−9 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Pinch.Internal.Builder: doubleLE :: Double -> Builder
+ Pinch.Internal.Builder: int64LE :: Int64 -> Builder
+ Pinch.Internal.Parser: doubleLE :: Parser Double
+ Pinch.Internal.Parser: int64LE :: Parser Int64

Files

CHANGES.md view
@@ -1,3 +1,9 @@+0.3.2.0 (2017-06-03)+====================++-   Compact: Fixed bug which caused incorrect encoding of doubles.++ 0.3.1.0 (2017-05-13) ==================== 
pinch.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           pinch-version:        0.3.1.0+version:        0.3.2.0 cabal-version:  >= 1.10 build-type:     Simple license:        BSD3
src/Pinch/Internal/Builder.hs view
@@ -21,7 +21,9 @@     , int16BE     , int32BE     , int64BE+    , int64LE     , doubleBE+    , doubleLE     , byteString     ) where @@ -116,10 +118,21 @@ int64BE = primFixed BP.int64BE {-# INLINE int64BE #-} +-- | Serialize a signed 64-bit integer in little endian format.+int64LE :: Int64 -> Builder+int64LE = primFixed BP.int64LE+{-# INLINE int64LE #-}+ -- | Serialize a signed 64-bit floating point number in big endian format. doubleBE :: Double -> Builder doubleBE = primFixed BP.doubleBE {-# INLINE doubleBE #-}++-- | Serialize a signed 64-bit floating point number in little endian format.+doubleLE :: Double -> Builder+doubleLE = primFixed BP.doubleLE+{-# INLINE doubleLE #-}+  -- | Inlcude the given ByteString as-is in the builder. --
src/Pinch/Internal/Parser.hs view
@@ -22,7 +22,9 @@     , int16     , int32     , int64+    , int64LE     , double+    , doubleLE     , take     ) where @@ -177,11 +179,33 @@          fromIntegral (b `BU.unsafeIndex` 7) {-# INLINE int64 #-} +-- | Produces a signed 64-bit integer (parsed in little endian byte ordering)+-- and advances the parser.+int64LE :: Parser Int64+int64LE = mk <$> take 8+  where+    {-# INLINE mk #-}+    mk b = fromIntegral $+        (fromIntegral (b `BU.unsafeIndex` 7) `w64ShiftL` 56) .|.+        (fromIntegral (b `BU.unsafeIndex` 6) `w64ShiftL` 48) .|.+        (fromIntegral (b `BU.unsafeIndex` 5) `w64ShiftL` 40) .|.+        (fromIntegral (b `BU.unsafeIndex` 4) `w64ShiftL` 32) .|.+        (fromIntegral (b `BU.unsafeIndex` 3) `w64ShiftL` 24) .|.+        (fromIntegral (b `BU.unsafeIndex` 2) `w64ShiftL` 16) .|.+        (fromIntegral (b `BU.unsafeIndex` 1) `w64ShiftL`  8) .|.+         fromIntegral (b `BU.unsafeIndex` 0)+{-# INLINE int64LE #-}  -- | Produces a 64-bit floating point number and advances the parser. double :: Parser Double double = int64 >>= \i -> return (ST.runST (cast i)) {-# INLINE double #-}++-- | Produces a 64-bit floating point number (parsed in little endian byte+-- ordering) and advances the parser.+doubleLE :: Parser Double+doubleLE = int64LE >>= \i -> return (ST.runST (cast i))+{-# INLINE doubleLE #-}   cast :: (A.MArray (A.STUArray s) a (ST s),
src/Pinch/Protocol/Compact.hs view
@@ -145,7 +145,7 @@ parseByte = VByte <$> P.int8  parseDouble :: Parser (Value TDouble)-parseDouble = VDouble <$> P.double+parseDouble = VDouble <$> P.doubleLE  parseInt16 :: Parser (Value TInt16) parseInt16 = VInt16 . fromIntegral . zigZagToInt <$> parseVarint@@ -253,7 +253,7 @@ {-# INLINE serializeByte #-}  serializeDouble :: Value TDouble -> Builder-serializeDouble (VDouble x) = BB.doubleBE x+serializeDouble (VDouble x) = BB.doubleLE x {-# INLINE serializeDouble #-}  serializeVarint :: Int64 -> Builder
tests/Pinch/Internal/BuilderParserSpec.hs view
@@ -37,8 +37,14 @@     prop "can round trip 64-bit integers" $         roundTrip P.int64 BB.int64BE +    prop "can round trip 64-bit little endian integers" $+        roundTrip P.int64LE BB.int64LE+     prop "can round trip doubles" $         roundTrip P.double BB.doubleBE++    prop "can round trip little endian doubles" $+        roundTrip P.doubleLE BB.doubleLE      prop "can round trip bytestrings" $ \(SomeByteString bs) ->         roundTrip (P.take (B.length bs)) BB.byteString bs
tests/Pinch/Internal/BuilderSpec.hs view
@@ -78,6 +78,22 @@             , ([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], -9223372036854775808)             ] +    it "can serialize 64-bit little endian integers" $+        builderCases BB.int64LE+            [ ([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 1)+            , ([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00], 4294967295)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00], 1099511627775)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00], 281474976710655)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00], 72057594037927935)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f], 9223372036854775807)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], -1)+            , ([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff], -4294967296)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff], -1099511627776)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff], -281474976710656)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff], -72057594037927936)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80], -9223372036854775808)+            ]+     it "can serialize doubles" $         builderCases BB.doubleBE             [ ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0.0)@@ -87,6 +103,17 @@             , ([0xbf, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a], -1.1)             , ([0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18], 3.141592653589793)             , ([0xbf, 0xf0, 0x00, 0x00, 0x00, 0x06, 0xdf, 0x38], -1.0000000001)+            ]++    it "can serialize little endian doubles" $+        builderCases BB.doubleLE+            [ ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0.0)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f], 1.0)+            , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0x3f], 1.0000000001)+            , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f], 1.1)+            , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0xbf], -1.1)+            , ([0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40], 3.141592653589793)+            , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0xbf], -1.0000000001)             ]      prop "can serialize byte strings" $ \(SomeByteString bs) ->
tests/Pinch/Internal/ParserSpec.hs view
@@ -94,6 +94,22 @@             , ([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], -9223372036854775808)             ] +    it "can parse 64-bit little endian integers" $+        parseCases P.int64LE+            [ ([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 1)+            , ([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00], 4294967295)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00], 1099511627775)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00], 281474976710655)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00], 72057594037927935)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f], 9223372036854775807)+            , ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], -1)+            , ([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff], -4294967296)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff], -1099511627776)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff], -281474976710656)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff], -72057594037927936)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80], -9223372036854775808)+            ]+     it "can parse doubles" $         parseCases P.double             [ ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0.0)@@ -103,6 +119,17 @@             , ([0xbf, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a], -1.1)             , ([0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18], 3.141592653589793)             , ([0xbf, 0xf0, 0x00, 0x00, 0x00, 0x06, 0xdf, 0x38], -1.0000000001)+            ]++    it "can parse little endian doubles" $+        parseCases P.doubleLE+            [ ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0.0)+            , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f], 1.0)+            , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0x3f], 1.0000000001)+            , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f], 1.1)+            , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0xbf], -1.1)+            , ([0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40], 3.141592653589793)+            , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0xbf], -1.0000000001)             ]      describe "take" $ do
tests/Pinch/Protocol/CompactSpec.hs view
@@ -152,12 +152,12 @@      it "can read and write doubles" $ readWriteCases         [ ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], vdub 0.0)-        , ([0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], vdub 1.0)-        , ([0x3f, 0xf0, 0x00, 0x00, 0x00, 0x06, 0xdf, 0x38], vdub 1.0000000001)-        , ([0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a], vdub 1.1)-        , ([0xbf, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a], vdub -1.1)-        , ([0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18], vdub 3.141592653589793)-        , ([0xbf, 0xf0, 0x00, 0x00, 0x00, 0x06, 0xdf, 0x38], vdub -1.0000000001)+        , ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f], vdub 1.0)+        , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0x3f], vdub 1.0000000001)+        , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f], vdub 1.1)+        , ([0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0xbf], vdub -1.1)+        , ([0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40], vdub 3.141592653589793)+        , ([0x38, 0xdf, 0x06, 0x00, 0x00, 0x00, 0xf0, 0xbf], vdub -1.0000000001)         ]      it "can read and write structs" $ readWriteCases