google-protobuf 3.21.0.rc.2-x64-mingw-ucrt

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 +361 -0
  3. data/ext/google/protobuf_c/convert.h +75 -0
  4. data/ext/google/protobuf_c/defs.c +1280 -0
  5. data/ext/google/protobuf_c/defs.h +107 -0
  6. data/ext/google/protobuf_c/extconf.rb +28 -0
  7. data/ext/google/protobuf_c/map.c +702 -0
  8. data/ext/google/protobuf_c/map.h +66 -0
  9. data/ext/google/protobuf_c/message.c +1402 -0
  10. data/ext/google/protobuf_c/message.h +104 -0
  11. data/ext/google/protobuf_c/protobuf.c +480 -0
  12. data/ext/google/protobuf_c/protobuf.h +120 -0
  13. data/ext/google/protobuf_c/repeated_field.c +657 -0
  14. data/ext/google/protobuf_c/repeated_field.h +63 -0
  15. data/ext/google/protobuf_c/ruby-upb.c +11115 -0
  16. data/ext/google/protobuf_c/ruby-upb.h +5612 -0
  17. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -0
  18. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  19. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  20. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  21. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -0
  22. data/ext/google/protobuf_c/wrap_memcpy.c +52 -0
  23. data/lib/google/3.1/protobuf_c.so +0 -0
  24. data/lib/google/protobuf/any_pb.rb +19 -0
  25. data/lib/google/protobuf/api_pb.rb +42 -0
  26. data/lib/google/protobuf/descriptor_dsl.rb +465 -0
  27. data/lib/google/protobuf/descriptor_pb.rb +269 -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 +201 -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 +92 -0
  37. data/lib/google/protobuf/well_known_types.rb +240 -0
  38. data/lib/google/protobuf/wrappers_pb.rb +50 -0
  39. data/lib/google/protobuf.rb +79 -0
  40. data/tests/basic.rb +739 -0
  41. data/tests/generated_code_test.rb +23 -0
  42. data/tests/stress.rb +38 -0
  43. metadata +138 -0
