msgpack_protocol 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +18 -0
- data/Rakefile +9 -0
- data/lib/msgpack_protocol.rb +39 -0
- data/msgpack_protocol.gemspec +27 -0
- data/spec/main_spec.rb +60 -0
- data/spec/spec_helper.rb +2 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5dbf549354b97d51525525bdbe6fa082899d4b5b
|
4
|
+
data.tar.gz: 52fc022a720cd3edcf6725d2481432fad42222e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15d0b3ed8d6f3183b78e3ed4de3b69469ce0ae1a79deefb848357e8b710342fef262f050c89b8f45c921d664b4ac412ad671e26b36e427682754b8ce830af643
|
7
|
+
data.tar.gz: ead310bb3ef27487e4e3f823afd37852296b0e689a5934267dc187b4c7431c8aab150d2d703eb8580a7ee933cdbf78744aca3cc5a595a78ae261a06a3f62b907
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 'Konstantin Makarchev'
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# MsgpackProtocol
|
2
|
+
Msgpack protocol for eventmachine
|
3
|
+
|
4
|
+
Install:
|
5
|
+
|
6
|
+
gem install msgpack_protocol
|
7
|
+
|
8
|
+
Usage:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class Server < EM::Connection
|
12
|
+
include EM::P::MsgpackProtocol
|
13
|
+
|
14
|
+
def receive_object obj
|
15
|
+
send_object({'you said' => obj})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'msgpack'
|
2
|
+
|
3
|
+
module EventMachine
|
4
|
+
module Protocols
|
5
|
+
# MsgpackProtocol allows for easy communication using marshaled ruby objects
|
6
|
+
#
|
7
|
+
# module RubyServer
|
8
|
+
# include EM::P::MsgpackProtocol
|
9
|
+
#
|
10
|
+
# def receive_object obj
|
11
|
+
# send_object({'you said' => obj})
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
module MsgpackProtocol
|
16
|
+
VERSION = '0.0.1'
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
@pac ||= MessagePack::Unpacker.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# @private
|
24
|
+
def receive_data data
|
25
|
+
@pac.feed_each(data) { |obj| receive_object obj }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Invoked with ruby objects received over the network
|
29
|
+
def receive_object obj
|
30
|
+
# stub
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sends a ruby object over the network
|
34
|
+
def send_object obj
|
35
|
+
send_data MessagePack::Packer.new.pack(obj).to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'msgpack_protocol'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "msgpack_protocol"
|
8
|
+
spec.version = EventMachine::Protocols::MsgpackProtocol::VERSION
|
9
|
+
spec.authors = ["'Konstantin Makarchev'"]
|
10
|
+
spec.email = ["'kostya27@gmail.com'"]
|
11
|
+
spec.summary = %q{Msgpack protocol for eventmachine}
|
12
|
+
spec.description = %q{Msgpack protocol for eventmachine}
|
13
|
+
spec.homepage = "https://github.com/kostya/msgpack_protocol"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "eventmachine"
|
22
|
+
spec.add_dependency "msgpack"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'eventmachine'
|
3
|
+
|
4
|
+
class Server < EM::Connection
|
5
|
+
include EM::P::MsgpackProtocol
|
6
|
+
|
7
|
+
def receive_object(obj)
|
8
|
+
$server_obj = obj
|
9
|
+
send_object(obj)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Client < EM::Connection
|
14
|
+
include EM::P::MsgpackProtocol
|
15
|
+
|
16
|
+
def receive_object(obj)
|
17
|
+
$client_obj = obj
|
18
|
+
EM.stop
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def send_and_receive(obj)
|
23
|
+
EM.run do
|
24
|
+
EM.start_server '127.0.0.1', 12346, Server
|
25
|
+
EM.connect '127.0.0.1', 12346, Client do |cn|
|
26
|
+
cn.send_object(obj)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "main" do
|
32
|
+
it "should work with string" do
|
33
|
+
obj = "bla"
|
34
|
+
send_and_receive(obj)
|
35
|
+
$client_obj.should == obj
|
36
|
+
$server_obj.should == obj
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should work struct" do
|
40
|
+
obj = ["bla", {'bla' => 12, [] => 19, [3,4] => [false,true]}]
|
41
|
+
send_and_receive(obj)
|
42
|
+
$client_obj.should == obj
|
43
|
+
$server_obj.should == obj
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should work super big data" do
|
47
|
+
obj = ['a'] * 300_000
|
48
|
+
send_and_receive(obj)
|
49
|
+
$client_obj.size.should == obj.size
|
50
|
+
$server_obj.size.should == obj.size
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should work big string" do
|
54
|
+
obj = 'a' * 10_000_000
|
55
|
+
send_and_receive(obj)
|
56
|
+
$client_obj.size.should == obj.size
|
57
|
+
$server_obj.size.should == obj.size
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: msgpack_protocol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- '''Konstantin Makarchev'''
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine
|
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: msgpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Msgpack protocol for eventmachine
|
84
|
+
email:
|
85
|
+
- '''kostya27@gmail.com'''
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/msgpack_protocol.rb
|
96
|
+
- msgpack_protocol.gemspec
|
97
|
+
- spec/main_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://github.com/kostya/msgpack_protocol
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.1.4
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Msgpack protocol for eventmachine
|
123
|
+
test_files:
|
124
|
+
- spec/main_spec.rb
|
125
|
+
- spec/spec_helper.rb
|