schleyfox-bert 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,8 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ ext/bert/c/Makefile
7
+ ext/bert/c/*.bundle
8
+ ext/bert/c/*.o
@@ -0,0 +1,31 @@
1
+ = 1.1.2 / 2010-02-08
2
+ * Bug fixes
3
+ * Fix bignum handling on 256 byte boundary
4
+ * Remove unnecessary rubygems require
5
+
6
+ = 1.1.1 / 2010-01-12
7
+ * Bug fixes
8
+ * require 'stringio'
9
+ * Fix number encoding problem on 32 bit arch
10
+
11
+ = 1.1.0 / 2009-10-27
12
+ * Major Changes
13
+ * Remove reliance on Erlectricity.
14
+ * Bug fixes
15
+ * Fix unsigned int problem in C decoder
16
+ * Fix stack overflow segfault in C binary decoder for > 8MB binaries
17
+ * Optimize C bytelist decoder
18
+ * Fix bignum encoding
19
+
20
+ = 1.0.0 / 2009-10-19
21
+ * No changes. Production ready!
22
+
23
+ = 0.2.0 / 2009-10-15
24
+ * Major changes
25
+ * Use {time, MegaSecs, Secs, Microsecs} for time serialization
26
+ * Use array of options for regex serialization
27
+ * Tests
28
+ * Add roundtrip tests
29
+
30
+ = 0.1.0 / 2009-10-08
31
+ * Birthday!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom Preston-Werner
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.
@@ -0,0 +1,77 @@
1
+ BERT
2
+ ====
3
+
4
+ A BERT (Binary ERlang Term) serialization library for Ruby. It can
5
+ encode Ruby objects into BERT format and decode BERT binaries into Ruby
6
+ objects.
7
+
8
+ See the BERT specification at [bert-rpc.org](http://bert-rpc.org).
9
+
10
+ Instances of the following Ruby classes will be automatically converted to the
11
+ proper simple BERT type:
12
+
13
+ * Fixnum
14
+ * Float
15
+ * Symbol
16
+ * Array
17
+ * String
18
+
19
+ Instances of the following Ruby classes will be automatically converted to the
20
+ proper complex BERT type:
21
+
22
+ * NilClass
23
+ * TrueClass
24
+ * FalseClass
25
+ * Hash
26
+ * Time
27
+ * Regexp
28
+
29
+ To designate tuples, simply prefix an Array literal with a `t` or use the
30
+ BERT::Tuple class:
31
+
32
+ t[:foo, [1, 2, 3]]
33
+ BERT::Tuple[:foo, [1, 2, 3]]
34
+
35
+ Both of these will be converted to (in Erlang syntax):
36
+
37
+ {foo, [1, 2, 3]}
38
+
39
+
40
+ Installation
41
+ ------------
42
+
43
+ gem install bert -s http://gemcutter.org
44
+
45
+
46
+ Usage
47
+ -----
48
+
49
+ require 'bert'
50
+
51
+ bert = BERT.encode(t[:user, {:name => 'TPW', :nick => 'mojombo'}])
52
+ # => "\203h\002d\000\004userh\002d\000\004dictl\000\000\000\002h\002d
53
+ \000\004namem\000\000\000\003TPWh\002d\000\004nickm\000\000\000
54
+ \amojomboj"
55
+
56
+ BERT.decode(bert)
57
+ # => t[:user, {:name=>"TPW", :nick=>"mojombo"}]
58
+
59
+
60
+
61
+ Note on Patches/Pull Requests
62
+ -----------------------------
63
+
64
+ * Fork the project.
65
+ * Make your feature addition or bug fix.
66
+ * Add tests for it. This is important so I don't break it in a
67
+ future version unintentionally.
68
+ * Commit, do not mess with rakefile, version, or history.
69
+ (if you want to have your own version, that is fine but
70
+ bump version in a commit by itself I can ignore when I pull)
71
+ * Send me a pull request. Bonus points for topic branches.
72
+
73
+
74
+ Copyright
75
+ ---------
76
+
77
+ Copyright (c) 2009 Tom Preston-Werner. See LICENSE for details.
@@ -0,0 +1,91 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "schleyfox-bert"
8
+ gem.summary = %Q{BERT Serializiation for Ruby}
9
+ gem.description = %Q{BERT Serializiation for Ruby (1.9 Update)}
10
+ gem.email = "tom@mojombo.com"
11
+ gem.homepage = "http://github.com/mojombo/bert"
12
+ gem.authors = ["Tom Preston-Werner"]
13
+ gem.add_development_dependency("thoughtbot-shoulda")
14
+ gem.require_paths = ["lib", "ext"]
15
+ gem.files.include("ext")
16
+ gem.extensions << 'ext/bert/c/extconf.rb'
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:runtests) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ task :make do
31
+ Dir.chdir('ext/bert/c') { `ruby extconf.rb`; `make` }
32
+ end
33
+
34
+ task :clean do
35
+ ['rm -f ext/bert/c/*.bundle', 'rm -f ext/bert/c/*.o'].each do |cmd|
36
+ `#{cmd}` && puts(cmd)
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies do
41
+ require 'fileutils'
42
+
43
+ puts "\nCleaning extension build files and running all specs in native ruby mode..."
44
+ ['rm -f ext/bert/c/*.bundle', 'rm -f ext/bert/c/*.o'].each do |cmd|
45
+ `#{cmd}` && puts(cmd)
46
+ end
47
+ pid = fork do
48
+ exec 'rake runtests'
49
+ end
50
+ Process.waitpid(pid)
51
+
52
+ puts "\nRunning `make` to build extensions and rerunning decoder specs..."
53
+ Dir.chdir('ext/bert/c') { `ruby extconf.rb`; `make` }
54
+ pid = fork do
55
+ exec 'rake runtests'
56
+ end
57
+ Process.waitpid(pid)
58
+ end
59
+
60
+ begin
61
+ require 'rcov/rcovtask'
62
+ Rcov::RcovTask.new do |test|
63
+ test.libs << 'test'
64
+ test.pattern = 'test/**/*_test.rb'
65
+ test.verbose = true
66
+ end
67
+ rescue LoadError
68
+ task :rcov do
69
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
70
+ end
71
+ end
72
+
73
+ task :default => :test
74
+
75
+ require 'rake/rdoctask'
76
+ Rake::RDocTask.new do |rdoc|
77
+ if File.exist?('VERSION')
78
+ version = File.read('VERSION')
79
+ else
80
+ version = ""
81
+ end
82
+
83
+ rdoc.rdoc_dir = 'rdoc'
84
+ rdoc.title = "bert #{version}"
85
+ rdoc.rdoc_files.include('README*')
86
+ rdoc.rdoc_files.include('lib/**/*.rb')
87
+ end
88
+
89
+ task :console do
90
+ exec('irb -I lib -rbert')
91
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.2
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'bert'
5
+ require 'json'
6
+ require 'yajl'
7
+ require 'benchmark'
8
+
9
+ ITER = 1_000
10
+
11
+ tiny = t[:ok, :awesome]
12
+ small = t[:ok, :answers, [42] * 42]
13
+ large = ["abc" * 1000] * 100
14
+ complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10
15
+
16
+ Benchmark.bm do |bench|
17
+ bench.report("BERT tiny") {ITER.times {BERT.decode(BERT.encode(tiny))}}
18
+ bench.report("BERT small") {ITER.times {BERT.decode(BERT.encode(small))}}
19
+ bench.report("BERT large") {ITER.times {BERT.decode(BERT.encode(large))}}
20
+ bench.report("BERT complex") {ITER.times {BERT.decode(BERT.encode(complex))}}
21
+
22
+ bench.report("JSON tiny") {ITER.times {JSON.load(JSON.dump(tiny))}}
23
+ bench.report("JSON small") {ITER.times {JSON.load(JSON.dump(small))}}
24
+ bench.report("JSON large") {ITER.times {JSON.load(JSON.dump(large))}}
25
+ bench.report("JSON complex") {ITER.times {JSON.load(JSON.dump(complex))}}
26
+
27
+ bench.report("YAJL tiny") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(tiny))}}
28
+ bench.report("YAJL small") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(small))}}
29
+ bench.report("YAJL large") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(large))}}
30
+ bench.report("YAJL complex") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(complex))}}
31
+
32
+ bench.report("Ruby tiny") {ITER.times {Marshal.load(Marshal.dump(tiny))}}
33
+ bench.report("Ruby small") {ITER.times {Marshal.load(Marshal.dump(small))}}
34
+ bench.report("Ruby large") {ITER.times {Marshal.load(Marshal.dump(large))}}
35
+ bench.report("Ruby complex") {ITER.times {Marshal.load(Marshal.dump(complex))}}
36
+ end
@@ -0,0 +1,87 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'yajl'
6
+ require 'benchmark'
7
+
8
+ ITER = 1_000
9
+
10
+ def setup
11
+ tiny = t[:ok, :awesome]
12
+ small = t[:ok, :answers, [42] * 42]
13
+ large = ["abc" * 1000] * 100
14
+ complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10
15
+
16
+ $tiny_encoded_bert = BERT.encode(tiny)
17
+ $small_encoded_bert = BERT.encode(small)
18
+ $large_encoded_bert = BERT.encode(large)
19
+ $complex_encoded_bert = BERT.encode(complex)
20
+
21
+ $tiny_encoded_json = JSON.dump(tiny)
22
+ $small_encoded_json = JSON.dump(small)
23
+ $large_encoded_json = JSON.dump(large)
24
+ $complex_encoded_json = JSON.dump(complex)
25
+
26
+ $tiny_encoded_yajl = Yajl::Encoder.encode(tiny)
27
+ $small_encoded_yajl = Yajl::Encoder.encode(small)
28
+ $large_encoded_yajl = Yajl::Encoder.encode(large)
29
+ $complex_encoded_yajl = Yajl::Encoder.encode(complex)
30
+
31
+ $tiny_encoded_ruby = Marshal.dump(tiny)
32
+ $small_encoded_ruby = Marshal.dump(small)
33
+ $large_encoded_ruby = Marshal.dump(large)
34
+ $complex_encoded_ruby = Marshal.dump(complex)
35
+ end
36
+
37
+ Benchmark.bm(13) do |bench|
38
+ pid = fork do
39
+ Dir.chdir(File.join(File.dirname(__FILE__), *%w[.. ext bert c])) { `make` }
40
+ require 'bert'
41
+ raise "Could not load C extension" unless BERT::Decode.impl == 'C'
42
+ setup
43
+ puts "BERT C Extension Decoder"
44
+ bench.report("BERT tiny") {ITER.times {BERT.decode($tiny_encoded_bert)}}
45
+ bench.report("BERT small") {ITER.times {BERT.decode($small_encoded_bert)}}
46
+ bench.report("BERT large") {ITER.times {BERT.decode($large_encoded_bert)}}
47
+ bench.report("BERT complex") {ITER.times {BERT.decode($complex_encoded_bert)}}
48
+ puts
49
+ end
50
+ Process.waitpid(pid)
51
+
52
+ pid = fork do
53
+ Dir.chdir(File.join(File.dirname(__FILE__), *%w[.. ext bert c])) do
54
+ ['*.bundle', '*.o'].each { |pat| `rm -f #{pat}` }
55
+ end
56
+ require 'bert'
57
+ raise "Not using Ruby decoder" unless BERT::Decode.impl == 'Ruby'
58
+ setup
59
+ puts "BERT Pure Ruby Decoder"
60
+ bench.report("BERT tiny") {ITER.times {BERT.decode($tiny_encoded_bert)}}
61
+ bench.report("BERT small") {ITER.times {BERT.decode($small_encoded_bert)}}
62
+ bench.report("BERT large") {ITER.times {BERT.decode($large_encoded_bert)}}
63
+ bench.report("BERT complex") {ITER.times {BERT.decode($complex_encoded_bert)}}
64
+ puts
65
+ end
66
+ Process.waitpid(pid)
67
+
68
+ require 'bert'
69
+ setup
70
+
71
+ bench.report("JSON tiny") {ITER.times {JSON.load($tiny_encoded_json)}}
72
+ bench.report("JSON small") {ITER.times {JSON.load($small_encoded_json)}}
73
+ bench.report("JSON large") {ITER.times {JSON.load($large_encoded_json)}}
74
+ bench.report("JSON complex") {ITER.times {JSON.load($complex_encoded_json)}}
75
+ puts
76
+
77
+ bench.report("YAJL tiny") {ITER.times {Yajl::Parser.parse($tiny_encoded_yajl)}}
78
+ bench.report("YAJL small") {ITER.times {Yajl::Parser.parse($small_encoded_yajl)}}
79
+ bench.report("YAJL large") {ITER.times {Yajl::Parser.parse($large_encoded_yajl)}}
80
+ bench.report("YAJL complex") {ITER.times {Yajl::Parser.parse($complex_encoded_yajl)}}
81
+ puts
82
+
83
+ bench.report("Ruby tiny") {ITER.times {Marshal.load($tiny_encoded_ruby)}}
84
+ bench.report("Ruby small") {ITER.times {Marshal.load($small_encoded_ruby)}}
85
+ bench.report("Ruby large") {ITER.times {Marshal.load($large_encoded_ruby)}}
86
+ bench.report("Ruby complex") {ITER.times {Marshal.load($complex_encoded_ruby)}}
87
+ end
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'bert'
5
+ require 'json'
6
+ require 'yajl'
7
+ require 'benchmark'
8
+
9
+ ITER = 1_000
10
+
11
+ tiny = t[:ok, :awesome]
12
+ small = t[:ok, :answers, [42] * 42]
13
+ large = ["abc" * 1000] * 100
14
+ complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10
15
+
16
+ Benchmark.bm(13) do |bench|
17
+ bench.report("BERT tiny") {ITER.times {BERT.encode(tiny)}}
18
+ bench.report("BERT small") {ITER.times {BERT.encode(small)}}
19
+ bench.report("BERT large") {ITER.times {BERT.encode(large)}}
20
+ bench.report("BERT complex") {ITER.times {BERT.encode(complex)}}
21
+ puts
22
+ bench.report("JSON tiny") {ITER.times {JSON.dump(tiny)}}
23
+ bench.report("JSON small") {ITER.times {JSON.dump(small)}}
24
+ bench.report("JSON large") {ITER.times {JSON.dump(large)}}
25
+ bench.report("JSON complex") {ITER.times {JSON.dump(complex)}}
26
+ puts
27
+ bench.report("JSON tiny") {ITER.times {Yajl::Encoder.encode(tiny)}}
28
+ bench.report("JSON small") {ITER.times {Yajl::Encoder.encode(small)}}
29
+ bench.report("JSON large") {ITER.times {Yajl::Encoder.encode(large)}}
30
+ bench.report("JSON complex") {ITER.times {Yajl::Encoder.encode(complex)}}
31
+ puts
32
+ bench.report("Ruby tiny") {ITER.times {Marshal.dump(tiny)}}
33
+ bench.report("Ruby small") {ITER.times {Marshal.dump(small)}}
34
+ bench.report("Ruby large") {ITER.times {Marshal.dump(large)}}
35
+ bench.report("Ruby complex") {ITER.times {Marshal.dump(complex)}}
36
+ end
@@ -0,0 +1,55 @@
1
+ user system total real
2
+
3
+ Comparisons
4
+
5
+ JSON tiny 0.020000 0.000000 0.020000 ( 0.017486)
6
+ JSON small 0.070000 0.000000 0.070000 ( 0.080681)
7
+ JSON large 15.260000 0.600000 15.860000 ( 16.427857)
8
+ JSON complex 1.470000 0.010000 1.480000 ( 1.558230)
9
+
10
+ YAJL tiny 0.010000 0.000000 0.010000 ( 0.015537)
11
+ YAJL small 0.050000 0.000000 0.050000 ( 0.061879)
12
+ YAJL large 3.610000 0.800000 4.410000 ( 4.675255)
13
+ YAJL complex 1.030000 0.000000 1.030000 ( 1.066871)
14
+
15
+ Ruby tiny 0.010000 0.000000 0.010000 ( 0.007117)
16
+ Ruby small 0.020000 0.000000 0.020000 ( 0.015964)
17
+ Ruby large 0.040000 0.000000 0.040000 ( 0.042695)
18
+ Ruby complex 0.040000 0.000000 0.040000 ( 0.048395)
19
+
20
+ Ruby encoder / Ruby decoder
21
+ 41503465479e8762916d6997d91639f0d7308a13
22
+
23
+ BERT tiny 0.090000 0.000000 0.090000 ( 0.092357)
24
+ BERT small 0.830000 0.000000 0.830000 ( 0.853270)
25
+ BERT large 4.190000 0.620000 4.810000 ( 4.959149)
26
+ BERT complex 19.380000 0.080000 19.460000 ( 20.402862)
27
+
28
+ Simple C decoder / Ruby encoder
29
+ 41503465479e8762916d6997d91639f0d7308a13
30
+
31
+ BERT tiny 0.030000 0.000000 0.030000 ( 0.033826)
32
+ BERT small 0.390000 0.010000 0.400000 ( 0.413229)
33
+ BERT large 2.270000 0.550000 2.820000 ( 3.029141)
34
+ BERT complex 8.680000 0.040000 8.720000 ( 9.097990)
35
+
36
+ Smarter Ruby decoder
37
+
38
+ BERT tiny 0.070000 0.000000 0.070000 ( 0.075155)
39
+ BERT small 0.810000 0.010000 0.820000 ( 0.831905)
40
+ BERT large 4.340000 0.600000 4.940000 ( 5.064875)
41
+ BERT complex 18.460000 0.070000 18.530000 ( 19.096184)
42
+
43
+ Smarter C decoder
44
+
45
+ BERT tiny 0.030000 0.000000 0.030000 ( 0.035685)
46
+ BERT small 0.350000 0.010000 0.360000 ( 0.358929)
47
+ BERT large 2.410000 0.560000 2.970000 ( 3.056593)
48
+ BERT complex 7.910000 0.040000 7.950000 ( 8.236641)
49
+
50
+ Smart C Decoder only
51
+
52
+ BERT tiny 0.000000 0.000000 0.000000 ( 0.001820)
53
+ BERT small 0.000000 0.000000 0.000000 ( 0.003859)
54
+ BERT large 0.430000 0.010000 0.440000 ( 0.499631)
55
+ BERT complex 0.080000 0.010000 0.090000 ( 0.086992)