protobuffy 3.6.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +67 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +25 -5
  6. data/CHANGES.md +55 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/LICENSE.txt +17 -9
  9. data/README.md +13 -12
  10. data/Rakefile +15 -11
  11. data/bin/protoc-gen-ruby +8 -3
  12. data/bin/rpc_server +1 -0
  13. data/examples/lib/example/reverse-client.rb +2 -2
  14. data/install-protobuf.sh +28 -0
  15. data/lib/protobuf.rb +57 -53
  16. data/lib/protobuf/cli.rb +94 -74
  17. data/lib/protobuf/code_generator.rb +60 -9
  18. data/lib/protobuf/decoder.rb +19 -65
  19. data/lib/protobuf/deprecation.rb +117 -0
  20. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
  21. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
  22. data/lib/protobuf/encoder.rb +13 -53
  23. data/lib/protobuf/enum.rb +58 -63
  24. data/lib/protobuf/field.rb +4 -4
  25. data/lib/protobuf/field/base_field.rb +101 -173
  26. data/lib/protobuf/field/bool_field.rb +17 -11
  27. data/lib/protobuf/field/bytes_field.rb +21 -35
  28. data/lib/protobuf/field/double_field.rb +0 -1
  29. data/lib/protobuf/field/enum_field.rb +23 -22
  30. data/lib/protobuf/field/field_array.rb +5 -4
  31. data/lib/protobuf/field/fixed32_field.rb +1 -1
  32. data/lib/protobuf/field/fixed64_field.rb +0 -1
  33. data/lib/protobuf/field/float_field.rb +4 -1
  34. data/lib/protobuf/field/int32_field.rb +0 -1
  35. data/lib/protobuf/field/int64_field.rb +0 -1
  36. data/lib/protobuf/field/integer_field.rb +0 -1
  37. data/lib/protobuf/field/message_field.rb +13 -28
  38. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  39. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  40. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  41. data/lib/protobuf/field/sint32_field.rb +0 -1
  42. data/lib/protobuf/field/sint64_field.rb +0 -1
  43. data/lib/protobuf/field/string_field.rb +2 -4
  44. data/lib/protobuf/field/uint32_field.rb +0 -1
  45. data/lib/protobuf/field/uint64_field.rb +0 -1
  46. data/lib/protobuf/field/varint_field.rb +30 -13
  47. data/lib/protobuf/generators/base.rb +30 -16
  48. data/lib/protobuf/generators/enum_generator.rb +6 -9
  49. data/lib/protobuf/generators/extension_generator.rb +1 -2
  50. data/lib/protobuf/generators/field_generator.rb +25 -13
  51. data/lib/protobuf/generators/file_generator.rb +157 -35
  52. data/lib/protobuf/generators/group_generator.rb +22 -17
  53. data/lib/protobuf/generators/message_generator.rb +13 -14
  54. data/lib/protobuf/generators/option_generator.rb +17 -0
  55. data/lib/protobuf/generators/printable.rb +12 -13
  56. data/lib/protobuf/generators/service_generator.rb +2 -3
  57. data/lib/protobuf/http.rb +2 -2
  58. data/lib/protobuf/lifecycle.rb +20 -33
  59. data/lib/protobuf/logging.rb +39 -0
  60. data/lib/protobuf/message.rb +114 -47
  61. data/lib/protobuf/message/fields.rb +170 -88
  62. data/lib/protobuf/message/serialization.rb +19 -18
  63. data/lib/protobuf/optionable.rb +53 -6
  64. data/lib/protobuf/rpc/buffer.rb +18 -19
  65. data/lib/protobuf/rpc/client.rb +22 -50
  66. data/lib/protobuf/rpc/connectors/base.rb +177 -12
  67. data/lib/protobuf/rpc/connectors/http.rb +14 -9
  68. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  69. data/lib/protobuf/rpc/connectors/socket.rb +13 -8
  70. data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
  71. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
  72. data/lib/protobuf/rpc/env.rb +12 -12
  73. data/lib/protobuf/rpc/error.rb +3 -3
  74. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  75. data/lib/protobuf/rpc/error/server_error.rb +9 -9
  76. data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
  77. data/lib/protobuf/rpc/middleware/logger.rb +8 -4
  78. data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
  79. data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
  80. data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
  81. data/lib/protobuf/rpc/rpc.pb.rb +4 -1
  82. data/lib/protobuf/rpc/server.rb +1 -1
  83. data/lib/protobuf/rpc/servers/http/server.rb +19 -17
  84. data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
  85. data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
  86. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
  87. data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
  88. data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
  89. data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
  90. data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
  91. data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
  92. data/lib/protobuf/rpc/service.rb +21 -27
  93. data/lib/protobuf/rpc/service_directory.rb +43 -27
  94. data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
  95. data/lib/protobuf/rpc/service_filters.rb +32 -55
  96. data/lib/protobuf/rpc/stat.rb +4 -8
  97. data/lib/protobuf/socket.rb +1 -2
  98. data/lib/protobuf/tasks/compile.rake +3 -4
  99. data/lib/protobuf/varint.rb +9 -0
  100. data/lib/protobuf/varint_pure.rb +13 -0
  101. data/lib/protobuf/version.rb +1 -1
  102. data/lib/protobuf/zmq.rb +2 -2
  103. data/proto/google/protobuf/descriptor.proto +190 -31
  104. data/protobuffy.gemspec +30 -17
  105. data/spec/benchmark/tasks.rb +27 -19
  106. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  107. data/spec/encoding/all_types_spec.rb +96 -84
  108. data/spec/encoding/extreme_values_spec.rb +0 -0
  109. data/spec/functional/class_inheritance_spec.rb +52 -0
  110. data/spec/functional/code_generator_spec.rb +38 -0
  111. data/spec/functional/socket_server_spec.rb +15 -15
  112. data/spec/functional/zmq_server_spec.rb +29 -27
  113. data/spec/lib/protobuf/cli_spec.rb +82 -67
  114. data/spec/lib/protobuf/code_generator_spec.rb +37 -10
  115. data/spec/lib/protobuf/enum_spec.rb +77 -46
  116. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  117. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  118. data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
  119. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  120. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  121. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  122. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  123. data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
  124. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  125. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  126. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  127. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  129. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
  131. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field_spec.rb +4 -6
  134. data/spec/lib/protobuf/generators/base_spec.rb +80 -13
  135. data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
  136. data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
  137. data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
  138. data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
  139. data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
  140. data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
  141. data/spec/lib/protobuf/message_spec.rb +578 -79
  142. data/spec/lib/protobuf/optionable_spec.rb +202 -26
  143. data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
  144. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
  145. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
  146. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
  147. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  148. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
  149. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
  150. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
  151. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
  152. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
  153. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
  154. data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
  163. data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
  165. data/spec/lib/protobuf/varint_spec.rb +29 -0
  166. data/spec/lib/protobuf_spec.rb +55 -28
  167. data/spec/spec_helper.rb +12 -27
  168. data/spec/support/all.rb +0 -1
  169. data/spec/support/packed_field.rb +4 -3
  170. data/spec/support/{test → protos}/all_types.data.bin +0 -0
  171. data/spec/support/{test → protos}/all_types.data.txt +0 -0
  172. data/spec/support/{test → protos}/enum.pb.rb +8 -4
  173. data/spec/support/{test → protos}/enum.proto +4 -1
  174. data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
  175. data/spec/support/protos/google_unittest.bin +0 -0
  176. data/spec/support/protos/google_unittest.pb.rb +798 -0
  177. data/spec/support/{test → protos}/google_unittest.proto +237 -66
  178. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  179. data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
  180. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  181. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  182. data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
  183. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  184. data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
  185. data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
  186. data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
  187. data/spec/support/{test → protos}/resource.pb.rb +47 -11
  188. data/spec/support/{test → protos}/resource.proto +24 -1
  189. data/spec/support/resource_service.rb +23 -0
  190. data/spec/support/server.rb +32 -61
  191. metadata +119 -59
  192. data/lib/protobuf/deprecator.rb +0 -42
  193. data/lib/protobuf/logger.rb +0 -93
  194. data/lib/protobuf/rpc/connector.rb +0 -21
  195. data/lib/protobuf/rpc/connectors/common.rb +0 -172
  196. data/spec/data/data.bin +0 -3
  197. data/spec/data/types.bin +0 -0
  198. data/spec/lib/protobuf/logger_spec.rb +0 -145
  199. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  200. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
  201. data/spec/support/test/defaults.pb.rb +0 -25
  202. data/spec/support/test/defaults.proto +0 -9
  203. data/spec/support/test/extended.pb.rb +0 -22
  204. data/spec/support/test/extended.proto +0 -10
  205. data/spec/support/test/google_unittest.pb.rb +0 -543
  206. data/spec/support/test/google_unittest_import.pb.rb +0 -37
  207. data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
  208. data/spec/support/test/resource_service.rb +0 -26
  209. data/spec/support/tolerance_matcher.rb +0 -40
