Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support proto3-suite 0.5.0 and later. #22

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion grpc-mqtt.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ synopsis: Run gRPC services over an MQTT connection
license: Apache-2.0
author: Arista Networks
maintainer: opensource@awakesecurity.com
copyright: 2021 Arista Networks
copyright: 2021-2022 Arista Networks
category: Network
build-type: Simple

Expand Down Expand Up @@ -95,6 +95,7 @@ library
Network.GRPC.MQTT.Message.Packet.Core
Network.GRPC.MQTT.Message.Request.Core
Proto.Mqtt
Proto3.Suite.DotProto.Internal.Compat
Proto3.Wire.Decode.Extra
Proto3.Wire.Encode.Extra
Proto3.Wire.Types.Extra
Expand Down
6 changes: 3 additions & 3 deletions src/Network/GRPC/MQTT/TH/Client.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (c) 2021 Arista Networks, Inc.
-- Copyright (c) 2021-2022 Arista Networks, Inc.
-- Use of this source code is governed by the Apache License 2.0
-- that can be found in the COPYING file.
{-# LANGUAGE TemplateHaskell #-}
Expand Down Expand Up @@ -40,15 +40,15 @@ import Network.GRPC.MQTT.Types
MQTTResult,
)
import Network.MQTT.Topic (Topic)
import Proto3.Suite.DotProto.Internal (prefixedFieldName)
import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName)
import Turtle (FilePath)

--------------------------------------------------------------------------------

mqttClientFuncs :: Turtle.FilePath -> Batched -> Q [Dec]
mqttClientFuncs fp defaultBatchedStream = fmap concat $
forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do
clientFuncName <- mkName <$> prefixedFieldName serviceName "mqttClient"
clientFuncName <- mkName <$> prefixedMethodName serviceName "mqttClient"
lift $ clientService clientFuncName (mkName serviceName) [(a, batched) | (a, batched, _, _) <- serviceMethods]

clientService :: Name -> Name -> [(String, Batched)] -> DecsQ
Expand Down
6 changes: 3 additions & 3 deletions src/Network/GRPC/MQTT/TH/Proto.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (c) 2021 Arista Networks, Inc.
-- Copyright (c) 2021-2022 Arista Networks, Inc.
-- Use of this source code is governed by the Apache License 2.0
-- that can be found in the COPYING file.
{-# LANGUAGE LambdaCase #-}
Expand Down Expand Up @@ -44,10 +44,10 @@ import Proto3.Suite.DotProto.Internal
dpIdentUnqualName,
importProto,
invalidMethodNameError,
prefixedFieldName,
protoPackageName,
typeLikeName,
)
import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName)
import Turtle (FilePath, directory, filename)

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -103,7 +103,7 @@ forEachService protoFilepath defBatchedStream action = showErrors . runExceptT $
(NonStreaming, NonStreaming) -> [e|wrapUnaryClientHandler|]
(Streaming, NonStreaming) -> [e|wrapClientStreamingClientHandler|]
(Streaming, Streaming) -> [e|wrapBiDiStreamingClientHandler useBatchedStream|]
clientFun <- prefixedFieldName serviceName nm
clientFun <- prefixedMethodName serviceName nm
return [(endpointPrefix <> nm, useBatchedStream, streamingWrapper, mkName clientFun)]
_ -> invalidMethodNameError rpcMethodName
serviceMethodName _ = pure []
Expand Down
8 changes: 4 additions & 4 deletions src/Network/GRPC/MQTT/TH/RemoteClient.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (c) 2021 Arista Networks, Inc.
-- Copyright (c) 2021-2022 Arista Networks, Inc.
-- Use of this source code is governed by the Apache License 2.0
-- that can be found in the COPYING file.
{-# LANGUAGE TemplateHaskell #-}
Expand Down Expand Up @@ -35,16 +35,16 @@ import Language.Haskell.TH
import Network.GRPC.HighLevel.Client (Client)
import Network.GRPC.MQTT.Types (Batched (Batched, Unbatched), MethodMap)
import Network.GRPC.MQTT.Wrapping (wrapServerStreamingClientHandler, wrapUnaryClientHandler)
import Proto3.Suite.DotProto.Internal (prefixedFieldName)
import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName)
import Turtle (FilePath)

--------------------------------------------------------------------------------

mqttRemoteClientMethodMap :: Turtle.FilePath -> Batched -> Q [Dec]
mqttRemoteClientMethodMap fp defaultBatchedStream = fmap concat $
forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do
clientFuncName <- mkName <$> prefixedFieldName serviceName "remoteClientMethodMap"
grpcClientName <- mkName <$> prefixedFieldName serviceName "client"
clientFuncName <- mkName <$> prefixedMethodName serviceName "remoteClientMethodMap"
grpcClientName <- mkName <$> prefixedMethodName serviceName "client"
lift $ rcMethodMap clientFuncName grpcClientName serviceMethods

rcMethodMap :: Name -> Name -> [(String, Batched, ExpQ, Name)] -> DecsQ
Expand Down
25 changes: 25 additions & 0 deletions src/Proto3/Suite/DotProto/Internal/Compat.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Copyright (c) 2022 Arista Networks, Inc.
-- Use of this source code is governed by the Apache License 2.0
-- that can be found in the COPYING file.
{-# LANGUAGE CPP #-}

-- | For versions of @proto3-suite@ starting with 0.5.0, merely
-- reexports `Proto3.Suite.DotProto.Internal.prefixedMethodName)`,
-- but for earlier versions emulates that function by defining it as
-- an alias of `Proto3.Suite.DotProto.Internal.prefixedFieldName`.
module Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName) where

#if MIN_VERSION_proto3_suite(0,5,0)

import Proto3.Suite.DotProto.Internal (prefixedMethodName)

#else

import Control.Monad.Except (MonadError)
import Proto3.Suite.DotProto.Internal (CompileError, prefixedFieldName)
import Relude (String)

prefixedMethodName :: MonadError CompileError m => String -> String -> m String
prefixedMethodName = prefixedFieldName

#endif