diff --git a/grpc-mqtt.cabal b/grpc-mqtt.cabal index 01504c3..67e5ce9 100644 --- a/grpc-mqtt.cabal +++ b/grpc-mqtt.cabal @@ -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 @@ -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 diff --git a/src/Network/GRPC/MQTT/TH/Client.hs b/src/Network/GRPC/MQTT/TH/Client.hs index ec41c73..2cb1b7e 100644 --- a/src/Network/GRPC/MQTT/TH/Client.hs +++ b/src/Network/GRPC/MQTT/TH/Client.hs @@ -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 #-} @@ -40,7 +40,7 @@ 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) -------------------------------------------------------------------------------- @@ -48,7 +48,7 @@ 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 diff --git a/src/Network/GRPC/MQTT/TH/Proto.hs b/src/Network/GRPC/MQTT/TH/Proto.hs index c0f44c5..0ee147a 100644 --- a/src/Network/GRPC/MQTT/TH/Proto.hs +++ b/src/Network/GRPC/MQTT/TH/Proto.hs @@ -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 #-} @@ -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) ------------------------------------------------------------------------------- @@ -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 [] diff --git a/src/Network/GRPC/MQTT/TH/RemoteClient.hs b/src/Network/GRPC/MQTT/TH/RemoteClient.hs index 49a9b4c..222615e 100644 --- a/src/Network/GRPC/MQTT/TH/RemoteClient.hs +++ b/src/Network/GRPC/MQTT/TH/RemoteClient.hs @@ -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 #-} @@ -35,7 +35,7 @@ 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) -------------------------------------------------------------------------------- @@ -43,8 +43,8 @@ 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 diff --git a/src/Proto3/Suite/DotProto/Internal/Compat.hs b/src/Proto3/Suite/DotProto/Internal/Compat.hs new file mode 100644 index 0000000..76cbe81 --- /dev/null +++ b/src/Proto3/Suite/DotProto/Internal/Compat.hs @@ -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