protobuf 1.4.2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +4 -0
  2. data/Rakefile +7 -7
  3. data/bin/rpc_server +2 -188
  4. data/bin/rprotoc +44 -38
  5. data/examples/addressbook.pb.rb +2 -2
  6. data/ext/Makefile +11 -0
  7. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
  8. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
  9. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
  10. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
  11. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
  12. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
  13. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
  14. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  15. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
  16. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
  17. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
  18. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
  19. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  20. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
  21. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
  22. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
  23. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
  24. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
  25. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
  26. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
  27. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
  28. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
  29. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
  30. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
  31. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
  32. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
  33. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
  34. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
  35. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
  36. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
  37. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
  38. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
  39. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
  40. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
  41. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
  42. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
  43. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
  44. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
  45. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
  46. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
  47. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
  48. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
  49. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
  50. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
  51. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
  52. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
  53. data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
  54. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
  55. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
  56. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
  57. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
  58. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
  59. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
  60. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
  61. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
  62. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
  63. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
  64. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
  65. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
  66. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
  67. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
  68. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
  69. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
  70. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
  71. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
  72. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
  73. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
  74. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
  75. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
  76. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
  77. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
  78. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
  79. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
  80. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
  81. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
  82. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
  83. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
  84. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
  85. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
  86. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
  87. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
  88. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
  89. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
  90. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
  91. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
  92. data/ext/ruby_generator/RubyGenerator.cpp +435 -0
  93. data/ext/ruby_generator/RubyGenerator.h +180 -0
  94. data/ext/ruby_generator/extconf.rb +24 -0
  95. data/lib/protobuf.rb +55 -33
  96. data/lib/protobuf/cli.rb +176 -0
  97. data/lib/protobuf/common/logger.rb +11 -11
  98. data/lib/protobuf/{message/enum.rb → enum.rb} +0 -10
  99. data/lib/protobuf/evented.rb +22 -0
  100. data/lib/protobuf/field.rb +57 -0
  101. data/lib/protobuf/field/base_field.rb +210 -0
  102. data/lib/protobuf/field/bool_field.rb +24 -0
  103. data/lib/protobuf/field/bytes_field.rb +38 -0
  104. data/lib/protobuf/field/double_field.rb +19 -0
  105. data/lib/protobuf/field/enum_field.rb +58 -0
  106. data/lib/protobuf/field/extension_fields.rb +24 -0
  107. data/lib/protobuf/field/field_array.rb +55 -0
  108. data/lib/protobuf/field/fixed32_field.rb +19 -0
  109. data/lib/protobuf/field/fixed64_field.rb +22 -0
  110. data/lib/protobuf/field/float_field.rb +29 -0
  111. data/lib/protobuf/field/int32_field.rb +10 -0
  112. data/lib/protobuf/field/int64_field.rb +10 -0
  113. data/lib/protobuf/field/integer_field.rb +19 -0
  114. data/lib/protobuf/field/message_field.rb +51 -0
  115. data/lib/protobuf/field/sfixed32_field.rb +21 -0
  116. data/lib/protobuf/field/sfixed64_field.rb +24 -0
  117. data/lib/protobuf/field/signed_integer_field.rb +23 -0
  118. data/lib/protobuf/field/sint32_field.rb +10 -0
  119. data/lib/protobuf/field/sint64_field.rb +10 -0
  120. data/lib/protobuf/field/string_field.rb +14 -0
  121. data/lib/protobuf/field/uint32_field.rb +10 -0
  122. data/lib/protobuf/field/uint64_field.rb +10 -0
  123. data/lib/protobuf/field/varint_field.rb +63 -0
  124. data/lib/protobuf/message.rb +376 -0
  125. data/lib/protobuf/message/message.rb +1 -475
  126. data/lib/protobuf/rpc/buffer.rb +1 -1
  127. data/lib/protobuf/rpc/client.rb +26 -26
  128. data/lib/protobuf/rpc/connector.rb +15 -14
  129. data/lib/protobuf/rpc/connectors/eventmachine.rb +13 -13
  130. data/lib/protobuf/rpc/rpc.pb.rb +39 -28
  131. data/lib/protobuf/rpc/server.rb +7 -28
  132. data/lib/protobuf/rpc/servers/evented_runner.rb +15 -15
  133. data/lib/protobuf/rpc/servers/socket/server.rb +2 -1
  134. data/lib/protobuf/rpc/servers/socket_runner.rb +5 -6
  135. data/lib/protobuf/rpc/servers/zmq_runner.rb +4 -5
  136. data/lib/protobuf/socket.rb +22 -0
  137. data/lib/protobuf/version.rb +2 -1
  138. data/lib/protobuf/zmq.rb +21 -0
  139. data/proto/rpc.pb.rb +48 -0
  140. data/protobuf.gemspec +14 -6
  141. data/spec/benchmark/tasks.rb +42 -23
  142. data/spec/functional/evented_server_spec.rb +2 -0
  143. data/spec/functional/socket_server_spec.rb +22 -26
  144. data/spec/functional/zmq_server_spec.rb +22 -26
  145. data/spec/lib/protobuf/cli_spec.rb +182 -0
  146. data/spec/{unit → lib/protobuf}/common/logger_spec.rb +0 -0
  147. data/spec/{unit → lib/protobuf/message}/enum_spec.rb +0 -0
  148. data/spec/{unit → lib/protobuf/message}/message_spec.rb +0 -0
  149. data/spec/{unit → lib/protobuf}/rpc/client_spec.rb +6 -4
  150. data/spec/lib/protobuf/rpc/connector_spec.rb +41 -0
  151. data/spec/{unit → lib/protobuf}/rpc/connectors/base_spec.rb +18 -18
  152. data/spec/{unit → lib/protobuf}/rpc/connectors/common_spec.rb +20 -20
  153. data/spec/{unit → lib/protobuf}/rpc/connectors/socket_spec.rb +9 -8
  154. data/spec/{unit → lib/protobuf}/rpc/connectors/zmq_spec.rb +1 -1
  155. data/spec/{unit → lib/protobuf}/rpc/servers/evented_server_spec.rb +4 -4
  156. data/spec/{unit → lib/protobuf}/rpc/servers/socket_server_spec.rb +11 -23
  157. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/broker_spec.rb +5 -0
  158. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/server_spec.rb +5 -0
  159. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/util_spec.rb +5 -0
  160. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/worker_spec.rb +5 -0
  161. data/spec/{unit → lib/protobuf}/rpc/service_spec.rb +0 -0
  162. data/spec/proto/test.pb.rb +48 -25
  163. data/spec/spec_helper.rb +9 -15
  164. data/spec/support/all.rb +7 -0
  165. data/spec/{helper → support}/server.rb +5 -7
  166. data/spec/{helper → support}/silent_constants.rb +4 -0
  167. data/spec/support/test_app_file.rb +2 -0
  168. data/spec/{helper → support}/tolerance_matcher.rb +0 -0
  169. data/test/proto/types.pb.rb +1 -1
  170. data/test/test_addressbook.rb +1 -1
  171. data/test/test_enum_value.rb +1 -1
  172. data/test/test_standard_message.rb +1 -1
  173. metadata +243 -107
  174. data/lib/protobuf/common/util.rb +0 -59
  175. data/lib/protobuf/compiler/compiler.rb +0 -52
  176. data/lib/protobuf/compiler/nodes.rb +0 -323
  177. data/lib/protobuf/compiler/proto.y +0 -216
  178. data/lib/protobuf/compiler/proto2.ebnf +0 -79
  179. data/lib/protobuf/compiler/proto_parser.rb +0 -1425
  180. data/lib/protobuf/compiler/template/rpc_service_implementation.erb +0 -42
  181. data/lib/protobuf/compiler/visitors.rb +0 -282
  182. data/lib/protobuf/descriptor/descriptor.proto +0 -286
  183. data/lib/protobuf/descriptor/descriptor.rb +0 -55
  184. data/lib/protobuf/descriptor/descriptor_builder.rb +0 -143
  185. data/lib/protobuf/descriptor/descriptor_proto.rb +0 -138
  186. data/lib/protobuf/descriptor/enum_descriptor.rb +0 -33
  187. data/lib/protobuf/descriptor/field_descriptor.rb +0 -49
  188. data/lib/protobuf/descriptor/file_descriptor.rb +0 -37
  189. data/lib/protobuf/message/field.rb +0 -684
  190. data/lib/protobuf/message/protoable.rb +0 -38
  191. data/spec/helper/all.rb +0 -7
  192. data/spec/unit/common/util_spec.rb +0 -17
  193. data/spec/unit/rpc/connector_spec.rb +0 -31
  194. data/spec/unit/rpc/connectors/eventmachine_client_spec.rb +0 -32
  195. data/spec/unit/rpc/connectors/eventmachine_spec.rb +0 -0
  196. data/test/check_unbuild.rb +0 -30
  197. data/test/test_compiler.rb +0 -325
  198. data/test/test_descriptor.rb +0 -122
