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.
@@ -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
@@ -1,6 +1,6 @@
1
- require 'test/unit'
2
- require 'protobuf/message'
1
+ require 'protobuf/message/message'
3
2
  require 'test/addressbook'
3
+ require 'test/unit'
4
4
 
5
5
  class MessageTest < Test::Unit::TestCase
6
6
  def test_bracketed_access
@@ -1,4 +1,4 @@
1
- require 'protobuf/message'
1
+ require 'protobuf/message/message'
2
2
 
3
3
  module Test
4
4
  module Types
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.1.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-01 00:00:00 +09:00
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
- - bin/ruby_protobuf
43
- - lib/protobuf/compiler.rb
44
- - lib/protobuf/decoder.rb
45
- - lib/protobuf/encoder.rb
46
- - lib/protobuf/enum.rb
47
- - lib/protobuf/extend.rb
48
- - lib/protobuf/field.rb
49
- - lib/protobuf/message.rb
50
- - lib/protobuf/parser.y
51
- - lib/protobuf/service.rb
52
- - lib/protobuf/wire_type.rb
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
File without changes
@@ -1,13 +0,0 @@
1
- module Protobuf
2
- class Enum
3
- def self.get_name_by_tag(tag)
4
- constants.find do |name|
5
- class_eval(name) == tag
6
- end
7
- end
8
-
9
- def self.valid_tag?(tag)
10
- not get_name_by_tag(tag).nil?
11
- end
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- module Protobuf
2
- class Service
3
- def self.rpc(hash)
4
- raise NotImplementedError('TODO')
5
- end
6
- end
7
- end