protobuf 0.2.0.2 → 0.2.0.3
raw patch · 4 files changed
+26/−2 lines, 4 files
Files
- CHANGELOG +3/−0
- protobuf.cabal +1/−1
- src/Data/ProtocolBuffers/Decode.hs +1/−1
- tests/Main.hs +21/−0
CHANGELOG view
@@ -1,3 +1,6 @@+0.2.0.3:+ - 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.2+version: 0.2.0.3 synopsis: Google Protocol Buffers via GHC.Generics description: Google Protocol Buffers via GHC.Generics.
src/Data/ProtocolBuffers/Decode.hs view
@@ -89,7 +89,7 @@ let tag = fromIntegral $ natVal (Proxy :: Proxy n) in case HashMap.lookup tag msg of Just val -> K1 . Field . c <$> foldMapM decodeWire val- Nothing -> empty+ Nothing -> pure . K1 . Field $ c mempty instance (DecodeWire a, KnownNat n) => GDecode (K1 i (Field n (OptionalField (Last (Value a))))) where gdecode msg = fieldDecode Optional msg <|> pure (K1 mempty)
tests/Main.hs view
@@ -28,6 +28,7 @@ import Data.ByteString.Char8 () import Data.ProtocolBuffers as Pb import Data.ProtocolBuffers.Internal as Pb+import Data.ProtocolBuffers.Orphans () import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HashMap import Data.Hex@@ -64,6 +65,9 @@ , testCase "Google Reference Test2" test2 , testCase "Google Reference Test3" test3 , testCase "Google Reference Test4" test4+ , testCase "Optional Enum Test5: Nothing" test5+ , testCase "Optional Enum Test5: Just Test5A" test6+ , testCase "Optional Enum Test5: Just Test5B" test7 , testCase "Google WireFormatTest ZigZag" wireFormatZZ ] @@ -344,6 +348,23 @@ test4 :: Assertion test4 = testSpecific msg =<< unhex "2206038e029ea705" where msg = Test4{test4_d = putField [3,270,86942]}++data Test5Enum = Test5A | Test5B deriving (Eq, Show, Enum)+data Test5 = Test5{test5_e :: Optional 5 (Enumeration Test5Enum)} deriving (Generic, Eq, Show)+instance Encode Test5+instance Decode Test5++test5 :: Assertion+test5 = testSpecific msg =<< unhex "" where+ msg = Test5{test5_e = putField Nothing}++test6 :: Assertion+test6 = testSpecific msg =<< unhex "2800" where+ msg = Test5{test5_e = putField $ Just Test5A }++test7 :: Assertion+test7 = testSpecific msg =<< unhex "2801" where+ msg = Test5{test5_e = putField $ Just Test5B } -- some from http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/wire_format_unittest.cc wireFormatZZ :: Assertion