From 0618511793c42c96d7a1884f2182d59d8b353e20 Mon Sep 17 00:00:00 2001 From: Tejas Chandrasekar <32821216+TejasSC@users.noreply.github.com> Date: Mon, 13 Aug 2018 17:26:42 +0800 Subject: [PATCH] [#1] Add first protocol buffers message and print its serialization to terminal (#3) * Add protobuf file with very simple message issue #1 * Edit proto-route.cabal and add Setup.hs files issue #1 * Encounter errors with Haskell file generation issue #1 * Attempt to fix .hs file generation errors with stack issue #1 * Resolve error in generating haskell files issue #1 * Create value of generated message and print to console issue #1 * Print serialized representation issue #1 * Encounter errors in ghci representation issue #1 * Resolve errors in ghci representation issue #1 * Refactor files to improve further modularity issue #1 * Modify ChangeLog.md to include links issue #1 * Re-modify ChangeLog.md to include links issue #1 --- CHANGELOG.md | 1 - README.md | 6 ------ Setup.hs | 3 +++ app/Main.hs | 5 ++--- proto-route.cabal | 37 +++++++++++++++++++++++++++---------- proto/protobuf1.proto | 5 +++++ src/Prelude.hs | 8 -------- src/ProtoExports.hs | 7 +++++++ src/ProtoRoute.hs | 21 ++++++++++++++++++--- stack.yaml | 4 ++++ test/Spec.hs | 2 ++ 11 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 Setup.hs create mode 100644 proto/protobuf1.proto delete mode 100644 src/Prelude.hs create mode 100644 src/ProtoExports.hs create mode 100644 stack.yaml create mode 100644 test/Spec.hs diff --git a/CHANGELOG.md b/CHANGELOG.md index 91746f2..825ea2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,4 +10,3 @@ The change log is available [on GitHub][2]. [1]: https://pvp.haskell.org [2]: https://github.com/holmusk/proto-route/releases - diff --git a/README.md b/README.md index 4995018..b2862fa 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,3 @@ [![Hackage](https://img.shields.io/hackage/v/proto-route.svg)](https://hackage.haskell.org/package/proto-route) [![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/holmusk/proto-route/blob/master/LICENSE) - - - - -Remote testing tool for protobuf endpoints - diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..44ef617 --- /dev/null +++ b/Setup.hs @@ -0,0 +1,3 @@ +import Data.ProtoLens.Setup (defaultMainGeneratingProtos) + +main = defaultMainGeneratingProtos "proto" diff --git a/app/Main.hs b/app/Main.hs index 19a5475..84971a7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,7 +1,6 @@ module Main where -import ProtoRoute (someFunc) +import qualified ProtoRoute main :: IO () -main = someFunc - +main = ProtoRoute.main diff --git a/proto-route.cabal b/proto-route.cabal index 41e135d..ef8326a 100644 --- a/proto-route.cabal +++ b/proto-route.cabal @@ -10,33 +10,50 @@ author: Holmusk maintainer: tech@holmusk.com copyright: 2018 Holmusk category: Protobuf, Network -build-type: Simple +build-type: Custom extra-doc-files: README.md , CHANGELOG.md cabal-version: 1.24 tested-with: GHC == 8.4.3 +extra-source-files: proto/protobuf1.proto source-repository head type: git location: https://github.com/holmusk/proto-route.git +custom-setup + setup-depends: + Cabal + , base + , proto-lens-protoc + library hs-source-dirs: src - exposed-modules: ProtoRoute - Prelude + exposed-modules: ProtoExports + ProtoRoute + Proto.Protobuf1 + Proto.Protobuf1_Fields ghc-options: -Wall - build-depends: base-noprelude - , universum + build-depends: base >=4.7 && <5 + , directory + , ghcid + , protobuf + , proto-lens + , proto-lens-protoc + , text default-language: Haskell2010 - + executable proto-route hs-source-dirs: app main-is: Main.hs ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N - build-depends: base-noprelude + build-depends: base + , directory + , ghcid + , protobuf + , proto-lens + , proto-lens-protoc , proto-route - , universum + , text default-language: Haskell2010 - - diff --git a/proto/protobuf1.proto b/proto/protobuf1.proto new file mode 100644 index 0000000..a1f6ca3 --- /dev/null +++ b/proto/protobuf1.proto @@ -0,0 +1,5 @@ +syntax = "proto2"; + +message SearchRequest { + required string query = 1; +} diff --git a/src/Prelude.hs b/src/Prelude.hs deleted file mode 100644 index 68500f2..0000000 --- a/src/Prelude.hs +++ /dev/null @@ -1,8 +0,0 @@ --- | Uses [universum](https://hackage.haskell.org/package/universum) as default Prelude. - -module Prelude - ( module Universum - ) where - -import Universum - diff --git a/src/ProtoExports.hs b/src/ProtoExports.hs new file mode 100644 index 0000000..c64a774 --- /dev/null +++ b/src/ProtoExports.hs @@ -0,0 +1,7 @@ +module ProtoExports + ( module Proto.Protobuf1 + , module Proto.Protobuf1_Fields + ) where + +import Proto.Protobuf1 +import Proto.Protobuf1_Fields diff --git a/src/ProtoRoute.hs b/src/ProtoRoute.hs index b89a49b..e9defd9 100644 --- a/src/ProtoRoute.hs +++ b/src/ProtoRoute.hs @@ -1,7 +1,22 @@ module ProtoRoute - ( someFunc + ( main ) where -someFunc :: IO () -someFunc = putStrLn ("someFunc" :: String) +import Language.Haskell.Ghcid (execStream, startGhci, stopGhci) +import System.Directory (getCurrentDirectory) +main :: IO () +main = do + let f = \_ s -> putStrLn s + curDir <- getCurrentDirectory + (g, _) <- startGhci "ghci" (Just curDir) f + let execStatement s = execStream g s f + execStatement "import Data.Text" + execStatement "import Data.ProtoLens.Encoding" + execStatement ":load src/ProtoExports" + execStatement "let sr = SearchRequest {_SearchRequest'query = pack \"test\"\ + \, _SearchRequest'_unknownFields = ([])}" + -- Value of generated msg, and its serialized representation + execStatement "sr" + execStatement "encodeMessage sr" + stopGhci g diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..5cc033f --- /dev/null +++ b/stack.yaml @@ -0,0 +1,4 @@ +resolver: lts-12.6 + +extra-deps: + - base-noprelude-4.10.1.0 diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented"