ruby_protobuf 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/History.txt +10 -2
  2. data/Manifest.txt +26 -12
  3. data/README.txt +6 -1
  4. data/Rakefile +51 -14
  5. data/TODO +15 -0
  6. data/VERSION +1 -0
  7. data/bin/rprotoc +11 -6
  8. data/lib/protobuf/common/exceptions.rb +11 -0
  9. data/lib/protobuf/common/util.rb +9 -0
  10. data/lib/protobuf/common/wire_type.rb +6 -6
  11. data/lib/protobuf/compiler/compiler.rb +16 -16
  12. data/lib/protobuf/compiler/nodes.rb +67 -65
  13. data/lib/protobuf/compiler/proto.y +31 -38
  14. data/lib/protobuf/compiler/proto_parser.rb +315 -294
  15. data/lib/protobuf/compiler/template/rpc_bin.erb +1 -1
  16. data/lib/protobuf/compiler/template/rpc_client.erb +1 -1
  17. data/lib/protobuf/compiler/template/rpc_service.erb +2 -2
  18. data/lib/protobuf/compiler/visitors.rb +45 -39
  19. data/lib/protobuf/descriptor/descriptor.proto +0 -0
  20. data/lib/protobuf/descriptor/descriptor.rb +11 -10
  21. data/lib/protobuf/descriptor/descriptor_builder.rb +6 -7
  22. data/lib/protobuf/descriptor/descriptor_proto.rb +51 -31
  23. data/lib/protobuf/descriptor/enum_descriptor.rb +5 -5
  24. data/lib/protobuf/descriptor/field_descriptor.rb +8 -9
  25. data/lib/protobuf/descriptor/file_descriptor.rb +0 -1
  26. data/lib/protobuf/message/decoder.rb +33 -35
  27. data/lib/protobuf/message/encoder.rb +23 -19
  28. data/lib/protobuf/message/enum.rb +43 -9
  29. data/lib/protobuf/message/field.rb +281 -193
  30. data/lib/protobuf/message/message.rb +166 -110
  31. data/lib/protobuf/message/protoable.rb +4 -3
  32. data/lib/protobuf/message/service.rb +1 -1
  33. data/lib/protobuf/rpc/client.rb +3 -3
  34. data/lib/protobuf/rpc/handler.rb +1 -1
  35. data/lib/protobuf/rpc/server.rb +8 -8
  36. data/lib/ruby_protobuf.rb +1 -1
  37. data/test/check_unbuild.rb +7 -7
  38. data/test/proto/addressbook.pb.rb +67 -0
  39. data/test/proto/addressbook.proto +2 -0
  40. data/test/proto/addressbook_base.pb.rb +59 -0
  41. data/test/proto/addressbook_base.proto +1 -1
  42. data/test/proto/addressbook_ext.pb.rb +21 -0
  43. data/test/proto/addressbook_ext.proto +2 -2
  44. data/test/{collision.rb → proto/collision.pb.rb} +0 -0
  45. data/test/{ext_collision.rb → proto/ext_collision.pb.rb} +1 -1
  46. data/test/{ext_range.rb → proto/ext_range.pb.rb} +4 -4
  47. data/test/proto/ext_range.proto +2 -2
  48. data/test/proto/float_default.proto +10 -0
  49. data/test/proto/lowercase.pb.rb +31 -0
  50. data/test/proto/lowercase.proto +9 -0
  51. data/test/{merge.rb → proto/merge.pb.rb} +2 -2
  52. data/test/proto/nested.pb.rb +31 -0
  53. data/test/proto/nested.proto +2 -0
  54. data/test/proto/optional_field.pb.rb +36 -0
  55. data/test/proto/optional_field.proto +12 -0
  56. data/test/proto/packed.pb.rb +23 -0
  57. data/test/proto/packed.proto +6 -0
  58. data/test/{types.rb → proto/types.pb.rb} +43 -1
  59. data/test/test_addressbook.rb +30 -17
  60. data/test/test_compiler.rb +79 -78
  61. data/test/test_descriptor.rb +12 -12
  62. data/test/test_enum_value.rb +41 -0
  63. data/test/test_extension.rb +10 -14
  64. data/test/test_lowercase.rb +11 -0
  65. data/test/test_message.rb +44 -41
  66. data/test/test_optional_field.rb +61 -38
  67. data/test/test_packed_field.rb +40 -0
  68. data/test/test_parse.rb +8 -8
  69. data/test/test_repeated_types.rb +29 -3
  70. data/test/test_serialize.rb +12 -12
  71. data/test/test_standard_message.rb +30 -30
  72. data/test/test_types.rb +95 -95
  73. metadata +69 -39
  74. data/test/addressbook.rb +0 -98
  75. data/test/addressbook_base.rb +0 -62
  76. data/test/addressbook_ext.rb +0 -12
  77. data/test/nested.rb +0 -25
  78. data/test/test_ruby_protobuf.rb +0 -1
