ruby_protobuf 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -3
- data/Manifest.txt +20 -11
- data/README.txt +1 -1
- data/lib/protobuf/{wire_type.rb → common/wire_type.rb} +0 -0
- data/lib/protobuf/{compiler.rb → compiler/compiler.rb} +13 -13
- data/lib/protobuf/{parser.y → compiler/parser.y} +0 -0
- data/lib/protobuf/descriptor/descriptor.proto +286 -0
- data/lib/protobuf/descriptor/descriptor.rb +54 -0
- data/lib/protobuf/descriptor/descriptor_builder.rb +144 -0
- data/lib/protobuf/descriptor/descriptor_proto.rb +119 -0
- data/lib/protobuf/descriptor/enum_descriptor.rb +33 -0
- data/lib/protobuf/descriptor/field_descriptor.rb +50 -0
- data/lib/protobuf/descriptor/file_descriptor.rb +38 -0
- data/lib/protobuf/{decoder.rb → message/decoder.rb} +1 -1
- data/lib/protobuf/{encoder.rb → message/encoder.rb} +12 -11
- data/lib/protobuf/message/enum.rb +21 -0
- data/lib/protobuf/{extend.rb → message/extend.rb} +1 -1
- data/lib/protobuf/{field.rb → message/field.rb} +82 -53
- data/lib/protobuf/{message.rb → message/message.rb} +12 -3
- data/lib/protobuf/message/service.rb +9 -0
- data/lib/ruby_protobuf.rb +1 -1
- data/test/addressbook.rb +22 -4
- data/test/check_unbuild.rb +30 -0
- data/test/data/data2.bin +3 -0
- data/test/test_addressbook.rb +2 -2
- data/test/test_compiler.rb +9 -9
- data/test/test_descriptor.rb +122 -0
- data/test/test_message.rb +2 -2
- data/test/types.rb +1 -1
- metadata +23 -14
- data/bin/ruby_protobuf +0 -0
- data/lib/protobuf/enum.rb +0 -13
- data/lib/protobuf/service.rb +0 -7
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/addressbook'
|
3
|
+
require 'protobuf/descriptor/descriptor_builder'
|
4
|
+
require 'protobuf/descriptor/descriptor_proto'
|
5
|
+
|
6
|
+
class DescriptorTest < Test::Unit::TestCase
|
7
|
+
include Google::Protobuf
|
8
|
+
def test_build
|
9
|
+
tutorial_proto = FileDescriptorProto.new
|
10
|
+
tutorial_proto.package = 'Build::Tutorial'
|
11
|
+
|
12
|
+
person_proto = DescriptorProto.new
|
13
|
+
tutorial_proto.message_type << person_proto
|
14
|
+
person_proto.name = 'Person'
|
15
|
+
|
16
|
+
person_name_proto = FieldDescriptorProto.new
|
17
|
+
person_proto.field << person_name_proto
|
18
|
+
person_name_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED
|
19
|
+
person_name_proto.type = FieldDescriptorProto::Type::TYPE_STRING
|
20
|
+
person_name_proto.name = 'name'
|
21
|
+
person_name_proto.number = 1
|
22
|
+
|
23
|
+
person_id_proto = FieldDescriptorProto.new
|
24
|
+
person_proto.field << person_id_proto
|
25
|
+
person_id_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED
|
26
|
+
person_id_proto.type = FieldDescriptorProto::Type::TYPE_INT32
|
27
|
+
person_id_proto.name = 'id'
|
28
|
+
person_id_proto.number = 2
|
29
|
+
|
30
|
+
person_email_proto = FieldDescriptorProto.new
|
31
|
+
person_proto.field << person_email_proto
|
32
|
+
person_email_proto.label = FieldDescriptorProto::Label::LABEL_OPTIONAL
|
33
|
+
person_email_proto.type = FieldDescriptorProto::Type::TYPE_STRING
|
34
|
+
person_email_proto.name = 'email'
|
35
|
+
person_email_proto.number = 3
|
36
|
+
|
37
|
+
person_phone_type_proto = EnumDescriptorProto.new
|
38
|
+
person_proto.enum_type << person_phone_type_proto
|
39
|
+
person_phone_type_proto.name = 'PhoneType'
|
40
|
+
|
41
|
+
person_phone_type_mobile_proto = EnumValueDescriptorProto.new
|
42
|
+
person_phone_type_proto.value << person_phone_type_mobile_proto
|
43
|
+
person_phone_type_mobile_proto.name = 'MOBILE'
|
44
|
+
person_phone_type_mobile_proto.number = 0
|
45
|
+
|
46
|
+
person_phone_type_home_proto = EnumValueDescriptorProto.new
|
47
|
+
person_phone_type_proto.value << person_phone_type_home_proto
|
48
|
+
person_phone_type_home_proto.name = 'HOME'
|
49
|
+
person_phone_type_home_proto.number = 1
|
50
|
+
|
51
|
+
person_phone_type_work_proto = EnumValueDescriptorProto.new
|
52
|
+
person_phone_type_proto.value << person_phone_type_work_proto
|
53
|
+
person_phone_type_work_proto.name = 'WORK'
|
54
|
+
person_phone_type_work_proto.number = 2
|
55
|
+
|
56
|
+
person_phone_number_proto = DescriptorProto.new
|
57
|
+
person_proto.nested_type << person_phone_number_proto
|
58
|
+
person_phone_number_proto.name = 'PhoneNumber'
|
59
|
+
|
60
|
+
person_phone_number_number_proto = FieldDescriptorProto.new
|
61
|
+
person_phone_number_proto.field << person_phone_number_number_proto
|
62
|
+
person_phone_number_number_proto.label = FieldDescriptorProto::Label::LABEL_REQUIRED
|
63
|
+
person_phone_number_number_proto.type = FieldDescriptorProto::Type::TYPE_STRING
|
64
|
+
person_phone_number_number_proto.name = 'number'
|
65
|
+
person_phone_number_number_proto.number = 1
|
66
|
+
|
67
|
+
person_phone_number_type_proto = FieldDescriptorProto.new
|
68
|
+
person_phone_number_proto.field << person_phone_number_type_proto
|
69
|
+
person_phone_number_type_proto.label = FieldDescriptorProto::Label::LABEL_OPTIONAL
|
70
|
+
person_phone_number_type_proto.type = FieldDescriptorProto::Type::TYPE_ENUM
|
71
|
+
person_phone_number_type_proto.type_name = 'PhoneType'
|
72
|
+
person_phone_number_type_proto.name = 'type'
|
73
|
+
person_phone_number_type_proto.number = 2
|
74
|
+
person_phone_number_type_proto.default_value = 'HOME'
|
75
|
+
|
76
|
+
person_phone_phone_number_proto = FieldDescriptorProto.new
|
77
|
+
person_proto.field << person_phone_phone_number_proto
|
78
|
+
person_phone_phone_number_proto.label = FieldDescriptorProto::Label::LABEL_REPEATED
|
79
|
+
person_phone_phone_number_proto.type = FieldDescriptorProto::Type::TYPE_MESSAGE
|
80
|
+
person_phone_phone_number_proto.type_name = 'PhoneNumber'
|
81
|
+
person_phone_phone_number_proto.name = 'phone'
|
82
|
+
person_phone_phone_number_proto.number = 4
|
83
|
+
|
84
|
+
address_book_proto = DescriptorProto.new
|
85
|
+
tutorial_proto.message_type << address_book_proto
|
86
|
+
address_book_proto.name = 'AddressBook'
|
87
|
+
|
88
|
+
address_book_person_proto = FieldDescriptorProto.new
|
89
|
+
address_book_proto.field << address_book_person_proto
|
90
|
+
address_book_person_proto.label = FieldDescriptorProto::Label::LABEL_REPEATED
|
91
|
+
address_book_person_proto.type = FieldDescriptorProto::Type::TYPE_MESSAGE
|
92
|
+
address_book_person_proto.type_name = 'Person'
|
93
|
+
address_book_person_proto.name = 'person'
|
94
|
+
address_book_person_proto.number = 1
|
95
|
+
|
96
|
+
Protobuf::Descriptor::DescriptorBuilder.build tutorial_proto
|
97
|
+
|
98
|
+
assert_nothing_raised {Build::Tutorial::Person}
|
99
|
+
assert_nothing_raised {Build::Tutorial::Person.new}
|
100
|
+
assert_equal ['email', 'id', 'name', 'phone'],
|
101
|
+
Build::Tutorial::Person.fields.map{|tag, field| field.name}.sort
|
102
|
+
|
103
|
+
assert_nothing_raised {Build::Tutorial::Person::PhoneNumber}
|
104
|
+
assert_nothing_raised {Build::Tutorial::Person::PhoneNumber.new}
|
105
|
+
assert_equal ['number', 'type'],
|
106
|
+
Build::Tutorial::Person::PhoneNumber.fields.map{|tag, field| field.name}.sort
|
107
|
+
|
108
|
+
assert_nothing_raised {Build::Tutorial::Person::PhoneType}
|
109
|
+
assert_equal 0, Build::Tutorial::Person::PhoneType::MOBILE
|
110
|
+
assert_equal 1, Build::Tutorial::Person::PhoneType::HOME
|
111
|
+
assert_equal 2, Build::Tutorial::Person::PhoneType::WORK
|
112
|
+
|
113
|
+
assert_nothing_raised {Build::Tutorial::AddressBook}
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_unbuild
|
117
|
+
proto = Protobuf::Descriptor::FileDescriptor.unbuild Tutorial::Person
|
118
|
+
proto.serialize_to_file 'person.bin'
|
119
|
+
puts
|
120
|
+
puts "run `test/check_unbuild.rb'"
|
121
|
+
end
|
122
|
+
end
|
data/test/test_message.rb
CHANGED
data/test/types.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-08-
|
12
|
+
date: 2008-08-03 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +26,6 @@ description: "== DESCRIPTION: Protocol Buffers for Ruby. == FEATURES/PROBLEMS:
|
|
26
26
|
email: andyjpn@gmail.com
|
27
27
|
executables:
|
28
28
|
- rprotoc
|
29
|
-
- ruby_protobuf
|
30
29
|
extensions: []
|
31
30
|
|
32
31
|
extra_rdoc_files:
|
@@ -39,26 +38,35 @@ files:
|
|
39
38
|
- README.txt
|
40
39
|
- Rakefile
|
41
40
|
- bin/rprotoc
|
42
|
-
-
|
43
|
-
- lib/protobuf/compiler.rb
|
44
|
-
- lib/protobuf/
|
45
|
-
- lib/protobuf/
|
46
|
-
- lib/protobuf/
|
47
|
-
- lib/protobuf/
|
48
|
-
- lib/protobuf/
|
49
|
-
- lib/protobuf/
|
50
|
-
- lib/protobuf/
|
51
|
-
- lib/protobuf/
|
52
|
-
- lib/protobuf/
|
41
|
+
- lib/protobuf/common/wire_type.rb
|
42
|
+
- lib/protobuf/compiler/compiler.rb
|
43
|
+
- lib/protobuf/compiler/parser.y
|
44
|
+
- lib/protobuf/descriptor/descriptor.proto
|
45
|
+
- lib/protobuf/descriptor/descriptor.rb
|
46
|
+
- lib/protobuf/descriptor/descriptor_builder.rb
|
47
|
+
- lib/protobuf/descriptor/descriptor_proto.rb
|
48
|
+
- lib/protobuf/descriptor/enum_descriptor.rb
|
49
|
+
- lib/protobuf/descriptor/field_descriptor.rb
|
50
|
+
- lib/protobuf/descriptor/file_descriptor.rb
|
51
|
+
- lib/protobuf/message/decoder.rb
|
52
|
+
- lib/protobuf/message/encoder.rb
|
53
|
+
- lib/protobuf/message/enum.rb
|
54
|
+
- lib/protobuf/message/extend.rb
|
55
|
+
- lib/protobuf/message/field.rb
|
56
|
+
- lib/protobuf/message/message.rb
|
57
|
+
- lib/protobuf/message/service.rb
|
53
58
|
- lib/ruby_protobuf.rb
|
54
59
|
- test/addressbook.proto
|
55
60
|
- test/addressbook.rb
|
61
|
+
- test/check_unbuild.rb
|
56
62
|
- test/data/data.bin
|
63
|
+
- test/data/data2.bin
|
57
64
|
- test/data/data_source.py
|
58
65
|
- test/data/types.bin
|
59
66
|
- test/data/types_source.py
|
60
67
|
- test/test_addressbook.rb
|
61
68
|
- test/test_compiler.rb
|
69
|
+
- test/test_descriptor.rb
|
62
70
|
- test/test_message.rb
|
63
71
|
- test/test_parse.rb
|
64
72
|
- test/test_ruby_protobuf.rb
|
@@ -101,3 +109,4 @@ test_files:
|
|
101
109
|
- test/test_types.rb
|
102
110
|
- test/test_serialize.rb
|
103
111
|
- test/test_compiler.rb
|
112
|
+
- test/test_descriptor.rb
|
data/bin/ruby_protobuf
DELETED
File without changes
|
data/lib/protobuf/enum.rb
DELETED