gRPC-haskell/examples/echo/echo-hs/Echo.hs
Joel Stanley 9a3be32ed7 Update echo client/server to use CG and high-level interfaces (#88)
* echo client/server example: dead code removal, add command line params, improve output messages

* Add nix-build result to .gitignore

* Merge echo-client and echo-server directories to echo-hs/ directory; rename main modules accordingly

* Use our protobuf compiler to generate bindings for the Echo service

* Simplify echo.proto to just one endpoint; use highlevel client/server interfaces and codegen for echo example

* Remove repetition counts and thread spawns from echo client, parameterize payload

* Update default.nix
2016-12-22 14:33:44 -06:00

105 lines
4.5 KiB
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
module Echo where
import qualified Prelude as Hs
import qualified Data.Protobuf.Wire.DotProto as HsProtobuf
import qualified Data.Protobuf.Wire.Types as HsProtobuf
import qualified Data.Protobuf.Wire.Class as HsProtobuf
import qualified Proto3.Wire as HsProtobuf
import Control.Applicative ((<*>), (<|>))
import qualified Data.Text 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.Int as Hs (Int16, Int32, Int64)
import qualified Data.Word as Hs (Word16, Word32, Word64)
import GHC.Generics as Hs
import GHC.Enum 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)
import Network.GRPC.LowLevel.Call as HsGRPC
data Echo request response = Echo{echoDoEcho ::
request 'HsGRPC.Normal EchoRequest EchoResponse ->
Hs.IO (response 'HsGRPC.Normal EchoResponse)}
deriving Hs.Generic
echoServer ::
Echo HsGRPC.ServerRequest HsGRPC.ServerResponse ->
HsGRPC.ServiceOptions -> Hs.IO ()
echoServer Echo{echoDoEcho = echoDoEcho}
(ServiceOptions serverHost serverPort useCompression
userAgentPrefix userAgentSuffix initialMetadata sslConfig logger)
= (HsGRPC.serverLoop
HsGRPC.defaultOptions{HsGRPC.optNormalHandlers =
[(HsGRPC.UnaryHandler (HsGRPC.MethodName "/echo.Echo/DoEcho")
(HsGRPC.convertGeneratedServerHandler echoDoEcho))],
HsGRPC.optClientStreamHandlers = [],
HsGRPC.optServerStreamHandlers = [],
HsGRPC.optBiDiStreamHandlers = [], optServerHost = serverHost,
optServerPort = serverPort, optUseCompression = useCompression,
optUserAgentPrefix = userAgentPrefix,
optUserAgentSuffix = userAgentSuffix,
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
optLogger = logger})
echoClient ::
HsGRPC.Client ->
Hs.IO (Echo HsGRPC.ClientRequest HsGRPC.ClientResult)
echoClient client
= (Hs.pure Echo) <*>
((Hs.pure (HsGRPC.clientRequest client)) <*>
(HsGRPC.clientRegisterMethod client
(HsGRPC.MethodName "/echo.Echo/DoEcho")))
data EchoRequest = EchoRequest{echoRequestMessage :: Hs.Text}
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
instance HsProtobuf.Named EchoRequest where
nameOf _ = (Hs.fromString "EchoRequest")
instance HsProtobuf.Message EchoRequest where
encodeMessage _
EchoRequest{echoRequestMessage = echoRequestMessage}
= (Hs.mconcat
[(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1)
echoRequestMessage)])
decodeMessage _
= (Hs.pure EchoRequest) <*>
(HsProtobuf.at HsProtobuf.decodeMessageField
(HsProtobuf.FieldNumber 1))
dotProto _
= [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1)
(HsProtobuf.Prim HsProtobuf.String)
(HsProtobuf.Single "message")
[]
Hs.Nothing)]
data EchoResponse = EchoResponse{echoResponseMessage :: Hs.Text}
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
instance HsProtobuf.Named EchoResponse where
nameOf _ = (Hs.fromString "EchoResponse")
instance HsProtobuf.Message EchoResponse where
encodeMessage _
EchoResponse{echoResponseMessage = echoResponseMessage}
= (Hs.mconcat
[(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1)
echoResponseMessage)])
decodeMessage _
= (Hs.pure EchoResponse) <*>
(HsProtobuf.at HsProtobuf.decodeMessageField
(HsProtobuf.FieldNumber 1))
dotProto _
= [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1)
(HsProtobuf.Prim HsProtobuf.String)
(HsProtobuf.Single "message")
[]
Hs.Nothing)]