Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion protobuf.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ library
base-orphans >= 0.5,
bytestring >= 0.9,
binary >= 0.7,
data-binary-ieee754 >= 0.4,
deepseq >= 1.1,
mtl == 2.*,
-- pretty,
Expand Down
20 changes: 13 additions & 7 deletions src/Data/ProtocolBuffers/Wire.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LBS
import Data.Foldable

Check warning on line 33 in src/Data/ProtocolBuffers/Wire.hs

View workflow job for this annotation

GitHub Actions / build (8.10.7)

The import of ‘Data.Foldable’ is redundant
import Data.Int
import Data.Monoid
import Data.Binary.Get
import qualified Data.Binary.IEEE754 as F
import GHC.Float (castFloatToWord32, castWord32ToFloat, castDoubleToWord64, castWord64ToDouble)
import Data.Binary.Builder.Sized hiding (empty)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
Expand All @@ -60,10 +60,16 @@
deriving (Eq, Ord, Show, Typeable)

putFloat32le :: Float -> Builder
putFloat32le = putWord32le . F.floatToWord
putFloat32le = putWord32le . castFloatToWord32

putFloat64le :: Double -> Builder
putFloat64le = putWord64le . F.doubleToWord
putFloat64le = putWord64le . castDoubleToWord64

getFloat32le :: Get Float
getFloat32le = castWord32ToFloat <$> getWord32le

getFloat64le :: Get Double
getFloat64le = castWord64ToDouble <$> getWord64le

getVarintPrefixedBS :: Get ByteString
getVarintPrefixedBS = getByteString =<< getVarInt
Expand Down Expand Up @@ -255,14 +261,14 @@
encodeWire t val = putWireTag t 5 <> putFloat32le val

instance DecodeWire Float where
decodeWire (Fixed32Field _ val) = pure $ F.wordToFloat val
decodeWire (Fixed32Field _ val) = pure $ castWord32ToFloat val
decodeWire _ = empty

instance EncodeWire Double where
encodeWire t val = putWireTag t 1 <> putFloat64le val

instance DecodeWire Double where
decodeWire (Fixed64Field _ val) = pure $ F.wordToDouble val
decodeWire (Fixed64Field _ val) = pure $ castWord64ToDouble val
decodeWire _ = empty

instance EncodeWire Builder where
Expand Down Expand Up @@ -409,7 +415,7 @@

instance DecodeWire (PackedList (Value Float)) where
decodeWire x = do
xs <- decodePackedList F.getFloat32le x
xs <- decodePackedList getFloat32le x
return . PackedList $ Value <$> xs

instance EncodeWire (PackedList (Value Double)) where
Expand All @@ -418,7 +424,7 @@

instance DecodeWire (PackedList (Value Double)) where
decodeWire x = do
xs <- decodePackedList F.getFloat64le x
xs <- decodePackedList getFloat64le x
return . PackedList $ Value <$> xs

instance EncodeWire (PackedList (Value Bool)) where
Expand Down
Loading