arpie 0.0.6 → 0.1.0
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.
- data/.gitignore +4 -0
- data/.yardopts +1 -0
- data/{BINARY_SPEC → BINARY.rdoc} +73 -28
- data/Gemfile +8 -0
- data/LICENCE +15 -0
- data/PROTOCOLS.rdoc +46 -0
- data/README.rdoc +17 -0
- data/Rakefile +6 -114
- data/arpie.gemspec +26 -0
- data/examples/em.rb +18 -0
- data/lib/arpie.rb +2 -4
- data/lib/arpie/binary.rb +18 -4
- data/lib/arpie/binary/bytes_type.rb +7 -2
- data/lib/arpie/binary/fixed_type.rb +11 -4
- data/lib/arpie/binary/list_type.rb +2 -0
- data/lib/arpie/binary/pack_type.rb +20 -10
- data/lib/arpie/em.rb +48 -0
- data/lib/arpie/error.rb +2 -4
- data/lib/arpie/protocol.rb +7 -23
- data/lib/arpie/version.rb +3 -0
- data/spec/binary_spec.rb +113 -8
- data/spec/bytes_binary_type_spec.rb +16 -3
- data/spec/em_spec.rb +27 -0
- data/spec/examples_spec.rb +11 -0
- data/spec/fixed_binary_type_spec.rb +2 -2
- data/spec/list_binary_type_spec.rb +9 -0
- data/spec/protocol_merge_and_split_spec.rb +3 -3
- data/spec/protocol_spec.rb +20 -43
- data/spec/spec_helper.rb +13 -12
- metadata +74 -83
- data/COPYING +0 -15
- data/README +0 -167
- data/lib/arpie/client.rb +0 -195
- data/lib/arpie/proxy.rb +0 -143
- data/lib/arpie/server.rb +0 -157
- data/lib/arpie/xmlrpc.rb +0 -108
- data/spec/client_server_spec.rb +0 -107
- data/tools/benchmark.rb +0 -52
- data/tools/protocol_benchmark.rb +0 -42
@@ -11,7 +11,7 @@ describe "BytesBinaryType" do
|
|
11
11
|
]
|
12
12
|
}
|
13
13
|
|
14
|
-
|
14
|
+
include_examples "Binary Tests with data"
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "virtual length" do subject {
|
@@ -24,7 +24,7 @@ describe "BytesBinaryType" do
|
|
24
24
|
]
|
25
25
|
}
|
26
26
|
|
27
|
-
|
27
|
+
include_examples "Binary Tests with data"
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "length as virtual should not update the virtual" do subject {
|
@@ -37,7 +37,7 @@ describe "BytesBinaryType" do
|
|
37
37
|
]
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
include_examples "Binary Tests with data"
|
41
41
|
|
42
42
|
it "does not change virtuals on data change" do
|
43
43
|
dd, b = @c.from(@d + "xxyzz")
|
@@ -46,4 +46,17 @@ describe "BytesBinaryType" do
|
|
46
46
|
dd.to.should == expect
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
describe "NULL-terminated strings" do subject {
|
51
|
+
[
|
52
|
+
Class.new(Arpie::Binary) do
|
53
|
+
field :s, :nstring
|
54
|
+
field :d, :uint8
|
55
|
+
end,
|
56
|
+
["abcd", 4].pack("Z* C")
|
57
|
+
]
|
58
|
+
}
|
59
|
+
|
60
|
+
include_examples "Binary Tests with data"
|
61
|
+
end
|
49
62
|
end
|
data/spec/em_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
require 'eventmachine'
|
4
|
+
|
5
|
+
describe 'Eventmachine usecase' do
|
6
|
+
specify do
|
7
|
+
$m = nil
|
8
|
+
|
9
|
+
EM::run {
|
10
|
+
EM::start_server "127.0.0.1", 19400, Arpie::EventMachine::ArpieProtocol,
|
11
|
+
Arpie::SeparatorProtocol.new do |proto|
|
12
|
+
def proto.receive(message)
|
13
|
+
$m = message
|
14
|
+
EventMachine::stop_event_loop
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
EM::connect "127.0.0.1", 19400, Arpie::EventMachine::ArpieProtocol,
|
19
|
+
Arpie::SeparatorProtocol.new do |proto|
|
20
|
+
|
21
|
+
proto.send("hi")
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
$m.should == "hi"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
EXPATH = File.dirname(__FILE__) + "/../examples"
|
2
|
+
|
3
|
+
describe "examples" do
|
4
|
+
for rb in Dir[EXPATH + "/*.rb"] do
|
5
|
+
describe rb do specify {
|
6
|
+
ret = `ruby -I#{File.dirname(__FILE__) + "/../lib"} #{rb}`
|
7
|
+
$?.should == 0
|
8
|
+
ret.strip.should == "ih"
|
9
|
+
} end
|
10
|
+
end
|
11
|
+
end
|
@@ -15,11 +15,11 @@ describe FixedBinaryType do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should raise error on mismatch in #from" do
|
18
|
-
proc { subject.from("aaa", :value => "aaaa") }.should raise_error
|
18
|
+
proc { subject.from("aaa", :value => "aaaa") }.should raise_error Arpie::EIncomplete
|
19
19
|
end
|
20
20
|
|
21
21
|
it "raises error on mismatch in #to" do
|
22
|
-
proc { subject.to("aaa", :value => "aaaa") }.should raise_error StreamError
|
22
|
+
proc { subject.to("aaa", :value => "aaaa") }.should raise_error Arpie::StreamError
|
23
23
|
end
|
24
24
|
|
25
25
|
it "raiseserror on missing option" do
|
@@ -30,5 +30,14 @@ describe "ListBinaryType" do
|
|
30
30
|
it "raises EIncomplete when partial data remains" do
|
31
31
|
proc { Outer.from [8, 0, 1, 2, 3, 4, 5, 6, 7, 4, 1, 2 ].pack("C*") }.should raise_error Arpie::EIncomplete
|
32
32
|
end
|
33
|
+
|
34
|
+
it "fails on invalid length specification" do
|
35
|
+
klass = Class.new(Arpie::Binary) do
|
36
|
+
list :maxonly, :of => :char,
|
37
|
+
:sizeof => :int8
|
38
|
+
end
|
39
|
+
|
40
|
+
proc { klass.from("\xff") }.should raise_error StreamError
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
@@ -36,7 +36,7 @@ class Merger < Arpie::Protocol
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "Merger::Splitter::Sized" do subject { [Splitter, Arpie::SizedProtocol] }
|
39
|
-
|
39
|
+
include_examples "ProtocolChainSetup"
|
40
40
|
|
41
41
|
it "should split messages correctly" do
|
42
42
|
chain_write(t = 'test')
|
@@ -48,7 +48,7 @@ describe "Merger::Splitter::Sized" do subject { [Splitter, Arpie::SizedProtocol]
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe "Merger::Splitter::Sized" do subject { [Merger, Splitter, Arpie::SizedProtocol] }
|
51
|
-
|
51
|
+
include_examples "ProtocolChainSetup"
|
52
52
|
|
53
53
|
it "should assemble split messages correctly" do
|
54
54
|
chain_write(t = 'test')
|
@@ -57,7 +57,7 @@ describe "Merger::Splitter::Sized" do subject { [Merger, Splitter, Arpie::SizedP
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "Merger::BufferedSplitter::Sized" do subject { [Merger, BufferedSplitter, Arpie::SizedProtocol] }
|
60
|
-
|
60
|
+
include_examples "ProtocolChainSetup"
|
61
61
|
|
62
62
|
it "should re-read io for more data if assembly fails" do
|
63
63
|
@chain.write_message(@w, "split")
|
data/spec/protocol_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
shared_examples "ProtocolChain" do
|
4
|
+
include_examples "ProtocolChainSetup"
|
5
5
|
|
6
6
|
it "should convert without io correctly" do
|
7
7
|
v = @chain.to @testdata_a
|
8
|
-
@chain.from(v
|
8
|
+
from = @chain.from(v[0])
|
9
|
+
from[0].should == @testdata_a
|
9
10
|
end
|
10
11
|
|
11
12
|
it "should read written binary data correctly" do
|
@@ -40,8 +41,11 @@ describe "ProtocolChain", :shared => true do
|
|
40
41
|
end
|
41
42
|
|
42
43
|
it "should read messages greater than MTU correctly" do
|
43
|
-
|
44
|
-
|
44
|
+
unless @testdata_a.is_a?(Array)
|
45
|
+
message = @testdata_a * (Arpie::MTU + 10)
|
46
|
+
chain_write(message)
|
47
|
+
chain_read.should == message
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
it "should not fail on interleaved io streams" do
|
@@ -54,8 +58,8 @@ describe "ProtocolChain", :shared => true do
|
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
|
-
|
58
|
-
|
61
|
+
shared_examples "ObjectProtocolChain" do
|
62
|
+
include_examples "ProtocolChain"
|
59
63
|
# Now, lets try some variations.
|
60
64
|
|
61
65
|
it "should read written objects correctly" do
|
@@ -69,8 +73,8 @@ describe "ObjectProtocolChain", :shared => true do
|
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
|
-
|
73
|
-
|
76
|
+
shared_examples "RPCProtocolChain" do
|
77
|
+
include_examples "RPCProtocolChainSetup"
|
74
78
|
|
75
79
|
it "should send namespace-less RPC calls correctly encoded" do
|
76
80
|
call = Arpie::RPCall.new(nil, 'meth', [1, 2, 3])
|
@@ -101,56 +105,29 @@ end
|
|
101
105
|
# Now, lets try some variations.
|
102
106
|
|
103
107
|
describe "Sized" do subject { [Arpie::SizedProtocol] }
|
104
|
-
|
108
|
+
include_examples "ProtocolChain"
|
105
109
|
end
|
106
110
|
|
107
111
|
describe "Sized::Sized" do subject { [Arpie::SizedProtocol, Arpie::SizedProtocol] }
|
108
|
-
|
112
|
+
include_examples "ProtocolChain"
|
109
113
|
end
|
110
114
|
|
111
115
|
describe "Sized::Marshal::Sized" do subject { [Arpie::SizedProtocol, Arpie::MarshalProtocol, Arpie::SizedProtocol] }
|
112
|
-
|
116
|
+
include_examples "ProtocolChain"
|
113
117
|
end
|
114
118
|
|
115
119
|
describe "Zlib::Marshal::Sized" do subject { [Arpie::ZlibProtocol, Arpie::MarshalProtocol, Arpie::SizedProtocol] }
|
116
|
-
|
120
|
+
include_examples "ProtocolChain"
|
117
121
|
end
|
118
122
|
|
119
123
|
# Shellwords is a bit of a special case, because it only encodes arrays.
|
120
124
|
describe "Shellwords::Separator" do subject { [Arpie::ShellwordsProtocol, Arpie::SeparatorProtocol] }
|
121
|
-
|
125
|
+
include_examples "ProtocolChain"
|
122
126
|
before do
|
123
127
|
@testdata_a, @testdata_b = ['I am test', '1'], ['I am test', '2']
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
127
|
-
describe "
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "HTTPTest" do subject { [Arpie::HTTPServerTestProtocol] }
|
132
|
-
it_should_behave_like "ProtocolChain"
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "YAML" do subject { [Arpie::YAMLProtocol] }
|
136
|
-
it_should_behave_like "ObjectProtocolChain"
|
131
|
+
describe "YAML::Sized" do subject { [Arpie::YAMLProtocol, Arpie::SizedProtocol] }
|
132
|
+
include_examples "ObjectProtocolChain"
|
137
133
|
end
|
138
|
-
|
139
|
-
describe "XMLRPC::Sized" do subject {
|
140
|
-
[
|
141
|
-
[Arpie::XMLRPCClientProtocol, Arpie::SizedProtocol],
|
142
|
-
[Arpie::XMLRPCServerProtocol, Arpie::SizedProtocol]
|
143
|
-
]
|
144
|
-
}
|
145
|
-
it_should_behave_like "RPCProtocolChain"
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "XMLRPC::HTTPTest" do subject {
|
149
|
-
[
|
150
|
-
[Arpie::XMLRPCClientProtocol, Arpie::HTTPClientTestProtocol],
|
151
|
-
[Arpie::XMLRPCServerProtocol, Arpie::HTTPServerTestProtocol]
|
152
|
-
]
|
153
|
-
}
|
154
|
-
it_should_behave_like "RPCProtocolChain"
|
155
|
-
end
|
156
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ unless Object.const_defined?('Arpie')
|
|
8
8
|
end
|
9
9
|
include Arpie
|
10
10
|
|
11
|
-
|
11
|
+
shared_examples "IO Mockup" do
|
12
12
|
before do
|
13
13
|
@r, @w = IO.pipe
|
14
14
|
end
|
@@ -30,8 +30,8 @@ describe "IO Mockup", :shared => true do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
shared_examples "ProtocolChainSetup" do
|
34
|
+
include_examples "IO Mockup"
|
35
35
|
|
36
36
|
before do
|
37
37
|
@chain = Arpie::ProtocolChain.new(* subject.map {|x| x.new })
|
@@ -46,8 +46,8 @@ describe "ProtocolChainSetup", :shared => true do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
shared_examples "RPCProtocolChainSetup" do
|
50
|
+
include_examples "IO Mockup"
|
51
51
|
|
52
52
|
before do
|
53
53
|
@client = Arpie::ProtocolChain.new(* subject[0].map {|x| x.new })
|
@@ -59,15 +59,16 @@ end
|
|
59
59
|
|
60
60
|
|
61
61
|
|
62
|
-
|
62
|
+
shared_examples "Binary Setup" do
|
63
|
+
end
|
64
|
+
|
65
|
+
shared_examples "Binary Tests" do
|
66
|
+
include_examples "Binary Setup"
|
67
|
+
|
63
68
|
before do
|
64
69
|
@c = subject[0]
|
65
70
|
@d = subject[1]
|
66
71
|
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "Binary Tests", :shared => true do
|
70
|
-
it_should_behave_like "Binary Setup"
|
71
72
|
|
72
73
|
it "reads and packs the given example binary" do
|
73
74
|
dd, b = @c.from(@d)
|
@@ -75,8 +76,8 @@ describe "Binary Tests", :shared => true do
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
|
79
|
-
|
79
|
+
shared_examples "Binary Tests with data" do
|
80
|
+
include_examples "Binary Tests"
|
80
81
|
|
81
82
|
it "should raise EIncomplete when not enough data is available" do
|
82
83
|
proc { @c.from("")}.should raise_error Arpie::EIncomplete
|
metadata
CHANGED
@@ -1,102 +1,93 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: arpie
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Bernhard Stoeckner
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 2.0.0
|
24
|
-
version:
|
25
|
-
description: A high-performing layered networking protocol framework. Simple to use, simple to extend.
|
26
|
-
email: elven@swordcoast.net
|
12
|
+
date: 2012-04-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Toolkit for handling binary data, network protocols, file formats, and
|
15
|
+
similar
|
16
|
+
email:
|
17
|
+
- le@e-ix.net
|
27
18
|
executables: []
|
28
|
-
|
29
19
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
|
36
|
-
-
|
37
|
-
-
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- .yardopts
|
24
|
+
- BINARY.rdoc
|
25
|
+
- Gemfile
|
26
|
+
- LICENCE
|
27
|
+
- PROTOCOLS.rdoc
|
28
|
+
- README.rdoc
|
38
29
|
- Rakefile
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
- spec/fixed_binary_type_spec.rb
|
43
|
-
- spec/list_binary_type_spec.rb
|
44
|
-
- spec/spec.opts
|
45
|
-
- spec/rcov.opts
|
46
|
-
- spec/spec_helper.rb
|
47
|
-
- spec/binary_spec.rb
|
48
|
-
- spec/client_server_spec.rb
|
49
|
-
- lib/arpie/xmlrpc.rb
|
50
|
-
- lib/arpie/proxy.rb
|
51
|
-
- lib/arpie/server.rb
|
30
|
+
- arpie.gemspec
|
31
|
+
- examples/em.rb
|
32
|
+
- lib/arpie.rb
|
52
33
|
- lib/arpie/binary.rb
|
53
|
-
- lib/arpie/protocol.rb
|
54
|
-
- lib/arpie/error.rb
|
55
|
-
- lib/arpie/client.rb
|
56
|
-
- lib/arpie/binary_types.rb
|
57
34
|
- lib/arpie/binary/bytes_type.rb
|
58
35
|
- lib/arpie/binary/fixed_type.rb
|
59
36
|
- lib/arpie/binary/list_type.rb
|
60
37
|
- lib/arpie/binary/pack_type.rb
|
61
|
-
- lib/arpie.rb
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
|
66
|
-
|
38
|
+
- lib/arpie/binary_types.rb
|
39
|
+
- lib/arpie/em.rb
|
40
|
+
- lib/arpie/error.rb
|
41
|
+
- lib/arpie/protocol.rb
|
42
|
+
- lib/arpie/version.rb
|
43
|
+
- spec/binary_spec.rb
|
44
|
+
- spec/bytes_binary_type_spec.rb
|
45
|
+
- spec/em_spec.rb
|
46
|
+
- spec/examples_spec.rb
|
47
|
+
- spec/fixed_binary_type_spec.rb
|
48
|
+
- spec/list_binary_type_spec.rb
|
49
|
+
- spec/protocol_merge_and_split_spec.rb
|
50
|
+
- spec/protocol_spec.rb
|
51
|
+
- spec/rcov.opts
|
52
|
+
- spec/spec.opts
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/elven/arpie
|
67
55
|
licenses: []
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
- --title
|
75
|
-
- "arpie: A high-performing layered networking protocol framework. Simple to use, simple to extend."
|
76
|
-
- --main
|
77
|
-
- README
|
78
|
-
- --exclude
|
79
|
-
- ^(examples|extras)/
|
80
|
-
require_paths:
|
56
|
+
post_install_message: ! "\n You have installed arpie 0.1.0 or greater. This breaks\n
|
57
|
+
\ compatibility with previous versions (0.0.x).\n\n Specifically, it removes
|
58
|
+
all client/server code, and\n XMLRPC integration, since EventMachine and similar
|
59
|
+
does\n all that in a much cleaner and more efficient way.\n "
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
81
62
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
94
75
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
rubygems_version: 1.3.4
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.23
|
98
78
|
signing_key:
|
99
79
|
specification_version: 3
|
100
|
-
summary:
|
101
|
-
test_files:
|
102
|
-
|
80
|
+
summary: Toolkit for handling binary data, network protocols, file formats, and similar
|
81
|
+
test_files:
|
82
|
+
- spec/binary_spec.rb
|
83
|
+
- spec/bytes_binary_type_spec.rb
|
84
|
+
- spec/em_spec.rb
|
85
|
+
- spec/examples_spec.rb
|
86
|
+
- spec/fixed_binary_type_spec.rb
|
87
|
+
- spec/list_binary_type_spec.rb
|
88
|
+
- spec/protocol_merge_and_split_spec.rb
|
89
|
+
- spec/protocol_spec.rb
|
90
|
+
- spec/rcov.opts
|
91
|
+
- spec/spec.opts
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc:
|