beefcake_go_rpcgen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9b81d4148382e09194bad4ef73d81d35be5fff2
4
+ data.tar.gz: e00780ca5c9f04a2c34ac0c9aff967ec2c262dc3
5
+ SHA512:
6
+ metadata.gz: ac8b95a3af8c4ed70e24dc79026a30b3c4397893b786f30787a6a35f3e9db1029d256680543e750184db0fc3d6aebbc0fe4c22eb9715181cd520e73e165f4512
7
+ data.tar.gz: f5e4432c52807ddcfca24912fd90dca63e8733bae4cff7b73c58654be675c8aeb3a538190d170e3875e45f81f59a157c02dcdfbb5eff7d123a5be81a6241c5c4
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # For MacOS:
19
+ #.DS_Store
20
+
21
+ # For TextMate
22
+ #*.tmproj
23
+ #tmtags
24
+
25
+ # For emacs:
26
+ #*~
27
+ #\#*
28
+ #.\#*
29
+
30
+ # For vim:
31
+ #*.swp
32
+
33
+ # For redcar:
34
+ #.redcar
35
+
36
+ # For rubinius:
37
+ #*.rbc
38
+
39
+ # Anything Vi related
40
+ *.sw[opn]
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ #ruby=2.1.2
4
+ #ruby-gemset=beefcake_go_rpcgen
5
+
6
+ gem 'beefcake', git: 'git@github.com:bradhe/beefcake.git'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "yard", "~> 0.7"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ GIT
2
+ remote: git@github.com:bradhe/beefcake.git
3
+ revision: 5db218816a38d9e74c6ed06b4def1dbacfd87204
4
+ specs:
5
+ beefcake (0.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ diff-lcs (1.1.3)
13
+ faraday (0.8.9)
14
+ multipart-post (~> 1.2.0)
15
+ git (1.2.8)
16
+ github_api (0.10.1)
17
+ addressable
18
+ faraday (~> 0.8.1)
19
+ hashie (>= 1.2)
20
+ multi_json (~> 1.4)
21
+ nokogiri (~> 1.5.2)
22
+ oauth2
23
+ hashie (3.3.1)
24
+ highline (1.6.21)
25
+ jeweler (1.8.8)
26
+ builder
27
+ bundler (~> 1.0)
28
+ git (>= 1.2.5)
29
+ github_api (= 0.10.1)
30
+ highline (>= 1.6.15)
31
+ nokogiri (= 1.5.10)
32
+ rake
33
+ rdoc
34
+ json (1.8.1)
35
+ jwt (1.0.0)
36
+ multi_json (1.10.1)
37
+ multi_xml (0.5.5)
38
+ multipart-post (1.2.0)
39
+ nokogiri (1.5.10)
40
+ oauth2 (1.0.0)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.5.2)
47
+ rake (10.3.2)
48
+ rdoc (4.1.2)
49
+ json (~> 1.4)
50
+ rspec (2.8.0)
51
+ rspec-core (~> 2.8.0)
52
+ rspec-expectations (~> 2.8.0)
53
+ rspec-mocks (~> 2.8.0)
54
+ rspec-core (2.8.0)
55
+ rspec-expectations (2.8.0)
56
+ diff-lcs (~> 1.1.2)
57
+ rspec-mocks (2.8.0)
58
+ yard (0.8.6.1)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ beefcake!
65
+ jeweler (~> 1.8.4)
66
+ rspec (~> 2.8.0)
67
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Brad Heller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Beefcake Go RPCGEN
2
+
3
+ An implementation of the [Go RPCGEN RPC
4
+ protocol](https://github.com/kylelemons/go-rpcgen/) for Beefcake client stubs.
5
+
6
+ ## How to use this gem
7
+
8
+ All you need to do is install it and require it. Assuming Beefcake is present,
9
+ everything will be configured for you!
10
+
11
+ ``` bash
12
+ $ gem install beecake_go_rpcgen
13
+ ```
14
+
15
+ ``` ruby
16
+ require "beefcake"
17
+ require "beefcake_go_rpcgen"
18
+ ```
19
+
20
+ Now, any communication over RPC clients will use this protocol!
21
+
22
+
23
+ ## Contributing to beefcake_go_rpcgen
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
26
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
27
+ * Fork the project.
28
+ * Start a feature/bugfix branch.
29
+ * Commit and push until you are happy with your contribution.
30
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
32
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "beefcake_go_rpcgen"
18
+ gem.homepage = "http://github.com/bradhe/beefcake_go_rpcgen"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Go RPCGen backend for Beefcake}
21
+ gem.description = %Q{An implementation of the Go RPCGen protocol}
22
+ gem.email = "brad@cloudability.com"
23
+ gem.authors = ["Brad Heller"]
24
+ gem.files = `git ls-files .`.split("\n").reject! do |file|
25
+ file.start_with?('spec')
26
+ file.start_with?('lib/tasks')
27
+ end
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new do |spec|
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ require 'yard'
46
+ YARD::Rake::YardocTask.new
47
+
48
+ Dir[File.expand_path('../lib/tasks/*.rake', __FILE__)].each do |rake_file|
49
+ load rake_file
50
+ end
51
+
52
+ task :environment do
53
+ # TODO: Anything...
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: beefcake_go_rpcgen 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "beefcake_go_rpcgen"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Brad Heller"]
14
+ s.date = "2014-09-11"
15
+ s.description = "An implementation of the Go RPCGen protocol"
16
+ s.email = "brad@cloudability.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ ".rspec",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README.md",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "beefcake_go_rpcgen.gemspec",
32
+ "lib/beefcake/client_backends/go_rpcgen_backend.rb",
33
+ "lib/beefcake_go_rpcgen.rb",
34
+ "lib/wire/.gitkeep",
35
+ "lib/wire/wire.pb.rb",
36
+ "lib/wire/wire.proto",
37
+ "spec/beefcake_go_rpcgen_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = "http://github.com/bradhe/beefcake_go_rpcgen"
41
+ s.licenses = ["MIT"]
42
+ s.rubygems_version = "2.2.2"
43
+ s.summary = "Go RPCGen backend for Beefcake"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 4
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<beefcake>, [">= 0"])
50
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
51
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ else
54
+ s.add_dependency(%q<beefcake>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
56
+ s.add_dependency(%q<yard>, ["~> 0.7"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<beefcake>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
62
+ s.add_dependency(%q<yard>, ["~> 0.7"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,84 @@
1
+ require 'beefcake/client_backends'
2
+ require 'wire/wire.pb'
3
+
4
+ module Beefcake
5
+ module ClientBackends
6
+ class GoRpcgenBackend < DefaultBackend
7
+ def next_sequence
8
+ @@sequence ||= 0
9
+ @@sequence += 1
10
+ end
11
+
12
+ def send_request(method, obj, opts={})
13
+ write_all(Header.new(method: method, seq: next_sequence))
14
+ write_all(obj)
15
+
16
+ return_klass = opts[:returns] || opts['returns']
17
+ read_all(return_klass)
18
+ end
19
+
20
+ def write_all(message)
21
+ str = encoded(message)
22
+
23
+ buf = Buffer.new
24
+ buf.append_uint64(str.length)
25
+ buf << str
26
+
27
+ socket.write(buf)
28
+ socket.flush
29
+ end
30
+
31
+ def read_all(klass)
32
+ # TODO: Anything with this message?
33
+ read_obj(Header)
34
+ read_obj(klass)
35
+ end
36
+
37
+ def read_obj(klass)
38
+ msg = socket.read(read_obj_size)
39
+ klass.decode(msg)
40
+ end
41
+
42
+ def read_obj_size
43
+ buf = Buffer.new
44
+ read_uvarint(buf)
45
+ size = buf.read_uint64
46
+ end
47
+
48
+ def read_uvarint(buf)
49
+ b = socket.recv(1).ord
50
+ buf << b
51
+ read_uvarint(buf) if (b >> 7) & 0x01 == 0x01
52
+ end
53
+
54
+ def encoded(obj)
55
+ ''.tap { |s| obj.encode(s) }
56
+ end
57
+
58
+ def socket
59
+ @socket ||= open_socket!
60
+ end
61
+
62
+ def open_socket!(timeout=5)
63
+ addr = Socket.getaddrinfo(host, nil)
64
+ sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
65
+
66
+ # If a timeout was requested, let's configure one.
67
+ if timeout
68
+ secs = timeout.to_i
69
+ usecs = Integer((timeout - secs) * 1_000_000)
70
+ optval = [secs, usecs].pack("l_2")
71
+ begin
72
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
73
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
74
+ rescue Exception => ex
75
+ warn "Unable to use raw socket timeouts: #{ex.class.name}: #{ex.message}"
76
+ end
77
+ end
78
+
79
+ sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
80
+ sock
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ # We need Beefcake in the stack for this...
4
+ require 'beefcake'
5
+ require 'beefcake/client_backends/go_rpcgen_backend'
6
+
7
+ Beefcake::Client.set_backend(Beefcake::ClientBackends::GoRpcgenBackend)
data/lib/wire/.gitkeep ADDED
File without changes
@@ -0,0 +1,13 @@
1
+ ## Generated from lib/wire/wire.proto for wire
2
+ require "beefcake"
3
+
4
+
5
+ class Header
6
+ include Beefcake::Message
7
+
8
+
9
+ optional :method, :string, 1
10
+ optional :seq, :uint64, 2
11
+ optional :error, :string, 3
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ package wire;
2
+
3
+ message header {
4
+ optional string method = 1;
5
+ optional uint64 seq = 2;
6
+ optional string error = 3;
7
+ }
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "BeefcakeGoRpcgen" do
4
+ context 'with regard to class methods' do
5
+ subject { Beefcake::Client.backend('0.0.0.0', 123) }
6
+
7
+ it 'should set the default backend' do
8
+ should be_a Beefcake::ClientBackends::GoRpcgenBackend
9
+ end
10
+ end
11
+
12
+ context 'with regard to client instances' do
13
+ let(:client) { Beefcake::Client.new('0.0.0.0', 123) }
14
+ subject { client.send(:backend) }
15
+
16
+ it 'should change the default backend for all instances' do
17
+ should be_a Beefcake::ClientBackends::GoRpcgenBackend
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'beefcake_go_rpcgen'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # TODO: Anything.
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beefcake_go_rpcgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brad Heller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: beefcake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.8.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.4
69
+ description: An implementation of the Go RPCGen protocol
70
+ email: brad@cloudability.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.md
76
+ files:
77
+ - ".document"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - VERSION
86
+ - beefcake_go_rpcgen.gemspec
87
+ - lib/beefcake/client_backends/go_rpcgen_backend.rb
88
+ - lib/beefcake_go_rpcgen.rb
89
+ - lib/wire/.gitkeep
90
+ - lib/wire/wire.pb.rb
91
+ - lib/wire/wire.proto
92
+ - spec/beefcake_go_rpcgen_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: http://github.com/bradhe/beefcake_go_rpcgen
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Go RPCGen backend for Beefcake
118
+ test_files: []