erlectricity 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/History.txt +11 -0
- data/VERSION.yml +2 -2
- data/benchmarks/bench.rb +21 -0
- data/erlectricity.gemspec +105 -0
- data/ext/decoder.c +8 -5
- data/lib/erlectricity/decoder.rb +5 -3
- data/lib/erlectricity/encoder.rb +24 -1
- data/test/decode_spec.rb +12 -1
- data/test/encode_spec.rb +6 -1
- data/test/test_helper.rb +1 -1
- metadata +9 -4
data/.gitignore
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.1.0 / 2009-10-08
|
2
|
+
* Minor Improvements
|
3
|
+
* Implement Bignum encoding
|
4
|
+
* Fix tests on Erlang R13B
|
5
|
+
|
6
|
+
== 1.0.2 / 2009-06-03
|
7
|
+
* Bug Fixes
|
8
|
+
* Fix decoding of atoms [github.com/bwbuchanan]
|
9
|
+
* Work around Ruby's reluctance to convert the empty string to
|
10
|
+
a symbol [github.com/bwbuchanan]
|
11
|
+
|
1
12
|
== 1.0.1 / 2009-05-03
|
2
13
|
* Bug Fixes
|
3
14
|
* Fix premature null byte termination on binary decode
|
data/VERSION.yml
CHANGED
data/benchmarks/bench.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'erlectricity'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
data = [:ok, [:foo, :bar, [99, "bottles", "of", "beer", 3.14], [true, false]]]
|
7
|
+
bert = Erlectricity::Encoder.encode(data)
|
8
|
+
|
9
|
+
p bert
|
10
|
+
|
11
|
+
Benchmark.bm do|b|
|
12
|
+
b.report("Decoder") do
|
13
|
+
100_000.times { Erl::Decoder.decode(bert) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# user system total real
|
18
|
+
# C Decoder 0.400000 0.000000 0.400000 ( 0.425373)
|
19
|
+
# Ruby Decoder 30.250000 0.220000 30.470000 ( 32.140890)
|
20
|
+
#
|
21
|
+
# C decoder is 75.56x faster than Ruby decoder on this data
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{erlectricity}
|
8
|
+
s.version = "1.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Scott Fleckenstein", "Tom Preston-Werner"]
|
12
|
+
s.date = %q{2009-10-08}
|
13
|
+
s.email = %q{tom@mojombo.com}
|
14
|
+
s.extensions = ["ext/extconf.rb"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"benchmarks/bench.rb",
|
27
|
+
"erlectricity.gemspec",
|
28
|
+
"examples/echo/README.md",
|
29
|
+
"examples/echo/echo.erl",
|
30
|
+
"examples/echo/echo.rb",
|
31
|
+
"examples/gruff/gruff.erl",
|
32
|
+
"examples/gruff/gruff_provider.rb",
|
33
|
+
"examples/gruff/gruff_run.sh",
|
34
|
+
"examples/gruff/stat_run.sh",
|
35
|
+
"examples/gruff/stat_writer.erl",
|
36
|
+
"examples/simple/README.md",
|
37
|
+
"examples/simple/rerl.rb",
|
38
|
+
"examples/simple/rerl.sh",
|
39
|
+
"examples/tinderl/README.md",
|
40
|
+
"examples/tinderl/tinderl.erl",
|
41
|
+
"examples/tinderl/tinderl.rb",
|
42
|
+
"ext/decoder.c",
|
43
|
+
"ext/extconf.rb",
|
44
|
+
"lib/erlectricity.rb",
|
45
|
+
"lib/erlectricity/condition.rb",
|
46
|
+
"lib/erlectricity/conditions/boolean.rb",
|
47
|
+
"lib/erlectricity/conditions/hash.rb",
|
48
|
+
"lib/erlectricity/conditions/static.rb",
|
49
|
+
"lib/erlectricity/conditions/type.rb",
|
50
|
+
"lib/erlectricity/constants.rb",
|
51
|
+
"lib/erlectricity/decoder.rb",
|
52
|
+
"lib/erlectricity/encoder.rb",
|
53
|
+
"lib/erlectricity/errors/decode_error.rb",
|
54
|
+
"lib/erlectricity/errors/encode_error.rb",
|
55
|
+
"lib/erlectricity/errors/erlectricity_error.rb",
|
56
|
+
"lib/erlectricity/matcher.rb",
|
57
|
+
"lib/erlectricity/port.rb",
|
58
|
+
"lib/erlectricity/receiver.rb",
|
59
|
+
"lib/erlectricity/types/function.rb",
|
60
|
+
"lib/erlectricity/types/list.rb",
|
61
|
+
"lib/erlectricity/types/new_function.rb",
|
62
|
+
"lib/erlectricity/types/new_reference.rb",
|
63
|
+
"lib/erlectricity/types/pid.rb",
|
64
|
+
"lib/erlectricity/types/reference.rb",
|
65
|
+
"lib/erlectricity/version.rb",
|
66
|
+
"test/condition_spec.rb",
|
67
|
+
"test/decode_spec.rb",
|
68
|
+
"test/encode_spec.rb",
|
69
|
+
"test/matcher_spec.rb",
|
70
|
+
"test/port_spec.rb",
|
71
|
+
"test/receiver_spec.rb",
|
72
|
+
"test/spec_suite.rb",
|
73
|
+
"test/test_helper.rb"
|
74
|
+
]
|
75
|
+
s.homepage = %q{http://github.com/mojombo/erlectricity}
|
76
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
77
|
+
s.require_paths = ["lib", "ext"]
|
78
|
+
s.rubyforge_project = %q{erlectricity}
|
79
|
+
s.rubygems_version = %q{1.3.5}
|
80
|
+
s.summary = %q{A library to interface erlang and ruby through the erlang port system}
|
81
|
+
s.test_files = [
|
82
|
+
"test/condition_spec.rb",
|
83
|
+
"test/decode_spec.rb",
|
84
|
+
"test/encode_spec.rb",
|
85
|
+
"test/matcher_spec.rb",
|
86
|
+
"test/port_spec.rb",
|
87
|
+
"test/receiver_spec.rb",
|
88
|
+
"test/spec_suite.rb",
|
89
|
+
"test/test_helper.rb",
|
90
|
+
"examples/echo/echo.rb",
|
91
|
+
"examples/gruff/gruff_provider.rb",
|
92
|
+
"examples/simple/rerl.rb",
|
93
|
+
"examples/tinderl/tinderl.rb"
|
94
|
+
]
|
95
|
+
|
96
|
+
if s.respond_to? :specification_version then
|
97
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
98
|
+
s.specification_version = 3
|
99
|
+
|
100
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
101
|
+
else
|
102
|
+
end
|
103
|
+
else
|
104
|
+
end
|
105
|
+
end
|
data/ext/decoder.c
CHANGED
@@ -116,7 +116,8 @@ VALUE read_list(unsigned char **pData) {
|
|
116
116
|
|
117
117
|
int size = read_4(pData);
|
118
118
|
|
119
|
-
VALUE
|
119
|
+
VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
|
120
|
+
VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(size));
|
120
121
|
|
121
122
|
int i;
|
122
123
|
for(i = 0; i < size; ++i) {
|
@@ -159,7 +160,8 @@ VALUE read_string(unsigned char **pData) {
|
|
159
160
|
unsigned char buf[length + 1];
|
160
161
|
read_string_raw(buf, pData, length);
|
161
162
|
|
162
|
-
VALUE
|
163
|
+
VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
|
164
|
+
VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(length));
|
163
165
|
|
164
166
|
int i = 0;
|
165
167
|
for(i; i < length; ++i) {
|
@@ -180,9 +182,9 @@ VALUE read_atom(unsigned char **pData) {
|
|
180
182
|
read_string_raw(buf, pData, length);
|
181
183
|
|
182
184
|
// Erlang true and false are actually atoms
|
183
|
-
if(strncmp((char *) buf, "true", length) == 0) {
|
185
|
+
if(length == 4 && strncmp((char *) buf, "true", length) == 0) {
|
184
186
|
return Qtrue;
|
185
|
-
} else if(strncmp((char *) buf, "false", length) == 0) {
|
187
|
+
} else if(length == 5 && strncmp((char *) buf, "false", length) == 0) {
|
186
188
|
return Qfalse;
|
187
189
|
} else {
|
188
190
|
return ID2SYM(rb_intern((char *) buf));
|
@@ -290,7 +292,8 @@ VALUE read_nil(unsigned char **pData) {
|
|
290
292
|
rb_raise(rb_eStandardError, "Invalid Type, not a nil list");
|
291
293
|
}
|
292
294
|
|
293
|
-
|
295
|
+
VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
|
296
|
+
return rb_funcall(newref_class, rb_intern("new"), 0);
|
294
297
|
}
|
295
298
|
|
296
299
|
// specials
|
data/lib/erlectricity/decoder.rb
CHANGED
@@ -98,6 +98,8 @@ module Erlectricity
|
|
98
98
|
true
|
99
99
|
when "false"
|
100
100
|
false
|
101
|
+
when ""
|
102
|
+
Marshal.load("\004\b:\005") # Workaround for inability to do ''.to_sym
|
101
103
|
else
|
102
104
|
a.to_sym
|
103
105
|
end
|
@@ -180,13 +182,13 @@ module Erlectricity
|
|
180
182
|
|
181
183
|
def read_nil
|
182
184
|
fail("Invalid Type, not a nil list") unless read_1 == NIL
|
183
|
-
[]
|
185
|
+
Erlectricity::List.new([])
|
184
186
|
end
|
185
187
|
|
186
188
|
def read_erl_string
|
187
189
|
fail("Invalid Type, not an erlang string") unless read_1 == STRING
|
188
190
|
length = read_2
|
189
|
-
read_string(length).unpack('C' * length)
|
191
|
+
Erlectricity::List.new(read_string(length).unpack('C' * length))
|
190
192
|
end
|
191
193
|
|
192
194
|
def read_list
|
@@ -194,7 +196,7 @@ module Erlectricity
|
|
194
196
|
length = read_4
|
195
197
|
list = (0...length).map { |i| read_any_raw }
|
196
198
|
read_1
|
197
|
-
list
|
199
|
+
Erlectricity::List.new(list)
|
198
200
|
end
|
199
201
|
|
200
202
|
def read_bin
|
data/lib/erlectricity/encoder.rb
CHANGED
@@ -82,7 +82,30 @@ module Erlectricity
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def write_bignum(num)
|
85
|
-
|
85
|
+
if num.is_a?(Bignum)
|
86
|
+
n = num.size
|
87
|
+
else
|
88
|
+
n = (num.to_s(2).size / 8.0).ceil
|
89
|
+
end
|
90
|
+
if n <= 256
|
91
|
+
write_1 SMALL_BIGNUM
|
92
|
+
write_1 n
|
93
|
+
write_bignum_guts(num)
|
94
|
+
else
|
95
|
+
write_1 LARGE_BIGNUM
|
96
|
+
write_4 n
|
97
|
+
write_bignum_guts(num)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def write_bignum_guts(num)
|
102
|
+
write_1 (num >= 0 ? 0 : 1)
|
103
|
+
num = num.abs
|
104
|
+
i = 0
|
105
|
+
while (rem = (num >> i * 8) % (256)) != 0
|
106
|
+
write_1 rem
|
107
|
+
i += 1
|
108
|
+
end
|
86
109
|
end
|
87
110
|
|
88
111
|
def write_new_reference(ref)
|
data/test/decode_spec.rb
CHANGED
@@ -90,15 +90,18 @@ context "When unpacking from a binary stream" do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
specify "an empty erlang list encoded as a nil should decode to an array" do
|
93
|
+
get("[]").class.should == Erl::List
|
93
94
|
get("[]").should == []
|
94
95
|
end
|
95
96
|
|
96
97
|
specify "an erlang list encoded as a string should decode to an array of bytes (less than ideal, but consistent)" do
|
98
|
+
get("\"asdasd\"").class.should == Erl::List
|
97
99
|
get("\"asdasd\"").should == "asdasd".split('').map{|c| c[0]}
|
98
100
|
get("\"#{'a' * 65534}\"").should == ['a'[0]] * 65534
|
99
101
|
end
|
100
102
|
|
101
|
-
specify "an erlang list encoded as a list should decode to
|
103
|
+
specify "an erlang list encoded as a list should decode to an erl::list" do
|
104
|
+
get("[3,4,256]").class.should == Erl::List
|
102
105
|
get("[3,4,256]").should == [3,4,256]
|
103
106
|
get("\"#{'a' * 65535 }\"").should == [97] * 65535
|
104
107
|
get("[3,4, foo, {3,4,5,bar}, 256]").should == [3,4, :foo, [3,4,5,:bar], 256]
|
@@ -110,10 +113,18 @@ context "When unpacking from a binary stream" do
|
|
110
113
|
get("<< 99,0,99 >>").should == "c\000c"
|
111
114
|
end
|
112
115
|
|
116
|
+
specify "the empty atom should decode to the empty symbol" do
|
117
|
+
empty_symbol = get("''")
|
118
|
+
empty_symbol.should.be.instance_of Symbol
|
119
|
+
empty_symbol.to_s.should == ""
|
120
|
+
end
|
121
|
+
|
113
122
|
specify "erlang atomic booleans should decode to ruby booleans" do
|
114
123
|
get("true").should == true
|
115
124
|
get("false").should == false
|
116
125
|
get("falsereio").should == :falsereio
|
126
|
+
get("t").should == :t
|
127
|
+
get("f").should == :f
|
117
128
|
end
|
118
129
|
|
119
130
|
specify "a good thing should be awesome" do
|
data/test/encode_spec.rb
CHANGED
@@ -36,6 +36,8 @@ context "When packing to a binary stream" do
|
|
36
36
|
write_any(-(1 << 27)).should == get_erl_with_magic("#{-(1 << 27)}")
|
37
37
|
|
38
38
|
# #SMALL_BIGNUMS
|
39
|
+
get{@encoder.write_fixnum(1254976067)}.should == get_erl("1254976067")
|
40
|
+
get{@encoder.write_fixnum(-1254976067)}.should == get_erl("-1254976067")
|
39
41
|
# get{@encoder.write_fixnum((1 << word_length))}.should == get_erl("#{(1 << word_length)}")
|
40
42
|
# get{@encoder.write_fixnum(-(1 << word_length) - 1)}.should == get_erl("#{-(1 << word_length) - 1}")
|
41
43
|
# get{@encoder.write_fixnum((1 << (255 * 8)) - 1)}.should == get_erl("#{(1 << (255 * 8)) - 1}")
|
@@ -46,7 +48,10 @@ context "When packing to a binary stream" do
|
|
46
48
|
# write_any((1 << (255 * 8)) - 1).should == get_erl_with_magic("#{(1 << (255 * 8)) - 1}")
|
47
49
|
# write_any(-((1 << (255 * 8)) - 1)).should == get_erl_with_magic("#{-((1 << (255 * 8)) - 1)}")
|
48
50
|
#
|
49
|
-
# #
|
51
|
+
# #LARGE_BIGNUMS
|
52
|
+
x = 1254976067 ** 256
|
53
|
+
get{@encoder.write_fixnum(x)}.should == get_erl("#{x}")
|
54
|
+
get{@encoder.write_fixnum(-x)}.should == get_erl("-#{x}")
|
50
55
|
# get{@encoder.write_fixnum((1 << (255 * 8)))}.should == get_erl("#{(1 << (255 * 8))}")
|
51
56
|
# get{@encoder.write_fixnum(-(1 << (255 * 8))}.should == get_erl("#{-(1 << (255 * 8)}")
|
52
57
|
# get{@encoder.write_fixnum((1 << (512 * 8))}.should == get_erl("#{(1 << (512 * 8))}")
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ $stdout.sync = true
|
|
10
10
|
|
11
11
|
class Test::Unit::TestCase
|
12
12
|
def run_erl(code)
|
13
|
-
cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(A)." -s erlang halt}
|
13
|
+
cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(binary_to_list(A))." -s erlang halt}
|
14
14
|
`#{cmd}`
|
15
15
|
end
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erlectricity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Fleckenstein
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-10-08 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -24,11 +24,14 @@ extra_rdoc_files:
|
|
24
24
|
- LICENSE
|
25
25
|
- README.md
|
26
26
|
files:
|
27
|
+
- .gitignore
|
27
28
|
- History.txt
|
28
29
|
- LICENSE
|
29
30
|
- README.md
|
30
31
|
- Rakefile
|
31
32
|
- VERSION.yml
|
33
|
+
- benchmarks/bench.rb
|
34
|
+
- erlectricity.gemspec
|
32
35
|
- examples/echo/README.md
|
33
36
|
- examples/echo/echo.erl
|
34
37
|
- examples/echo/echo.rb
|
@@ -77,6 +80,8 @@ files:
|
|
77
80
|
- test/test_helper.rb
|
78
81
|
has_rdoc: true
|
79
82
|
homepage: http://github.com/mojombo/erlectricity
|
83
|
+
licenses: []
|
84
|
+
|
80
85
|
post_install_message:
|
81
86
|
rdoc_options:
|
82
87
|
- --charset=UTF-8
|
@@ -98,9 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
103
|
requirements: []
|
99
104
|
|
100
105
|
rubyforge_project: erlectricity
|
101
|
-
rubygems_version: 1.3.
|
106
|
+
rubygems_version: 1.3.5
|
102
107
|
signing_key:
|
103
|
-
specification_version:
|
108
|
+
specification_version: 3
|
104
109
|
summary: A library to interface erlang and ruby through the erlang port system
|
105
110
|
test_files:
|
106
111
|
- test/condition_spec.rb
|