protobuf 2.8.13 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +84 -5
- data/CONTRIBUTING.md +3 -3
- data/Rakefile +46 -7
- data/lib/protobuf/cli.rb +2 -20
- data/lib/protobuf/decoder.rb +74 -0
- data/lib/protobuf/deprecator.rb +42 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +17 -16
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +86 -85
- data/lib/protobuf/encoder.rb +62 -0
- data/lib/protobuf/enum.rb +298 -37
- data/lib/protobuf/field/base_field.rb +41 -27
- data/lib/protobuf/field/bool_field.rb +22 -4
- data/lib/protobuf/field/bytes_field.rb +36 -15
- data/lib/protobuf/field/double_field.rb +10 -3
- data/lib/protobuf/field/enum_field.rb +21 -18
- data/lib/protobuf/field/field_array.rb +26 -16
- data/lib/protobuf/field/fixed32_field.rb +10 -4
- data/lib/protobuf/field/fixed64_field.rb +10 -3
- data/lib/protobuf/field/float_field.rb +18 -5
- data/lib/protobuf/field/int32_field.rb +14 -4
- data/lib/protobuf/field/int64_field.rb +14 -4
- data/lib/protobuf/field/integer_field.rb +9 -4
- data/lib/protobuf/field/message_field.rb +16 -7
- data/lib/protobuf/field/sfixed32_field.rb +10 -3
- data/lib/protobuf/field/sfixed64_field.rb +12 -7
- data/lib/protobuf/field/signed_integer_field.rb +7 -0
- data/lib/protobuf/field/sint32_field.rb +14 -4
- data/lib/protobuf/field/sint64_field.rb +14 -4
- data/lib/protobuf/field/string_field.rb +11 -1
- data/lib/protobuf/field/uint32_field.rb +14 -4
- data/lib/protobuf/field/uint64_field.rb +14 -4
- data/lib/protobuf/field/varint_field.rb +11 -9
- data/lib/protobuf/field.rb +42 -25
- data/lib/protobuf/generators/enum_generator.rb +12 -1
- data/lib/protobuf/generators/field_generator.rb +1 -1
- data/lib/protobuf/lifecycle.rb +3 -4
- data/lib/protobuf/message/fields.rb +122 -0
- data/lib/protobuf/message/serialization.rb +84 -0
- data/lib/protobuf/message.rb +21 -221
- data/lib/protobuf/optionable.rb +23 -0
- data/lib/protobuf/rpc/client.rb +2 -4
- data/lib/protobuf/rpc/connector.rb +0 -2
- data/lib/protobuf/rpc/connectors/common.rb +2 -2
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +14 -16
- data/lib/protobuf/rpc/env.rb +58 -0
- data/lib/protobuf/rpc/error.rb +8 -5
- data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
- data/lib/protobuf/rpc/middleware/logger.rb +91 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/rpc.pb.rb +15 -16
- data/lib/protobuf/rpc/server.rb +14 -64
- data/lib/protobuf/rpc/servers/socket/server.rb +0 -2
- data/lib/protobuf/rpc/servers/socket/worker.rb +11 -15
- data/lib/protobuf/rpc/servers/zmq/util.rb +4 -1
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -13
- data/lib/protobuf/rpc/servers/zmq_runner.rb +1 -1
- data/lib/protobuf/rpc/service.rb +38 -72
- data/lib/protobuf/rpc/service_dispatcher.rb +20 -108
- data/lib/protobuf/version.rb +1 -2
- data/lib/protobuf.rb +5 -13
- data/protobuf.gemspec +5 -5
- data/spec/benchmark/tasks.rb +2 -77
- data/spec/functional/zmq_server_spec.rb +13 -21
- data/spec/lib/protobuf/cli_spec.rb +5 -43
- data/spec/lib/protobuf/enum_spec.rb +194 -61
- data/spec/lib/protobuf/field_spec.rb +194 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +24 -1
- data/spec/lib/protobuf/generators/field_generator_spec.rb +6 -6
- data/spec/lib/protobuf/message_spec.rb +52 -70
- data/spec/lib/protobuf/optionable_spec.rb +46 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +1 -93
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -7
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +8 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +0 -6
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +10 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +30 -105
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_spec.rb +20 -24
- data/spec/lib/protobuf_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/support/packed_field.rb +15 -14
- data/spec/support/server.rb +4 -21
- data/spec/support/test/defaults.pb.rb +4 -4
- data/spec/support/test/enum.pb.rb +13 -1
- data/spec/support/test/enum.proto +15 -0
- data/spec/support/test/extended.pb.rb +1 -1
- data/spec/support/test/google_unittest.pb.rb +239 -241
- data/spec/support/test/google_unittest_import.pb.rb +2 -2
- data/spec/support/test/multi_field_extensions.pb.rb +2 -2
- data/spec/support/test/resource.pb.rb +19 -18
- data/spec/support/test/resource.proto +1 -0
- data/spec/support/test/resource_service.rb +5 -0
- metadata +78 -57
- data/bin/rprotoc +0 -8
- data/lib/protobuf/enum_value.rb +0 -85
- data/lib/protobuf/evented.rb +0 -37
- data/lib/protobuf/ext/eventmachine.rb +0 -14
- data/lib/protobuf/field/extension_fields.rb +0 -32
- data/lib/protobuf/message/decoder.rb +0 -72
- data/lib/protobuf/message/message.rb +0 -1
- data/lib/protobuf/rpc/connectors/em_client.rb +0 -84
- data/lib/protobuf/rpc/connectors/eventmachine.rb +0 -87
- data/lib/protobuf/rpc/servers/evented/server.rb +0 -36
- data/lib/protobuf/rpc/servers/evented_runner.rb +0 -31
- data/spec/functional/embedded_service_spec.rb +0 -7
- data/spec/functional/evented_server_spec.rb +0 -64
- data/spec/lib/protobuf/enum_value_spec.rb +0 -29
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +0 -19
@@ -4,9 +4,8 @@
|
|
4
4
|
require 'protobuf/message'
|
5
5
|
|
6
6
|
module Google
|
7
|
-
|
8
7
|
module Protobuf
|
9
|
-
|
8
|
+
|
10
9
|
##
|
11
10
|
# Message Classes
|
12
11
|
#
|
@@ -14,7 +13,9 @@ module Google
|
|
14
13
|
class FileDescriptorProto < ::Protobuf::Message; end
|
15
14
|
class DescriptorProto < ::Protobuf::Message
|
16
15
|
class ExtensionRange < ::Protobuf::Message; end
|
16
|
+
|
17
17
|
end
|
18
|
+
|
18
19
|
class FieldDescriptorProto < ::Protobuf::Message
|
19
20
|
class Type < ::Protobuf::Enum
|
20
21
|
define :TYPE_DOUBLE, 1
|
@@ -36,14 +37,15 @@ module Google
|
|
36
37
|
define :TYPE_SINT32, 17
|
37
38
|
define :TYPE_SINT64, 18
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
class Label < ::Protobuf::Enum
|
41
42
|
define :LABEL_OPTIONAL, 1
|
42
43
|
define :LABEL_REQUIRED, 2
|
43
44
|
define :LABEL_REPEATED, 3
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
end
|
48
|
+
|
47
49
|
class EnumDescriptorProto < ::Protobuf::Message; end
|
48
50
|
class EnumValueDescriptorProto < ::Protobuf::Message; end
|
49
51
|
class ServiceDescriptorProto < ::Protobuf::Message; end
|
@@ -54,8 +56,9 @@ module Google
|
|
54
56
|
define :CODE_SIZE, 2
|
55
57
|
define :LITE_RUNTIME, 3
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
end
|
61
|
+
|
59
62
|
class MessageOptions < ::Protobuf::Message; end
|
60
63
|
class FieldOptions < ::Protobuf::Message
|
61
64
|
class CType < ::Protobuf::Enum
|
@@ -63,32 +66,38 @@ module Google
|
|
63
66
|
define :CORD, 1
|
64
67
|
define :STRING_PIECE, 2
|
65
68
|
end
|
66
|
-
|
69
|
+
|
67
70
|
end
|
71
|
+
|
68
72
|
class EnumOptions < ::Protobuf::Message; end
|
69
73
|
class EnumValueOptions < ::Protobuf::Message; end
|
70
74
|
class ServiceOptions < ::Protobuf::Message; end
|
71
75
|
class MethodOptions < ::Protobuf::Message; end
|
72
76
|
class UninterpretedOption < ::Protobuf::Message
|
73
77
|
class NamePart < ::Protobuf::Message; end
|
78
|
+
|
74
79
|
end
|
80
|
+
|
75
81
|
class SourceCodeInfo < ::Protobuf::Message
|
76
82
|
class Location < ::Protobuf::Message; end
|
83
|
+
|
77
84
|
end
|
78
|
-
|
85
|
+
|
86
|
+
|
87
|
+
|
79
88
|
##
|
80
89
|
# Message Fields
|
81
90
|
#
|
82
91
|
class FileDescriptorSet
|
83
92
|
repeated ::Google::Protobuf::FileDescriptorProto, :file, 1
|
84
93
|
end
|
85
|
-
|
94
|
+
|
86
95
|
class FileDescriptorProto
|
87
|
-
optional
|
88
|
-
optional
|
89
|
-
repeated
|
90
|
-
repeated
|
91
|
-
repeated
|
96
|
+
optional :string, :name, 1
|
97
|
+
optional :string, :package, 2
|
98
|
+
repeated :string, :dependency, 3
|
99
|
+
repeated :int32, :public_dependency, 10
|
100
|
+
repeated :int32, :weak_dependency, 11
|
92
101
|
repeated ::Google::Protobuf::DescriptorProto, :message_type, 4
|
93
102
|
repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 5
|
94
103
|
repeated ::Google::Protobuf::ServiceDescriptorProto, :service, 6
|
@@ -96,14 +105,14 @@ module Google
|
|
96
105
|
optional ::Google::Protobuf::FileOptions, :options, 8
|
97
106
|
optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9
|
98
107
|
end
|
99
|
-
|
108
|
+
|
100
109
|
class DescriptorProto
|
101
110
|
class ExtensionRange
|
102
|
-
optional
|
103
|
-
optional
|
111
|
+
optional :int32, :start, 1
|
112
|
+
optional :int32, :end, 2
|
104
113
|
end
|
105
|
-
|
106
|
-
optional
|
114
|
+
|
115
|
+
optional :string, :name, 1
|
107
116
|
repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2
|
108
117
|
repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6
|
109
118
|
repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3
|
@@ -111,138 +120,130 @@ module Google
|
|
111
120
|
repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5
|
112
121
|
optional ::Google::Protobuf::MessageOptions, :options, 7
|
113
122
|
end
|
114
|
-
|
123
|
+
|
115
124
|
class FieldDescriptorProto
|
116
|
-
optional
|
117
|
-
optional
|
125
|
+
optional :string, :name, 1
|
126
|
+
optional :int32, :number, 3
|
118
127
|
optional ::Google::Protobuf::FieldDescriptorProto::Label, :label, 4
|
119
128
|
optional ::Google::Protobuf::FieldDescriptorProto::Type, :type, 5
|
120
|
-
optional
|
121
|
-
optional
|
122
|
-
optional
|
129
|
+
optional :string, :type_name, 6
|
130
|
+
optional :string, :extendee, 2
|
131
|
+
optional :string, :default_value, 7
|
123
132
|
optional ::Google::Protobuf::FieldOptions, :options, 8
|
124
133
|
end
|
125
|
-
|
134
|
+
|
126
135
|
class EnumDescriptorProto
|
127
|
-
optional
|
136
|
+
optional :string, :name, 1
|
128
137
|
repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2
|
129
138
|
optional ::Google::Protobuf::EnumOptions, :options, 3
|
130
139
|
end
|
131
|
-
|
140
|
+
|
132
141
|
class EnumValueDescriptorProto
|
133
|
-
optional
|
134
|
-
optional
|
142
|
+
optional :string, :name, 1
|
143
|
+
optional :int32, :number, 2
|
135
144
|
optional ::Google::Protobuf::EnumValueOptions, :options, 3
|
136
145
|
end
|
137
|
-
|
146
|
+
|
138
147
|
class ServiceDescriptorProto
|
139
|
-
optional
|
148
|
+
optional :string, :name, 1
|
140
149
|
repeated ::Google::Protobuf::MethodDescriptorProto, :method, 2
|
141
150
|
optional ::Google::Protobuf::ServiceOptions, :options, 3
|
142
151
|
end
|
143
|
-
|
152
|
+
|
144
153
|
class MethodDescriptorProto
|
145
|
-
optional
|
146
|
-
optional
|
147
|
-
optional
|
154
|
+
optional :string, :name, 1
|
155
|
+
optional :string, :input_type, 2
|
156
|
+
optional :string, :output_type, 3
|
148
157
|
optional ::Google::Protobuf::MethodOptions, :options, 4
|
149
158
|
end
|
150
|
-
|
159
|
+
|
151
160
|
class FileOptions
|
152
|
-
optional
|
153
|
-
optional
|
154
|
-
optional
|
155
|
-
optional
|
161
|
+
optional :string, :java_package, 1
|
162
|
+
optional :string, :java_outer_classname, 8
|
163
|
+
optional :bool, :java_multiple_files, 10, :default => false
|
164
|
+
optional :bool, :java_generate_equals_and_hash, 20, :default => false
|
156
165
|
optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
|
157
|
-
optional
|
158
|
-
optional
|
159
|
-
optional
|
160
|
-
optional
|
166
|
+
optional :string, :go_package, 11
|
167
|
+
optional :bool, :cc_generic_services, 16, :default => false
|
168
|
+
optional :bool, :java_generic_services, 17, :default => false
|
169
|
+
optional :bool, :py_generic_services, 18, :default => false
|
161
170
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
162
|
-
|
163
171
|
# Extension Fields
|
164
172
|
extensions 1000...536870912
|
165
173
|
end
|
166
|
-
|
174
|
+
|
167
175
|
class MessageOptions
|
168
|
-
optional
|
169
|
-
optional
|
176
|
+
optional :bool, :message_set_wire_format, 1, :default => false
|
177
|
+
optional :bool, :no_standard_descriptor_accessor, 2, :default => false
|
170
178
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
171
|
-
|
172
179
|
# Extension Fields
|
173
180
|
extensions 1000...536870912
|
174
181
|
end
|
175
|
-
|
182
|
+
|
176
183
|
class FieldOptions
|
177
184
|
optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING
|
178
|
-
optional
|
179
|
-
optional
|
180
|
-
optional
|
181
|
-
optional
|
182
|
-
optional
|
185
|
+
optional :bool, :packed, 2
|
186
|
+
optional :bool, :lazy, 5, :default => false
|
187
|
+
optional :bool, :deprecated, 3, :default => false
|
188
|
+
optional :string, :experimental_map_key, 9
|
189
|
+
optional :bool, :weak, 10, :default => false
|
183
190
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
184
|
-
|
185
191
|
# Extension Fields
|
186
192
|
extensions 1000...536870912
|
187
193
|
end
|
188
|
-
|
194
|
+
|
189
195
|
class EnumOptions
|
190
|
-
optional
|
196
|
+
optional :bool, :allow_alias, 2, :default => true
|
191
197
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
192
|
-
|
193
198
|
# Extension Fields
|
194
199
|
extensions 1000...536870912
|
195
200
|
end
|
196
|
-
|
201
|
+
|
197
202
|
class EnumValueOptions
|
198
203
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
199
|
-
|
200
204
|
# Extension Fields
|
201
205
|
extensions 1000...536870912
|
202
206
|
end
|
203
|
-
|
207
|
+
|
204
208
|
class ServiceOptions
|
205
209
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
206
|
-
|
207
210
|
# Extension Fields
|
208
211
|
extensions 1000...536870912
|
209
212
|
end
|
210
|
-
|
213
|
+
|
211
214
|
class MethodOptions
|
212
215
|
repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
|
213
|
-
|
214
216
|
# Extension Fields
|
215
217
|
extensions 1000...536870912
|
216
218
|
end
|
217
|
-
|
219
|
+
|
218
220
|
class UninterpretedOption
|
219
221
|
class NamePart
|
220
|
-
required
|
221
|
-
required
|
222
|
+
required :string, :name_part, 1
|
223
|
+
required :bool, :is_extension, 2
|
222
224
|
end
|
223
|
-
|
225
|
+
|
224
226
|
repeated ::Google::Protobuf::UninterpretedOption::NamePart, :name, 2
|
225
|
-
optional
|
226
|
-
optional
|
227
|
-
optional
|
228
|
-
optional
|
229
|
-
optional
|
230
|
-
optional
|
231
|
-
end
|
232
|
-
|
227
|
+
optional :string, :identifier_value, 3
|
228
|
+
optional :uint64, :positive_int_value, 4
|
229
|
+
optional :int64, :negative_int_value, 5
|
230
|
+
optional :double, :double_value, 6
|
231
|
+
optional :bytes, :string_value, 7
|
232
|
+
optional :string, :aggregate_value, 8
|
233
|
+
end
|
234
|
+
|
233
235
|
class SourceCodeInfo
|
234
236
|
class Location
|
235
|
-
repeated
|
236
|
-
repeated
|
237
|
-
optional
|
238
|
-
optional
|
237
|
+
repeated :int32, :path, 1, :packed => true
|
238
|
+
repeated :int32, :span, 2, :packed => true
|
239
|
+
optional :string, :leading_comments, 3
|
240
|
+
optional :string, :trailing_comments, 4
|
239
241
|
end
|
240
|
-
|
242
|
+
|
241
243
|
repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1
|
242
244
|
end
|
243
|
-
|
244
|
-
|
245
|
+
|
245
246
|
end
|
246
|
-
|
247
|
+
|
247
248
|
end
|
248
249
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Protobuf
|
2
|
+
class Encoder
|
3
|
+
|
4
|
+
def self.encode(stream, message)
|
5
|
+
new(stream, message).encode
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :message, :stream
|
9
|
+
|
10
|
+
def initialize(message, stream)
|
11
|
+
unless message.respond_to?(:each_field_for_serialization)
|
12
|
+
raise ArgumentError, "Message instance must respond to :each_field_for_serialization"
|
13
|
+
end
|
14
|
+
|
15
|
+
@message = message
|
16
|
+
@stream = stream
|
17
|
+
end
|
18
|
+
|
19
|
+
def encode
|
20
|
+
message.each_field_for_serialization do |field, value|
|
21
|
+
encode_field(field, value)
|
22
|
+
end
|
23
|
+
|
24
|
+
stream
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def encode_field(field, value)
|
30
|
+
if field.repeated?
|
31
|
+
encode_repeated_field(field, value)
|
32
|
+
else
|
33
|
+
write_pair(field, value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def encode_packed_field(field, value)
|
38
|
+
key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED
|
39
|
+
packed_value = value.map { |val| field.encode(val) }.join
|
40
|
+
stream << ::Protobuf::Field::VarintField.encode(key)
|
41
|
+
stream << ::Protobuf::Field::VarintField.encode(packed_value.size)
|
42
|
+
stream << packed_value
|
43
|
+
end
|
44
|
+
|
45
|
+
def encode_repeated_field(field, value)
|
46
|
+
if field.packed?
|
47
|
+
encode_packed_field(field, value)
|
48
|
+
else
|
49
|
+
value.each { |val| write_pair(field, val) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Encode key and value, and write to +stream+.
|
54
|
+
def write_pair(field, value)
|
55
|
+
key = (field.tag << 3) | field.wire_type
|
56
|
+
stream << ::Protobuf::Field::VarintField.encode(key)
|
57
|
+
stream << field.encode(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|