google-protobuf 3.19.0.rc.1-x86_64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/ext/google/protobuf_c/convert.c +348 -0
  3. data/ext/google/protobuf_c/convert.h +72 -0
  4. data/ext/google/protobuf_c/defs.c +1284 -0
  5. data/ext/google/protobuf_c/defs.h +107 -0
  6. data/ext/google/protobuf_c/extconf.rb +20 -0
  7. data/ext/google/protobuf_c/map.c +694 -0
  8. data/ext/google/protobuf_c/map.h +67 -0
  9. data/ext/google/protobuf_c/message.c +1328 -0
  10. data/ext/google/protobuf_c/message.h +101 -0
  11. data/ext/google/protobuf_c/protobuf.c +470 -0
  12. data/ext/google/protobuf_c/protobuf.h +117 -0
  13. data/ext/google/protobuf_c/repeated_field.c +659 -0
  14. data/ext/google/protobuf_c/repeated_field.h +63 -0
  15. data/ext/google/protobuf_c/ruby-upb.c +9171 -0
  16. data/ext/google/protobuf_c/ruby-upb.h +4704 -0
  17. data/ext/google/protobuf_c/wrap_memcpy.c +51 -0
  18. data/lib/google/2.3/protobuf_c.bundle +0 -0
  19. data/lib/google/2.4/protobuf_c.bundle +0 -0
  20. data/lib/google/2.5/protobuf_c.bundle +0 -0
  21. data/lib/google/2.6/protobuf_c.bundle +0 -0
  22. data/lib/google/2.7/protobuf_c.bundle +0 -0
  23. data/lib/google/3.0/protobuf_c.bundle +0 -0
  24. data/lib/google/protobuf/any_pb.rb +19 -0
  25. data/lib/google/protobuf/api_pb.rb +41 -0
  26. data/lib/google/protobuf/descriptor_dsl.rb +458 -0
  27. data/lib/google/protobuf/descriptor_pb.rb +266 -0
  28. data/lib/google/protobuf/duration_pb.rb +19 -0
  29. data/lib/google/protobuf/empty_pb.rb +17 -0
  30. data/lib/google/protobuf/field_mask_pb.rb +18 -0
  31. data/lib/google/protobuf/message_exts.rb +53 -0
  32. data/lib/google/protobuf/repeated_field.rb +188 -0
  33. data/lib/google/protobuf/source_context_pb.rb +18 -0
  34. data/lib/google/protobuf/struct_pb.rb +37 -0
  35. data/lib/google/protobuf/timestamp_pb.rb +19 -0
  36. data/lib/google/protobuf/type_pb.rb +91 -0
  37. data/lib/google/protobuf/well_known_types.rb +235 -0
  38. data/lib/google/protobuf/wrappers_pb.rb +50 -0
  39. data/lib/google/protobuf.rb +79 -0
  40. data/tests/basic.rb +640 -0
  41. data/tests/generated_code_test.rb +23 -0
  42. data/tests/stress.rb +38 -0
  43. metadata +144 -0
