packages feed

protobuf 0.2.0.4 → 0.2.1.0

raw patch · 5 files changed

+72/−10 lines, 5 files

Files

CHANGELOG view
@@ -1,8 +1,11 @@+0.2.1.0:+  - Fix #17: Repeated n (Enumeration a) difficulty+ 0.2.0.4:-  - Fix #13 "Getting the error "Always is not a Monoid"+  - Fix #13: Getting the error "Always is not a Monoid  0.2.0.3:-  - Fix #11 "Missing optional enum in incoming message causes decodeMessage to fail"+  - Fix #11: Missing optional enum in incoming message causes decodeMessage to fail  0.2.0.2:   - Export {get,put}Varint* from Data.ProtocolBuffers.Internal
protobuf.cabal view
@@ -1,5 +1,5 @@ name:                protobuf-version:             0.2.0.4+version:             0.2.1.0 synopsis:            Google Protocol Buffers via GHC.Generics description:   Google Protocol Buffers via GHC.Generics.
src/Data/ProtocolBuffers.hs view
@@ -12,20 +12,24 @@ -- -- @ --{-\# LANGUAGE DeriveGeneric \#-}+--{-\# LANGUAGE DataKinds     \#-} ----- import "Data.Int"+--import "Data.Int" --import "Data.ProtocolBuffers" --import "Data.Text" --import "GHC.Generics" ('GHC.Generics.Generic') --import "GHC.TypeLits"+--import "Data.Monoid"+--import "Data.Serialize"+--import "Data.Hex"  -- cabal install hex (for testing) -- -- data Foo = Foo---   { field1 :: 'Required' '1' ('Value' 'Data.Int.Int64') -- ^ The last field with tag = 1---   , field2 :: 'Optional' '2' ('Value' 'Data.Text.Text') -- ^ The last field with tag = 2---   , field3 :: 'Repeated' '3' ('Value' 'Prelude.Bool') -- ^ All fields with tag = 3, ordering is preserved+--   { field1 :: 'Required' 1 ('Value' 'Data.Int.Int64') -- ^ The last field with tag = 1+--   , field2 :: 'Optional' 2 ('Value' 'Data.Text.Text') -- ^ The last field with tag = 2+--   , field3 :: 'Repeated' 3 ('Value' 'Prelude.Bool')   -- ^ All fields with tag = 3, ordering is preserved --   } deriving ('GHC.Generics.Generic', 'Prelude.Show') ----- instance 'Encode' Foo+--instance 'Encode' Foo --instance 'Decode' Foo -- @ --
src/Data/ProtocolBuffers/Wire.hs view
@@ -436,6 +436,11 @@     c :: a -> Int32     c = fromIntegral . fromEnum +instance Enum a => DecodeWire (Enumeration a) where+  decodeWire f = c <$> decodeWire f where+    c :: Int32 -> Enumeration a+    c = Enumeration . toEnum . fromIntegral+ instance Enum a => DecodeWire (Maybe (Enumeration a)) where   decodeWire f = c <$> decodeWire f where     c :: Int32 -> Maybe (Enumeration a)
tests/Main.hs view
@@ -71,6 +71,14 @@   , testCase "Optional Enum Test5: Nothing" test5   , testCase "Optional Enum Test5: Just Test5A" test6   , testCase "Optional Enum Test5: Just Test5B" test7+  , testCase "Repeated Enum Test6: []" test8+  , testCase "Repeated Enum Test6: [Test6A]" test9+  , testCase "Repeated Enum Test6: [Test6A, Test6B]" test10+  , testCase "Repeated Enum Test6: [Test6A, Test6A]" test11+  , testCase "Repeated Enum Test6: [Test6A, Test6B, Test6A]" test12+  , testCase "Repeated Enum Test7: []" test13+  , testCase "Repeated Enum Test7: [Test7]" test14+  , testCase "Repeated Enum Test7: [Test7, Test7]" test15   , testCase "Google WireFormatTest ZigZag" wireFormatZZ   ] @@ -347,7 +355,7 @@   -- is also recommended since these are encoded as varints which have   -- fairly high overhead for negative tags   n <- choose (536870912, toInteger $ (maxBound :: Int))-  case someNatVal n of +  case someNatVal n of     Just (SomeNat x) -> g x  prop_reify_valid_tag :: forall r . (forall n . KnownNat n => Proxy n -> Gen r) -> Gen r@@ -359,7 +367,7 @@   -- is also recommended since these are encoded as varints which have   -- fairly high overhead for negative tags   n <- choose (0, 536870911)-  case someNatVal n of +  case someNatVal n of     Just (SomeNat x) -> f x  prop_req_reify :: forall a r . a -> (forall n . KnownNat n => RequiredValue n a -> Gen r) -> Gen r@@ -448,6 +456,16 @@ instance Encode Test5 instance Decode Test5 +data Test6Enum = Test6A | Test6B deriving (Eq, Show, Enum)+data Test6 = Test6{test6_e :: Repeated 6 (Enumeration Test6Enum)} deriving (Generic, Eq, Show)+instance Encode Test6+instance Decode Test6++data Test7Enum = Test7A deriving (Eq, Show, Enum)+data Test7 = Test7{test7_e :: Repeated 7 (Enumeration Test7Enum)} deriving (Generic, Eq, Show)+instance Encode Test7+instance Decode Test7+ test5 :: Assertion test5 = testSpecific msg =<< unhex "" where   msg = Test5{test5_e = putField Nothing}@@ -459,6 +477,38 @@ test7 :: Assertion test7 = testSpecific msg =<< unhex "2801" where   msg = Test5{test5_e = putField $ Just Test5B }++test8 :: Assertion+test8 = testSpecific msg =<< unhex "" where+  msg = Test6{test6_e = putField $ [] }++test9 :: Assertion+test9 = testSpecific msg =<< unhex "3000" where+  msg = Test6{test6_e = putField $ [Test6A] }++test10 :: Assertion+test10 = testSpecific msg =<< unhex "30003001" where+  msg = Test6{test6_e = putField $ [Test6A, Test6B]}++test11 :: Assertion+test11 = testSpecific msg =<< unhex "30003000" where+  msg = Test6{test6_e = putField $ [Test6A, Test6A]}++test12 :: Assertion+test12 = testSpecific msg =<< unhex "300030013000" where+  msg = Test6{test6_e = putField $ [Test6A, Test6B, Test6A]}++test13 :: Assertion+test13 = testSpecific msg =<< unhex "" where+  msg = Test7{test7_e = putField $ [] }++test14 :: Assertion+test14 = testSpecific msg =<< unhex "3800" where+  msg = Test7{test7_e = putField $ [Test7A] }++test15 :: Assertion+test15 = testSpecific msg =<< unhex "38003800" where+  msg = Test7{test7_e = putField $ [Test7A, Test7A] }  -- some from http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/wire_format_unittest.cc wireFormatZZ :: Assertion