@@ -0,0 +1,268 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf'
7
+ require 'protobuf/rpc/service'
8
+
9
+
10
+ ##
11
+ # Imports
12
+ #
13
+ require 'google/protobuf/descriptor.pb'
14
+
15
+ module Protobuf_unittest
16
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
17
+
18
+ ##
19
+ # Enum Classes
20
+ #
21
+ class MethodOpt1 < ::Protobuf::Enum
22
+ define :METHODOPT1_VAL1, 1
23
+ define :METHODOPT1_VAL2, 2
24
+ end
25
+
26
+ class AggregateEnum < ::Protobuf::Enum
27
+ set_option :".protobuf_unittest.enumopt", { :s => "EnumAnnotation" }
28
+
29
+ define :VALUE, 1
30
+ end
31
+
32
+
33
+ ##
34
+ # Message Classes
35
+ #
36
+ class TestMessageWithCustomOptions < ::Protobuf::Message
37
+ class AnEnum < ::Protobuf::Enum
38
+ set_option :".protobuf_unittest.enum_opt1", -789
39
+
40
+ define :ANENUM_VAL1, 1
41
+ define :ANENUM_VAL2, 2
42
+ end
43
+
44
+ end
45
+
46
+ class CustomOptionFooRequest < ::Protobuf::Message; end
47
+ class CustomOptionFooResponse < ::Protobuf::Message; end
48
+ class CustomOptionFooClientMessage < ::Protobuf::Message; end
49
+ class CustomOptionFooServerMessage < ::Protobuf::Message; end
50
+ class DummyMessageContainingEnum < ::Protobuf::Message
51
+ class TestEnumType < ::Protobuf::Enum
52
+ define :TEST_OPTION_ENUM_TYPE1, 22
53
+ define :TEST_OPTION_ENUM_TYPE2, -23
54
+ end
55
+
56
+ end
57
+
58
+ class DummyMessageInvalidAsOptionType < ::Protobuf::Message; end
59
+ class CustomOptionMinIntegerValues < ::Protobuf::Message; end
60
+ class CustomOptionMaxIntegerValues < ::Protobuf::Message; end
61
+ class CustomOptionOtherValues < ::Protobuf::Message; end
62
+ class SettingRealsFromPositiveInts < ::Protobuf::Message; end
63
+ class SettingRealsFromNegativeInts < ::Protobuf::Message; end
64
+ class ComplexOptionType1 < ::Protobuf::Message; end
65
+ class ComplexOptionType2 < ::Protobuf::Message
66
+ class ComplexOptionType4 < ::Protobuf::Message; end
67
+
68
+ end
69
+
70
+ class ComplexOptionType3 < ::Protobuf::Message; end
71
+ class VariousComplexOptions < ::Protobuf::Message; end
72
+ class AggregateMessageSet < ::Protobuf::Message; end
73
+ class AggregateMessageSetElement < ::Protobuf::Message; end
74
+ class Aggregate < ::Protobuf::Message; end
75
+ class AggregateMessage < ::Protobuf::Message; end
76
+ class NestedOptionType < ::Protobuf::Message
77
+ class NestedEnum < ::Protobuf::Enum
78
+ set_option :".protobuf_unittest.enum_opt1", 1003
79
+
80
+ define :NESTED_ENUM_VALUE, 1
81
+ end
82
+
83
+ class NestedMessage < ::Protobuf::Message; end
84
+
85
+ end
86
+
87
+ class OldOptionType < ::Protobuf::Message
88
+ class TestEnum < ::Protobuf::Enum
89
+ define :OLD_VALUE, 0
90
+ end
91
+
92
+ end
93
+
94
+ class NewOptionType < ::Protobuf::Message
95
+ class TestEnum < ::Protobuf::Enum
96
+ define :OLD_VALUE, 0
97
+ define :NEW_VALUE, 1
98
+ end
99
+
100
+ end
101
+
102
+ class TestMessageWithRequiredEnumOption < ::Protobuf::Message; end
103
+
104
+
105
+ ##
106
+ # File Options
107
+ #
108
+ set_option :cc_generic_services, true
109
+ set_option :java_generic_services, true
110
+ set_option :py_generic_services, true
111
+ set_option :".protobuf_unittest.file_opt1", 9876543210
112
+ set_option :".protobuf_unittest.fileopt", { :i => 100, :s => "FileAnnotation", :sub => { :s => "NestedFileAnnotation" }, :file => { :".protobuf_unittest.fileopt" => { :s => "FileExtensionAnnotation" } }, :mset => { :".protobuf_unittest.AggregateMessageSetElement.message_set_extension" => { :s => "EmbeddedMessageSetElement" } } }
113
+
114
+
115
+ ##
116
+ # Message Fields
117
+ #
118
+ class TestMessageWithCustomOptions
119
+ optional :string, :field1, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".protobuf_unittest.field_opt1" => 8765432109
120
+ end
121
+
122
+ class ComplexOptionType1
123
+ optional :int32, :foo, 1
124
+ optional :int32, :foo2, 2
125
+ optional :int32, :foo3, 3
126
+ repeated :int32, :foo4, 4
127
+ # Extension Fields
128
+ extensions 100...536870912
129
+ optional :int32, :".protobuf_unittest.quux", 7663707, :extension => true
130
+ optional ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.corge", 7663442, :extension => true
131
+ end
132
+
133
+ class ComplexOptionType2
134
+ class ComplexOptionType4
135
+ optional :int32, :waldo, 1
136
+ end
137
+
138
+ optional ::Protobuf_unittest::ComplexOptionType1, :bar, 1
139
+ optional :int32, :baz, 2
140
+ optional ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :fred, 3
141
+ repeated ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :barney, 4
142
+ # Extension Fields
143
+ extensions 100...536870912
144
+ optional :int32, :".protobuf_unittest.grault", 7650927, :extension => true
145
+ optional ::Protobuf_unittest::ComplexOptionType1, :".protobuf_unittest.garply", 7649992, :extension => true
146
+ end
147
+
148
+ class ComplexOptionType3
149
+ optional :int32, :qux, 1
150
+ end
151
+
152
+ class AggregateMessageSet
153
+ # Extension Fields
154
+ extensions 4...536870912
155
+ optional ::Protobuf_unittest::AggregateMessageSetElement, :".protobuf_unittest.AggregateMessageSetElement.message_set_extension", 15447542, :extension => true
156
+ end
157
+
158
+ class AggregateMessageSetElement
159
+ optional :string, :s, 1
160
+ end
161
+
162
+ class Aggregate
163
+ optional :int32, :i, 1
164
+ optional :string, :s, 2
165
+ optional ::Protobuf_unittest::Aggregate, :sub, 3
166
+ optional ::Google::Protobuf::FileOptions, :file, 4
167
+ optional ::Protobuf_unittest::AggregateMessageSet, :mset, 5
168
+ end
169
+
170
+ class AggregateMessage
171
+ optional :int32, :fieldname, 1, :".protobuf_unittest.fieldopt" => { :s => "FieldAnnotation" }
172
+ end
173
+
174
+ class NestedOptionType
175
+ class NestedMessage
176
+ optional :int32, :nested_field, 1, :".protobuf_unittest.field_opt1" => 1002
177
+ end
178
+
179
+ end
180
+
181
+ class OldOptionType
182
+ required ::Protobuf_unittest::OldOptionType::TestEnum, :value, 1
183
+ end
184
+
185
+ class NewOptionType
186
+ required ::Protobuf_unittest::NewOptionType::TestEnum, :value, 1
187
+ end
188
+
189
+
190
+ ##
191
+ # Extended Message Fields
192
+ #
193
+ class ::Google::Protobuf::FileOptions < ::Protobuf::Message
194
+ optional :uint64, :".protobuf_unittest.file_opt1", 7736974, :extension => true
195
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.fileopt", 15478479, :extension => true
196
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.Aggregate.nested", 15476903, :extension => true
197
+ optional :int32, :".protobuf_unittest.NestedOptionType.nested_extension", 7912573, :extension => true, :".protobuf_unittest.field_opt2" => 1005
198
+ end
199
+
200
+ class ::Google::Protobuf::MessageOptions < ::Protobuf::Message
201
+ optional :int32, :".protobuf_unittest.message_opt1", 7739036, :extension => true
202
+ optional :bool, :".protobuf_unittest.bool_opt", 7706090, :extension => true
203
+ optional :int32, :".protobuf_unittest.int32_opt", 7705709, :extension => true
204
+ optional :int64, :".protobuf_unittest.int64_opt", 7705542, :extension => true
205
+ optional :uint32, :".protobuf_unittest.uint32_opt", 7704880, :extension => true
206
+ optional :uint64, :".protobuf_unittest.uint64_opt", 7702367, :extension => true
207
+ optional :sint32, :".protobuf_unittest.sint32_opt", 7701568, :extension => true
208
+ optional :sint64, :".protobuf_unittest.sint64_opt", 7700863, :extension => true
209
+ optional :fixed32, :".protobuf_unittest.fixed32_opt", 7700307, :extension => true
210
+ optional :fixed64, :".protobuf_unittest.fixed64_opt", 7700194, :extension => true
211
+ optional :sfixed32, :".protobuf_unittest.sfixed32_opt", 7698645, :extension => true
212
+ optional :sfixed64, :".protobuf_unittest.sfixed64_opt", 7685475, :extension => true
213
+ optional :float, :".protobuf_unittest.float_opt", 7675390, :extension => true
214
+ optional :double, :".protobuf_unittest.double_opt", 7673293, :extension => true
215
+ optional :string, :".protobuf_unittest.string_opt", 7673285, :extension => true
216
+ optional :bytes, :".protobuf_unittest.bytes_opt", 7673238, :extension => true
217
+ optional ::Protobuf_unittest::DummyMessageContainingEnum::TestEnumType, :".protobuf_unittest.enum_opt", 7673233, :extension => true
218
+ optional ::Protobuf_unittest::DummyMessageInvalidAsOptionType, :".protobuf_unittest.message_type_opt", 7665967, :extension => true
219
+ optional ::Protobuf_unittest::ComplexOptionType1, :".protobuf_unittest.complex_opt1", 7646756, :extension => true
220
+ optional ::Protobuf_unittest::ComplexOptionType2, :".protobuf_unittest.complex_opt2", 7636949, :extension => true
221
+ optional ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.complex_opt3", 7636463, :extension => true
222
+ repeated :int32, :".protobuf_unittest.repeated_opt1", 7636464, :extension => true
223
+ repeated ::Protobuf_unittest::ComplexOptionType3, :".protobuf_unittest.repeated_opt2", 7636465, :extension => true
224
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.msgopt", 15480088, :extension => true
225
+ optional ::Protobuf_unittest::OldOptionType, :".protobuf_unittest.required_enum_opt", 106161807, :extension => true
226
+ optional ::Protobuf_unittest::ComplexOptionType2::ComplexOptionType4, :".protobuf_unittest.ComplexOptionType2.ComplexOptionType4.complex_opt4", 7633546, :extension => true
227
+ end
228
+
229
+ class ::Google::Protobuf::FieldOptions < ::Protobuf::Message
230
+ optional :fixed64, :".protobuf_unittest.field_opt1", 7740936, :extension => true
231
+ optional :int32, :".protobuf_unittest.field_opt2", 7753913, :default => 42, :extension => true
232
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.fieldopt", 15481374, :extension => true
233
+ end
234
+
235
+ class ::Google::Protobuf::EnumOptions < ::Protobuf::Message
236
+ optional :sfixed32, :".protobuf_unittest.enum_opt1", 7753576, :extension => true
237
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.enumopt", 15483218, :extension => true
238
+ end
239
+
240
+ class ::Google::Protobuf::EnumValueOptions < ::Protobuf::Message
241
+ optional :int32, :".protobuf_unittest.enum_value_opt1", 1560678, :extension => true
242
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.enumvalopt", 15486921, :extension => true
243
+ end
244
+
245
+ class ::Google::Protobuf::ServiceOptions < ::Protobuf::Message
246
+ optional :sint64, :".protobuf_unittest.service_opt1", 7887650, :extension => true
247
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.serviceopt", 15497145, :extension => true
248
+ end
249
+
250
+ class ::Google::Protobuf::MethodOptions < ::Protobuf::Message
251
+ optional ::Protobuf_unittest::MethodOpt1, :".protobuf_unittest.method_opt1", 7890860, :extension => true
252
+ optional ::Protobuf_unittest::Aggregate, :".protobuf_unittest.methodopt", 15512713, :extension => true
253
+ end
254
+
255
+
256
+ ##
257
+ # Service Classes
258
+ #
259
+ class TestServiceWithCustomOptions < ::Protobuf::Rpc::Service
260
+ rpc :foo, ::Protobuf_unittest::CustomOptionFooRequest, ::Protobuf_unittest::CustomOptionFooResponse
261
+ end
262
+
263
+ class AggregateService < ::Protobuf::Rpc::Service
264
+ rpc :method, ::Protobuf_unittest::AggregateMessage, ::Protobuf_unittest::AggregateMessage
265
+ end
266
+
267
+ end
268
+
@@ -0,0 +1,424 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ // Author: benjy@google.com (Benjy Weinberger)
32
+ // Based on original Protocol Buffers design by
33
+ // Sanjay Ghemawat, Jeff Dean, and others.
34
+ //
35
+ // A proto file used to test the "custom options" feature of google.protobuf.
36
+
37
+ syntax = "proto2";
38
+
39
+ // Some generic_services option(s) added automatically.
40
+ // See: http://go/proto2-generic-services-default
41
+ option cc_generic_services = true; // auto-added
42
+ option java_generic_services = true; // auto-added
43
+ option py_generic_services = true;
44
+
45
+ // A custom file option (defined below).
46
+ option (file_opt1) = 9876543210;
47
+
48
+ import "google/protobuf/descriptor.proto";
49
+
50
+ // We don't put this in a package within proto2 because we need to make sure
51
+ // that the generated code doesn't depend on being in the proto2 namespace.
52
+ package protobuf_unittest;
53
+
54
+
55
+ // Some simple test custom options of various types.
56
+
57
+ extend google.protobuf.FileOptions {
58
+ optional uint64 file_opt1 = 7736974;
59
+ }
60
+
61
+ extend google.protobuf.MessageOptions {
62
+ optional int32 message_opt1 = 7739036;
63
+ }
64
+
65
+ extend google.protobuf.FieldOptions {
66
+ optional fixed64 field_opt1 = 7740936;
67
+ // This is useful for testing that we correctly register default values for
68
+ // extension options.
69
+ optional int32 field_opt2 = 7753913 [default=42];
70
+ }
71
+
72
+ extend google.protobuf.EnumOptions {
73
+ optional sfixed32 enum_opt1 = 7753576;
74
+ }
75
+
76
+ extend google.protobuf.EnumValueOptions {
77
+ optional int32 enum_value_opt1 = 1560678;
78
+ }
79
+
80
+ extend google.protobuf.ServiceOptions {
81
+ optional sint64 service_opt1 = 7887650;
82
+ }
83
+
84
+ enum MethodOpt1 {
85
+ METHODOPT1_VAL1 = 1;
86
+ METHODOPT1_VAL2 = 2;
87
+ }
88
+
89
+ extend google.protobuf.MethodOptions {
90
+ optional MethodOpt1 method_opt1 = 7890860;
91
+ }
92
+
93
+ // A test message with custom options at all possible locations (and also some
94
+ // regular options, to make sure they interact nicely).
95
+ message TestMessageWithCustomOptions {
96
+ option message_set_wire_format = false;
97
+
98
+ option (message_opt1) = -56;
99
+
100
+ optional string field1 = 1 [ctype=CORD,
101
+ (field_opt1)=8765432109];
102
+
103
+ enum AnEnum {
104
+ option (enum_opt1) = -789;
105
+
106
+ ANENUM_VAL1 = 1;
107
+ ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
108
+ }
109
+ }
110
+
111
+
112
+ // A test RPC service with custom options at all possible locations (and also
113
+ // some regular options, to make sure they interact nicely).
114
+ message CustomOptionFooRequest {
115
+ }
116
+
117
+ message CustomOptionFooResponse {
118
+ }
119
+
120
+ message CustomOptionFooClientMessage {
121
+ }
122
+
123
+ message CustomOptionFooServerMessage {
124
+ }
125
+
126
+ service TestServiceWithCustomOptions {
127
+ option (service_opt1) = -9876543210;
128
+
129
+ rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
130
+ option (method_opt1) = METHODOPT1_VAL2;
131
+ }
132
+ }
133
+
134
+
135
+
136
+ // Options of every possible field type, so we can test them all exhaustively.
137
+
138
+ message DummyMessageContainingEnum {
139
+ enum TestEnumType {
140
+ TEST_OPTION_ENUM_TYPE1 = 22;
141
+ TEST_OPTION_ENUM_TYPE2 = -23;
142
+ }
143
+ }
144
+
145
+ message DummyMessageInvalidAsOptionType {
146
+ }
147
+
148
+ extend google.protobuf.MessageOptions {
149
+ optional bool bool_opt = 7706090;
150
+ optional int32 int32_opt = 7705709;
151
+ optional int64 int64_opt = 7705542;
152
+ optional uint32 uint32_opt = 7704880;
153
+ optional uint64 uint64_opt = 7702367;
154
+ optional sint32 sint32_opt = 7701568;
155
+ optional sint64 sint64_opt = 7700863;
156
+ optional fixed32 fixed32_opt = 7700307;
157
+ optional fixed64 fixed64_opt = 7700194;
158
+ optional sfixed32 sfixed32_opt = 7698645;
159
+ optional sfixed64 sfixed64_opt = 7685475;
160
+ optional float float_opt = 7675390;
161
+ optional double double_opt = 7673293;
162
+ optional string string_opt = 7673285;
163
+ optional bytes bytes_opt = 7673238;
164
+ optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
165
+ optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
166
+ }
167
+
168
+ message CustomOptionMinIntegerValues {
169
+ option (bool_opt) = false;
170
+ option (int32_opt) = -0x80000000;
171
+ option (int64_opt) = -0x8000000000000000;
172
+ option (uint32_opt) = 0;
173
+ option (uint64_opt) = 0;
174
+ option (sint32_opt) = -0x80000000;
175
+ option (sint64_opt) = -0x8000000000000000;
176
+ option (fixed32_opt) = 0;
177
+ option (fixed64_opt) = 0;
178
+ option (sfixed32_opt) = -0x80000000;
179
+ option (sfixed64_opt) = -0x8000000000000000;
180
+ }
181
+
182
+ message CustomOptionMaxIntegerValues {
183
+ option (bool_opt) = true;
184
+ option (int32_opt) = 0x7FFFFFFF;
185
+ option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
186
+ option (uint32_opt) = 0xFFFFFFFF;
187
+ option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
188
+ option (sint32_opt) = 0x7FFFFFFF;
189
+ option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
190
+ option (fixed32_opt) = 0xFFFFFFFF;
191
+ option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
192
+ option (sfixed32_opt) = 0x7FFFFFFF;
193
+ option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
194
+ }
195
+
196
+ message CustomOptionOtherValues {
197
+ option (int32_opt) = -100; // To test sign-extension.
198
+ option (float_opt) = 12.3456789;
199
+ option (double_opt) = 1.234567890123456789;
200
+ option (string_opt) = "Hello, \"World\"";
201
+ option (bytes_opt) = "Hello\0World";
202
+ option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
203
+ }
204
+
205
+ message SettingRealsFromPositiveInts {
206
+ option (float_opt) = 12;
207
+ option (double_opt) = 154;
208
+ }
209
+
210
+ message SettingRealsFromNegativeInts {
211
+ option (float_opt) = -12;
212
+ option (double_opt) = -154;
213
+ }
214
+
215
+ // Options of complex message types, themselves combined and extended in
216
+ // various ways.
217
+
218
+ // TODO: do we want to support packed ints?
219
+ // e.g.: repeated int32 foo4 = 4 [packed = true];
220
+ message ComplexOptionType1 {
221
+ optional int32 foo = 1;
222
+ optional int32 foo2 = 2;
223
+ optional int32 foo3 = 3;
224
+ repeated int32 foo4 = 4;
225
+
226
+ extensions 100 to max;
227
+ }
228
+
229
+ message ComplexOptionType2 {
230
+ optional ComplexOptionType1 bar = 1;
231
+ optional int32 baz = 2;
232
+
233
+ message ComplexOptionType4 {
234
+ optional int32 waldo = 1;
235
+
236
+ extend google.protobuf.MessageOptions {
237
+ optional ComplexOptionType4 complex_opt4 = 7633546;
238
+ }
239
+ }
240
+
241
+ optional ComplexOptionType4 fred = 3;
242
+ repeated ComplexOptionType4 barney = 4;
243
+
244
+ extensions 100 to max;
245
+ }
246
+
247
+ message ComplexOptionType3 {
248
+ optional int32 qux = 1;
249
+ }
250
+
251
+ extend ComplexOptionType1 {
252
+ optional int32 quux = 7663707;
253
+ optional ComplexOptionType3 corge = 7663442;
254
+ }
255
+
256
+ extend ComplexOptionType2 {
257
+ optional int32 grault = 7650927;
258
+ optional ComplexOptionType1 garply = 7649992;
259
+ }
260
+
261
+ extend google.protobuf.MessageOptions {
262
+ optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
263
+ optional ComplexOptionType2 complex_opt2 = 7636949;
264
+ optional ComplexOptionType3 complex_opt3 = 7636463;
265
+ repeated int32 repeated_opt1 = 7636464;
266
+ repeated protobuf_unittest.ComplexOptionType3 repeated_opt2 = 7636465;
267
+ }
268
+
269
+ // Note that we try various different ways of naming the same extension.
270
+ message VariousComplexOptions {
271
+ option (.protobuf_unittest.complex_opt1).foo = 42;
272
+ option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
273
+ option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
274
+ option (protobuf_unittest.complex_opt1).foo4 = 99;
275
+ option (protobuf_unittest.complex_opt1).foo4 = 88;
276
+ option (complex_opt2).baz = 987;
277
+ option (complex_opt2).(grault) = 654;
278
+ option (complex_opt2).bar.foo = 743;
279
+ option (complex_opt2).bar.(quux) = 1999;
280
+ option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
281
+ option (complex_opt2).(garply).foo = 741;
282
+ option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
283
+ option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
284
+ option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
285
+ option (complex_opt2).fred.waldo = 321;
286
+ option (complex_opt2).barney = { waldo: 101 };
287
+ option (complex_opt2).barney = { waldo: 212 };
288
+ option (protobuf_unittest.complex_opt3).qux = 9;
289
+ option (repeated_opt1) = 1;
290
+ option (repeated_opt1) = 2;
291
+ option (repeated_opt2) = { qux: 3 };
292
+ option (repeated_opt2) = { qux: 4 };
293
+ /*option (complex_opt3).complexoptiontype5.plugh = 22;*/
294
+ /*option (complexopt6).xyzzy = 24;*/
295
+ }
296
+
297
+ // ------------------------------------------------------
298
+ // Definitions for testing aggregate option parsing.
299
+ // See descriptor_unittest.cc.
300
+
301
+ message AggregateMessageSet {
302
+ option message_set_wire_format = false;
303
+ extensions 4 to max;
304
+ }
305
+
306
+ message AggregateMessageSetElement {
307
+ extend AggregateMessageSet {
308
+ optional AggregateMessageSetElement message_set_extension = 15447542;
309
+ }
310
+ optional string s = 1;
311
+ }
312
+
313
+ // A helper type used to test aggregate option parsing
314
+ message Aggregate {
315
+ optional int32 i = 1;
316
+ optional string s = 2;
317
+
318
+ // A nested object
319
+ optional Aggregate sub = 3;
320
+
321
+ // To test the parsing of extensions inside aggregate values
322
+ optional google.protobuf.FileOptions file = 4;
323
+ extend google.protobuf.FileOptions {
324
+ optional Aggregate nested = 15476903;
325
+ }
326
+
327
+ // An embedded message set
328
+ optional AggregateMessageSet mset = 5;
329
+ }
330
+
331
+ // Allow Aggregate to be used as an option at all possible locations
332
+ // in the .proto grammer.
333
+ extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
334
+ extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
335
+ extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
336
+ extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
337
+ extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
338
+ extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
339
+ extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
340
+
341
+ // Try using AggregateOption at different points in the proto grammar
342
+ option (fileopt) = {
343
+ s: 'FileAnnotation'
344
+ // Also test the handling of comments
345
+ /* of both types */ i: 100
346
+
347
+ sub { s: 'NestedFileAnnotation' }
348
+
349
+ // Include a google.protobuf.FileOptions and recursively extend it with
350
+ // another fileopt.
351
+ file {
352
+ [protobuf_unittest.fileopt] {
353
+ s:'FileExtensionAnnotation'
354
+ }
355
+ }
356
+
357
+ // A message set inside an option value
358
+ mset {
359
+ [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
360
+ s: 'EmbeddedMessageSetElement'
361
+ }
362
+ }
363
+ };
364
+
365
+ message AggregateMessage {
366
+ option (msgopt) = { i:101 s:'MessageAnnotation' };
367
+ optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
368
+ }
369
+
370
+ service AggregateService {
371
+ option (serviceopt) = { s:'ServiceAnnotation' };
372
+ rpc Method (AggregateMessage) returns (AggregateMessage) {
373
+ option (methodopt) = { s:'MethodAnnotation' };
374
+ }
375
+ }
376
+
377
+ enum AggregateEnum {
378
+ option (enumopt) = { s:'EnumAnnotation' };
379
+ // TODO: support enum value options
380
+ VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
381
+ }
382
+
383
+ // Test custom options for nested type.
384
+ message NestedOptionType {
385
+ message NestedMessage {
386
+ option (message_opt1) = 1001;
387
+ optional int32 nested_field = 1 [(field_opt1) = 1002];
388
+ }
389
+ enum NestedEnum {
390
+ option (enum_opt1) = 1003;
391
+ // TODO: support enum value options
392
+ NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
393
+ }
394
+ extend google.protobuf.FileOptions {
395
+ optional int32 nested_extension = 7912573 [(field_opt2) = 1005];
396
+ }
397
+ }
398
+
399
+ // Custom message option that has a required enum field.
400
+ // WARNING: this is strongly discouraged!
401
+ message OldOptionType {
402
+ enum TestEnum {
403
+ OLD_VALUE = 0;
404
+ }
405
+ required TestEnum value = 1;
406
+ }
407
+
408
+ // Updated version of the custom option above.
409
+ message NewOptionType {
410
+ enum TestEnum {
411
+ OLD_VALUE = 0;
412
+ NEW_VALUE = 1;
413
+ }
414
+ required TestEnum value = 1;
415
+ }
416
+
417
+ extend google.protobuf.MessageOptions {
418
+ optional OldOptionType required_enum_opt = 106161807;
419
+ }
420
+
421
+ // Test message using the "required_enum_opt" option defined above.
422
+ message TestMessageWithRequiredEnumOption {
423
+ option (required_enum_opt) = { value: OLD_VALUE };
424
+ }