data/History.txt CHANGED
@@ -1,5 +1,14 @@
1
- === 0.3.3 / 2009-07-10
1
+ === 0.4.1 / 2010-04-30
2
2
 
3
+ * 0.4.1
4
+ * Switched to 'jeweler'.
5
+ * 0.4.0 alpha
6
+ * Change coding styles.
7
+ * Support packed repeated field.
8
+ * Incompatibility issues.
9
+ * Use camel case for a generated module name.
10
+ * Internal API changes.
11
+ * Enum values.
3
12
  * 0.3.3 (rev.218)
4
13
  * Support C-like comment.
5
14
  * Optimize for speed.
@@ -17,4 +26,3 @@
17
26
  * 0.1.0 fixed a small bug
18
27
  * 0.0.1 major enhancement
19
28
  * Birthday!
20
-
data/Manifest.txt CHANGED
@@ -2,12 +2,14 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- script/mk_parser
5
+ TODO
6
6
  bin/rprotoc
7
- examples/addressbook.proto
8
7
  examples/addressbook.pb.rb
8
+ examples/addressbook.proto
9
9
  examples/reading_a_message.rb
10
10
  examples/writing_a_message.rb
11
+ lib/protobuf/common/exceptions.rb
12
+ lib/protobuf/common/util.rb
11
13
  lib/protobuf/common/wire_type.rb
12
14
  lib/protobuf/compiler/compiler.rb
13
15
  lib/protobuf/compiler/nodes.rb
@@ -37,38 +39,50 @@ lib/protobuf/rpc/client.rb
37
39
  lib/protobuf/rpc/handler.rb
38
40
  lib/protobuf/rpc/server.rb
39
41
  lib/ruby_protobuf.rb
40
- test/addressbook.rb
41
- test/addressbook_base.rb
42
- test/addressbook_ext.rb
42
+ script/mk_parser
43
43
  test/check_unbuild.rb
44
- test/collision.rb
45
44
  test/data/data.bin
46
45
  test/data/data_source.py
47
46
  test/data/types.bin
48
47
  test/data/types_source.py
49
48
  test/data/unk.png
50
- test/ext_collision.rb
51
- test/ext_range.rb
52
- test/merge.rb
53
- test/nested.rb
49
+ test/proto/addressbook.pb.rb
54
50
  test/proto/addressbook.proto
51
+ test/proto/addressbook_base.pb.rb
55
52
  test/proto/addressbook_base.proto
53
+ test/proto/addressbook_ext.pb.rb
56
54
  test/proto/addressbook_ext.proto
55
+ test/proto/collision.pb.rb
57
56
  test/proto/collision.proto
57
+ test/proto/ext_collision.pb.rb
58
58
  test/proto/ext_collision.proto
59
+ test/proto/ext_range.pb.rb
59
60
  test/proto/ext_range.proto
61
+ test/proto/float_default.proto
62
+ test/proto/lowercase.pb.rb
63
+ test/proto/lowercase.proto
64
+ test/proto/merge.pb.rb
60
65
  test/proto/merge.proto
66
+ test/proto/nested.pb.rb
61
67
  test/proto/nested.proto
68
+ test/proto/optional_field.pb.rb
69
+ test/proto/optional_field.proto
70
+ test/proto/packed.pb.rb
71
+ test/proto/packed.proto
62
72
  test/proto/rpc.proto
