packages feed

http2-grpc-proto3-wire (empty) → 0.1.0.0

raw patch · 6 files changed

+140/−0 lines, 6 filesdep +basedep +binarydep +bytestringsetup-changed

Dependencies added: base, binary, bytestring, case-insensitive, http2-grpc-types, proto3-wire, zlib

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for http2-grpc-proto-lens++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# http2-grpc-types++A module to put in common HTTP2/gRPC types, values, and helpers.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ http2-grpc-proto3-wire.cabal view
@@ -0,0 +1,46 @@+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: 5763fda48e0b655570de42018be2d5c7893885f926e89a00cfdd05120b37ea66++name:           http2-grpc-proto3-wire+version:        0.1.0.0+synopsis:       Encoders based on `proto3-wire` for gRPC over HTTP2.+description:    Please see the README on GitHub at <https://github.com/haskell-grpc-native/http2-grpc-haskell/blob/master/http2-grpc-proto3-wire/README.md>+category:       Network+homepage:       https://github.com/haskell-grpc-native/http2-grpc-haskell#readme+bug-reports:    https://github.com/haskell-grpc-native/http2-grpc-haskell/issues+author:         Alejandro Serrano+maintainer:     lucas@dicioccio.fr+copyright:      2019 Alejandro Serrano+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/haskell-grpc-native/http2-grpc-haskell++library+  exposed-modules:+      Network.GRPC.HTTP2.Proto3Wire+  other-modules:+      Paths_http2_grpc_proto3_wire+  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+    , http2-grpc-types+    , proto3-wire >=1 && <1.1+    , zlib >=0.6.2 && <0.7+  default-language: Haskell2010
+ src/Network/GRPC/HTTP2/Proto3Wire.hs view
@@ -0,0 +1,56 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}++module Network.GRPC.HTTP2.Proto3Wire where++import           Data.Bifunctor (first)+import           Data.Binary.Builder (fromByteString, singleton, putWord32be)+import           Data.Binary.Get (getByteString, getInt8, getWord32be, runGetIncremental)+import           Data.ByteString.Char8 (ByteString)+import qualified Data.ByteString.Char8 as ByteString+import           Data.ByteString.Lazy (toStrict)++import qualified Proto3.Wire.Encode as PBEnc+import qualified Proto3.Wire.Decode as PBDec++import Network.GRPC.HTTP2.Types+import Network.GRPC.HTTP2.Encoding++-- | A proxy type for giving static information about RPCs.+data RPC = RPC { pkg :: ByteString, srv :: ByteString, meth :: ByteString }++instance IsRPC RPC where+  path rpc = "/" <> pkg rpc <> "." <> srv rpc <> "/" <> meth rpc+  {-# INLINE path #-}++class Proto3WireEncoder a where+  proto3WireEncode :: a -> PBEnc.MessageBuilder+  proto3WireDecode :: PBDec.Parser PBDec.RawMessage a++instance (Proto3WireEncoder i) => GRPCInput RPC i where+  encodeInput _ = encode+  decodeInput _ = decoder++instance (Proto3WireEncoder o) => GRPCOutput RPC o where+  encodeOutput _ = encode+  decodeOutput _ = decoder++encode :: Proto3WireEncoder 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 $ toStrict $ PBEnc.toLazyByteString (proto3WireEncode plain)++decoder :: Proto3WireEncoder 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+    first show . PBDec.parse proto3WireDecode <$> (decompress =<< getByteString (fromIntegral n))