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,55 +0,0 @@
1
- module Protobuf
2
- module Descriptor
3
- class Descriptor
4
- def initialize(message_class)
5
- @message_class = message_class
6
- end
7
-
8
- def proto_type
9
- 'Google::Protobuf::DescriptorProto'
10
- end
11
-
12
- def build(proto, opt={})
13
- mod = opt[:module]
14
- cls = mod.const_set(proto.name, Class.new(@message_class))
15
- proto.nested_type.each do |message_proto|
16
- Protobuf::Message.descriptor.build(message_proto, :module => cls)
17
- end
18
- proto.enum_type.each do |enum_proto|
19
- Protobuf::Enum.descriptor.build(enum_proto, :module => cls)
20
- end
21
- proto.field.each do |field_proto|
22
- Protobuf::Field::BaseField.descriptor.build(field_proto, :class => cls)
23
- end
24
- end
25
-
26
- def unbuild(parent_proto)
27
- message_proto = Google::Protobuf::DescriptorProto.new
28
- message_proto.name = @message_class.to_s.split('::').last
29
- @message_class.fields.each do |tag, field|
30
- field.descriptor.unbuild(message_proto)
31
- end
32
- ObjectSpace.each_object(Class) do |cls|
33
- if innerclass?(@message_class, cls)
34
- cls.descriptor.unbuild(message_proto)
35
- end
36
- end
37
-
38
- case parent_proto
39
- when Google::Protobuf::FileDescriptorProto
40
- parent_proto.message_type << message_proto
41
- when Google::Protobuf::DescriptorProto
42
- parent_proto.nested_type << message_proto
43
- else
44
- raise TypeError, parent_proto.class.name
45
- end
46
- end
47
-
48
- private
49
-
50
- def innerclass?(parent, child)
51
- child.name =~ /::/ && child.name.split('::')[0..-2].join('::') == parent.name
52
- end
53
- end
54
- end
55
- end
@@ -1,143 +0,0 @@
1
- require 'protobuf/descriptor/file_descriptor'
2
-
3
- module Protobuf
4
- module Descriptor
5
- def self.id2type(type_id)
6
- require 'protobuf/descriptor/descriptor_proto'
7
- case type_id
8
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE then
9
- :double
10
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT then
11
- :float
12
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64 then
13
- :int64
14
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64 then
15
- :unit64
16
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32 then
17
- :int64
18
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64 then
19
- :fixed64
20
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32 then
21
- :fixed32
22
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL then
23
- :bool
24
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING then
25
- :string
26
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP then
27
- :group
28
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE then
29
- :message
30
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES then
31
- :bytes
32
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32 then
33
- :uint32
34
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM then
35
- :enum
36
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32 then
37
- :sfixed32
38
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64 then
39
- :sfixed64
40
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32 then
41
- :sint32
42
- when Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64 then
43
- :sint64
44
- else
45
- raise ArgumentError, "Invalid type: #{proto.type}"
46
- end
47
- end
48
-
49
- def self.type2id(type)
50
- require 'protobuf/descriptor/descriptor_proto'
51
- case type
52
- when :double then
53
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_DOUBLE
54
- when :float then
55
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_FLOAT
56
- when :int64 then
57
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT64
58
- when :unit64 then
59
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT64
60
- when :int64 then
61
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_INT32
62
- when :fixed64 then
63
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED64
64
- when :fixed32 then
65
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_FIXED32
66
- when :bool then
67
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_BOOL
68
- when :string then
69
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING
70
- when :group then
71
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_GROUP
72
- when :message then
73
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE
74
- when :bytes then
75
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_BYTES
76
- when :uint32 then
77
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32
78
- when :enum then
79
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM
80
- when :sfixed32 then
81
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED32
82
- when :sfixed64 then
83
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_SFIXED64
84
- when :sint32 then
85
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT32
86
- when :sint64 then
87
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_SINT64
88
- else
89
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE
90
- end
91
- end
92
-
93
- def self.id2label(label_id)
94
- require 'protobuf/descriptor/descriptor_proto'
95
- case label_id
96
- when Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED then
97
- :required
98
- when Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL then
99
- :optional
100
- when Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED then
101
- :repeated
102
- else
103
- raise ArgumentError, "Invalid label: #{proto.label}"
104
- end
105
- end
106
-
107
- def self.label2id(label)
108
- require 'protobuf/descriptor/descriptor_proto'
109
- case label
110
- when :required then
111
- Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED
112
- when :optional then
113
- Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL
114
- when :repeated then
115
- Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED
116
- else
117
- raise ArgumentError, "Invalid label: #{label}"
118
- end
119
- end
120
-
121
- class DescriptorBuilder
122
- class <<self
123
-
124
- def proto_type
125
- nil
126
- end
127
-
128
- def build(proto, opt={})
129
- acceptable_descriptor(proto).build(proto)
130
- end
131
-
132
- def acceptable_descriptor(proto)
133
- Protobuf::Descriptor.constants.each do |class_name|
134
- descriptor_class = Protobuf::Descriptor.const_get(class_name)
135
- if descriptor_class.respond_to?(:proto_type) && descriptor_class.proto_type == proto.class.name
136
- return descriptor_class
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end
@@ -1,138 +0,0 @@
1
- require 'protobuf/message/message'
2
- require 'protobuf/message/enum'
3
- require 'protobuf/message/extend'
4
-
5
- module Google
6
- module Protobuf
7
- ::Protobuf::OPTIONS[:"java_package"] = "com.google.protobuf"
8
- ::Protobuf::OPTIONS[:"java_outer_classname"] = "DescriptorProtos"
9
- ::Protobuf::OPTIONS[:"optimize_for"] = :SPEED
10
- class FileDescriptorProto < ::Protobuf::Message
11
- defined_in __FILE__
12
- optional :string, :name, 1
13
- optional :string, :package, 2
14
- repeated :string, :dependency, 3
15
- repeated :DescriptorProto, :message_type, 4
16
- repeated :EnumDescriptorProto, :enum_type, 5
17
- repeated :ServiceDescriptorProto, :service, 6
18
- repeated :FieldDescriptorProto, :extension, 7
19
- optional :FileOptions, :options, 8
20
- end
21
- class DescriptorProto < ::Protobuf::Message
22
- defined_in __FILE__
23
- optional :string, :name, 1
24
- repeated :FieldDescriptorProto, :field, 2
25
- repeated :FieldDescriptorProto, :extension, 6
26
- repeated :DescriptorProto, :nested_type, 3
27
- repeated :EnumDescriptorProto, :enum_type, 4
28
- class ExtensionRange < ::Protobuf::Message
29
- defined_in __FILE__
30
- optional :int32, :start, 1
31
- optional :int32, :end, 2
32
- end
33
- repeated :ExtensionRange, :extension_range, 5
34
- optional :MessageOptions, :options, 7
35
- end
36
- class FieldDescriptorProto < ::Protobuf::Message
37
- defined_in __FILE__
38
- class Type < ::Protobuf::Enum
39
- defined_in __FILE__
40
- define :TYPE_DOUBLE, 1
41
- define :TYPE_FLOAT, 2
42
- define :TYPE_INT64, 3
43
- define :TYPE_UINT64, 4
44
- define :TYPE_INT32, 5
45
- define :TYPE_FIXED64, 6
46
- define :TYPE_FIXED32, 7
47
- define :TYPE_BOOL, 8
48
- define :TYPE_STRING, 9
49
- define :TYPE_GROUP, 10
50
- define :TYPE_MESSAGE, 11
51
- define :TYPE_BYTES, 12
52
- define :TYPE_UINT32, 13
53
- define :TYPE_ENUM, 14
54
- define :TYPE_SFIXED32, 15
55
- define :TYPE_SFIXED64, 16
56
- define :TYPE_SINT32, 17
57
- define :TYPE_SINT64, 18
58
- end
59
- class Label < ::Protobuf::Enum
60
- defined_in __FILE__
61
- define :LABEL_OPTIONAL, 1
62
- define :LABEL_REQUIRED, 2
63
- define :LABEL_REPEATED, 3
64
- end
65
- optional :string, :name, 1
66
- optional :int32, :number, 3
67
- optional :Label, :label, 4
68
- optional :Type, :type, 5
69
- optional :string, :type_name, 6
70
- optional :string, :extendee, 2
71
- optional :string, :default_value, 7
72
- optional :FieldOptions, :options, 8
73
- end
74
- class EnumDescriptorProto < ::Protobuf::Message
75
- defined_in __FILE__
76
- optional :string, :name, 1
77
- repeated :EnumValueDescriptorProto, :value, 2
78
- optional :EnumOptions, :options, 3
79
- end
80
- class EnumValueDescriptorProto < ::Protobuf::Message
81
- defined_in __FILE__
82
- optional :string, :name, 1
83
- optional :int32, :number, 2
84
- optional :EnumValueOptions, :options, 3
85
- end
86
- class ServiceDescriptorProto < ::Protobuf::Message
87
- defined_in __FILE__
88
- optional :string, :name, 1
89
- repeated :MethodDescriptorProto, :method, 2
90
- optional :ServiceOptions, :options, 3
91
- end
92
- class MethodDescriptorProto < ::Protobuf::Message
93
- defined_in __FILE__
94
- optional :string, :name, 1
95
- optional :string, :input_type, 2
96
- optional :string, :output_type, 3
97
- optional :MethodOptions, :options, 4
98
- end
99
- class FileOptions < ::Protobuf::Message
100
- defined_in __FILE__
101
- optional :string, :java_package, 1
102
- optional :string, :java_outer_classname, 8
103
- optional :bool, :java_multiple_files, 10, :default => false
104
- class OptimizeMode < ::Protobuf::Enum
105
- defined_in __FILE__
106
- define :SPEED, 1
107
- define :CODE_SIZE, 2
108
- end
109
- optional :OptimizeMode, :optimize_for, 9, :default => :CODE_SIZE
110
- end
111
- class MessageOptions < ::Protobuf::Message
112
- defined_in __FILE__
113
- optional :bool, :message_set_wire_format, 1, :default => false
114
- end
115
- class FieldOptions < ::Protobuf::Message
116
- defined_in __FILE__
117
- optional :CType, :ctype, 1
118
- class CType < ::Protobuf::Enum
119
- defined_in __FILE__
120
- define :CORD, 1
121
- define :STRING_PIECE, 2
122
- end
123
- optional :string, :experimental_map_key, 9
124
- end
125
- class EnumOptions < ::Protobuf::Message
126
- defined_in __FILE__
127
- end
128
- class EnumValueOptions < ::Protobuf::Message
129
- defined_in __FILE__
130
- end
131
- class ServiceOptions < ::Protobuf::Message
132
- defined_in __FILE__
133
- end
134
- class MethodOptions < ::Protobuf::Message
135
- defined_in __FILE__
136
- end
137
- end
138
- end
@@ -1,33 +0,0 @@
1
- module Protobuf
2
- module Descriptor
3
- class EnumDescriptor
4
- def initialize(enum_class)
5
- @enum_class = enum_class
6
- end
7
-
8
- def proto_type
9
- Google::Protobuf::EnumDescriptorProto
10
- end
11
-
12
- def build(proto, opt)
13
- mod = opt[:module]
14
- cls = mod.const_set(proto.name, Class.new(Protobuf::Enum))
15
- proto.value.each do |value_proto|
16
- cls.class_eval { define value_proto.name, value_proto.number }
17
- end
18
- end
19
-
20
- def unbuild(parent_proto)
21
- enum_proto = Google::Protobuf::EnumDescriptorProto.new
22
- enum_proto.name = @enum_class.name.split('::').last
23
- @enum_class.values.each do |name, value|
24
- enum_value_proto = Google::Protobuf::EnumValueDescriptorProto.new
25
- enum_value_proto.name = name.to_s
26
- enum_value_proto.number = value.value
27
- enum_proto.value << enum_value_proto
28
- end
29
- parent_proto.enum_type << enum_proto
30
- end
31
- end
32
- end
33
- end
@@ -1,49 +0,0 @@
1
- module Protobuf
2
- module Descriptor
3
- class FieldDescriptor
4
- def initialize(field_instance=nil)
5
- @field_instance = field_instance
6
- end
7
-
8
- def proto_type
9
- 'Google::Protobuf::FieldDescriptorProto'
10
- end
11
-
12
- def build(proto, opt={})
13
- cls = opt[:class]
14
- rule = Protobuf::Descriptor.id2label(proto.label)
15
- type = Protobuf::Descriptor.id2type(proto.type)
16
- type = proto.type_name.to_sym if [:message, :enum].include?(type)
17
- opts = {}
18
- opts[:default] = proto.default_value if proto.default_value
19
- cls.define_field(rule, type, proto.name, proto.number, opts)
20
- end
21
-
22
- def unbuild(parent_proto, extension=false)
23
- field_proto = Google::Protobuf::FieldDescriptorProto.new
24
- field_proto.name = @field_instance.name.to_s
25
- field_proto.number = @field_instance.tag
26
- field_proto.label = Protobuf::Descriptor.label2id(@field_instance.rule)
27
- field_proto.type = Protobuf::Descriptor.type2id(@field_instance.type)
28
- if [Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE,
29
- Google::Protobuf::FieldDescriptorProto::Type::TYPE_ENUM].include? field_proto.type
30
- field_proto.type_name = @field_instance.type.to_s.split('::').last
31
- end
32
- field_proto.default_value = @field_instance.default.to_s if @field_instance.default
33
-
34
- case parent_proto
35
- when Google::Protobuf::FileDescriptorProto then
36
- parent_proto.extension << field_proto
37
- when Google::Protobuf::DescriptorProto then
38
- if extension
39
- parent_proto.extension << field_proto
40
- else
41
- parent_proto.field << field_proto
42
- end
43
- else
44
- raise TypeError, parent_proto.class.name
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,37 +0,0 @@
1
- module Protobuf
2
- module Descriptor
3
- class FileDescriptor
4
- class << self
5
- def proto_type
6
- 'Google::Protobuf::FileDescriptorProto'
7
- end
8
-
9
- def build(proto, opt={})
10
- mod = Object
11
- if package = proto.package and not package.empty?
12
- module_names = package.split '::'
13
- module_names.each do |module_name|
14
- mod = mod.const_set module_name, Module.new
15
- end
16
- end
17
- proto.message_type.each do |message_proto|
18
- Protobuf::Message.descriptor.build message_proto, :module => mod
19
- end
20
- proto.enum_type.each do |enum_proto|
21
- Protobuf::Enum.descriptor.build enum_proto, :module => mod
22
- end
23
- end
24
-
25
- def unbuild(messages)
26
- messages = [messages] unless messages.is_a? Array
27
- proto = Google::Protobuf::FileDescriptorProto.new
28
- proto.package = messages.first.to_s.split('::')[0..-2].join('::') if messages.first.to_s =~ /::/
29
- messages.each do |message|
30
- message.descriptor.unbuild proto
31
- end
32
- proto
33
- end
34
- end
35
- end
36
- end
37
- end