@@ -0,0 +1,266 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/descriptor.proto
3
+
4
+ descriptor_data = File.binread(__FILE__).split("\n__END__\n", 2)[1]
5
+ Google::Protobuf::DescriptorPool.generated_pool.add_serialized_file(descriptor_data)
6
+
7
+ module Google
8
+ module Protobuf
9
+ FileDescriptorSet = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorSet").msgclass
10
+ FileDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorProto").msgclass
11
+ DescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto").msgclass
12
+ DescriptorProto::ExtensionRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ExtensionRange").msgclass
13
+ DescriptorProto::ReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ReservedRange").msgclass
14
+ ExtensionRangeOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ExtensionRangeOptions").msgclass
15
+ FieldDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto").msgclass
16
+ FieldDescriptorProto::Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Type").enummodule
17
+ FieldDescriptorProto::Label = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Label").enummodule
18
+ OneofDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofDescriptorProto").msgclass
19
+ EnumDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto").msgclass
20
+ EnumDescriptorProto::EnumReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto.EnumReservedRange").msgclass
21
+ EnumValueDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueDescriptorProto").msgclass
22
+ ServiceDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceDescriptorProto").msgclass
23
+ MethodDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodDescriptorProto").msgclass
24
+ FileOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions").msgclass
25
+ FileOptions::OptimizeMode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions.OptimizeMode").enummodule
26
+ MessageOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MessageOptions").msgclass
27
+ FieldOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions").msgclass
28
+ FieldOptions::CType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.CType").enummodule
29
+ FieldOptions::JSType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.JSType").enummodule
30
+ OneofOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofOptions").msgclass
31
+ EnumOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumOptions").msgclass
32
+ EnumValueOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueOptions").msgclass
33
+ ServiceOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceOptions").msgclass
34
+ MethodOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions").msgclass
35
+ MethodOptions::IdempotencyLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions.IdempotencyLevel").enummodule
36
+ UninterpretedOption = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption").msgclass
37
+ UninterpretedOption::NamePart = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption.NamePart").msgclass
38
+ SourceCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo").msgclass
39
+ SourceCodeInfo::Location = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo.Location").msgclass
40
+ GeneratedCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo").msgclass
41
+ GeneratedCodeInfo::Annotation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo.Annotation").msgclass
42
+ end
43
+ end
44
+
45
+ __END__
46
+
47
+ google/protobuf/descriptor.protogoogle.protobuf"G
48
+ FileDescriptorSet2
49
+ file ( 2$.google.protobuf.FileDescriptorProto"�
50
+ FileDescriptorProto
51
+ name ( 
52
+ package ( 
53
+
54
+ dependency ( 
55
+ public_dependency
56
+ (
57
+ weak_dependency (6
58
+ message_type ( 2 .google.protobuf.DescriptorProto7
59
+ enum_type ( 2$.google.protobuf.EnumDescriptorProto8
60
+ service ( 2'.google.protobuf.ServiceDescriptorProto8
61
+ extension ( 2%.google.protobuf.FieldDescriptorProto-
62
+ options ( 2.google.protobuf.FileOptions9
63
+ source_code_info ( 2.google.protobuf.SourceCodeInfo
64
+ syntax ( "�
65
+ DescriptorProto
66
+ name ( 4
67
+ field ( 2%.google.protobuf.FieldDescriptorProto8
68
+ extension ( 2%.google.protobuf.FieldDescriptorProto5
69
+ nested_type ( 2 .google.protobuf.DescriptorProto7
70
+ enum_type ( 2$.google.protobuf.EnumDescriptorProtoH
71
+ extension_range ( 2/.google.protobuf.DescriptorProto.ExtensionRange9
72
+
73
+ oneof_decl ( 2%.google.protobuf.OneofDescriptorProto0
74
+ options ( 2.google.protobuf.MessageOptionsF
75
+ reserved_range ( 2..google.protobuf.DescriptorProto.ReservedRange
76
+
77
+ ( e
78
+ ExtensionRange
79
+ start (
80
+ end (7
81
+ options ( 2&.google.protobuf.ExtensionRangeOptions+
82
+
83
+ start (
84
+ end ("g
85
+ ExtensionRangeOptionsC
86
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
87
+ FieldDescriptorProto
88
+ name ( 
89
+ number (:
90
+ label (2+.google.protobuf.FieldDescriptorProto.Label8
91
+ type (2*.google.protobuf.FieldDescriptorProto.Type
92
+ type_name ( 
93
+ extendee ( 
94
+
95
+ oneof_index (
96
+ json_name
97
+ ( .
98
+ options ( 2.google.protobuf.FieldOptions
99
+ proto3_optional ("�
100
+ Type
101
+ TYPE_DOUBLE
102
+
103
+ TYPE_FLOAT
104
+
105
+ TYPE_INT64
106
+ TYPE_UINT64
107
+
108
+ TYPE_INT32
109
+ TYPE_FIXED64
110
+ TYPE_FIXED32
111
+ TYPE_BOOL
112
+ TYPE_STRING 
113
+
114
+ TYPE_GROUP
115
+ 
116
+ TYPE_MESSAGE 
117
+
118
+ TYPE_BYTES 
119
+ TYPE_UINT32
120
+ TYPE_ENUM
121
+
122
+
123
+ TYPE_SINT32
124
+ TYPE_SINT64"C
125
+ Label
126
+ LABEL_OPTIONAL
127
+ LABEL_REQUIRED
128
+ LABEL_REPEATED"T
129
+ OneofDescriptorProto
130
+ name ( .
131
+ options ( 2.google.protobuf.OneofOptions"�
132
+ EnumDescriptorProto
133
+ name ( 8
134
+ value ( 2).google.protobuf.EnumValueDescriptorProto-
135
+ options ( 2.google.protobuf.EnumOptionsN
136
+ reserved_range ( 26.google.protobuf.EnumDescriptorProto.EnumReservedRange
137
+
138
+ EnumReservedRange
139
+ start (
140
+ end ("l
141
+ EnumValueDescriptorProto
142
+ name ( 
143
+ number (2
144
+ options ( 2!.google.protobuf.EnumValueOptions"�
145
+ ServiceDescriptorProto
146
+ name ( 6
147
+ method ( 2&.google.protobuf.MethodDescriptorProto0
148
+ options ( 2.google.protobuf.ServiceOptions"�
149
+ MethodDescriptorProto
150
+ name ( 
151
+
152
+ input_type ( 
153
+ output_type ( /
154
+ options ( 2.google.protobuf.MethodOptions
155
+ client_streaming (:false
156
+ server_streaming (:false"�
157
+ FileOptions
158
+ java_package ( 
159
+ java_outer_classname ( "
160
+ java_multiple_files
161
+ (:false)
162
+ java_generate_equals_and_hash (B%
163
+ java_string_check_utf8 (:falseF
164
+ optimize_for (2).google.protobuf.FileOptions.OptimizeMode:SPEED
165
+
166
+ go_package ( "
167
+ cc_generic_services (:false$
168
+ java_generic_services (:false"
169
+ py_generic_services (:false#
170
+ php_generic_services* (:false
171
+
172
+ deprecated (:false
173
+ cc_enable_arenas (:true
174
+ objc_class_prefix$ ( 
175
+ csharp_namespace% ( 
176
+ swift_prefix' ( 
177
+ php_class_prefix( ( 
178
+
179
+ php_metadata_namespace, ( 
180
+ ruby_package- ( C
181
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption":
182
+ OptimizeMode
183
+ SPEED
184
+ CODE_SIZE
185
+ LITE_RUNTIME* �����J&'"�
186
+ MessageOptions&
187
+ message_set_wire_format (:false.
188
+ no_standard_descriptor_accessor (:false
189
+
190
+ deprecated (:false
191
+ map_entry (C
192
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����JJJJ J 
193
+ "�
194
+ FieldOptions:
195
+ ctype (2#.google.protobuf.FieldOptions.CType:STRING
196
+ packed (?
197
+ jstype (2$.google.protobuf.FieldOptions.JSType: JS_NORMAL
198
+ lazy (:false
199
+
200
+ deprecated (:false
201
+ weak
202
+ (:falseC
203
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"/
204
+ CType
205
+
206
+ STRING
207
+ CORD
208
+ STRING_PIECE"5
209
+ JSType
210
+ JS_NORMAL
211
+ JS_STRING
212
+ JS_NUMBER* �����J"^
213
+ OneofOptionsC
214
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
215
+ EnumOptions
216
+ allow_alias (
217
+
218
+ deprecated (:falseC
219
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����J"}
220
+ EnumValueOptions
221
+
222
+ deprecated (:falseC
223
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"{
224
+ ServiceOptions
225
+
226
+ deprecated! (:falseC
227
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
228
+
229
+
230
+ deprecated! (:false_
231
+ idempotency_level" (2/.google.protobuf.MethodOptions.IdempotencyLevel:IDEMPOTENCY_UNKNOWNC
232
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"P
233
+ IdempotencyLevel
234
+ IDEMPOTENCY_UNKNOWN
235
+ NO_SIDE_EFFECTS
236
+
237
+ IDEMPOTENT* �����"�
238
+ UninterpretedOption;
239
+ name ( 2-.google.protobuf.UninterpretedOption.NamePart
240
+ identifier_value ( 
241
+ positive_int_value (
242
+ negative_int_value (
243
+ double_value (
244
+ string_value ( 
245
+ aggregate_value ( 3
246
+ NamePart
247
+ name_part ( 
248
+ is_extension ("�
249
+ SourceCodeInfo:
250
+ location ( 2(.google.protobuf.SourceCodeInfo.Location�
251
+ Location
252
+ path (B
253
+ span (B
254
+ leading_comments ( 
255
+ trailing_comments ( !
256
+ leading_detached_comments ( "�
257
+ GeneratedCodeInfoA
258
+
259
+ annotation ( 2-.google.protobuf.GeneratedCodeInfo.AnnotationO
260
+
261
+ Annotation
262
+ path (B
263
+ source_file ( 
264
+ begin (
265
+ end (B~
266
+ com.google.protobufBDescriptorProtosHZ-google.golang.org/protobuf/types/descriptorpb��GPB�Google.Protobuf.Reflection
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/duration.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/duration.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.Duration" do
9
+ optional :seconds, :int64, 1
10
+ optional :nanos, :int32, 2
11
+ end
12
+ end
13
+ end
14
+
15
+ module Google
16
+ module Protobuf
17
+ Duration = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/empty.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/empty.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.Empty" do
9
+ end
10
+ end
11
+ end
12
+
13
+ module Google
14
+ module Protobuf
15
+ Empty = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/field_mask.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/field_mask.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.FieldMask" do
9
+ repeated :paths, :string, 1
10
+ end
11
+ end
12
+ end
13
+
14
+ module Google
15
+ module Protobuf
16
+ FieldMask = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
17
+ end
18
+ end
@@ -0,0 +1,53 @@
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
+ module Google
32
+ module Protobuf
33
+ module MessageExts
34
+
35
+ #this is only called in jruby; mri loades the ClassMethods differently
36
+ def self.included(klass)
37
+ klass.extend(ClassMethods)
38
+ end
39
+
40
+ module ClassMethods
41
+ end
42
+
43
+ def to_json(options = {})
44
+ self.class.encode_json(self, options)
45
+ end
46
+
47
+ def to_proto
48
+ self.class.encode(self)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,188 @@
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
+ require 'forwardable'
32
+
33
+ #
34
+ # This class makes RepeatedField act (almost-) like a Ruby Array.
35
+ # It has convenience methods that extend the core C or Java based
36
+ # methods.
37
+ #
38
+ # This is a best-effort to mirror Array behavior. Two comments:
39
+ # 1) patches always welcome :)
40
+ # 2) if performance is an issue, feel free to rewrite the method
41
+ # in jruby and C. The source code has plenty of examples
42
+ #
43
+ # KNOWN ISSUES
44
+ # - #[]= doesn't allow less used approaches such as `arr[1, 2] = 'fizz'`
45
+ # - #concat should return the orig array
46
+ # - #push should accept multiple arguments and push them all at the same time
47
+ #
48
+ module Google
49
+ module Protobuf
50
+ class RepeatedField
51
+ extend Forwardable
52
+
53
+ # methods defined in C or Java:
54
+ # +
55
+ # [], at
56
+ # []=
57
+ # concat
58
+ # clear
59
+ # dup, clone
60
+ # each
61
+ # push, <<
62
+ # replace
63
+ # length, size
64
+ # ==
65
+ # to_ary, to_a
66
+ # also all enumerable
67
+ #
68
+ # NOTE: using delegators rather than method_missing to make the
69
+ # relationship explicit instead of implicit
70
+ def_delegators :to_ary,
71
+ :&, :*, :-, :'<=>',
72
+ :assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
73
+ :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
74
+ :include?, :index, :inspect, :join,
75
+ :pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
76
+ :rassoc, :repeated_combination, :repeated_permutation, :reverse,
77
+ :rindex, :rotate, :sample, :shuffle, :shelljoin,
78
+ :to_s, :transpose, :uniq, :|
79
+
80
+
81
+ def first(n=nil)
82
+ n ? self[0...n] : self[0]
83
+ end
84
+
85
+
86
+ def last(n=nil)
87
+ n ? self[(self.size-n-1)..-1] : self[-1]
88
+ end
89
+
90
+
91
+ def pop(n=nil)
92
+ if n
93
+ results = []
94
+ n.times{ results << pop_one }
95
+ return results
96
+ else
97
+ return pop_one
98
+ end
99
+ end
100
+
101
+
102
+ def empty?
103
+ self.size == 0
104
+ end
105
+
106
+ # array aliases into enumerable
107
+ alias_method :each_index, :each_with_index
108
+ alias_method :slice, :[]
109
+ alias_method :values_at, :select
110
+ alias_method :map, :collect
111
+
112
+
113
+ class << self
114
+ def define_array_wrapper_method(method_name)
115
+ define_method(method_name) do |*args, &block|
116
+ arr = self.to_a
117
+ result = arr.send(method_name, *args)
118
+ self.replace(arr)
119
+ return result if result
120
+ return block ? block.call : result
121
+ end
122
+ end
123
+ private :define_array_wrapper_method
124
+
125
+
126
+ def define_array_wrapper_with_result_method(method_name)
127
+ define_method(method_name) do |*args, &block|
128
+ # result can be an Enumerator, Array, or nil
129
+ # Enumerator can sometimes be returned if a block is an optional argument and it is not passed in
130
+ # nil usually specifies that no change was made
131
+ result = self.to_a.send(method_name, *args, &block)
132
+ if result
133
+ new_arr = result.to_a
134
+ self.replace(new_arr)
135
+ if result.is_a?(Enumerator)
136
+ # generate a fresh enum; rewinding the exiting one, in Ruby 2.2, will
137
+ # reset the enum with the same length, but all the #next calls will
138
+ # return nil
139
+ result = new_arr.to_enum
140
+ # generate a wrapper enum so any changes which occur by a chained
141
+ # enum can be captured
142
+ ie = ProxyingEnumerator.new(self, result)
143
+ result = ie.to_enum
144
+ end
145
+ end
146
+ result
147
+ end
148
+ end
149
+ private :define_array_wrapper_with_result_method
150
+ end
151
+
152
+
153
+ %w(delete delete_at shift slice! unshift).each do |method_name|
154
+ define_array_wrapper_method(method_name)
155
+ end
156
+
157
+
158
+ %w(collect! compact! delete_if fill flatten! insert reverse!
159
+ rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
160
+ define_array_wrapper_with_result_method(method_name)
161
+ end
162
+ alias_method :keep_if, :select!
163
+ alias_method :map!, :collect!
164
+ alias_method :reject!, :delete_if
165
+
166
+
167
+ # propagates changes made by user of enumerator back to the original repeated field.
168
+ # This only applies in cases where the calling function which created the enumerator,
169
+ # such as #sort!, modifies itself rather than a new array, such as #sort
170
+ class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerator)
171
+ def each(*args, &block)
172
+ results = []
173
+ external_enumerator.each_with_index do |val, i|
174
+ result = yield(val)
175
+ results << result
176
+ #nil means no change occurred from yield; usually occurs when #to_a is called
177
+ if result
178
+ repeated_field[i] = result if result != val
179
+ end
180
+ end
181
+ results
182
+ end
183
+ end
184
+
185
+
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/source_context.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/source_context.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.SourceContext" do
9
+ optional :file_name, :string, 1
10
+ end
11
+ end
12
+ end
13
+
14
+ module Google
15
+ module Protobuf
16
+ SourceContext = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/struct.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/struct.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.Struct" do
9
+ map :fields, :string, :message, 1, "google.protobuf.Value"
10
+ end
11
+ add_message "google.protobuf.Value" do
12
+ oneof :kind do
13
+ optional :null_value, :enum, 1, "google.protobuf.NullValue"
14
+ optional :number_value, :double, 2
15
+ optional :string_value, :string, 3
16
+ optional :bool_value, :bool, 4
17
+ optional :struct_value, :message, 5, "google.protobuf.Struct"
18
+ optional :list_value, :message, 6, "google.protobuf.ListValue"
19
+ end
20
+ end
21
+ add_message "google.protobuf.ListValue" do
22
+ repeated :values, :message, 1, "google.protobuf.Value"
23
+ end
24
+ add_enum "google.protobuf.NullValue" do
25
+ value :NULL_VALUE, 0
26
+ end
27
+ end
28
+ end
29
+
30
+ module Google
31
+ module Protobuf
32
+ Struct = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
33
+ Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
34
+ ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
35
+ NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/timestamp.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("google/protobuf/timestamp.proto", :syntax => :proto3) do
8
+ add_message "google.protobuf.Timestamp" do
9
+ optional :seconds, :int64, 1
10
+ optional :nanos, :int32, 2
11
+ end
12
+ end
13
+ end
14
+
15
+ module Google
16
+ module Protobuf
17
+ Timestamp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
18
+ end
19
+ end