chrisk-protopuffs 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.specification +108 -0
- data/README.rdoc +1 -1
- data/Rakefile +48 -0
- data/VERSION.yml +2 -2
- data/lib/protopuffs/message/base.rb +1 -1
- data/lib/protopuffs/message/field.rb +9 -0
- data/protopuffs.gemspec +77 -0
- data/test/message_field_test.rb +3 -1
- data/test/test_helper.rb +28 -0
- data/test/wire_format_test.rb +15 -0
- metadata +21 -15
data/.gitignore
ADDED
data/.specification
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: protopuffs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kampmeier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: treetop
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: shoulda
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: A new implementation of Protocol Buffers in Ruby
|
46
|
+
email: chris@kampers.net
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
- LICENSE.txt
|
54
|
+
files:
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.rdoc
|
57
|
+
- VERSION.yml
|
58
|
+
- lib/protopuffs
|
59
|
+
- lib/protopuffs/message
|
60
|
+
- lib/protopuffs/message/base.rb
|
61
|
+
- lib/protopuffs/message/field.rb
|
62
|
+
- lib/protopuffs/message/wire_type.rb
|
63
|
+
- lib/protopuffs/parser
|
64
|
+
- lib/protopuffs/parser/parser.rb
|
65
|
+
- lib/protopuffs/parser/protocol_buffer.treetop
|
66
|
+
- lib/protopuffs.rb
|
67
|
+
- test/abstract_syntax_tree_test.rb
|
68
|
+
- test/fixtures
|
69
|
+
- test/fixtures/proto
|
70
|
+
- test/fixtures/proto/person.proto
|
71
|
+
- test/message_base_test.rb
|
72
|
+
- test/message_field_test.rb
|
73
|
+
- test/parse_tree_test.rb
|
74
|
+
- test/protopuffs_test.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
- test/text_format_test.rb
|
77
|
+
- test/wire_format_test.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/chrisk/protopuffs
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --inline-source
|
85
|
+
- --charset=UTF-8
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.4
|
104
|
+
signing_key:
|
105
|
+
specification_version: 2
|
106
|
+
summary: Sex, drugs, and protocol buffers
|
107
|
+
test_files: []
|
108
|
+
|
data/README.rdoc
CHANGED
@@ -59,7 +59,7 @@ or hashes, as well as <tt>#attributes=</tt>
|
|
59
59
|
Protopuffs currently only supports a base set of the <tt>.proto</tt> file
|
60
60
|
syntax. Here's what's missing:
|
61
61
|
|
62
|
-
*
|
62
|
+
* the sfixed64 type
|
63
63
|
* sint32 and sint64 types (due to lack of support for ZigZag encoding)
|
64
64
|
* packed repeated fields (the <tt>[packed=true]</tt> option)
|
65
65
|
* enumerations
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rcov/rcovtask'
|
7
|
+
begin require 'metric_fu'; rescue LoadError; end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'jeweler'
|
11
|
+
Jeweler::Tasks.new do |s|
|
12
|
+
s.name = "protopuffs"
|
13
|
+
s.summary = %Q{Sex, drugs, and protocol buffers}
|
14
|
+
s.email = "chris@kampers.net"
|
15
|
+
s.homepage = "http://github.com/chrisk/protopuffs"
|
16
|
+
s.description = "A new implementation of Protocol Buffers in Ruby"
|
17
|
+
s.authors = ["Chris Kampmeier"]
|
18
|
+
s.add_dependency "treetop"
|
19
|
+
s.add_development_dependency "mocha"
|
20
|
+
s.add_development_dependency "shoulda"
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::TestTask.new do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::RDocTask.new do |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = 'Protopuffs'
|
35
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
36
|
+
rdoc.rdoc_files.include('README*')
|
37
|
+
rdoc.rdoc_files.include('LICENSE*')
|
38
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
end
|
40
|
+
|
41
|
+
Rcov::RcovTask.new do |t|
|
42
|
+
t.libs << 'test'
|
43
|
+
t.rcov_opts << '--exclude "gems/*"'
|
44
|
+
t.test_files = FileList['test/**/*_test.rb']
|
45
|
+
t.verbose = true
|
46
|
+
end
|
47
|
+
|
48
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
@@ -81,7 +81,7 @@ module Protopuffs
|
|
81
81
|
|
82
82
|
until @buffer.eof?
|
83
83
|
tag = MessageField.shift_tag(@buffer)
|
84
|
-
field = self.class.fields.find { |
|
84
|
+
field = self.class.fields.find { |f| f.tag == tag }
|
85
85
|
next if field.nil?
|
86
86
|
value_bytes = field.class.shift(@buffer)
|
87
87
|
|
@@ -18,6 +18,7 @@ module Protopuffs
|
|
18
18
|
when "bytes" then Bytes.new(*args)
|
19
19
|
when "float" then Float.new(*args)
|
20
20
|
when "fixed32" then Fixed32.new(*args)
|
21
|
+
when "sfixed32" then SFixed32.new(*args)
|
21
22
|
else Embedded.new(type, *args)
|
22
23
|
end
|
23
24
|
end
|
@@ -139,6 +140,14 @@ module Protopuffs
|
|
139
140
|
def self.encode(value); [value].pack('V') end
|
140
141
|
end
|
141
142
|
|
143
|
+
class SFixed32 < Fixed32Base
|
144
|
+
def decode(bytes)
|
145
|
+
value = bytes.unpack('V').first
|
146
|
+
value >= 2**31 ? value -= 2**32 : value
|
147
|
+
end
|
148
|
+
def self.encode(value); [value].pack('V') end
|
149
|
+
end
|
150
|
+
|
142
151
|
class Float < Fixed32Base
|
143
152
|
def decode(bytes); bytes.unpack('e').first end
|
144
153
|
def self.encode(value); [value].pack('e') end
|
data/protopuffs.gemspec
ADDED
@@ -0,0 +1,77 @@
|
|
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{protopuffs}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chris Kampmeier"]
|
12
|
+
s.date = %q{2009-09-21}
|
13
|
+
s.description = %q{A new implementation of Protocol Buffers in Ruby}
|
14
|
+
s.email = %q{chris@kampers.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
".specification",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"lib/protopuffs.rb",
|
27
|
+
"lib/protopuffs/message/base.rb",
|
28
|
+
"lib/protopuffs/message/field.rb",
|
29
|
+
"lib/protopuffs/message/wire_type.rb",
|
30
|
+
"lib/protopuffs/parser/parser.rb",
|
31
|
+
"lib/protopuffs/parser/protocol_buffer.treetop",
|
32
|
+
"protopuffs.gemspec",
|
33
|
+
"test/abstract_syntax_tree_test.rb",
|
34
|
+
"test/fixtures/proto/person.proto",
|
35
|
+
"test/message_base_test.rb",
|
36
|
+
"test/message_field_test.rb",
|
37
|
+
"test/parse_tree_test.rb",
|
38
|
+
"test/protopuffs_test.rb",
|
39
|
+
"test/test_helper.rb",
|
40
|
+
"test/text_format_test.rb",
|
41
|
+
"test/wire_format_test.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/chrisk/protopuffs}
|
44
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.5}
|
47
|
+
s.summary = %q{Sex, drugs, and protocol buffers}
|
48
|
+
s.test_files = [
|
49
|
+
"test/abstract_syntax_tree_test.rb",
|
50
|
+
"test/message_base_test.rb",
|
51
|
+
"test/message_field_test.rb",
|
52
|
+
"test/parse_tree_test.rb",
|
53
|
+
"test/protopuffs_test.rb",
|
54
|
+
"test/test_helper.rb",
|
55
|
+
"test/text_format_test.rb",
|
56
|
+
"test/wire_format_test.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_runtime_dependency(%q<treetop>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<treetop>, [">= 0"])
|
69
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
70
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<treetop>, [">= 0"])
|
74
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
75
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
data/test/message_field_test.rb
CHANGED
@@ -30,6 +30,7 @@ class MessageFieldTest < Test::Unit::TestCase
|
|
30
30
|
[ "bytes", Protopuffs::Bytes],
|
31
31
|
[ "float", Protopuffs::Float],
|
32
32
|
[ "fixed32", Protopuffs::Fixed32],
|
33
|
+
[ "sfixed32", Protopuffs::SFixed32],
|
33
34
|
[ "embedded", Protopuffs::Embedded],
|
34
35
|
].each do |type, klass|
|
35
36
|
assert_kind_of klass, Protopuffs::MessageField.factory(type, "optional", "a_string", 1, 2)
|
@@ -50,7 +51,8 @@ class MessageFieldTest < Test::Unit::TestCase
|
|
50
51
|
numeric_types = [Protopuffs::Double, Protopuffs::Float,
|
51
52
|
Protopuffs::Int32, Protopuffs::Int64,
|
52
53
|
Protopuffs::UInt32, Protopuffs::UInt64,
|
53
|
-
Protopuffs::Fixed32, Protopuffs::Fixed64
|
54
|
+
Protopuffs::Fixed32, Protopuffs::Fixed64,
|
55
|
+
Protopuffs::SFixed32]
|
54
56
|
numeric_types.each do |type|
|
55
57
|
assert_equal 0, type.new("optional", "number", 1).default
|
56
58
|
assert_equal 0, type.new("optional", "number", 1, nil).default
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'test/unit'
|
5
|
+
|
6
|
+
gem "polyglot", "=0.2.9"
|
7
|
+
gem "treetop", "=1.4.2"
|
8
|
+
|
9
|
+
gem "thoughtbot-shoulda", "=2.10.2"
|
5
10
|
require 'shoulda'
|
11
|
+
|
12
|
+
gem "mocha", "=0.9.8"
|
6
13
|
require 'mocha'
|
7
14
|
|
8
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -58,5 +65,26 @@ class Test::Unit::TestCase
|
|
58
65
|
end
|
59
66
|
end
|
60
67
|
|
68
|
+
def self.should_encode_and_decode_wire_format_and_fields(bytes, fields)
|
69
|
+
self.should_encode_wire_format_from_fields(bytes, fields)
|
70
|
+
self.should_decode_wire_format_to_fields(bytes, fields)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.should_losslessly_encode_and_decode_a_random_sample(fields)
|
74
|
+
raise ArgumentError if fields.size > 1
|
75
|
+
name, range = fields.shift
|
76
|
+
should "get the same value back after encoding and decoding a random sample of the values #{range.inspect} for field #{name.inspect}" do
|
77
|
+
size = range.last - range.first
|
78
|
+
size -= 1 if range.exclude_end?
|
79
|
+
values_to_test = [range.first, range.first + size]
|
80
|
+
250.times { values_to_test << range.first + rand(size) }
|
81
|
+
values_to_test.each do |value|
|
82
|
+
@message.send("#{name}=", value)
|
83
|
+
@message.from_wire_format(@message.to_wire_format)
|
84
|
+
assert_equal value, @message.send(name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
61
89
|
end
|
62
90
|
|
data/test/wire_format_test.rb
CHANGED
@@ -193,6 +193,21 @@ class WireFormatTest < Test::Unit::TestCase
|
|
193
193
|
end
|
194
194
|
|
195
195
|
|
196
|
+
context "a message with one sfixed32 field tagged #1" do
|
197
|
+
setup do
|
198
|
+
fields = [Protopuffs::SFixed32.new("required", "a", 1)]
|
199
|
+
Protopuffs::Message::Base.define_message_class("Test1", fields)
|
200
|
+
@message = Protopuffs::Message::Test1.new
|
201
|
+
end
|
202
|
+
|
203
|
+
should_encode_and_decode_wire_format_and_fields [0x0D, 0x05, 0x00, 0x00, 0x80],
|
204
|
+
:a => -2**31 + 5
|
205
|
+
should_encode_and_decode_wire_format_and_fields [0x0D, 0x05, 0x80, 0x00, 0x00],
|
206
|
+
:a => 2**15 + 5
|
207
|
+
should_losslessly_encode_and_decode_a_random_sample :a => -2**31...2**31
|
208
|
+
end
|
209
|
+
|
210
|
+
|
196
211
|
context "a message with one repeating int32 field tagged #1" do
|
197
212
|
setup do
|
198
213
|
fields = [Protopuffs::Int32.new("repeated", "a", 1)]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrisk-protopuffs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kampmeier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,24 +49,23 @@ executables: []
|
|
49
49
|
extensions: []
|
50
50
|
|
51
51
|
extra_rdoc_files:
|
52
|
-
- README.rdoc
|
53
52
|
- LICENSE.txt
|
53
|
+
- README.rdoc
|
54
54
|
files:
|
55
|
+
- .gitignore
|
56
|
+
- .specification
|
55
57
|
- LICENSE.txt
|
56
58
|
- README.rdoc
|
59
|
+
- Rakefile
|
57
60
|
- VERSION.yml
|
58
|
-
- lib/protopuffs
|
59
|
-
- lib/protopuffs/message
|
61
|
+
- lib/protopuffs.rb
|
60
62
|
- lib/protopuffs/message/base.rb
|
61
63
|
- lib/protopuffs/message/field.rb
|
62
64
|
- lib/protopuffs/message/wire_type.rb
|
63
|
-
- lib/protopuffs/parser
|
64
65
|
- lib/protopuffs/parser/parser.rb
|
65
66
|
- lib/protopuffs/parser/protocol_buffer.treetop
|
66
|
-
-
|
67
|
+
- protopuffs.gemspec
|
67
68
|
- test/abstract_syntax_tree_test.rb
|
68
|
-
- test/fixtures
|
69
|
-
- test/fixtures/proto
|
70
69
|
- test/fixtures/proto/person.proto
|
71
70
|
- test/message_base_test.rb
|
72
71
|
- test/message_field_test.rb
|
@@ -75,11 +74,11 @@ files:
|
|
75
74
|
- test/test_helper.rb
|
76
75
|
- test/text_format_test.rb
|
77
76
|
- test/wire_format_test.rb
|
78
|
-
has_rdoc:
|
77
|
+
has_rdoc: false
|
79
78
|
homepage: http://github.com/chrisk/protopuffs
|
79
|
+
licenses:
|
80
80
|
post_install_message:
|
81
81
|
rdoc_options:
|
82
|
-
- --inline-source
|
83
82
|
- --charset=UTF-8
|
84
83
|
require_paths:
|
85
84
|
- lib
|
@@ -98,9 +97,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
97
|
requirements: []
|
99
98
|
|
100
99
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.3.5
|
102
101
|
signing_key:
|
103
|
-
specification_version:
|
102
|
+
specification_version: 3
|
104
103
|
summary: Sex, drugs, and protocol buffers
|
105
|
-
test_files:
|
106
|
-
|
104
|
+
test_files:
|
105
|
+
- test/abstract_syntax_tree_test.rb
|
106
|
+
- test/message_base_test.rb
|
107
|
+
- test/message_field_test.rb
|
108
|
+
- test/parse_tree_test.rb
|
109
|
+
- test/protopuffs_test.rb
|
110
|
+
- test/test_helper.rb
|
111
|
+
- test/text_format_test.rb
|
112
|
+
- test/wire_format_test.rb
|