Update Arithmetic example to use newer proto3-suite (#102)

Related to https://github.com/awakesecurity/proto3-suite/issues/119
This commit is contained in:
Gabriel Gonzalez 2020-02-10 10:19:29 -08:00 committed by GitHub
parent bc155c1a52
commit 595cb6a3bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 30 deletions

View File

@ -1,6 +1,8 @@
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-} {-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
@ -9,30 +11,35 @@
-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT! -- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
module Arithmetic where module Arithmetic where
import qualified Prelude as Hs import qualified Prelude as Hs
import qualified Proto3.Suite.DotProto as HsProtobuf
import qualified Proto3.Suite.Types as HsProtobuf
import qualified Proto3.Suite.Class as HsProtobuf import qualified Proto3.Suite.Class as HsProtobuf
import qualified Proto3.Suite.DotProto as HsProtobuf
import qualified Proto3.Suite.JSONPB as HsJSONPB import qualified Proto3.Suite.JSONPB as HsJSONPB
import Proto3.Suite.JSONPB ((.=), (.:)) import Proto3.Suite.JSONPB ((.=), (.:))
import qualified Proto3.Suite.Types as HsProtobuf
import qualified Proto3.Wire as HsProtobuf import qualified Proto3.Wire as HsProtobuf
import Control.Applicative ((<*>), (<|>), (<$>))
import qualified Control.Applicative as Hs import qualified Control.Applicative as Hs
import Control.Applicative ((<*>), (<|>), (<$>))
import qualified Control.DeepSeq as Hs
import qualified Control.Monad as Hs import qualified Control.Monad as Hs
import qualified Data.Text.Lazy as Hs (Text)
import qualified Data.ByteString as Hs import qualified Data.ByteString as Hs
import qualified Data.String as Hs (fromString) import qualified Data.Coerce as Hs
import qualified Data.Vector as Hs (Vector)
import qualified Data.Int as Hs (Int16, Int32, Int64) import qualified Data.Int as Hs (Int16, Int32, Int64)
import qualified Data.Word as Hs (Word16, Word32, Word64) import qualified Data.List.NonEmpty as Hs (NonEmpty(..))
import qualified Data.Map as Hs (Map, mapKeysMonotonic)
import qualified Data.Proxy as Proxy import qualified Data.Proxy as Proxy
import qualified GHC.Generics as Hs import qualified Data.String as Hs (fromString)
import qualified Data.Text.Lazy as Hs (Text)
import qualified Data.Vector as Hs (Vector)
import qualified Data.Word as Hs (Word16, Word32, Word64)
import qualified GHC.Enum as Hs import qualified GHC.Enum as Hs
import qualified GHC.Generics as Hs
import qualified Unsafe.Coerce as Hs
import Network.GRPC.HighLevel.Generated as HsGRPC import Network.GRPC.HighLevel.Generated as HsGRPC
import Network.GRPC.HighLevel.Client as HsGRPC import Network.GRPC.HighLevel.Client as HsGRPC
import Network.GRPC.HighLevel.Server as HsGRPC hiding (serverLoop) import Network.GRPC.HighLevel.Server as HsGRPC hiding (serverLoop)
import Network.GRPC.HighLevel.Server.Unregistered as HsGRPC import Network.GRPC.HighLevel.Server.Unregistered as HsGRPC
(serverLoop) (serverLoop)
data Arithmetic request response = Arithmetic{arithmeticAdd :: data Arithmetic request response = Arithmetic{arithmeticAdd ::
request 'HsGRPC.Normal Arithmetic.TwoInts request 'HsGRPC.Normal Arithmetic.TwoInts
Arithmetic.OneInt Arithmetic.OneInt
@ -46,7 +53,7 @@ data Arithmetic request response = Arithmetic{arithmeticAdd ::
(response 'HsGRPC.ClientStreaming (response 'HsGRPC.ClientStreaming
Arithmetic.OneInt)} Arithmetic.OneInt)}
deriving Hs.Generic deriving Hs.Generic
arithmeticServer :: arithmeticServer ::
Arithmetic HsGRPC.ServerRequest HsGRPC.ServerResponse -> Arithmetic HsGRPC.ServerRequest HsGRPC.ServerResponse ->
HsGRPC.ServiceOptions -> Hs.IO () HsGRPC.ServiceOptions -> Hs.IO ()
@ -72,7 +79,7 @@ arithmeticServer
optUserAgentSuffix = userAgentSuffix, optUserAgentSuffix = userAgentSuffix,
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig, optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
optLogger = logger}) optLogger = logger})
arithmeticClient :: arithmeticClient ::
HsGRPC.Client -> HsGRPC.Client ->
Hs.IO (Arithmetic HsGRPC.ClientRequest HsGRPC.ClientResult) Hs.IO (Arithmetic HsGRPC.ClientRequest HsGRPC.ClientResult)
@ -85,13 +92,15 @@ arithmeticClient client
((Hs.pure (HsGRPC.clientRequest client)) <*> ((Hs.pure (HsGRPC.clientRequest client)) <*>
(HsGRPC.clientRegisterMethod client (HsGRPC.clientRegisterMethod client
(HsGRPC.MethodName "/arithmetic.Arithmetic/RunningSum"))) (HsGRPC.MethodName "/arithmetic.Arithmetic/RunningSum")))
data TwoInts = TwoInts{twoIntsX :: Hs.Int32, twoIntsY :: Hs.Int32} data TwoInts = TwoInts{twoIntsX :: Hs.Int32, twoIntsY :: Hs.Int32}
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData)
instance HsProtobuf.Named TwoInts where instance HsProtobuf.Named TwoInts where
nameOf _ = (Hs.fromString "TwoInts") nameOf _ = (Hs.fromString "TwoInts")
instance HsProtobuf.HasDefault TwoInts
instance HsProtobuf.Message TwoInts where instance HsProtobuf.Message TwoInts where
encodeMessage _ TwoInts{twoIntsX = twoIntsX, twoIntsY = twoIntsY} encodeMessage _ TwoInts{twoIntsX = twoIntsX, twoIntsY = twoIntsY}
= (Hs.mconcat = (Hs.mconcat
@ -117,24 +126,24 @@ instance HsProtobuf.Message TwoInts where
(HsProtobuf.Single "y") (HsProtobuf.Single "y")
[] []
"")] "")]
instance HsJSONPB.ToJSONPB TwoInts where instance HsJSONPB.ToJSONPB TwoInts where
toJSONPB (TwoInts f1 f2) = (HsJSONPB.object ["x" .= f1, "y" .= f2]) toJSONPB (TwoInts f1 f2) = (HsJSONPB.object ["x" .= f1, "y" .= f2])
toEncodingPB (TwoInts f1 f2) toEncodingPB (TwoInts f1 f2)
= (HsJSONPB.pairs ["x" .= f1, "y" .= f2]) = (HsJSONPB.pairs ["x" .= f1, "y" .= f2])
instance HsJSONPB.FromJSONPB TwoInts where instance HsJSONPB.FromJSONPB TwoInts where
parseJSONPB parseJSONPB
= (HsJSONPB.withObject "TwoInts" = (HsJSONPB.withObject "TwoInts"
(\ obj -> (Hs.pure TwoInts) <*> obj .: "x" <*> obj .: "y")) (\ obj -> (Hs.pure TwoInts) <*> obj .: "x" <*> obj .: "y"))
instance HsJSONPB.ToJSON TwoInts where instance HsJSONPB.ToJSON TwoInts where
toJSON = HsJSONPB.toAesonValue toJSON = HsJSONPB.toAesonValue
toEncoding = HsJSONPB.toAesonEncoding toEncoding = HsJSONPB.toAesonEncoding
instance HsJSONPB.FromJSON TwoInts where instance HsJSONPB.FromJSON TwoInts where
parseJSON = HsJSONPB.parseJSONPB parseJSON = HsJSONPB.parseJSONPB
instance HsJSONPB.ToSchema TwoInts where instance HsJSONPB.ToSchema TwoInts where
declareNamedSchema _ declareNamedSchema _
= do let declare_x = HsJSONPB.declareSchemaRef = do let declare_x = HsJSONPB.declareSchemaRef
@ -153,13 +162,15 @@ instance HsJSONPB.ToSchema TwoInts where
HsJSONPB._schemaProperties = HsJSONPB._schemaProperties =
HsJSONPB.insOrdFromList HsJSONPB.insOrdFromList
[("x", twoIntsX), ("y", twoIntsY)]}}) [("x", twoIntsX), ("y", twoIntsY)]}})
data OneInt = OneInt{oneIntResult :: Hs.Int32} data OneInt = OneInt{oneIntResult :: Hs.Int32}
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData)
instance HsProtobuf.Named OneInt where instance HsProtobuf.Named OneInt where
nameOf _ = (Hs.fromString "OneInt") nameOf _ = (Hs.fromString "OneInt")
instance HsProtobuf.HasDefault OneInt
instance HsProtobuf.Message OneInt where instance HsProtobuf.Message OneInt where
encodeMessage _ OneInt{oneIntResult = oneIntResult} encodeMessage _ OneInt{oneIntResult = oneIntResult}
= (Hs.mconcat = (Hs.mconcat
@ -175,23 +186,23 @@ instance HsProtobuf.Message OneInt where
(HsProtobuf.Single "result") (HsProtobuf.Single "result")
[] []
"")] "")]
instance HsJSONPB.ToJSONPB OneInt where instance HsJSONPB.ToJSONPB OneInt where
toJSONPB (OneInt f1) = (HsJSONPB.object ["result" .= f1]) toJSONPB (OneInt f1) = (HsJSONPB.object ["result" .= f1])
toEncodingPB (OneInt f1) = (HsJSONPB.pairs ["result" .= f1]) toEncodingPB (OneInt f1) = (HsJSONPB.pairs ["result" .= f1])
instance HsJSONPB.FromJSONPB OneInt where instance HsJSONPB.FromJSONPB OneInt where
parseJSONPB parseJSONPB
= (HsJSONPB.withObject "OneInt" = (HsJSONPB.withObject "OneInt"
(\ obj -> (Hs.pure OneInt) <*> obj .: "result")) (\ obj -> (Hs.pure OneInt) <*> obj .: "result"))
instance HsJSONPB.ToJSON OneInt where instance HsJSONPB.ToJSON OneInt where
toJSON = HsJSONPB.toAesonValue toJSON = HsJSONPB.toAesonValue
toEncoding = HsJSONPB.toAesonEncoding toEncoding = HsJSONPB.toAesonEncoding
instance HsJSONPB.FromJSON OneInt where instance HsJSONPB.FromJSON OneInt where
parseJSON = HsJSONPB.parseJSONPB parseJSON = HsJSONPB.parseJSONPB
instance HsJSONPB.ToSchema OneInt where instance HsJSONPB.ToSchema OneInt where
declareNamedSchema _ declareNamedSchema _
= do let declare_result = HsJSONPB.declareSchemaRef = do let declare_result = HsJSONPB.declareSchemaRef
@ -205,4 +216,4 @@ instance HsJSONPB.ToSchema OneInt where
Hs.Just HsJSONPB.SwaggerObject}, Hs.Just HsJSONPB.SwaggerObject},
HsJSONPB._schemaProperties = HsJSONPB._schemaProperties =
HsJSONPB.insOrdFromList HsJSONPB.insOrdFromList
[("result", oneIntResult)]}}) [("result", oneIntResult)]}})

View File

@ -122,6 +122,7 @@ executable arithmetic-server
, async , async
, bytestring == 0.10.* , bytestring == 0.10.*
, containers >=0.5 && <0.7 , containers >=0.5 && <0.7
, deepseq
, grpc-haskell , grpc-haskell
, grpc-haskell-core , grpc-haskell-core
, optparse-generic , optparse-generic
@ -145,6 +146,7 @@ executable arithmetic-client
, async , async
, bytestring == 0.10.* , bytestring == 0.10.*
, containers >=0.5 && <0.7 , containers >=0.5 && <0.7
, deepseq
, grpc-haskell , grpc-haskell
, grpc-haskell-core , grpc-haskell-core
, optparse-generic , optparse-generic