73
+ test/proto/types.pb.rb
63
74
  test/proto/types.proto
64
75
  test/test_addressbook.rb
65
76
  test/test_compiler.rb
66
77
  test/test_descriptor.rb
78
+ test/test_enum_value.rb
67
79
  test/test_extension.rb
80
+ test/test_lowercase.rb
68
81
  test/test_message.rb
82
+ test/test_optional_field.rb
83
+ test/test_packed_field.rb
69
84
  test/test_parse.rb
70
- test/test_ruby_protobuf.rb
85
+ test/test_repeated_types.rb
71
86
  test/test_serialize.rb
72
87
  test/test_standard_message.rb
73
88
  test/test_types.rb
74
- test/types.rb
data/README.txt CHANGED
@@ -24,11 +24,16 @@ Protocol Buffers for Ruby.
24
24
 
25
25
  * sudo gem install ruby_protobuf
26
26
 
27
+ == AUTHORS:
28
+
29
+ MATSUYAMA Kengo <macksx@gmail.com>
30
+ ANDO Yasushi <andyjpn@gmail.com>
31
+
27
32
  == LICENSE:
28
33
 
29
34
  (The MIT License)
30
35
 
31
- Copyright (c) 2008 FIX
36
+ Copyright (c) 2008 ANDO Yasushi
32
37
 
33
38
  Permission is hereby granted, free of charge, to any person obtaining
34
39
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,18 +1,55 @@
1
- # -*- ruby -*-
2
-
3
- $:.push(File.dirname(__FILE__) + '/lib')
4
1
  require 'rubygems'
5
- require 'hoe'
6
- require 'ruby_protobuf'
7
-
8
- Hoe.spec('ruby_protobuf') do |p|
9
- p.version = RubyProtobuf::VERSION
10
- p.rubyforge_name = 'ruby-protobuf'
11
- p.developer('MATSUYAMA Kengo', 'macksx@gmail.com')
12
- p.summary = 'Protocol Buffers for Ruby'
13
- p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
14
- p.url = 'http://code.google.com/p/ruby-protobuf'
15
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruby_protobuf"
8
+ gem.summary = %Q{Protocol Buffers for Ruby}
9
+ gem.description = %Q{Ruby implementation for Protocol Buffers.}
10
+ gem.email = "macksx@gmail.com"
11
+ gem.homepage = "http://code.google.com/p/ruby-protobuf"
12
+ gem.authors = ["MATSUYAMA Kengo"]
13
+ #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ruby_protobuf #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
53
  end
17
54
 
18
55
  # vim: syntax=ruby
data/TODO ADDED
@@ -0,0 +1,15 @@
1
+ TODO
2
+
3
+ * Documents
4
+ * RDoc.
5
+ * Compiler
6
+ * Identifier names.
7
+ * Check validity for default value. (Enum class)
8
+ * Encoder/Decoder
9
+ * Unknown fields.
10
+ * Implementation
11
+ * DynamicMessage class.
12
+ * Improve descriptor.
13
+ * Rewrite extension fields.
14
+ * Tests
15
+ * RPC tests.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.1
data/bin/rprotoc CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'optparse'
3
- if File.exist? "#{File.dirname(__FILE__)}/../lib"
4
+
5
+ if File.directory?("#{File.dirname(__FILE__)}/../lib")
4
6
  $: << "#{File.dirname(__FILE__)}/../lib"
5
7
  else
6
8
  require 'rubygems'
@@ -10,17 +12,20 @@ require 'ruby_protobuf'
10
12
  require 'protobuf/compiler/compiler'
11
13
 
12
14
 
13
- options = {}
15
+ options = {
16
+ :proto_path => '.',
17
+ :out => '.',
18
+ }
14
19
  opts = OptionParser.new("#{$0} [OPTIONS] PROTO_FILE")
15
20
  opts.on('-p', '--proto_path <PATH>', 'Specify the directory in which to search for imports. The current directory is default.'){|v| options[:proto_path] = v}
16
21
  opts.on('-o', '--out <OUT_DIR>', 'Specify the directory in which Ruby source file is generated. The current directory is default.'){|v| options[:out] = v}