@@ -1,42 +0,0 @@
1
- <%-
2
- module_array = module_name.split('::')
3
- class_indent = ' '*(module_array.size)
4
- -%>
5
- require 'protobuf/rpc/service'
6
- require '<%= required_file %>'
7
-
8
- ## !! DO NOT EDIT THIS FILE !!
9
- ##
10
- ## To implement this service as defined by the protobuf, simply
11
- ## reopen <%= module_name %>::<%= service_name %> and implement each service method:
12
- ##
13
- <%- module_array.each_with_index do |m, i| -%>
14
- ## <%= "#{"\t"*i}module #{m}" %>
15
- <%- end -%>
16
- ## <%= class_indent %>class <%= service_name %>
17
- ## <%= class_indent %>
18
- <%- rpcs.each do |name, request, response| -%>
19
- ## <%= class_indent %> # request -> <%= module_name %>::<%= request %>
20
- ## <%= class_indent %> # response -> <%= module_name %>::<%= response %>
21
- ## <%= class_indent %> def <%= Util.underscore(name) %>
22
- ## <%= class_indent %> # TODO: implement <%= Util.underscore(name) %>
23
- ## <%= class_indent %> end
24
- ## <%= class_indent %>
25
- <%- end -%>
26
- ## <%= class_indent %>end
27
- <%- (module_array.size-1).downto(0) do |i| -%>
28
- ## <%= "#{"\t"*i}end" %>
29
- <%- end -%>
30
- ##
31
-
32
- <%- module_array.each_with_index do |m, i| -%>
33
- <%= "#{"\t"*i}module #{m}" %>
34
- <%- end -%>
35
- <%= class_indent %>class <%= service_name %> < Protobuf::Rpc::Service
36
- <%- rpcs.each do |name, request, response| -%>
37
- <%= class_indent %> rpc :<%= Util.underscore(name) %>, <%= request %>, <%= response %>
38
- <%- end -%>
39
- <%= class_indent %>end
40
- <%- (module_array.size-1).downto(0) do |i| -%>
41
- <%= "#{"\t"*i}end" %>
42
- <%- end -%>
@@ -1,282 +0,0 @@
1
- require 'erb'
2
- require 'fileutils'
3
- require 'protobuf/descriptor/descriptor_proto'
4
-
5
- module Protobuf
6
- module Visitor
7
- class Base
8
- attr_reader :silent
9
-
10
- def create_file_with_backup(filename, contents, executable=false)
11
- if File.exist?(filename)
12
- if File.read(filename) == contents
13
- # do nothing
14
- return
15
- else
16
- backup_filename = "#{filename}.#{Time.now.to_i}"
17
- log_writing("#{backup_filename}", "backingup...")
18
- FileUtils.copy(filename, backup_filename)
19
- end
20
- end
21
-
22
- FileUtils.mkpath(File.dirname(filename))
23
- File.open(filename, 'w') do |file|
24
- log_writing(filename)
25
- file.write(contents)
26
- end
27
- FileUtils.chmod(0755, filename) if executable
28
- end
29
-
30
- def log_writing(filename, message="wrote")
31
- puts "#{message} #{filename}" unless silent
32
- end
33
- end
34
-
35
- class CreateMessageVisitor < Base
36
- attr_accessor :package, :indent, :context, :attach_proto, :proto_file
37
-
38
- def initialize(proto_file=nil, proto_dir='.', out_dir='.')
39
- @proto_dir, @out_dir = proto_dir, out_dir
40
- @indent = 0
41
- @context = []
42
- @attach_proto = false
43
- @proto_file = proto_file
44
- end
45
-
46
- def attach_proto?
47
- @attach_proto
48
- end
49
-
50
- def commented_proto_contents
51
- if proto_file
52
- proto_filepath = if File.exist?(proto_file)
53
- then proto_file
54
- else "#{@proto_dir}/#{proto_file}"
55
- end
56
- File.read(proto_filepath).gsub(/^/, '# ')
57
- end
58
- end
59
-
60
- def write(str)
61
- ruby << "#{' ' * @indent}#{str}"
62
- end
63
-
64
- def increment
65
- @indent += 1
66
- end
67
-
68
- def decrement
69
- @indent -= 1
70
- end
71
-
72
- def close_ruby
73
- while 0 < indent
74
- decrement
75
- write('end')
76
- end
77
- end
78
-
79
- def ruby
80
- @ruby ||= []
81
- end
82
-
83
- def to_s
84
- @ruby.join("\n")
85
- end
86
-
87
- def in_context(klass, &block)
88
- increment
89
- context.push klass
90
- block.call
91
- context.pop
92
- decrement
93
- end
94
-
95
- def visit(node)
96
- node.accept_message_visitor(self)
97
- self
98
- end
99
-
100
- def required_message_from_proto(proto_file)
101
- rb_path = [
102
- proto_file.sub(/\.proto\z/, '.pb.rb')
103
- ].join('/').gsub(/\/{2,}/, '/')
104
-
105
- unless File.exist?(rb_path)
106
- Compiler.compile(proto_file, @proto_dir, @out_dir)
107
- end
108
-
109
- rb_path.sub(/\.rb$/, '')
110
- end
111
-
112
- def create_files(filename, out_dir, file_create)
113
- $: << File.expand_path(out_dir)
114
- Class.new.class_eval(to_s) # check the message
115
- $:.delete File.expand_path(out_dir)
116
- rescue LoadError
117
- puts "Error creating file #{filename}"
118
- puts $!.message
119
- exit 1
120
- else
121
-
122
- file = File.basename(filename)
123
- message_module = Util.module_to_path(package.map{|p| p.to_s.capitalize}.join('::'))
124
- filename = "#{out_dir}/#{message_module}/#{file}"
125
-
126
- if file_create
127
- log_writing(filename)
128
- FileUtils.mkpath(File.dirname(filename))
129
- File.open(filename, 'w') {|file| file.write(to_s) }
130
- else
131
- to_s
132
- end
133
- end
134
- end
135
-
136
- class CreateRpcVisitor < Base
137
- attr_accessor :package, :services, :current_service, :file_contents
138
-
139
- def initialize
140
- @services = {}
141
- @create_file = true
142
- @file_contents = {}
143
- end
144
-
145
- def visit(node)
146
- node.accept_rpc_visitor(self)
147
- self
148
- end
149
-
150
- def add_rpc(name, request, response)
151
- (@services[@current_service] ||= []) << [name, Util.moduleize(request), Util.moduleize(response)]
152
- end
153
-
154
- def create_files(message_file, out_dir, create_file=true)
155
- @create_file = create_file
156
- @services.each do |service_name, rpcs|
157
- underscored_name = Util.underscore(service_name.to_s)
158
- message_module = package.map{|p| p.to_s.capitalize}.join('::')
159
- required_file = [
160
- Util.module_to_path(message_module),
161
- File.basename(message_file, '.rb')
162
- ].join('/').gsub(/\/{2,}/, '/')
163
-
164
- create_service(message_file, out_dir, underscored_name, message_module, service_name, rpcs, required_file)
165
- end
166
- @file_contents
167
- end
168
-
169
- def create_service(message_file, out_dir, underscored_name, module_name, service_name, rpcs, required_file)
170
- service_filename = "#{out_dir}/#{Util.module_to_path(module_name)}/#{underscored_name}.rb"
171
- service_contents = template_erb('rpc_service_implementation').result(binding)
172
- create_file_with_backup(service_filename, service_contents) if @create_file
173
- @file_contents[service_filename] = service_contents
174
- end
175
-
176
- private
177
-
178
- def template_erb(template)
179
- ERB.new(File.read("#{File.dirname(__FILE__)}/template/#{template}.erb"), nil, '-')
180
- end
181
- end
182
-
183
- class CreateDescriptorVisitor < Base
184
- attr_reader :file_descriptor
185
- attr_accessor :filename
186
-
187
- def initialize(filename=nil)
188
- @context = []
189
- @filename = filename
190
- end
191
-
192
- def visit(node)
193
- node.accept_descriptor_visitor(self)
194
- self
195
- end
196
-
197
- def in_context(descriptor, &block)
198
- @context.push descriptor
199
- block.call
200
- @context.pop
201
- end
202
-
203
- def current_descriptor
204
- @context.last
205
- end
206
-
207
- def file_descriptor=(descriptor)
208
- @file_descriptor = descriptor
209
- @file_descriptor.name = @filename
210
- end
211
-
212
- def add_option(name, value)
213
- options =
214
- case current_descriptor
215
- when Google::Protobuf::FileDescriptorProto then
216
- Google::Protobuf::FileOptions.new
217
- when Google::Protobuf::DescriptorProto then
218
- Google::Protobuf::MessageOptions.new
219
- when Google::Protobuf::FieldDescriptorProto then
220
- Google::Protobuf::FieldOptions.new
221
- when Google::Protobuf::EnumDescriptorProto then
222
- Google::Protobuf::EnumOptions.new
223
- when Google::Protobuf::EnumValueDescriptorProto then
224
- Google::Protobuf::EnumValueOptions.new
225
- when Google::Protobuf::ServiceDescriptorProto then
226
- Google::Protobuf::ServiceOptions.new
227
- when Google::Protobuf::MethodDescriptorProto then
228
- Google::Protobuf::MethodOptions.new
229
- else
230
- raise ArgumentError, 'Invalid context'
231
- end
232
- #TODO how should options be handled?
233
- #current_descriptor.options << option
234
- end
235
-
236
- def descriptor=(descriptor)
237
- case current_descriptor
238
- when Google::Protobuf::FileDescriptorProto then
239
- current_descriptor.message_type << descriptor
240
- when Google::Protobuf::DescriptorProto then
241
- current_descriptor.nested_type << descriptor
242
- else
243
- raise ArgumentError, 'Invalid context'
244
- end
245
- end
246
- alias message_descriptor= descriptor=
247
-
248
- def enum_descriptor=(descriptor)
249
- current_descriptor.enum_type << descriptor
250
- end
251
-
252
- def enum_value_descriptor=(descriptor)
253
- current_descriptor.value << descriptor
254
- end
255
-
256
- def service_descriptor=(descriptor)
257
- current_descriptor.service << descriptor
258
- end
259
-
260
- def method_descriptor=(descriptor)
261
- current_descriptor.method << descriptor
262
- end
263
-
264
- def field_descriptor=(descriptor)
265
- case current_descriptor
266
- when Google::Protobuf::FileDescriptorProto then
267
- current_descriptor.extension << descriptor
268
- when Google::Protobuf::DescriptorProto then
269
- current_descriptor.field << descriptor
270
- #TODO: how should i distiguish between field and extension
271
- #current_descriptor.extension << descriptor
272
- else
273
- raise ArgumentError, 'Invalid context'
274
- end
275
- end
276
-
277
- def extension_range_descriptor=(descriptor)
278
- current_descriptor.extension_range << descriptor
279
- end
280
- end
281
- end
282
- end
@@ -1,286 +0,0 @@
1
- // Protocol Buffers - Google's data interchange format
2
- // Copyright 2008 Google Inc.
3
- // http://code.google.com/p/protobuf/
4
- //
5
- // Licensed under the Apache License, Version 2.0 (the "License");
6
- // you may not use this file except in compliance with the License.
7
- // You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing, software
12
- // distributed under the License is distributed on an "AS IS" BASIS,
13
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- // See the License for the specific language governing permissions and
15
- // limitations under the License.
16
-
17
- // Author: kenton@google.com (Kenton Varda)
18
- // Based on original Protocol Buffers design by
19
- // Sanjay Ghemawat, Jeff Dean, and others.
20
- //
21
- // The messages in this file describe the definitions found in .proto files.
22
- // A valid .proto file can be translated directly to a FileDescriptorProto
23
- // without any other information (e.g. without reading its imports).
24
-
25
-
26
-
27
- package google.protobuf;
28
- option java_package = "com.google.protobuf";
29
- option java_outer_classname = "DescriptorProtos";
30
-
31
- // descriptor.proto must be optimized for speed because reflection-based
32
- // algorithms don't work during bootstrapping.
33
- option optimize_for = SPEED;
34
-
35
- // Describes a complete .proto file.
36
- message FileDescriptorProto {
37
- optional string name = 1; // file name, relative to root of source tree
38
- optional string package = 2; // e.g. "foo", "foo.bar", etc.
39
-
40
- // Names of files imported by this file.
41
- repeated string dependency = 3;
42
-
43
- // All top-level definitions in this file.
44
- repeated DescriptorProto message_type = 4;
45
- repeated EnumDescriptorProto enum_type = 5;
46
- repeated ServiceDescriptorProto service = 6;
47
- repeated FieldDescriptorProto extension = 7;
48
-
49
- optional FileOptions options = 8;
50
- }
51
-
52
- // Describes a message type.
53
- message DescriptorProto {
54
- optional string name = 1;
55
-
56
- repeated FieldDescriptorProto field = 2;
57
- repeated FieldDescriptorProto extension = 6;
58
-
59
- repeated DescriptorProto nested_type = 3;
60
- repeated EnumDescriptorProto enum_type = 4;
61
-
62
- message ExtensionRange {
63
- optional int32 start = 1;
64
- optional int32 end = 2;
65
- }
66
- repeated ExtensionRange extension_range = 5;
67
-
68
- optional MessageOptions options = 7;
69
- }
70
-
71
- // Describes a field within a message.
72
- message FieldDescriptorProto {
73
- enum Type {
74
- // 0 is reserved for errors.
75
- // Order is weird for historical reasons.
76
- TYPE_DOUBLE = 1;
77
- TYPE_FLOAT = 2;
78
- TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
79
- // take 10 bytes. Use TYPE_SINT64 if negative
80
- // values are likely.
81
- TYPE_UINT64 = 4;
82
- TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
83
- // take 10 bytes. Use TYPE_SINT32 if negative
84
- // values are likely.
85
- TYPE_FIXED64 = 6;
86
- TYPE_FIXED32 = 7;
87
- TYPE_BOOL = 8;
88
- TYPE_STRING = 9;
89
- TYPE_GROUP = 10; // Tag-delimited aggregate.
90
- TYPE_MESSAGE = 11; // Length-delimited aggregate.
91
-
92
- // New in version 2.
93
- TYPE_BYTES = 12;
94
- TYPE_UINT32 = 13;
95
- TYPE_ENUM = 14;
96
- TYPE_SFIXED32 = 15;
97
- TYPE_SFIXED64 = 16;
98
- TYPE_SINT32 = 17; // Uses ZigZag encoding.
99
- TYPE_SINT64 = 18; // Uses ZigZag encoding.
100
- };
101
-
102
- enum Label {
103
- // 0 is reserved for errors
104
- LABEL_OPTIONAL = 1;
105
- LABEL_REQUIRED = 2;
106
- LABEL_REPEATED = 3;
107
- // TODO(sanjay): Should we add LABEL_MAP?
108
- };
109
-
110
- optional string name = 1;
111
- optional int32 number = 3;
112
- optional Label label = 4;
113
-
114
- // If type_name is set, this need not be set. If both this and type_name
115
- // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
116
- optional Type type = 5;
117
-
118
- // For message and enum types, this is the name of the type. If the name
119
- // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
120
- // rules are used to find the type (i.e. first the nested types within this
121
- // message are searched, then within the parent, on up to the root
122
- // namespace).
123
- optional string type_name = 6;
124
-
125
- // For extensions, this is the name of the type being extended. It is
126
- // resolved in the same manner as type_name.
127
- optional string extendee = 2;
128
-
129
- // For numeric types, contains the original text representation of the value.
130
- // For booleans, "true" or "false".
131
- // For strings, contains the default text contents (not escaped in any way).
132
- // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
133
- // TODO(kenton): Base-64 encode?
134
- optional string default_value = 7;
135
-
136
- optional FieldOptions options = 8;
137
- }
138
-
139
- // Describes an enum type.
140
- message EnumDescriptorProto {
141
- optional string name = 1;
142
-
143
- repeated EnumValueDescriptorProto value = 2;
144
-
145
- optional EnumOptions options = 3;
146
- }
147
-
148
- // Describes a value within an enum.
149
- message EnumValueDescriptorProto {
150
- optional string name = 1;
151
- optional int32 number = 2;
152
-
153
- optional EnumValueOptions options = 3;
154
- }
155
-
156
- // Describes a service.
157
- message ServiceDescriptorProto {
158
- optional string name = 1;
159
- repeated MethodDescriptorProto method = 2;
160
-
161
- optional ServiceOptions options = 3;
162
- }
163
-
164
- // Describes a method of a service.
165
- message MethodDescriptorProto {
166
- optional string name = 1;
167
-
168
- // Input and output type names. These are resolved in the same way as
169
- // FieldDescriptorProto.type_name, but must refer to a message type.
170
- optional string input_type = 2;
171
- optional string output_type = 3;
172
-
173
- optional MethodOptions options = 4;
174
- }
175
-
176
- // ===================================================================
177
- // Options
178
-
179
- // Each of the definitions above may have "options" attached. These are
180
- // just annotations which may cause code to be generated slightly differently
181
- // or may contain hints for code that manipulates protocol messages.
182
-
183
- // TODO(kenton): Allow extensions to options.
184
-
185
- message FileOptions {
186
-
187
- // Sets the Java package where classes generated from this .proto will be
188
- // placed. By default, the proto package is used, but this is often
189
- // inappropriate because proto packages do not normally start with backwards
190
- // domain names.
191
- optional string java_package = 1;
192
-
193
-
194
- // If set, all the classes from the .proto file are wrapped in a single
195
- // outer class with the given name. This applies to both Proto1
196
- // (equivalent to the old "--one_java_file" option) and Proto2 (where
197
- // a .proto always translates to a single class, but you may want to
198
- // explicitly choose the class name).
199
- optional string java_outer_classname = 8;
200
-
201
- // If set true, then the Java code generator will generate a separate .java
202
- // file for each top-level message, enum, and service defined in the .proto
203
- // file. Thus, these types will *not* be nested inside the outer class
204
- // named by java_outer_classname. However, the outer class will still be
205
- // generated to contain the file's getDescriptor() method as well as any
206
- // top-level extensions defined in the file.
207
- optional bool java_multiple_files = 10 [default=false];
208
-
209
- // Generated classes can be optimized for speed or code size.
210
- enum OptimizeMode {
211
- SPEED = 1; // Generate complete code for parsing, serialization, etc.
212
- CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
213
- }
214
- optional OptimizeMode optimize_for = 9 [default=CODE_SIZE];
215
- }
216
-
217
- message MessageOptions {
218
- // Set true to use the old proto1 MessageSet wire format for extensions.
219
- // This is provided for backwards-compatibility with the MessageSet wire
220
- // format. You should not use this for any other reason: It's less
221
- // efficient, has fewer features, and is more complicated.
222
- //
223
- // The message must be defined exactly as follows:
224
- // message Foo {
225
- // option message_set_wire_format = true;
226
- // extensions 4 to max;
227
- // }
228
- // Note that the message cannot have any defined fields; MessageSets only
229
- // have extensions.
230
- //
231
- // All extensions of your type must be singular messages; e.g. they cannot
232
- // be int32s, enums, or repeated messages.
233
- //
234
- // Because this is an option, the above two restrictions are not enforced by
235
- // the protocol compiler.
236
- optional bool message_set_wire_format = 1 [default=false];
237
- }
238
-
239
- message FieldOptions {
240
- // The ctype option instructs the C++ code generator to use a different
241
- // representation of the field than it normally would. See the specific
242
- // options below. This option is not yet implemented in the open source
243
- // release -- sorry, we'll try to include it in a future version!
244
- optional CType ctype = 1;
245
- enum CType {
246
- CORD = 1;
247
-
248
- STRING_PIECE = 2;
249
- }
250
-
251
- // EXPERIMENTAL. DO NOT USE.
252
- // For "map" fields, the name of the field in the enclosed type that
253
- // is the key for this map. For example, suppose we have:
254
- // message Item {
255
- // required string name = 1;
256
- // required string value = 2;
257
- // }
258
- // message Config {
259
- // repeated Item items = 1 [experimental_map_key="name"];
260
- // }
261
- // In this situation, the map key for Item will be set to "name".
262
- // TODO: Fully-implement this, then remove the "experimental_" prefix.
263
- optional string experimental_map_key = 9;
264
- }
265
-
266
- message EnumOptions {
267
- }
268
-
269
- message EnumValueOptions {
270
- }
271
-
272
- message ServiceOptions {
273
-
274
- // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
275
- // framework. We apologize for hoarding these numbers to ourselves, but
276
- // we were already using them long before we decided to release Protocol
277
- // Buffers.
278
- }
279
-
280
- message MethodOptions {
281
-
282
- // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
283
- // framework. We apologize for hoarding these numbers to ourselves, but
284
- // we were already using them long before we decided to release Protocol
285
- // Buffers.
286
- }