http2-grpc-types 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+27/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.GRPC.HTTP2.Encoding: Compression :: ByteString -> Bool -> (ByteString -> ByteString) -> (ByteString -> Get ByteString) -> Compression
+ Network.GRPC.HTTP2.Encoding: Decoding :: Compression -> Decoding
+ Network.GRPC.HTTP2.Encoding: Encoding :: Compression -> Encoding
+ Network.GRPC.HTTP2.Encoding: [_compressionByteSet] :: Compression -> Bool
+ Network.GRPC.HTTP2.Encoding: [_compressionFunction] :: Compression -> (ByteString -> ByteString)
+ Network.GRPC.HTTP2.Encoding: [_compressionName] :: Compression -> ByteString
+ Network.GRPC.HTTP2.Encoding: [_decompressionFunction] :: Compression -> (ByteString -> Get ByteString)
+ Network.GRPC.HTTP2.Encoding: [_getDecodingCompression] :: Decoding -> Compression
+ Network.GRPC.HTTP2.Encoding: [_getEncodingCompression] :: Encoding -> Compression
+ Network.GRPC.HTTP2.Encoding: newtype Decoding
+ Network.GRPC.HTTP2.Encoding: newtype Encoding
Files
- http2-grpc-types.cabal +2/−2
- src/Network/GRPC/HTTP2/Encoding.hs +24/−11
- src/Network/GRPC/HTTP2/Types.hs +1/−1
http2-grpc-types.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: ac7deaf4e4e16246c07477c353a2f55ac558d8b90ae2a0682e21c1bfd613a057+-- hash: b69cc858a2d802606efae0a96ca6853e07cf06e31173a75330bb02c6f7ee5e1d name: http2-grpc-types-version: 0.1.0.0+version: 0.2.0.0 synopsis: Types for gRPC over HTTP2 common for client and servers. description: Please see the README on GitHub at <https://github.com/lucasdicioccio/http2-grpc-types#readme> category: Network
src/Network/GRPC/HTTP2/Encoding.hs view
@@ -16,7 +16,9 @@ , encodeInput , encodeOutput -- * Compression.- , Compression+ , Compression(..)+ , Encoding(..)+ , Decoding(..) , grpcCompressionHV , uncompressed , gzip@@ -24,7 +26,7 @@ import qualified Codec.Compression.GZip as GZip import Data.Binary.Builder (Builder, toLazyByteString, fromByteString, singleton, putWord32be)-import Data.Binary.Get (getByteString, getInt8, getWord32be, runGetIncremental, Decoder(..))+import Data.Binary.Get (getByteString, getInt8, getWord32be, runGetIncremental, Decoder(..), Get) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as ByteString import Data.ByteString.Lazy (fromStrict, toStrict)@@ -38,9 +40,9 @@ decoder :: Message a => Compression -> Decoder (Either String a) decoder compression = runGetIncremental $ do isCompressed <- getInt8 -- 1byte- let decompress = if isCompressed == 0 then id else (_decompressionFunction compression)+ let decompress = if isCompressed == 0 then pure else (_decompressionFunction compression) n <- getWord32be -- 4bytes- decodeMessage . decompress <$> getByteString (fromIntegral n)+ decodeMessage <$> (decompress =<< getByteString (fromIntegral n)) -- | Tries finalizing a Decoder. fromDecoder :: Decoder (Either String a) -> Either String a@@ -67,10 +69,10 @@ encode compression plain = mconcat [ singleton (if _compressionByteSet compression then 1 else 0) , putWord32be (fromIntegral $ ByteString.length bin)- , fromByteString (_compressionFunction compression $ bin)+ , fromByteString bin ] where- bin = encodeMessage plain+ bin = _compressionFunction compression $ encodeMessage plain -- | Finalizes a Builder. fromBuilder :: Builder -> ByteString@@ -80,14 +82,16 @@ :: (Service s, HasMethod s m) => RPC s m -> Compression- -> MethodInput s m -> Builder+ -> MethodInput s m+ -> Builder encodeInput _ = encode encodeOutput :: (Service s, HasMethod s m) => RPC s m -> Compression- -> MethodOutput s m -> Builder+ -> MethodOutput s m+ -> Builder encodeOutput _ = encode -- | Opaque type for handling compression.@@ -98,16 +102,25 @@ _compressionName :: ByteString , _compressionByteSet :: Bool , _compressionFunction :: (ByteString -> ByteString)- , _decompressionFunction :: (ByteString -> ByteString)+ , _decompressionFunction :: (ByteString -> Get ByteString) } +-- | Compression for Encoding.+newtype Encoding = Encoding { _getEncodingCompression :: Compression }++-- | Compression for Decoding.+newtype Decoding = Decoding { _getDecodingCompression :: Compression }++ grpcCompressionHV :: Compression -> HeaderValue grpcCompressionHV = _compressionName -- | Do not compress. uncompressed :: Compression-uncompressed = Compression "identity" False id id+uncompressed = Compression "identity" False id (\_ -> fail "decoder uninstalled") -- | Use gzip as compression. gzip :: Compression-gzip = Compression "gzip" True (toStrict . GZip.compress . fromStrict) (toStrict . GZip.decompress . fromStrict)+gzip = Compression "gzip" True+ (toStrict . GZip.compress . fromStrict)+ (pure . toStrict . GZip.decompress . fromStrict)
src/Network/GRPC/HTTP2/Types.hs view
@@ -29,7 +29,7 @@ grpcAcceptEncodingH = "grpc-accept-encoding" grpcAcceptEncodingHVdefault :: HeaderValue-grpcAcceptEncodingHVdefault = "identity,gzip"+grpcAcceptEncodingHVdefault = "identity" grpcStatusH :: HeaderKey grpcStatusH = "grpc-status"