17
- opts.on_tail('-v', '--version', 'Show version.'){puts(opts.ver); exit}
18
- opts.on_tail('-h', '--help', 'Show this message.'){puts(opts.help); exit}
22
+ opts.on_tail('-v', '--version', 'Show version.'){ puts(opts.ver); exit }
23
+ opts.on_tail('-h', '--help', 'Show this message.'){ puts(opts.help); exit }
19
24
 
20
25
  ::Version = RubyProtobuf::VERSION
21
26
 
22
27
  begin
23
- opts.order! ARGV
28
+ opts.order!
24
29
  rescue OptionParser::ParseError
25
30
  $stderr.puts $!.to_s
26
31
  exit 1
@@ -33,4 +38,4 @@ unless proto_file
33
38
  exit
34
39
  end
35
40
 
36
- Protobuf::Compiler.compile(proto_file, (options[:proto_path] or '.'), (options[:out] or '.'))
41
+ Protobuf::Compiler.compile(proto_file, options[:proto_path], options[:out])
@@ -0,0 +1,11 @@
1
+ module Protobuf
2
+
3
+ class Error < StandardError; end
4
+
5
+ class InvalidWireType < Error; end
6
+
7
+ class NotInitializedError < Error; end
8
+
9
+ class TagCollisionError < Error; end
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ module Protobuf
2
+ module Util
3
+ module_function
4
+
5
+ def camelize(name)
6
+ name.to_s.gsub(/(?:\A|_)(\w)/) { $1.upcase }
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,10 @@
1
1
  module Protobuf
2
- class WireType
3
- VARINT = 0
4
- FIXED64 = 1
2
+ module WireType
3
+ VARINT = 0
4
+ FIXED64 = 1
5
5
  LENGTH_DELIMITED = 2
6
- START_GROUP = 3
7
- END_GROUP = 4
8
- FIXED32 = 5
6
+ START_GROUP = 3
7
+ END_GROUP = 4
8
+ FIXED32 = 5
9
9
  end
10
10
  end
@@ -6,45 +6,45 @@ require 'protobuf/compiler/visitors'
6
6
  module Protobuf
7
7
  class Compiler
8
8
  def self.compile(proto_file, proto_dir='.', out_dir='.', file_create=true)
9
- self.new.compile proto_file, proto_dir, out_dir, file_create
9
+ self.new.compile(proto_file, proto_dir, out_dir, file_create)
10
10
  end
11
11
 
12
12
  def compile(proto_file, proto_dir='.', out_dir='.', file_create=true)
13
- create_message proto_file, proto_dir, out_dir, file_create
14
- create_rpc proto_file, proto_dir, out_dir, file_create
13
+ create_message(proto_file, proto_dir, out_dir, file_create)
14
+ create_rpc(proto_file, proto_dir, out_dir, file_create)
15
15
  end
16
16
 
17
17
  def create_message(proto_file, proto_dir='.', out_dir='.', file_create=true)
18
18
  rb_file = File.join(out_dir, File.basename(proto_file).sub(/\.[^\0]*\z/, '') + '.pb.rb')
19
- proto_path = validate_existence proto_file, proto_dir
19
+ proto_path = validate_existence(proto_file, proto_dir)
20
20
 
21
- message_visitor = Protobuf::Visitor::CreateMessageVisitor.new proto_file, proto_dir, out_dir
22
- File.open proto_path, 'r' do |file|
23
- message_visitor.visit Protobuf::ProtoParser.new.parse(file)
21
+ message_visitor = Visitor::CreateMessageVisitor.new(proto_file, proto_dir, out_dir)
22
+ File.open(proto_path) do |file|
23
+ message_visitor.visit(ProtoParser.new.parse(file))
24
24
  end
25
- message_visitor.create_files rb_file, out_dir, file_create
25
+ message_visitor.create_files(rb_file, out_dir, file_create)
26
26
  end
27
27
 
28
28
  def create_rpc(proto_file, proto_dir='.', out_dir='.', file_create=true)
29
29
  message_file = File.join(out_dir, File.basename(proto_file).sub(/\.[^\0]*\z/, '') + '.pb.rb')
