grpc_server_template 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b23eaf6091f23b8347992cfd008b345fb22291132c2e16a932f6e5541b7768c9
4
- data.tar.gz: 5f709ab979016084834eaff5bb405e4ab8a29bd22e24081808da7d4d8a79a22a
3
+ metadata.gz: 3df25ea41a90a8d164a5872c098f3acb11fc65690f7be9461222edff4a4db3fa
4
+ data.tar.gz: '09a260195ac6ef6ce251f965b6699346818144977068e882f4f336130d1fd9ed'
5
5
  SHA512:
6
- metadata.gz: 1d2c943947594ed46aeaede76be1853a43ede5f3fb866b8b795d32be8ba83e9ef9a92554a08503cec580e99812c8d08281bc1c5732f82739227cbf5f0145f21d
7
- data.tar.gz: c70166ee858a876e24b3f9138755191b785d39c1a53a6a1d92320eedf8cf024f03b7a52e28f6401f0599b439378330a66a863292f364f51803fbcb24f9de0125
6
+ metadata.gz: 46a8d80f28606961a44e67f17d23d3b588369589513f231f84d302593d059778b662d962e2615b5bdb84eeca6657c3dd1934ab16b0ca5a14c3e0c21372f97cf0
7
+ data.tar.gz: 9814af0813578012ae0084ada32ce498b0658e73218d35e8284808a10ab5cd88e23e2ad9f66b34b60f6529d5c7c2200dcb61e4e19eb8122fef0fd3ea5bde9c6e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc_server_template (0.1.1)
4
+ grpc_server_template (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,14 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor"
4
- require "fileutils"
5
- require "erb"
6
4
 
7
5
  module GrpcServerTemplate
6
+ # Cli class
8
7
  class Cli < Thor
9
- desc "create PROJECT_NAME", "Creates a new gRPC Ruby server project with the given name"
10
- def create(project_name)
11
- system("echo 'Hello world #{project_name}'")
8
+ desc "build", "Build gRPC from proto file"
9
+ def build
10
+ system("bin/build")
11
+ end
12
+
13
+ desc "client", "runs the client"
14
+ def client
15
+ system("bin/client")
16
+ end
17
+
18
+ desc "server", "runs the server"
19
+ def server
20
+ system("bin/server")
12
21
  end
13
22
  end
14
23
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'messages'
4
+ require_relative 'service'
5
+
6
+ module GrpcServerTemplate
7
+ # Client
8
+ class Client
9
+ class << self
10
+ def say_hello(name: "server")
11
+ stub = GrpcServerTemplate::Stub.new('0.0.0.0:50052', :this_channel_is_insecure)
12
+ req = GrpcServerTemplate::Messages::HelloRequest.new(name: name)
13
+ resp_obj = stub.say_hello(req)
14
+ puts "Response: #{resp_obj}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'messages'
4
+ require_relative 'service'
5
+
6
+ module GrpcServerTemplate
7
+ # Handler
8
+ class Handler < GrpcServerTemplate::Service
9
+ def say_hello(hello_req, _unused_call)
10
+ puts "Request: #{hello_req}"
11
+ GrpcServerTemplate::Messages::HelloReply.new(message: "Hello #{hello_req.name}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: grpc_server_template.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("grpc_server_template.proto", :syntax => :proto3) do
8
+ add_message "HelloRequest" do
9
+ optional :name, :string, 1
10
+ end
11
+ add_message "HelloReply" do
12
+ optional :message, :string, 1
13
+ end
14
+ end
15
+ end
16
+
17
+ module GrpcServerTemplate
18
+ # Messages
19
+ class Messages
20
+ HelloRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("HelloRequest").msgclass
21
+ HelloReply = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("HelloReply").msgclass
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'handler'
4
+
5
+ module GrpcServerTemplate
6
+ # Server
7
+ class Server
8
+ class << self
9
+ def start(port: 50052)
10
+ @server = GRPC::RpcServer.new
11
+ @server.add_http2_port("0.0.0.0:#{port}", :this_port_is_insecure)
12
+ @server.handle(GrpcServerTemplate::Handler)
13
+ @server.run_till_terminated
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,21 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: grpc_server_template.proto for package ''
3
+
4
+ require 'grpc'
5
+ require_relative 'messages'
6
+
7
+ module GrpcServerTemplate
8
+ # The greeting service definition.
9
+ class Service
10
+
11
+ include ::GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'GrpcServerTemplate'
16
+
17
+ rpc :SayHello, GrpcServerTemplate::Messages::HelloRequest, GrpcServerTemplate::Messages::HelloReply
18
+ end
19
+
20
+ Stub = Service.rpc_stub_class
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcServerTemplate
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -4,5 +4,4 @@ Dir[File.join(__dir__, "grpc_server_template", "*.rb")].sort.each { |file| requi
4
4
 
5
5
  module GrpcServerTemplate
6
6
  class Error < StandardError; end
7
- # Your code goes here...
8
7
  end
@@ -0,0 +1,16 @@
1
+ syntax = "proto3";
2
+
3
+ // The greeting service definition.
4
+ service GrpcServerTemplate {
5
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
6
+ }
7
+
8
+ // The request message containing the user's name.
9
+ message HelloRequest {
10
+ string name = 1;
11
+ }
12
+
13
+ // The response message containing the greetings
14
+ message HelloReply {
15
+ string message = 1;
16
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_server_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvance
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A template for the ruby grpc server.
14
14
  email:
@@ -30,7 +30,13 @@ files:
30
30
  - grpc_server_template.gemspec
31
31
  - lib/grpc_server_template.rb
32
32
  - lib/grpc_server_template/cli.rb
33
+ - lib/grpc_server_template/client.rb
34
+ - lib/grpc_server_template/handler.rb
35
+ - lib/grpc_server_template/messages.rb
36
+ - lib/grpc_server_template/server.rb
37
+ - lib/grpc_server_template/service.rb
33
38
  - lib/grpc_server_template/version.rb
39
+ - protos/grpc_server_template.proto
34
40
  - sig/grpc_server_template.rbs
35
41
  homepage: https://github.com/Sylvance/grpc_server_template/blob/main/README.md
36
42
  licenses: []