mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-22 19:19:42 +01:00
Update Arithmetic
example to use newer proto3-suite
(#102)
Related to https://github.com/awakesecurity/proto3-suite/issues/119
This commit is contained in:
parent
bc155c1a52
commit
595cb6a3bf
2 changed files with 43 additions and 30 deletions
71
examples/tutorial/Arithmetic.hs
generated
71
examples/tutorial/Arithmetic.hs
generated
|
@ -1,6 +1,8 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
|
||||
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
|
||||
|
@ -9,30 +11,35 @@
|
|||
-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
|
||||
module Arithmetic where
|
||||
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.DotProto as HsProtobuf
|
||||
import qualified Proto3.Suite.JSONPB as HsJSONPB
|
||||
import Proto3.Suite.JSONPB ((.=), (.:))
|
||||
import qualified Proto3.Suite.Types as HsProtobuf
|
||||
import qualified Proto3.Wire as HsProtobuf
|
||||
import Control.Applicative ((<*>), (<|>), (<$>))
|
||||
import qualified Control.Applicative as Hs
|
||||
import Control.Applicative ((<*>), (<|>), (<$>))
|
||||
import qualified Control.DeepSeq 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.String as Hs (fromString)
|
||||
import qualified Data.Vector as Hs (Vector)
|
||||
import qualified Data.Coerce as Hs
|
||||
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 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.Generics as Hs
|
||||
import qualified Unsafe.Coerce as Hs
|
||||
import Network.GRPC.HighLevel.Generated as HsGRPC
|
||||
import Network.GRPC.HighLevel.Client as HsGRPC
|
||||
import Network.GRPC.HighLevel.Server as HsGRPC hiding (serverLoop)
|
||||
import Network.GRPC.HighLevel.Server.Unregistered as HsGRPC
|
||||
(serverLoop)
|
||||
|
||||
|
||||
data Arithmetic request response = Arithmetic{arithmeticAdd ::
|
||||
request 'HsGRPC.Normal Arithmetic.TwoInts
|
||||
Arithmetic.OneInt
|
||||
|
@ -46,7 +53,7 @@ data Arithmetic request response = Arithmetic{arithmeticAdd ::
|
|||
(response 'HsGRPC.ClientStreaming
|
||||
Arithmetic.OneInt)}
|
||||
deriving Hs.Generic
|
||||
|
||||
|
||||
arithmeticServer ::
|
||||
Arithmetic HsGRPC.ServerRequest HsGRPC.ServerResponse ->
|
||||
HsGRPC.ServiceOptions -> Hs.IO ()
|
||||
|
@ -72,7 +79,7 @@ arithmeticServer
|
|||
optUserAgentSuffix = userAgentSuffix,
|
||||
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
|
||||
optLogger = logger})
|
||||
|
||||
|
||||
arithmeticClient ::
|
||||
HsGRPC.Client ->
|
||||
Hs.IO (Arithmetic HsGRPC.ClientRequest HsGRPC.ClientResult)
|
||||
|
@ -85,13 +92,15 @@ arithmeticClient client
|
|||
((Hs.pure (HsGRPC.clientRequest client)) <*>
|
||||
(HsGRPC.clientRegisterMethod client
|
||||
(HsGRPC.MethodName "/arithmetic.Arithmetic/RunningSum")))
|
||||
|
||||
|
||||
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
|
||||
nameOf _ = (Hs.fromString "TwoInts")
|
||||
|
||||
|
||||
instance HsProtobuf.HasDefault TwoInts
|
||||
|
||||
instance HsProtobuf.Message TwoInts where
|
||||
encodeMessage _ TwoInts{twoIntsX = twoIntsX, twoIntsY = twoIntsY}
|
||||
= (Hs.mconcat
|
||||
|
@ -117,24 +126,24 @@ instance HsProtobuf.Message TwoInts where
|
|||
(HsProtobuf.Single "y")
|
||||
[]
|
||||
"")]
|
||||
|
||||
|
||||
instance HsJSONPB.ToJSONPB TwoInts where
|
||||
toJSONPB (TwoInts f1 f2) = (HsJSONPB.object ["x" .= f1, "y" .= f2])
|
||||
toEncodingPB (TwoInts f1 f2)
|
||||
= (HsJSONPB.pairs ["x" .= f1, "y" .= f2])
|
||||
|
||||
|
||||
instance HsJSONPB.FromJSONPB TwoInts where
|
||||
parseJSONPB
|
||||
= (HsJSONPB.withObject "TwoInts"
|
||||
(\ obj -> (Hs.pure TwoInts) <*> obj .: "x" <*> obj .: "y"))
|
||||
|
||||
|
||||
instance HsJSONPB.ToJSON TwoInts where
|
||||
toJSON = HsJSONPB.toAesonValue
|
||||
toEncoding = HsJSONPB.toAesonEncoding
|
||||
|
||||
|
||||
instance HsJSONPB.FromJSON TwoInts where
|
||||
parseJSON = HsJSONPB.parseJSONPB
|
||||
|
||||
|
||||
instance HsJSONPB.ToSchema TwoInts where
|
||||
declareNamedSchema _
|
||||
= do let declare_x = HsJSONPB.declareSchemaRef
|
||||
|
@ -153,13 +162,15 @@ instance HsJSONPB.ToSchema TwoInts where
|
|||
HsJSONPB._schemaProperties =
|
||||
HsJSONPB.insOrdFromList
|
||||
[("x", twoIntsX), ("y", twoIntsY)]}})
|
||||
|
||||
|
||||
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
|
||||
nameOf _ = (Hs.fromString "OneInt")
|
||||
|
||||
|
||||
instance HsProtobuf.HasDefault OneInt
|
||||
|
||||
instance HsProtobuf.Message OneInt where
|
||||
encodeMessage _ OneInt{oneIntResult = oneIntResult}
|
||||
= (Hs.mconcat
|
||||
|
@ -175,23 +186,23 @@ instance HsProtobuf.Message OneInt where
|
|||
(HsProtobuf.Single "result")
|
||||
[]
|
||||
"")]
|
||||
|
||||
|
||||
instance HsJSONPB.ToJSONPB OneInt where
|
||||
toJSONPB (OneInt f1) = (HsJSONPB.object ["result" .= f1])
|
||||
toEncodingPB (OneInt f1) = (HsJSONPB.pairs ["result" .= f1])
|
||||
|
||||
|
||||
instance HsJSONPB.FromJSONPB OneInt where
|
||||
parseJSONPB
|
||||
= (HsJSONPB.withObject "OneInt"
|
||||
(\ obj -> (Hs.pure OneInt) <*> obj .: "result"))
|
||||
|
||||
|
||||
instance HsJSONPB.ToJSON OneInt where
|
||||
toJSON = HsJSONPB.toAesonValue
|
||||
toEncoding = HsJSONPB.toAesonEncoding
|
||||
|
||||
|
||||
instance HsJSONPB.FromJSON OneInt where
|
||||
parseJSON = HsJSONPB.parseJSONPB
|
||||
|
||||
|
||||
instance HsJSONPB.ToSchema OneInt where
|
||||
declareNamedSchema _
|
||||
= do let declare_result = HsJSONPB.declareSchemaRef
|
||||
|
@ -205,4 +216,4 @@ instance HsJSONPB.ToSchema OneInt where
|
|||
Hs.Just HsJSONPB.SwaggerObject},
|
||||
HsJSONPB._schemaProperties =
|
||||
HsJSONPB.insOrdFromList
|
||||
[("result", oneIntResult)]}})
|
||||
[("result", oneIntResult)]}})
|
|
@ -122,6 +122,7 @@ executable arithmetic-server
|
|||
, async
|
||||
, bytestring == 0.10.*
|
||||
, containers >=0.5 && <0.7
|
||||
, deepseq
|
||||
, grpc-haskell
|
||||
, grpc-haskell-core
|
||||
, optparse-generic
|
||||
|
@ -145,6 +146,7 @@ executable arithmetic-client
|
|||
, async
|
||||
, bytestring == 0.10.*
|
||||
, containers >=0.5 && <0.7
|
||||
, deepseq
|
||||
, grpc-haskell
|
||||
, grpc-haskell-core
|
||||
, optparse-generic
|
||||
|
|
Loading…
Reference in a new issue