30
- proto_path = validate_existence proto_file, proto_dir
30
+ proto_path = validate_existence(proto_file, proto_dir)
31
31
 
32
- rpc_visitor = Protobuf::Visitor::CreateRpcVisitor.new
33
- File.open proto_path, 'r' do |file|
34
- rpc_visitor.visit Protobuf::ProtoParser.new.parse(file)
32
+ rpc_visitor = Visitor::CreateRpcVisitor.new
33
+ File.open(proto_path) do |file|
34
+ rpc_visitor.visit(ProtoParser.new.parse(file))
35
35
  end
36
- rpc_visitor.create_files message_file, out_dir, file_create
36
+ rpc_visitor.create_files(message_file, out_dir, file_create)
37
37
  end
38
38
 
39
39
  def validate_existence(path, base_dir)
40
- if File.exist? path
40
+ if File.exist?(path)
41
41
  path
42
42
  else
43
43
  newpath = File.join(base_dir, path)
44
- if File.exist? newpath
44
+ if File.exist?(newpath)
45
45
  newpath
46
46
  else
47
- raise ArgumentError.new("File does not exist: #{path}")
47
+ raise ArgumentError, "File does not exist: #{path}"
48
48
  end
49
49
  end
50
50
  end
@@ -1,10 +1,11 @@
1
+ require 'protobuf/common/util'
1
2
  require 'protobuf/descriptor/descriptor_proto'
2
3
 
3
4
  module Protobuf
4
5
  module Node
5
6
  class Base
6
7
  def define_in_the_file(visitor)
7
- visitor.write "defined_in __FILE__" if visitor.attach_proto?
8
+ visitor.write("defined_in __FILE__") if visitor.attach_proto?
8
9
  end
9
10
 
10
11
  def accept_message_visitor(visitor)
@@ -16,48 +17,48 @@ module Protobuf
16
17
  def accept_descriptor_visitor(visitor)
17
18
  end
18
19
  end
19
-
20
+
20
21
  class ProtoNode < Base
21
22
  attr_reader :children
22
23
 
23
24
  def initialize(children)
24
- @children = children
25
+ @children = children || []
25
26
  end
26
27
 
27
28
  def accept_message_visitor(visitor)
28
- visitor.write '### Generated by rprotoc. DO NOT EDIT!'
29
- visitor.write "### <proto file: #{visitor.proto_file}>" if visitor.attach_proto?
30
- visitor.write visitor.commented_proto_contents if visitor.attach_proto?
31
- visitor.write <<-eos
29
+ visitor.write('### Generated by rprotoc. DO NOT EDIT!')
30
+ visitor.write("### <proto file: #{visitor.proto_file}>") if visitor.attach_proto?
31
+ visitor.write(visitor.commented_proto_contents) if visitor.attach_proto?
32
+ visitor.write(<<-EOS)
32
33
  require 'protobuf/message/message'
33
34
  require 'protobuf/message/enum'
34
35
  require 'protobuf/message/service'
35
36
  require 'protobuf/message/extend'
36
- eos
37
- @children.map{|child| child.accept_message_visitor visitor}
37
+ EOS
38
+ @children.each {|child| child.accept_message_visitor(visitor) }
38
39
  visitor.close_ruby
39
40
  end
40
41
 
41
42
  def accept_rpc_visitor(visitor)
42
- @children.map{|child| child.accept_rpc_visitor visitor}
43
+ @children.each {|child| child.accept_rpc_visitor(visitor) }
43
44
  end
44
45
 
45
46
  def accept_descriptor_visitor(visitor)
46
- descriptor = Google::Protobuf::FileDescriptorProto.new :name => visitor.filename
47
+ descriptor = Google::Protobuf::FileDescriptorProto.new(:name => visitor.filename)
47
48
  visitor.file_descriptor = descriptor
48
- visitor.in_context descriptor do
49
- @children.map{|child| child.accept_descriptor_visitor visitor}
49
+ visitor.in_context(descriptor) do
50
+ @children.each {|child| child.accept_descriptor_visitor(visitor) }
50
51
  end
51
52
  end
52
53
  end
53
-
54
+
54
55
  class ImportNode < Base
