packages feed

http2-grpc-types 0.4.0.0 → 0.5.0.0

raw patch · 3 files changed

+40/−100 lines, 3 filesdep −proto-lens

Dependencies removed: proto-lens

Files

http2-grpc-types.cabal view
@@ -1,30 +1,31 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 6fea17114fd9c6684b39bf40b59d52a036cf2cd144e6590d71fd033a6d3cd865+-- hash: 8de0f7774c8b31f1c73ee3c020d13c6a97ee986e7513ac0bb9739c4b0561dfb4  name:           http2-grpc-types-version:        0.4.0.0+version:        0.5.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>+description:    Please see the README on GitHub at <https://github.com/haskell-grpc-native/http2-grpc-haskell/blob/master/http2-grpc-types/README.md> category:       Network-homepage:       https://github.com/lucasdicioccio/http2-grpc-types#readme-bug-reports:    https://github.com/lucasdicioccio/http2-grpc-types/issues-author:         Lucas DiCioccio+homepage:       https://github.com/haskell-grpc-native/http2-grpc-haskell#readme+bug-reports:    https://github.com/haskell-grpc-native/http2-grpc-haskell/issues+author:         Lucas DiCioccio, Alejandro Serrano maintainer:     lucas@dicioccio.fr-copyright:      2018 Lucas DiCioccio+copyright:      2018, 2019 Lucas DiCioccio, Alejandro Serrano license:        BSD3 license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10 extra-source-files:-    ChangeLog.md     README.md+    ChangeLog.md  source-repository head   type: git-  location: https://github.com/lucasdicioccio/http2-grpc-types+  location: https://github.com/haskell-grpc-native/http2-grpc-haskell  library   exposed-modules:@@ -34,11 +35,11 @@       Paths_http2_grpc_types   hs-source-dirs:       src+  ghc-options: -Wall   build-depends:       base >=4.11 && <5     , binary >=0.8.5 && <0.11     , bytestring >=0.10.8 && <0.11     , case-insensitive >=1.2.0 && <1.3-    , proto-lens >=0.5 && <0.6     , zlib >=0.6.2 && <0.7   default-language: Haskell2010
src/Network/GRPC/HTTP2/Encoding.hs view
@@ -1,20 +1,18 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE MultiParamTypeClasses #-}  -- | Module for GRPC binary encoding/decoding from and to binary messages. -- -- So far, only "pure" compression algorithms are supported as we rely on -- 'Decoder' (resp. 'Builder') which run with no interleaved side-effects. module Network.GRPC.HTTP2.Encoding (-  -- * Decoding.-    decoder-  , fromDecoder-  , decodeInput-  , decodeOutput-  -- * Encoding.-  , encode+  -- * Encoding and decoding.+    GRPCInput(..)+  , GRPCOutput(..)+  , Builder+  , Decoder   , fromBuilder-  , encodeInput-  , encodeOutput+  , fromDecoder   -- * Compression.   , Compression(..)   , Encoding(..)@@ -25,74 +23,30 @@   ) where  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(..), Get)+import           Data.Binary.Builder (toLazyByteString, Builder)+import           Data.Binary.Get (Decoder(..), Get) import           Data.ByteString.Char8 (ByteString)-import qualified Data.ByteString.Char8 as ByteString import           Data.ByteString.Lazy (fromStrict, toStrict)-import           Data.ProtoLens.Encoding (encodeMessage, decodeMessage)-import           Data.ProtoLens.Message (Message)-import           Data.ProtoLens.Service.Types (Service(..), HasMethod, HasMethodImpl(..))  import           Network.GRPC.HTTP2.Types --- | Decoder for gRPC/HTTP2-encoded Protobuf messages.-decoder :: Message a => Compression -> Decoder (Either String a)-decoder compression = runGetIncremental $ do-    isCompressed <- getInt8      -- 1byte-    let decompress = if isCompressed == 0 then pure else (_decompressionFunction compression)-    n <- getWord32be             -- 4bytes-    decodeMessage <$> (decompress =<< getByteString (fromIntegral n))---- | Tries finalizing a Decoder.-fromDecoder :: Decoder (Either String a) -> Either String a-fromDecoder (Fail _ _ msg) = Left msg-fromDecoder (Partial _)    = Left "got only a subet of the message"-fromDecoder (Done _ _ val) = val--decodeOutput-  :: (Service s, HasMethod s m)-  => RPC s m-  -> Compression-  -> Decoder (Either String (MethodOutput s m))-decodeOutput _ = decoder--decodeInput-  :: (Service s, HasMethod s m)-  => RPC s m-  -> Compression-  -> Decoder (Either String (MethodInput s m))-decodeInput _ = decoder+class IsRPC r => GRPCInput r i where+  encodeInput :: r -> Compression -> i -> Builder+  decodeInput :: r -> Compression -> Decoder (Either String i) --- | Encodes as binary using gRPC/HTTP2 framing.-encode :: Message m => Compression -> m -> Builder-encode compression plain =-    mconcat [ singleton (if _compressionByteSet compression then 1 else 0)-            , putWord32be (fromIntegral $ ByteString.length bin)-            , fromByteString bin-            ]-  where-    bin = _compressionFunction compression $ encodeMessage plain+class IsRPC r => GRPCOutput r o where+  encodeOutput :: r -> Compression -> o -> Builder+  decodeOutput :: r -> Compression -> Decoder (Either String o)  -- | Finalizes a Builder. fromBuilder :: Builder -> ByteString fromBuilder = toStrict . toLazyByteString -encodeInput-  :: (Service s, HasMethod s m)-  => RPC s m-  -> Compression-  -> MethodInput s m-  -> Builder-encodeInput _ = encode--encodeOutput-  :: (Service s, HasMethod s m)-  => RPC s m-  -> Compression-  -> MethodOutput s m-  -> Builder-encodeOutput _ = encode+-- | Tries finalizing a Decoder.+fromDecoder :: Decoder (Either String a) -> Either String a+fromDecoder (Fail _ _ msg) = Left msg+fromDecoder (Partial _)    = Left "got only a subet of the message"+fromDecoder (Done _ _ val) = val  -- | Opaque type for handling compression. --@@ -101,8 +55,8 @@ data Compression = Compression {     _compressionName       :: ByteString   , _compressionByteSet    :: Bool-  , _compressionFunction   :: (ByteString -> ByteString)-  , _decompressionFunction :: (ByteString -> Get ByteString)+  , _compressionFunction   :: ByteString -> ByteString+  , _decompressionFunction :: ByteString -> Get ByteString   }  -- | Compression for Encoding.
src/Network/GRPC/HTTP2/Types.hs view
@@ -8,12 +8,9 @@  import           Control.Exception (Exception) import           Data.Maybe (fromMaybe)-import           Data.ProtoLens.Service.Types (Service(..), HasMethod, HasMethodImpl(..))-import           Data.Proxy (Proxy(..)) import           Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as ByteString import           Data.CaseInsensitive (CI)-import           GHC.TypeLits (Symbol, symbolVal)  -- | HTTP2 Header Key. type HeaderKey = CI ByteString@@ -155,7 +152,7 @@     message = (grpcMessageH, msg)  -- | In case a server replies with a gRPC status/message pair un-understood by this library.-data InvalidGRPCStatus = InvalidGRPCStatus [(HeaderKey, HeaderValue)]+newtype InvalidGRPCStatus = InvalidGRPCStatus [(HeaderKey, HeaderValue)]   deriving (Show, Eq, Ord)  instance Exception InvalidGRPCStatus@@ -168,22 +165,10 @@   where     message = fromMaybe "" (lookup grpcMessageH pairs) --- | A proxy type for giving static information about RPCs.-data RPC (s :: *) (m :: Symbol) = RPC---- | Returns the HTTP2 :path for a given RPC.-path :: (Service s, HasMethod s m) => RPC s m -> HeaderValue-{-# INLINE path #-}-path rpc = "/" <> pkg rpc Proxy <> "." <> srv rpc Proxy <> "/" <> meth rpc Proxy-  where-    pkg :: (Service s) => RPC s m -> Proxy (ServicePackage s) -> HeaderValue-    pkg _ p = ByteString.pack $ symbolVal p--    srv :: (Service s) => RPC s m -> Proxy (ServiceName s) -> HeaderValue-    srv _ p = ByteString.pack $ symbolVal p--    meth :: (Service s, HasMethod s m) => RPC s m -> Proxy (MethodName s m) -> HeaderValue-    meth _ p = ByteString.pack $ symbolVal p+-- | A class to represent RPC information.+class IsRPC t where+  -- | Returns the HTTP2 :path for a given RPC.+  path :: t -> HeaderValue  -- | Timeout in seconds. newtype Timeout = Timeout Int