@@ -0,0 +1,269 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/descriptor.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ descriptor_data = File.binread(__FILE__).split("\n__END__\n", 2)[1]
7
+ Google::Protobuf::DescriptorPool.generated_pool.add_serialized_file(descriptor_data)
8
+
9
+ module Google
10
+ module Protobuf
11
+ FileDescriptorSet = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorSet").msgclass
12
+ FileDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileDescriptorProto").msgclass
13
+ DescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto").msgclass
14
+ DescriptorProto::ExtensionRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ExtensionRange").msgclass
15
+ DescriptorProto::ReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DescriptorProto.ReservedRange").msgclass
16
+ ExtensionRangeOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ExtensionRangeOptions").msgclass
17
+ FieldDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto").msgclass
18
+ FieldDescriptorProto::Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Type").enummodule
19
+ FieldDescriptorProto::Label = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldDescriptorProto.Label").enummodule
20
+ OneofDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofDescriptorProto").msgclass
21
+ EnumDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto").msgclass
22
+ EnumDescriptorProto::EnumReservedRange = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumDescriptorProto.EnumReservedRange").msgclass
23
+ EnumValueDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueDescriptorProto").msgclass
24
+ ServiceDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceDescriptorProto").msgclass
25
+ MethodDescriptorProto = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodDescriptorProto").msgclass
26
+ FileOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions").msgclass
27
+ FileOptions::OptimizeMode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FileOptions.OptimizeMode").enummodule
28
+ MessageOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MessageOptions").msgclass
29
+ FieldOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions").msgclass
30
+ FieldOptions::CType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.CType").enummodule
31
+ FieldOptions::JSType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.JSType").enummodule
32
+ OneofOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofOptions").msgclass
33
+ EnumOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumOptions").msgclass
34
+ EnumValueOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueOptions").msgclass
35
+ ServiceOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ServiceOptions").msgclass
36
+ MethodOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions").msgclass
37
+ MethodOptions::IdempotencyLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.MethodOptions.IdempotencyLevel").enummodule
38
+ UninterpretedOption = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption").msgclass
39
+ UninterpretedOption::NamePart = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UninterpretedOption.NamePart").msgclass
40
+ SourceCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo").msgclass
41
+ SourceCodeInfo::Location = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo.Location").msgclass
42
+ GeneratedCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo").msgclass
43
+ GeneratedCodeInfo::Annotation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo.Annotation").msgclass
44
+ end
45
+ end
46
+
47
+ __END__
48
+
49
+ google/protobuf/descriptor.protogoogle.protobuf"G
50
+ FileDescriptorSet2
51
+ file ( 2$.google.protobuf.FileDescriptorProto"�
52
+ FileDescriptorProto
53
+ name ( 
54
+ package ( 
55
+
56
+ dependency ( 
57
+ public_dependency
58
+ (
59
+ weak_dependency (6
60
+ message_type ( 2 .google.protobuf.DescriptorProto7
61
+ enum_type ( 2$.google.protobuf.EnumDescriptorProto8
62
+ service ( 2'.google.protobuf.ServiceDescriptorProto8
63
+ extension ( 2%.google.protobuf.FieldDescriptorProto-
64
+ options ( 2.google.protobuf.FileOptions9
65
+ source_code_info ( 2.google.protobuf.SourceCodeInfo
66
+ syntax ( "�
67
+ DescriptorProto
68
+ name ( 4
69
+ field ( 2%.google.protobuf.FieldDescriptorProto8
70
+ extension ( 2%.google.protobuf.FieldDescriptorProto5
71
+ nested_type ( 2 .google.protobuf.DescriptorProto7
72
+ enum_type ( 2$.google.protobuf.EnumDescriptorProtoH
73
+ extension_range ( 2/.google.protobuf.DescriptorProto.ExtensionRange9
74
+
75
+ oneof_decl ( 2%.google.protobuf.OneofDescriptorProto0
76
+ options ( 2.google.protobuf.MessageOptionsF
77
+ reserved_range ( 2..google.protobuf.DescriptorProto.ReservedRange
78
+
79
+ ( e
80
+ ExtensionRange
81
+ start (
82
+ end (7
83
+ options ( 2&.google.protobuf.ExtensionRangeOptions+
84
+
85
+ start (
86
+ end ("g
87
+ ExtensionRangeOptionsC
88
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
89
+ FieldDescriptorProto
90
+ name ( 
91
+ number (:
92
+ label (2+.google.protobuf.FieldDescriptorProto.Label8
93
+ type (2*.google.protobuf.FieldDescriptorProto.Type
94
+ type_name ( 
95
+ extendee ( 
96
+
97
+ oneof_index (
98
+ json_name
99
+ ( .
100
+ options ( 2.google.protobuf.FieldOptions
101
+ proto3_optional ("�
102
+ Type
103
+ TYPE_DOUBLE
104
+
105
+ TYPE_FLOAT
106
+
107
+ TYPE_INT64
108
+ TYPE_UINT64
109
+
110
+ TYPE_INT32
111
+ TYPE_FIXED64
112
+ TYPE_FIXED32
113
+ TYPE_BOOL
114
+ TYPE_STRING 
115
+
116
+ TYPE_GROUP
117
+ 
118
+ TYPE_MESSAGE 
119
+
120
+ TYPE_BYTES 
121
+ TYPE_UINT32
122
+ TYPE_ENUM
123
+
124
+
125
+ TYPE_SINT32
126
+ TYPE_SINT64"C
127
+ Label
128
+ LABEL_OPTIONAL
129
+ LABEL_REQUIRED
130
+ LABEL_REPEATED"T
131
+ OneofDescriptorProto
132
+ name ( .
133
+ options ( 2.google.protobuf.OneofOptions"�
134
+ EnumDescriptorProto
135
+ name ( 8
136
+ value ( 2).google.protobuf.EnumValueDescriptorProto-
137
+ options ( 2.google.protobuf.EnumOptionsN
138
+ reserved_range ( 26.google.protobuf.EnumDescriptorProto.EnumReservedRange
139
+
140
+ EnumReservedRange
141
+ start (
142
+ end ("l
143
+ EnumValueDescriptorProto
144
+ name ( 
145
+ number (2
146
+ options ( 2!.google.protobuf.EnumValueOptions"�
147
+ ServiceDescriptorProto
148
+ name ( 6
149
+ method ( 2&.google.protobuf.MethodDescriptorProto0
150
+ options ( 2.google.protobuf.ServiceOptions"�
151
+ MethodDescriptorProto
152
+ name ( 
153
+
154
+ input_type ( 
155
+ output_type ( /
156
+ options ( 2.google.protobuf.MethodOptions
157
+ client_streaming (:false
158
+ server_streaming (:false"�
159
+ FileOptions
160
+ java_package ( 
161
+ java_outer_classname ( "
162
+ java_multiple_files
163
+ (:false)
164
+ java_generate_equals_and_hash (B%
165
+ java_string_check_utf8 (:falseF
166
+ optimize_for (2).google.protobuf.FileOptions.OptimizeMode:SPEED
167
+
168
+ go_package ( "
169
+ cc_generic_services (:false$
170
+ java_generic_services (:false"
171
+ py_generic_services (:false#
172
+ php_generic_services* (:false
173
+
174
+ deprecated (:false
175
+ cc_enable_arenas (:true
176
+ objc_class_prefix$ ( 
177
+ csharp_namespace% ( 
178
+ swift_prefix' ( 
179
+ php_class_prefix( ( 
180
+
181
+ php_metadata_namespace, ( 
182
+ ruby_package- ( C
183
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption":
184
+ OptimizeMode
185
+ SPEED
186
+ CODE_SIZE
187
+ LITE_RUNTIME* �����J&'"�
188
+ MessageOptions&
189
+ message_set_wire_format (:false.
190
+ no_standard_descriptor_accessor (:false
191
+
192
+ deprecated (:false
193
+ map_entry (C
194
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����JJJJ J 
195
+ "�
196
+ FieldOptions:
197
+ ctype (2#.google.protobuf.FieldOptions.CType:STRING
198
+ packed (?
199
+ jstype (2$.google.protobuf.FieldOptions.JSType: JS_NORMAL
200
+ lazy (:false
201
+ unverified_lazy (:false
202
+
203
+ deprecated (:false
204
+ weak
205
+ (:falseC
206
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"/
207
+ CType
208
+
209
+ STRING
210
+ CORD
211
+ STRING_PIECE"5
212
+ JSType
213
+ JS_NORMAL
214
+ JS_STRING
215
+ JS_NUMBER* �����J"^
216
+ OneofOptionsC
217
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
218
+ EnumOptions
219
+ allow_alias (
220
+
221
+ deprecated (:falseC
222
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����J"}
223
+ EnumValueOptions
224
+
225
+ deprecated (:falseC
226
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"{
227
+ ServiceOptions
228
+
229
+ deprecated! (:falseC
230
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
231
+
232
+
233
+ deprecated! (:false_
234
+ idempotency_level" (2/.google.protobuf.MethodOptions.IdempotencyLevel:IDEMPOTENCY_UNKNOWNC
235
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"P
236
+ IdempotencyLevel
237
+ IDEMPOTENCY_UNKNOWN
238
+ NO_SIDE_EFFECTS
239
+
240
+ IDEMPOTENT* �����"�
241
+ UninterpretedOption;
242
+ name ( 2-.google.protobuf.UninterpretedOption.NamePart
243
+ identifier_value ( 
244
+ positive_int_value (
245
+ negative_int_value (
246
+ double_value (
247
+ string_value ( 
248
+ aggregate_value ( 3
249
+ NamePart
250
+ name_part ( 
251
+ is_extension ("�
252
+ SourceCodeInfo:
253
+ location ( 2(.google.protobuf.SourceCodeInfo.Location�
254
+ Location
255
+ path (B
256
+ span (B
257
+ leading_comments ( 
258
+ trailing_comments ( !
259
+ leading_detached_comments ( "�
260
+ GeneratedCodeInfoA
261
+
262
+ annotation ( 2-.google.protobuf.GeneratedCodeInfo.AnnotationO
263
+
264
+ Annotation
265
+ path (B
266
+ source_file ( 
267
+ begin (
268
+ end (B~
269
+ 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(options = {})
48
+ self.class.encode(self, options)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,201 @@
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
+ if n.nil?
83
+ return self[0]
84
+ elsif n < 0
85
+ raise ArgumentError, "negative array size"
86
+ else
87
+ return self[0...n]
88
+ end
89
+ end
90
+
91
+
92
+ def last(n=nil)
93
+ if n.nil?
94
+ return self[-1]
95
+ elsif n < 0
96
+ raise ArgumentError, "negative array size"
97
+ else
98
+ start = [self.size-n, 0].max
99
+ return self[start...self.size]
100
+ end
101
+ end
102
+
103
+
104
+ def pop(n=nil)
105
+ if n
106
+ results = []
107
+ n.times{ results << pop_one }
108
+ return results
109
+ else
110
+ return pop_one
111
+ end
112
+ end
113
+
114
+
115
+ def empty?
116
+ self.size == 0
117
+ end
118
+
119
+ # array aliases into enumerable
120
+ alias_method :each_index, :each_with_index
121
+ alias_method :slice, :[]
122
+ alias_method :values_at, :select
123
+ alias_method :map, :collect
124
+
125
+
126
+ class << self
127
+ def define_array_wrapper_method(method_name)
128
+ define_method(method_name) do |*args, &block|
129
+ arr = self.to_a
130
+ result = arr.send(method_name, *args)
131
+ self.replace(arr)
132
+ return result if result
133
+ return block ? block.call : result
134
+ end
135
+ end
136
+ private :define_array_wrapper_method
137
+
138
+
139
+ def define_array_wrapper_with_result_method(method_name)
140
+ define_method(method_name) do |*args, &block|
141
+ # result can be an Enumerator, Array, or nil
142
+ # Enumerator can sometimes be returned if a block is an optional argument and it is not passed in
143
+ # nil usually specifies that no change was made
144
+ result = self.to_a.send(method_name, *args, &block)
145
+ if result
146
+ new_arr = result.to_a
147
+ self.replace(new_arr)
148
+ if result.is_a?(Enumerator)
149
+ # generate a fresh enum; rewinding the exiting one, in Ruby 2.2, will
150
+ # reset the enum with the same length, but all the #next calls will
151
+ # return nil
152
+ result = new_arr.to_enum
153
+ # generate a wrapper enum so any changes which occur by a chained
154
+ # enum can be captured
155
+ ie = ProxyingEnumerator.new(self, result)
156
+ result = ie.to_enum
157
+ end
158
+ end
159
+ result
160
+ end
161
+ end
162
+ private :define_array_wrapper_with_result_method
163
+ end
164
+
165
+
166
+ %w(delete delete_at shift slice! unshift).each do |method_name|
167
+ define_array_wrapper_method(method_name)
168
+ end
169
+
170
+
171
+ %w(collect! compact! delete_if fill flatten! insert reverse!
172
+ rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
173
+ define_array_wrapper_with_result_method(method_name)
174
+ end
175
+ alias_method :keep_if, :select!
176
+ alias_method :map!, :collect!
177
+ alias_method :reject!, :delete_if
178
+
179
+
180
+ # propagates changes made by user of enumerator back to the original repeated field.
181
+ # This only applies in cases where the calling function which created the enumerator,
182
+ # such as #sort!, modifies itself rather than a new array, such as #sort
183
+ class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerator)
184
+ def each(*args, &block)
185
+ results = []
186
+ external_enumerator.each_with_index do |val, i|
187
+ result = yield(val)
188
+ results << result
189
+ #nil means no change occurred from yield; usually occurs when #to_a is called
190
+ if result
191
+ repeated_field[i] = result if result != val
192
+ end
193
+ end
194
+ results
195
+ end
196
+ end
197
+
198
+
199
+ end
200
+ end
201
+ 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