55
56
  def initialize(path)
56
57
  @path = path
57
58
  end
58
59
 
59
60
  def accept_message_visitor(visitor)
60
- visitor.write "require '#{visitor.required_message_from_proto @path}'"
61
+ visitor.write("require '#{visitor.required_message_from_proto(@path)}'")
61
62
  end
62
63
 
63
64
  def accept_descriptor_visitor(visitor)
@@ -72,7 +73,7 @@ require 'protobuf/message/extend'
72
73
 
73
74
  def accept_message_visitor(visitor)
74
75
  @path_list.each do |path|
75
- visitor.write "module #{path.to_s.capitalize}"
76
+ visitor.write("module #{Util.camelize(path)}")
76
77
  visitor.increment
77
78
  end
78
79
  end
@@ -82,7 +83,7 @@ require 'protobuf/message/extend'
82
83
  end
83
84
 
84
85
  def accept_descriptor_visitor(visitor)
85
- visitor.current_descriptor.package = @path_list.join '.'
86
+ visitor.current_descriptor.package = @path_list.join('.')
86
87
  end
87
88
  end
88
89
 
@@ -92,11 +93,11 @@ require 'protobuf/message/extend'
92
93
  end
93
94
 
94
95
  def accept_message_visitor(visitor)
95
- visitor.write "::Protobuf::OPTIONS[:#{@name_list.join('.').inspect}] = #{@value.inspect}"
96
+ visitor.write("::Protobuf::OPTIONS[:#{@name_list.join('.').inspect}] = #{@value.inspect}")
96
97
  end
97
98
 
98
99
  def accept_descriptor_visitor(visitor)
99
- visitor.add_option @name_list.join('.'), @value
100
+ visitor.add_option(@name_list.join('.'), @value)
100
101
  end
101
102
  end
102
103
 
@@ -108,21 +109,19 @@ require 'protobuf/message/extend'
108
109
  def accept_message_visitor(visitor)
109
110
  class_name = @name.to_s
110
111
  class_name.gsub!(/\A[a-z]/) {|c| c.upcase}
111
- visitor.write "class #{class_name} < ::Protobuf::Message"
112
- visitor.in_context self.class do
113
- define_in_the_file visitor
114
- #@children.each {|child| child.accept_message_visitor visitor}
115
- @children.each {|child| next if child == ';'; child.accept_message_visitor visitor}
116
- # TODO: `next if child == ';';' is a monky patching. There must be a parser error.
112
+ visitor.write("class #{class_name} < ::Protobuf::Message")
113
+ visitor.in_context(self.class) do
114
+ define_in_the_file(visitor)
115
+ @children.each {|child| child.accept_message_visitor(visitor) }
117
116
  end
118
- visitor.write "end"
117
+ visitor.write('end')
119
118
  end
120
119
 
121
120
  def accept_descriptor_visitor(visitor)
122
- descriptor = Google::Protobuf::DescriptorProto.new :name => @name.to_s
121
+ descriptor = Google::Protobuf::DescriptorProto.new(:name => @name.to_s)
123
122
  visitor.descriptor = descriptor
124
- visitor.in_context descriptor do
125
- @children.each {|child| child.accept_descriptor_visitor visitor}
123
+ visitor.in_context(descriptor) do
124
+ @children.each {|child| child.accept_descriptor_visitor(visitor) }
126
125
  end
127
126
  end
128
127
  end
@@ -134,12 +133,12 @@ require 'protobuf/message/extend'
134
133
 
135
134
  def accept_message_visitor(visitor)
136
135
  name = @name.is_a?(Array) ? @name.join : name.to_s
137
- visitor.write "class #{name} < ::Protobuf::Message"
138
- visitor.in_context self.class do
139
- define_in_the_file visitor
140
- @children.each {|child| child.accept_message_visitor visitor}
136
+ visitor.write("class #{name} < ::Protobuf::Message")
137
+ visitor.in_context(self.class) do
138
+ define_in_the_file(visitor)
139
+ @children.each {|child| child.accept_message_visitor(visitor) }
141
140
  end
142
- visitor.write "end"
141
+ visitor.write('end')
143
142
  end
