@@ -31,7 +31,9 @@ import Data.ArrayBuffer.Typed as AT
3131import Data.ArrayBuffer.Types (DataView, Uint8Array)
3232import Data.Either (Either(..))
3333import Data.Float32 (Float32)
34−import Data.Long.Internal (Long, Signed, Unsigned, fromLowHighBits, unsignedToSigned, lowBits)
34+import Data.Long.Internal (Long, Signed, Unsigned, fromLowHighBits, highBits, lowBits, unsignedToSigned)
35+import Data.Long.Internal as Long
36+import Data.Maybe (Maybe(..))
3537import Data.TextDecoding (decodeUtf8)
3638import Data.UInt (UInt)
3739import Data.UInt as UInt
@@ -70,6 +72,11 @@ int32 = do
7072 -- for positive or all 1 for negative.
7173 -- The conformance tests seem to like it if we just throw away
7274 -- the hight bits. So that's what we'll do.
75+ --
76+ -- conformance checker hates this:
77+ -- case Long.toInt n of
78+ -- Nothing -> fail "int32 value out of range."
79+ -- Just x -> pure x
7380
7481-- | __int64__
7582-- | [Scalar Value Type](https://developers.google.com/protocol-buffers/docs/proto3#scalar)
@@ -91,7 +98,12 @@ uint64 = varint64
9198-- | __sint32__
9299-- | [Scalar Value Type](https://developers.google.com/protocol-buffers/docs/proto3#scalar)
93100sint32 :: forall m. MonadEffect m => ParserT DataView m Int
94−sint32 = zigzag32 <$> varint32
101+sint32 = do
102+ n <- zigzag64 <$> varint64
103+ -- pure $ lowBits n
104+ case Long.toInt n of
105+ Nothing -> fail "sint32 value out of range."
106+ Just x -> pure x
95107
96108-- | __sint64__
97109-- | [Scalar Value Type](https://developers.google.com/protocol-buffers/docs/proto3#scalar)
@@ -122,8 +134,8 @@ sfixed64 = fromLowHighBits <$> Parse.anyInt32le <*> Parse.anyInt32le
122134-- | [Scalar Value Type](https://developers.google.com/protocol-buffers/docs/proto3#scalar)
123135bool :: forall m. MonadEffect m => ParserT DataView m Boolean
124136bool = do
125− x <- varint32
126− if x == UInt.fromInt 0
137+ x <- varint64
138+ if lowBits x == 0 && highBits x == 0
127139 then pure false
128140 else pure true
129141