ruby_protobuf 0.3.0 → 0.3.2
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/History.txt +3 -1
- data/bin/mk_parser +2 -0
- data/bin/rprotoc +1 -1
- data/lib/protobuf/compiler/compiler.rb +12 -12
- data/lib/protobuf/compiler/nodes.rb +140 -35
- data/lib/protobuf/compiler/proto.y +7 -4
- data/lib/protobuf/compiler/proto_parser.rb +170 -167
- data/lib/protobuf/compiler/template/rpc_bin.erb +1 -1
- data/lib/protobuf/compiler/template/rpc_client.erb +1 -1
- data/lib/protobuf/compiler/visitors.rb +168 -16
- data/lib/protobuf/message/enum.rb +3 -0
- data/lib/protobuf/message/field.rb +52 -37
- data/lib/protobuf/message/message.rb +37 -14
- data/lib/protobuf/message/protoable.rb +37 -0
- data/lib/ruby_protobuf.rb +1 -1
- data/test/addressbook.rb +36 -0
- data/test/check_unbuild.rb +1 -1
- data/test/collision.rb +18 -0
- data/test/data/types.bin +0 -0
- data/test/data/unk.png +0 -0
- data/test/ext_collision.rb +25 -0
- data/test/ext_range.rb +23 -0
- data/test/merge.rb +40 -0
- data/test/nested.rb +25 -0
- data/test/proto/addressbook.pb.rb +69 -0
- data/test/{addressbook.proto → proto/addressbook.proto} +1 -0
- data/test/proto/addressbook.rb +69 -0
- data/test/{addressbook_base.proto → proto/addressbook_base.proto} +0 -0
- data/test/{addressbook_ext.proto → proto/addressbook_ext.proto} +0 -0
- data/test/proto/bool_default.pb.rb +16 -0
- data/test/proto/bool_default.proto +3 -0
- data/test/proto/collision.proto +5 -0
- data/test/proto/ext_collision.proto +8 -0
- data/test/proto/ext_range.proto +7 -0
- data/test/proto/float_default.proto +2 -0
- data/test/proto/merge.proto +15 -0
- data/test/proto/nested.proto +7 -0
- data/test/{rpc.proto → proto/rpc.proto} +0 -0
- data/test/{types.proto → proto/types.proto} +0 -0
- data/test/test_compiler.rb +191 -12
- data/test/test_message.rb +86 -0
- data/test/test_standard_message.rb +8 -5
- data/test/test_types.rb +9 -8
- metadata +26 -13
- data/Manifest.txt +0 -62
- data/examples/addressbook.proto +0 -24
- data/examples/addressbook.rb +0 -30
- data/examples/reading_a_message.rb +0 -32
- data/examples/writing_a_message.rb +0 -46
@@ -40,20 +40,23 @@ class StandardMessageTest < Test::Unit::TestCase
|
|
40
40
|
person.phone.last.type = Tutorial::Person::PhoneType::WORK
|
41
41
|
|
42
42
|
person2 = person.dup
|
43
|
-
|
43
|
+
assert person == person2
|
44
|
+
assert !person.eql?(person2)
|
44
45
|
assert_equal person.name, person2.name
|
45
46
|
assert_equal person.id, person2.id
|
46
47
|
assert_equal person.email, person2.email
|
47
48
|
assert_equal person.phone.size, person2.phone.size
|
48
|
-
|
49
|
+
assert person.phone.first == person2.phone.first
|
50
|
+
assert !person.phone.first.eql?(person2.phone.first)
|
49
51
|
assert_equal person.phone.first.number, person2.phone.first.number
|
50
52
|
assert_equal person.phone.first.type, person2.phone.first.type
|
51
|
-
|
53
|
+
assert person.phone.last == person2.phone.last
|
54
|
+
assert !person.phone.last.eql?(person2.phone.last)
|
52
55
|
assert_equal person.phone.last.number, person2.phone.last.number
|
53
56
|
assert_equal person.phone.last.type, person2.phone.last.type
|
54
57
|
end
|
55
58
|
|
56
|
-
def
|
59
|
+
def test_inspect
|
57
60
|
person = Tutorial::Person.new
|
58
61
|
person.name = 'name'
|
59
62
|
person.id = 1234
|
@@ -65,7 +68,7 @@ class StandardMessageTest < Test::Unit::TestCase
|
|
65
68
|
person.phone.last.number = '456-123'
|
66
69
|
person.phone.last.type = Tutorial::Person::PhoneType::WORK
|
67
70
|
|
68
|
-
assert_equal <<-eos, person.
|
71
|
+
assert_equal <<-eos, person.inspect
|
69
72
|
name: "name"
|
70
73
|
id: 1234
|
71
74
|
email: "abc@cde.fgh"
|
data/test/test_types.rb
CHANGED
@@ -16,7 +16,9 @@ class TypesTest < Test::Unit::TestCase
|
|
16
16
|
types.type10 = 100000
|
17
17
|
types.type11 = false
|
18
18
|
types.type12 = 'hello all types'
|
19
|
-
|
19
|
+
image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read}
|
20
|
+
types.type13 = image_bin
|
21
|
+
|
20
22
|
serialized_string = types.serialize_to_string
|
21
23
|
|
22
24
|
types2 = Test::Types::TestTypes.new
|
@@ -33,7 +35,8 @@ class TypesTest < Test::Unit::TestCase
|
|
33
35
|
assert_equal 100000, types2.type10
|
34
36
|
assert !types2.type11
|
35
37
|
assert_equal 'hello all types', types2.type12
|
36
|
-
|
38
|
+
assert_equal 10938, types2.type13.size
|
39
|
+
assert_equal image_bin, types2.type13
|
37
40
|
end
|
38
41
|
|
39
42
|
def test_parse
|
@@ -49,9 +52,9 @@ class TypesTest < Test::Unit::TestCase
|
|
49
52
|
assert_equal(-10, types.type8)
|
50
53
|
assert_equal 10000, types.type9
|
51
54
|
assert_equal 100000, types.type10
|
52
|
-
assert_equal false, types.type11
|
55
|
+
assert_equal false, !!types.type11
|
53
56
|
assert_equal 'hello all types', types.type12
|
54
|
-
|
57
|
+
assert_equal File.open('test/data/unk.png', 'r+b'){|f| f.read}, types.type13
|
55
58
|
end
|
56
59
|
|
57
60
|
def test_double
|
@@ -168,13 +171,11 @@ class TypesTest < Test::Unit::TestCase
|
|
168
171
|
|
169
172
|
def test_bytes
|
170
173
|
types = Test::Types::TestTypes.new
|
171
|
-
# TODO
|
172
|
-
=begin
|
173
174
|
assert_nothing_raised do types.type13 = '' end
|
174
175
|
assert_nothing_raised do types.type13 = 'hello' end
|
175
|
-
|
176
|
+
assert_nothing_raised do types.type13 = nil end
|
176
177
|
assert_raise TypeError do types.type13 = 0 end
|
177
178
|
assert_raise TypeError do types.type13 = true end
|
178
|
-
=end
|
179
|
+
assert_raise TypeError do types.type13 = [] end
|
179
180
|
end
|
180
181
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ANDO Yasushi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-30 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -25,23 +25,19 @@ dependencies:
|
|
25
25
|
description: "== DESCRIPTION: Protocol Buffers for Ruby. == FEATURES/PROBLEMS: * Compile .proto file to ruby script * Parse the binary wire format for protocol buffer * Serialize data to the binary wire format for protocol buffer"
|
26
26
|
email: andyjpn@gmail.com
|
27
27
|
executables:
|
28
|
+
- mk_parser
|
28
29
|
- rprotoc
|
29
30
|
extensions: []
|
30
31
|
|
31
32
|
extra_rdoc_files:
|
32
33
|
- History.txt
|
33
|
-
- Manifest.txt
|
34
34
|
- README.txt
|
35
35
|
files:
|
36
36
|
- History.txt
|
37
|
-
- Manifest.txt
|
38
37
|
- README.txt
|
39
38
|
- Rakefile
|
39
|
+
- bin/mk_parser
|
40
40
|
- bin/rprotoc
|
41
|
-
- examples/addressbook.proto
|
42
|
-
- examples/addressbook.rb
|
43
|
-
- examples/reading_a_message.rb
|
44
|
-
- examples/writing_a_message.rb
|
45
41
|
- lib/protobuf/common/wire_type.rb
|
46
42
|
- lib/protobuf/compiler/compiler.rb
|
47
43
|
- lib/protobuf/compiler/compiler_old.rb
|
@@ -66,23 +62,41 @@ files:
|
|
66
62
|
- lib/protobuf/message/extend.rb
|
67
63
|
- lib/protobuf/message/field.rb
|
68
64
|
- lib/protobuf/message/message.rb
|
65
|
+
- lib/protobuf/message/protoable.rb
|
69
66
|
- lib/protobuf/message/service.rb
|
70
67
|
- lib/protobuf/rpc/client.rb
|
71
68
|
- lib/protobuf/rpc/handler.rb
|
72
69
|
- lib/protobuf/rpc/server.rb
|
73
70
|
- lib/ruby_protobuf.rb
|
74
|
-
- test/addressbook.proto
|
75
71
|
- test/addressbook.rb
|
76
|
-
- test/addressbook_base.proto
|
77
72
|
- test/addressbook_base.rb
|
78
|
-
- test/addressbook_ext.proto
|
79
73
|
- test/addressbook_ext.rb
|
80
74
|
- test/check_unbuild.rb
|
75
|
+
- test/collision.rb
|
81
76
|
- test/data/data.bin
|
82
77
|
- test/data/data_source.py
|
83
78
|
- test/data/types.bin
|
84
79
|
- test/data/types_source.py
|
85
|
-
- test/
|
80
|
+
- test/data/unk.png
|
81
|
+
- test/ext_collision.rb
|
82
|
+
- test/ext_range.rb
|
83
|
+
- test/merge.rb
|
84
|
+
- test/nested.rb
|
85
|
+
- test/proto/addressbook.pb.rb
|
86
|
+
- test/proto/addressbook.proto
|
87
|
+
- test/proto/addressbook.rb
|
88
|
+
- test/proto/addressbook_base.proto
|
89
|
+
- test/proto/addressbook_ext.proto
|
90
|
+
- test/proto/bool_default.pb.rb
|
91
|
+
- test/proto/bool_default.proto
|
92
|
+
- test/proto/collision.proto
|
93
|
+
- test/proto/ext_collision.proto
|
94
|
+
- test/proto/ext_range.proto
|
95
|
+
- test/proto/float_default.proto
|
96
|
+
- test/proto/merge.proto
|
97
|
+
- test/proto/nested.proto
|
98
|
+
- test/proto/rpc.proto
|
99
|
+
- test/proto/types.proto
|
86
100
|
- test/test_addressbook.rb
|
87
101
|
- test/test_compiler.rb
|
88
102
|
- test/test_descriptor.rb
|
@@ -93,7 +107,6 @@ files:
|
|
93
107
|
- test/test_serialize.rb
|
94
108
|
- test/test_standard_message.rb
|
95
109
|
- test/test_types.rb
|
96
|
-
- test/types.proto
|
97
110
|
- test/types.rb
|
98
111
|
has_rdoc: true
|
99
112
|
homepage:
|
data/Manifest.txt
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.txt
|
4
|
-
Rakefile
|
5
|
-
bin/rprotoc
|
6
|
-
examples/addressbook.proto
|
7
|
-
examples/addressbook.rb
|
8
|
-
examples/reading_a_message.rb
|
9
|
-
examples/writing_a_message.rb
|
10
|
-
lib/protobuf/common/wire_type.rb
|
11
|
-
lib/protobuf/compiler/compiler.rb
|
12
|
-
lib/protobuf/compiler/compiler_old.rb
|
13
|
-
lib/protobuf/compiler/nodes.rb
|
14
|
-
lib/protobuf/compiler/proto.y
|
15
|
-
lib/protobuf/compiler/proto2.ebnf
|
16
|
-
lib/protobuf/compiler/proto_parser.rb
|
17
|
-
lib/protobuf/compiler/template/rpc_bin.erb
|
18
|
-
lib/protobuf/compiler/template/rpc_client.erb
|
19
|
-
lib/protobuf/compiler/template/rpc_service.erb
|
20
|
-
lib/protobuf/compiler/visitors.rb
|
21
|
-
lib/protobuf/descriptor/descriptor.proto
|
22
|
-
lib/protobuf/descriptor/descriptor.rb
|
23
|
-
lib/protobuf/descriptor/descriptor_builder.rb
|
24
|
-
lib/protobuf/descriptor/descriptor_proto.rb
|
25
|
-
lib/protobuf/descriptor/enum_descriptor.rb
|
26
|
-
lib/protobuf/descriptor/field_descriptor.rb
|
27
|
-
lib/protobuf/descriptor/file_descriptor.rb
|
28
|
-
lib/protobuf/message/decoder.rb
|
29
|
-
lib/protobuf/message/encoder.rb
|
30
|
-
lib/protobuf/message/enum.rb
|
31
|
-
lib/protobuf/message/extend.rb
|
32
|
-
lib/protobuf/message/field.rb
|
33
|
-
lib/protobuf/message/message.rb
|
34
|
-
lib/protobuf/message/service.rb
|
35
|
-
lib/protobuf/rpc/client.rb
|
36
|
-
lib/protobuf/rpc/handler.rb
|
37
|
-
lib/protobuf/rpc/server.rb
|
38
|
-
lib/ruby_protobuf.rb
|
39
|
-
test/addressbook.proto
|
40
|
-
test/addressbook.rb
|
41
|
-
test/addressbook_base.proto
|
42
|
-
test/addressbook_base.rb
|
43
|
-
test/addressbook_ext.proto
|
44
|
-
test/addressbook_ext.rb
|
45
|
-
test/check_unbuild.rb
|
46
|
-
test/data/data.bin
|
47
|
-
test/data/data_source.py
|
48
|
-
test/data/types.bin
|
49
|
-
test/data/types_source.py
|
50
|
-
test/rpc.proto
|
51
|
-
test/test_addressbook.rb
|
52
|
-
test/test_compiler.rb
|
53
|
-
test/test_descriptor.rb
|
54
|
-
test/test_extension.rb
|
55
|
-
test/test_message.rb
|
56
|
-
test/test_parse.rb
|
57
|
-
test/test_ruby_protobuf.rb
|
58
|
-
test/test_serialize.rb
|
59
|
-
test/test_standard_message.rb
|
60
|
-
test/test_types.rb
|
61
|
-
test/types.proto
|
62
|
-
test/types.rb
|
data/examples/addressbook.proto
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
package tutorial;
|
2
|
-
|
3
|
-
message Person {
|
4
|
-
required string name = 1;
|
5
|
-
required int32 id = 2;
|
6
|
-
optional string email = 3;
|
7
|
-
|
8
|
-
enum PhoneType {
|
9
|
-
MOBILE = 0;
|
10
|
-
HOME = 1;
|
11
|
-
WORK = 2;
|
12
|
-
}
|
13
|
-
|
14
|
-
message PhoneNumber {
|
15
|
-
required string number = 1;
|
16
|
-
optional PhoneType type = 2 [default = HOME];
|
17
|
-
}
|
18
|
-
|
19
|
-
repeated PhoneNumber phone = 4;
|
20
|
-
}
|
21
|
-
|
22
|
-
message AddressBook {
|
23
|
-
repeated Person person = 1;
|
24
|
-
}
|
data/examples/addressbook.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'protobuf/message/message'
|
2
|
-
require 'protobuf/message/enum'
|
3
|
-
require 'protobuf/message/service'
|
4
|
-
require 'protobuf/message/extend'
|
5
|
-
|
6
|
-
module Tutorial
|
7
|
-
|
8
|
-
class Person < ::Protobuf::Message
|
9
|
-
required :string, :name, 1
|
10
|
-
required :int32, :id, 2
|
11
|
-
optional :string, :email, 3
|
12
|
-
|
13
|
-
class PhoneType < ::Protobuf::Enum
|
14
|
-
MOBILE = 0
|
15
|
-
HOME = 1
|
16
|
-
WORK = 2
|
17
|
-
end
|
18
|
-
|
19
|
-
class PhoneNumber < ::Protobuf::Message
|
20
|
-
required :string, :number, 1
|
21
|
-
optional :PhoneType, :type, 2, {:default => :HOME}
|
22
|
-
end
|
23
|
-
|
24
|
-
repeated :PhoneNumber, :phone, 4
|
25
|
-
end
|
26
|
-
|
27
|
-
class AddressBook < ::Protobuf::Message
|
28
|
-
repeated :Person, :person, 1
|
29
|
-
end
|
30
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby
|
2
|
-
|
3
|
-
require 'addressbook'
|
4
|
-
|
5
|
-
def list_people(address_book)
|
6
|
-
address_book.person.each do |person|
|
7
|
-
puts "Person ID: #{person.id}"
|
8
|
-
puts " Name: #{person.name}"
|
9
|
-
puts " E-mail: #{person.email}" unless person.email.empty?
|
10
|
-
person.phone.each do |phone_number|
|
11
|
-
print(case phone_number.type
|
12
|
-
when Tutorial::Person::PhoneType::MOBILE
|
13
|
-
' Mobile phone #: '
|
14
|
-
when Tutorial::Person::PhoneType::HOME
|
15
|
-
' Home phone #: '
|
16
|
-
when Tutorial::Person::PhoneType::WORK
|
17
|
-
' Work phone #: '
|
18
|
-
end)
|
19
|
-
puts phone_number.number
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
unless ARGV.size == 1
|
25
|
-
puts "Usage: #{$0} ADDRESS_BOOK_FILE"
|
26
|
-
exit
|
27
|
-
end
|
28
|
-
|
29
|
-
address_book = Tutorial::AddressBook.new
|
30
|
-
address_book.parse_from_file ARGV[0]
|
31
|
-
|
32
|
-
list_people address_book
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby
|
2
|
-
|
3
|
-
require 'addressbook'
|
4
|
-
|
5
|
-
def prompt_for_address(person)
|
6
|
-
print 'Enter person ID number: '
|
7
|
-
person.id = STDIN.gets.strip.to_i
|
8
|
-
print 'Enter name: '
|
9
|
-
person.name = STDIN.gets.strip
|
10
|
-
print 'Enter email address (blank for none): '
|
11
|
-
email = STDIN.gets.strip
|
12
|
-
person.email = email unless email.empty?
|
13
|
-
|
14
|
-
loop do
|
15
|
-
print 'Enter a phone number (or leave blank to finish): '
|
16
|
-
break if (number = STDIN.gets.strip).empty?
|
17
|
-
|
18
|
-
person.phone << Tutorial::Person::PhoneNumber.new
|
19
|
-
person.phone.last.number = number
|
20
|
-
|
21
|
-
print 'Is this a mobile, home, or work phone? '
|
22
|
-
person.phone.last.type =
|
23
|
-
case type = STDIN.gets.strip
|
24
|
-
when 'mobile'
|
25
|
-
Tutorial::Person::PhoneType::MOBILE
|
26
|
-
when 'home'
|
27
|
-
Tutorial::Person::PhoneType::HOME
|
28
|
-
when 'work'
|
29
|
-
Tutorial::Person::PhoneType::WORK
|
30
|
-
else
|
31
|
-
puts 'Unknown phone type; leaving as default value.'
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
unless ARGV.size == 1
|
38
|
-
puts "Usage: #{$0} ADDRESS_BOOK_FILE"
|
39
|
-
exit
|
40
|
-
end
|
41
|
-
|
42
|
-
address_book = Tutorial::AddressBook.new
|
43
|
-
address_book.parse_from_file ARGV[0] if File.exist? ARGV[0]
|
44
|
-
address_book.person << Tutorial::Person.new
|
45
|
-
prompt_for_address address_book.person.last
|
46
|
-
address_book.serialize_to_file ARGV[0]
|