144
143
 
145
144
  def accept_descriptor_visitor(visitor)
@@ -153,19 +152,19 @@ require 'protobuf/message/extend'
153
152
  end
154
153
 
155
154
  def accept_message_visitor(visitor)
156
- visitor.write "class #{@name} < ::Protobuf::Enum"
157
- visitor.in_context self.class do
158
- define_in_the_file visitor
159
- @children.each {|child| child.accept_message_visitor visitor}
155
+ visitor.write("class #{@name} < ::Protobuf::Enum")
156
+ visitor.in_context(self.class) do
157
+ define_in_the_file(visitor)
158
+ @children.each {|child| child.accept_message_visitor(visitor) }
160
159
  end
161
- visitor.write "end"
160
+ visitor.write('end')
162
161
  end
163
162
 
164
163
  def accept_descriptor_visitor(visitor)
165
- descriptor = Google::Protobuf::EnumDescriptorProto.new :name => @name.to_s
164
+ descriptor = Google::Protobuf::EnumDescriptorProto.new(:name => @name.to_s)
166
165
  visitor.enum_descriptor = descriptor
167
- visitor.in_context descriptor do
168
- @children.each {|child| child.accept_descriptor_visitor visitor}
166
+ visitor.in_context(descriptor) do
167
+ @children.each {|child| child.accept_descriptor_visitor(visitor) }
169
168
  end
170
169
  end
171
170
  end
@@ -176,11 +175,11 @@ require 'protobuf/message/extend'
176
175
  end
177
176
 
178
177
  def accept_message_visitor(visitor)
179
- visitor.write "#{@name} = #{@value}"
178
+ visitor.write("define :#{@name}, #{@value}")
180
179
  end
181
180
 
182
181
  def accept_descriptor_visitor(visitor)
183
- descriptor = Google::Protobuf::EnumValueDescriptorProto.new :name => @name.to_s, :number => @value
182
+ descriptor = Google::Protobuf::EnumValueDescriptorProto.new(:name => @name.to_s, :number => @value)
184
183
  visitor.enum_value_descriptor = descriptor
185
184
  end
186
185
  end
@@ -196,14 +195,14 @@ require 'protobuf/message/extend'
196
195
 
197
196
  def accept_rpc_visitor(visitor)
198
197
  visitor.current_service = @name
199
- @children.each {|child| child.accept_rpc_visitor visitor}
198
+ @children.each {|child| child.accept_rpc_visitor(visitor) }
200
199
  end
201
200
 
202
201
  def accept_descriptor_visitor(visitor)
203
- descriptor = Google::Protobuf::ServiceDescriptorProto.new :name => @name.to_s
202
+ descriptor = Google::Protobuf::ServiceDescriptorProto.new(:name => @name.to_s)
204
203
  visitor.service_descriptor = descriptor
205
- visitor.in_context descriptor do
206
- @children.each {|child| child.accept_descriptor_visitor visitor}
204
+ visitor.in_context(descriptor) do
205
+ @children.each {|child| child.accept_descriptor_visitor(visitor) }
207
206
  end
208
207
  end
209
208
  end
@@ -218,11 +217,11 @@ require 'protobuf/message/extend'
218
217
  end
219
218
 
220
219
  def accept_rpc_visitor(visitor)
221
- visitor.add_rpc @name, @request, @response
220
+ visitor.add_rpc(@name, @request, @response)
222
221
  end
223
222
 
224
223
  def accept_descriptor_visitor(visitor)
225
- descriptor = Google::Protobuf::MethodDescriptorProto.new :name => @name.to_s, :input_type => @request.to_s, :output_type => @response.to_s
224
+ descriptor = Google::Protobuf::MethodDescriptorProto.new(:name => @name.to_s, :input_type => @request.to_s, :output_type => @response.to_s)
226
225
  visitor.method_descriptor = descriptor
227
226
  end
228
227
  end
@@ -233,11 +232,11 @@ require 'protobuf/message/extend'
233
232
  end
234
233
 
235
234
  def accept_message_visitor(visitor)
236
- raise NotImplementedError.new
235
+ raise NotImplementedError
237
236
  end
238
237
 
239
238
  def accept_descriptor_visitor(visitor)
240
- raise NotImplementedError.new
239
+ raise NotImplementedError
241
240
  end
242
241
  end
243
242
 
@@ -248,20 +247,20 @@ require 'protobuf/message/extend'
248
247
 
249
248
  def accept_message_visitor(visitor)
250
249
  opts = @opts.empty? ? '' : ", #{@opts.map{|k, v| ":#{k} => #{v.inspect}" }.join(', ')}"
251
- if visitor.context.first == Protobuf::Node::ExtendNode
252
- opts += ', :extension => true'
250
+ if visitor.context.first == ExtendNode
251
+ opts << ', :extension => true'
253
252
  end
254
253
  type = if @type.is_a?(Array)
255
254
  then (@type.size > 1) ? "'#{@type.join '::'}'" : @type[0]
256
255
  else @type
257
256
  end
258
- visitor.write "#{@label} :#{type}, :#{@name}, #{@value}#{opts}"
257
+ visitor.write("#{@label} :#{type}, :#{@name}, #{@value}#{opts}")
259
258
  end
260
259
 
261
260
  def accept_descriptor_visitor(visitor)
262
- descriptor = Google::Protobuf::FieldDescriptorProto.new :name => @name.to_s, :number => @value
263
- descriptor.label = Google::Protobuf::FieldDescriptorProto::Label.const_get "LABEL_#{@label.to_s.upcase}"
264
- descriptor.type = Google::Protobuf::FieldDescriptorProto::Type.const_get "TYPE_#{@type.to_s.upcase}" if predefined_type?
261
+ descriptor = Google::Protobuf::FieldDescriptorProto.new(:name => @name.to_s, :number => @value)
262
+ descriptor.label = Google::Protobuf::FieldDescriptorProto::Label.const_get("LABEL_#{@label.to_s.upcase}")
263
+ descriptor.type = Google::Protobuf::FieldDescriptorProto::Type.const_get("TYPE_#{@type.to_s.upcase}") if predefined_type?
265
264
  descriptor.type_name = @type.is_a?(Array) ? @type.join : @type.to_s
266
265
  @opts.each do |key, val|
267
266
  case key.to_sym
@@ -272,8 +271,11 @@ require 'protobuf/message/extend'
272
271
  visitor.field_descriptor = descriptor
273
272
  end
274
273
 
274
+ private
275
+
275
276
  def predefined_type?
276
- %w{double float int64 uint64 int32 fixed64 fixed32 bool string group message bytes uint32 enum sfixed32 sfixed64 sint32 sint64}.include? @type.to_s
277
+ # TODO: constantize
278
+ %w{double float int64 uint64 int32 fixed64 fixed32 bool string group message bytes uint32 enum sfixed32 sfixed64 sint32 sint64}.include?(@type.to_s)
277
279
  end
278
280
  end
279
281
 
@@ -283,15 +285,15 @@ require 'protobuf/message/extend'
283
285
  end
284
286
 
285
287
  def accept_message_visitor(visitor)
286
- visitor.write "extensions #{@range.first.to_s}"
288
+ visitor.write("extensions #{@range.first.to_s}")
287
289
  end
288
290
 
289
291
  def accept_descriptor_visitor(visitor)
290
- descriptor = Google::Protobuf::DescriptorProto::ExtensionRange.new :start => @range.first.low
292
+ descriptor = Google::Protobuf::DescriptorProto::ExtensionRange.new(:start => @range.first.low)
291
293
  case @range.first.high
292
- when NilClass; # ignore
293
- when :max; descriptor.end = 1
294
- else; descriptor.end = @range.first.high
294
+ when NilClass then # ignore
295
+ when :max then descriptor.end = 1
296
+ else descriptor.end = @range.first.high
295
297
  end
296
298
  visitor.extension_range_descriptor = descriptor
297
299
  end
@@ -306,7 +308,7 @@ require 'protobuf/message/extend'
306
308
 
307
309
  #def accept_message_visitor(visitor)
308
310
  #end
309
-
311
+
310
312
  def to_s
311
313
  if @high.nil?
312
314
  @low.to_s