protostar 0.1.0.beta1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +647 -0
- data/THIRD_PARTY_NOTICES.md +61 -0
- data/exe/protoc-gen-protostar +7 -0
- data/exe/protostar +7 -0
- data/lib/protostar/builder/generator.rb +71 -0
- data/lib/protostar/builder/sink.rb +35 -0
- data/lib/protostar/builder.rb +965 -0
- data/lib/protostar/cli.rb +267 -0
- data/lib/protostar/codec/decode_generator.rb +199 -0
- data/lib/protostar/codec/decoder.rb +296 -0
- data/lib/protostar/codec/encode_generator.rb +224 -0
- data/lib/protostar/codec/encoder.rb +121 -0
- data/lib/protostar/codec/sizer.rb +91 -0
- data/lib/protostar/codec.rb +15 -0
- data/lib/protostar/compiler/ast.rb +193 -0
- data/lib/protostar/compiler/emitters/descriptor_set.rb +57 -0
- data/lib/protostar/compiler/emitters/google_ruby.rb +103 -0
- data/lib/protostar/compiler/emitters/grpc.rb +175 -0
- data/lib/protostar/compiler/emitters/protostar_rbs.rb +252 -0
- data/lib/protostar/compiler/emitters/rbs.rb +394 -0
- data/lib/protostar/compiler/emitters/ruby.rb +503 -0
- data/lib/protostar/compiler/emitters.rb +268 -0
- data/lib/protostar/compiler/include/LICENSE +32 -0
- data/lib/protostar/compiler/include/google/protobuf/any.proto +106 -0
- data/lib/protostar/compiler/include/google/protobuf/api.proto +229 -0
- data/lib/protostar/compiler/include/google/protobuf/compiler/plugin.proto +180 -0
- data/lib/protostar/compiler/include/google/protobuf/cpp_features.proto +87 -0
- data/lib/protostar/compiler/include/google/protobuf/descriptor.proto +1532 -0
- data/lib/protostar/compiler/include/google/protobuf/duration.proto +115 -0
- data/lib/protostar/compiler/include/google/protobuf/empty.proto +51 -0
- data/lib/protostar/compiler/include/google/protobuf/field_mask.proto +243 -0
- data/lib/protostar/compiler/include/google/protobuf/java_features.proto +132 -0
- data/lib/protostar/compiler/include/google/protobuf/source_context.proto +48 -0
- data/lib/protostar/compiler/include/google/protobuf/struct.proto +111 -0
- data/lib/protostar/compiler/include/google/protobuf/timestamp.proto +145 -0
- data/lib/protostar/compiler/include/google/protobuf/type.proto +217 -0
- data/lib/protostar/compiler/include/google/protobuf/wrappers.proto +157 -0
- data/lib/protostar/compiler/lexer.rb +659 -0
- data/lib/protostar/compiler/linker.rb +894 -0
- data/lib/protostar/compiler/option_interpreter.rb +363 -0
- data/lib/protostar/compiler/parser.rb +1696 -0
- data/lib/protostar/compiler/retention.rb +104 -0
- data/lib/protostar/compiler/run.rb +184 -0
- data/lib/protostar/compiler/source_info.rb +161 -0
- data/lib/protostar/compiler/symbol_table.rb +223 -0
- data/lib/protostar/compiler/text_format.rb +340 -0
- data/lib/protostar/compiler/validator.rb +944 -0
- data/lib/protostar/compiler.rb +304 -0
- data/lib/protostar/diagnostics/codes.rb +1307 -0
- data/lib/protostar/diagnostics/formats.rb +64 -0
- data/lib/protostar/diagnostics/renderer.rb +240 -0
- data/lib/protostar/diagnostics/source.rb +153 -0
- data/lib/protostar/diagnostics.rb +117 -0
- data/lib/protostar/dsl.rb +367 -0
- data/lib/protostar/enum.rb +70 -0
- data/lib/protostar/errors.rb +23 -0
- data/lib/protostar/google/protobuf/any_pb.rb +90 -0
- data/lib/protostar/google/protobuf/api_pb.rb +199 -0
- data/lib/protostar/google/protobuf/compiler/plugin_pb.rb +168 -0
- data/lib/protostar/google/protobuf/descriptor_pb.rb +1239 -0
- data/lib/protostar/google/protobuf/duration_pb.rb +99 -0
- data/lib/protostar/google/protobuf/empty_pb.rb +36 -0
- data/lib/protostar/google/protobuf/field_mask_pb.rb +228 -0
- data/lib/protostar/google/protobuf/source_context_pb.rb +33 -0
- data/lib/protostar/google/protobuf/struct_pb.rb +91 -0
- data/lib/protostar/google/protobuf/timestamp_pb.rb +129 -0
- data/lib/protostar/google/protobuf/type_pb.rb +202 -0
- data/lib/protostar/google/protobuf/wrappers_pb.rb +125 -0
- data/lib/protostar/google_protobuf_shim.rb +24 -0
- data/lib/protostar/json/encoder.rb +340 -0
- data/lib/protostar/json/errors.rb +34 -0
- data/lib/protostar/json/parser.rb +437 -0
- data/lib/protostar/json/path.rb +39 -0
- data/lib/protostar/json.rb +95 -0
- data/lib/protostar/lint/command.rb +197 -0
- data/lib/protostar/lint/config.rb +98 -0
- data/lib/protostar/lint/context.rb +126 -0
- data/lib/protostar/lint/directives.rb +56 -0
- data/lib/protostar/lint/fixer.rb +165 -0
- data/lib/protostar/lint/naming.rb +54 -0
- data/lib/protostar/lint/rule.rb +120 -0
- data/lib/protostar/lint/rules/comment_enum.rb +31 -0
- data/lib/protostar/lint/rules/comment_enum_value.rb +32 -0
- data/lib/protostar/lint/rules/comment_field.rb +33 -0
- data/lib/protostar/lint/rules/comment_message.rb +31 -0
- data/lib/protostar/lint/rules/comment_rpc.rb +31 -0
- data/lib/protostar/lint/rules/comment_service.rb +31 -0
- data/lib/protostar/lint/rules/edition_recommended.rb +31 -0
- data/lib/protostar/lint/rules/enum_first_value_zero.rb +34 -0
- data/lib/protostar/lint/rules/enum_pascal_case.rb +25 -0
- data/lib/protostar/lint/rules/enum_value_prefix.rb +38 -0
- data/lib/protostar/lint/rules/enum_value_upper_snake_case.rb +28 -0
- data/lib/protostar/lint/rules/enum_zero_value_suffix.rb +41 -0
- data/lib/protostar/lint/rules/field_lower_snake_case.rb +34 -0
- data/lib/protostar/lint/rules/field_not_required.rb +39 -0
- data/lib/protostar/lint/rules/field_number_reuse_risk.rb +45 -0
- data/lib/protostar/lint/rules/field_numbers_hot_range.rb +44 -0
- data/lib/protostar/lint/rules/file_lower_snake_case.rb +27 -0
- data/lib/protostar/lint/rules/import_no_public.rb +29 -0
- data/lib/protostar/lint/rules/import_no_weak.rb +28 -0
- data/lib/protostar/lint/rules/import_used.rb +33 -0
- data/lib/protostar/lint/rules/message_pascal_case.rb +27 -0
- data/lib/protostar/lint/rules/no_deprecated_features.rb +50 -0
- data/lib/protostar/lint/rules/no_groups.rb +34 -0
- data/lib/protostar/lint/rules/oneof_lower_snake_case.rb +27 -0
- data/lib/protostar/lint/rules/package_defined.rb +28 -0
- data/lib/protostar/lint/rules/package_directory_match.rb +33 -0
- data/lib/protostar/lint/rules/package_lower_snake_case.rb +28 -0
- data/lib/protostar/lint/rules/package_same_directory.rb +39 -0
- data/lib/protostar/lint/rules/package_version_suffix.rb +31 -0
- data/lib/protostar/lint/rules/reserved_names_with_numbers.rb +44 -0
- data/lib/protostar/lint/rules/rpc_pascal_case.rb +25 -0
- data/lib/protostar/lint/rules/rpc_request_response_unique.rb +40 -0
- data/lib/protostar/lint/rules/rpc_request_standard_name.rb +32 -0
- data/lib/protostar/lint/rules/rpc_response_standard_name.rb +31 -0
- data/lib/protostar/lint/rules/service_pascal_case.rb +25 -0
- data/lib/protostar/lint/rules/service_suffix.rb +28 -0
- data/lib/protostar/lint/rules/syntax_specified.rb +35 -0
- data/lib/protostar/lint/runner.rb +135 -0
- data/lib/protostar/lint.rb +122 -0
- data/lib/protostar/message/accessors.rb +86 -0
- data/lib/protostar/message/coercion.rb +171 -0
- data/lib/protostar/message/field_info.rb +145 -0
- data/lib/protostar/message/reflection.rb +149 -0
- data/lib/protostar/message.rb +572 -0
- data/lib/protostar/plugin.rb +94 -0
- data/lib/protostar/schema/default_value.rb +113 -0
- data/lib/protostar/schema/descriptor.rb +41 -0
- data/lib/protostar/schema/draft/copy.rb +88 -0
- data/lib/protostar/schema/draft/resolution.rb +177 -0
- data/lib/protostar/schema/draft.rb +779 -0
- data/lib/protostar/schema/enum.rb +106 -0
- data/lib/protostar/schema/extension_range.rb +37 -0
- data/lib/protostar/schema/features.rb +153 -0
- data/lib/protostar/schema/field.rb +201 -0
- data/lib/protostar/schema/file.rb +217 -0
- data/lib/protostar/schema/freezer.rb +61 -0
- data/lib/protostar/schema/message.rb +104 -0
- data/lib/protostar/schema/oneof.rb +38 -0
- data/lib/protostar/schema/options.rb +367 -0
- data/lib/protostar/schema/pool.rb +179 -0
- data/lib/protostar/schema/proto.rb +576 -0
- data/lib/protostar/schema/resolver.rb +118 -0
- data/lib/protostar/schema/service.rb +89 -0
- data/lib/protostar/schema/source_info.rb +53 -0
- data/lib/protostar/schema.rb +65 -0
- data/lib/protostar/short_names/any.rb +7 -0
- data/lib/protostar/short_names/duration.rb +7 -0
- data/lib/protostar/short_names/empty.rb +7 -0
- data/lib/protostar/short_names/field_mask.rb +7 -0
- data/lib/protostar/short_names/struct.rb +9 -0
- data/lib/protostar/short_names/timestamp.rb +7 -0
- data/lib/protostar/short_names/wrappers.rb +15 -0
- data/lib/protostar/text/extensions.rb +114 -0
- data/lib/protostar/text/parser.rb +439 -0
- data/lib/protostar/text/printer.rb +304 -0
- data/lib/protostar/text/tokenizer.rb +116 -0
- data/lib/protostar/text.rb +67 -0
- data/lib/protostar/types.rb +152 -0
- data/lib/protostar/unknown_field.rb +58 -0
- data/lib/protostar/version.rb +5 -0
- data/lib/protostar/view/generator.rb +298 -0
- data/lib/protostar/view/map.rb +194 -0
- data/lib/protostar/view/repeated.rb +143 -0
- data/lib/protostar/view/scan.rb +183 -0
- data/lib/protostar/view.rb +283 -0
- data/lib/protostar/well_known/any.rb +52 -0
- data/lib/protostar/well_known/duration.rb +53 -0
- data/lib/protostar/well_known/list_value.rb +63 -0
- data/lib/protostar/well_known/struct.rb +55 -0
- data/lib/protostar/well_known/timestamp.rb +64 -0
- data/lib/protostar/well_known/value.rb +60 -0
- data/lib/protostar/well_known.rb +38 -0
- data/lib/protostar/wire/io_source.rb +40 -0
- data/lib/protostar/wire/reader.rb +254 -0
- data/lib/protostar/wire/writer.rb +201 -0
- data/lib/protostar/wire.rb +96 -0
- data/lib/protostar.rb +95 -0
- data/shims/google-protobuf/lib/google/protobuf/any_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/api_pb.rb +22 -0
- data/shims/google-protobuf/lib/google/protobuf/compiler/plugin_pb.rb +25 -0
- data/shims/google-protobuf/lib/google/protobuf/descriptor_pb.rb +72 -0
- data/shims/google-protobuf/lib/google/protobuf/descriptor_pool.rb +164 -0
- data/shims/google-protobuf/lib/google/protobuf/descriptors.rb +553 -0
- data/shims/google-protobuf/lib/google/protobuf/duration_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/empty_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/field_mask_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/internal/convert.rb +180 -0
- data/shims/google-protobuf/lib/google/protobuf/internal/extensions.rb +154 -0
- data/shims/google-protobuf/lib/google/protobuf/internal/json.rb +104 -0
- data/shims/google-protobuf/lib/google/protobuf/internal/well_known.rb +140 -0
- data/shims/google-protobuf/lib/google/protobuf/map.rb +216 -0
- data/shims/google-protobuf/lib/google/protobuf/message.rb +544 -0
- data/shims/google-protobuf/lib/google/protobuf/message_exts.rb +41 -0
- data/shims/google-protobuf/lib/google/protobuf/plugin_pb.rb +4 -0
- data/shims/google-protobuf/lib/google/protobuf/repeated_field.rb +366 -0
- data/shims/google-protobuf/lib/google/protobuf/source_context_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/struct_pb.rb +20 -0
- data/shims/google-protobuf/lib/google/protobuf/timestamp_pb.rb +17 -0
- data/shims/google-protobuf/lib/google/protobuf/type_pb.rb +27 -0
- data/shims/google-protobuf/lib/google/protobuf/well_known_types.rb +37 -0
- data/shims/google-protobuf/lib/google/protobuf/wrappers_pb.rb +25 -0
- data/shims/google-protobuf/lib/google/protobuf.rb +107 -0
- data/shims/google-protobuf/lib/google/protobuf_ffi.rb +5 -0
- data/shims/google-protobuf/lib/google/protobuf_native.rb +5 -0
- data/sig/protostar/google/protobuf/any_pb.rbs +77 -0
- data/sig/protostar/google/protobuf/api_pb.rbs +242 -0
- data/sig/protostar/google/protobuf/compiler/plugin_pb.rbs +264 -0
- data/sig/protostar/google/protobuf/descriptor_pb.rbs +2220 -0
- data/sig/protostar/google/protobuf/duration_pb.rbs +82 -0
- data/sig/protostar/google/protobuf/empty_pb.rbs +18 -0
- data/sig/protostar/google/protobuf/field_mask_pb.rbs +170 -0
- data/sig/protostar/google/protobuf/source_context_pb.rbs +24 -0
- data/sig/protostar/google/protobuf/struct_pb.rbs +135 -0
- data/sig/protostar/google/protobuf/timestamp_pb.rbs +102 -0
- data/sig/protostar/google/protobuf/type_pb.rbs +304 -0
- data/sig/protostar/google/protobuf/wrappers_pb.rbs +169 -0
- data/sig/protostar/lint.rbs +216 -0
- data/sig/protostar.rbs +326 -0
- metadata +366 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
|
|
5
|
+
module Google
|
|
6
|
+
module Protobuf
|
|
7
|
+
# An Array-like list of values of one type, checked on every write. A
|
|
8
|
+
# message's repeated field reads as a RepeatedField over the message's
|
|
9
|
+
# own storage, so writes to it are writes to the message.
|
|
10
|
+
class RepeatedField
|
|
11
|
+
include Enumerable
|
|
12
|
+
extend Forwardable
|
|
13
|
+
|
|
14
|
+
# @overload new(type, initial_values = [])
|
|
15
|
+
# @overload new(type, type_class, initial_values = [])
|
|
16
|
+
# @param type_class [Class, Module] a message class or enum module, for :message and :enum
|
|
17
|
+
# @param type [Symbol] :int32, :string, :message, :enum and so on
|
|
18
|
+
def self.new(*args)
|
|
19
|
+
raise ArgumentError, "Expected at least 1 argument." if args.empty?
|
|
20
|
+
type, *rest = args
|
|
21
|
+
sub, initial = Internal.type_class(type, rest, 0)
|
|
22
|
+
raise ArgumentError, "Expected array as initialize argument" unless initial.nil? || initial.is_a?(Array)
|
|
23
|
+
instance = allocate
|
|
24
|
+
instance.__setup(type, sub, [], "")
|
|
25
|
+
initial&.each { |v| instance.push(v) }
|
|
26
|
+
instance
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @api private
|
|
30
|
+
def self.__for_field(fd, array)
|
|
31
|
+
instance = allocate
|
|
32
|
+
instance.__setup(fd.type, fd.subtype, array, "")
|
|
33
|
+
instance
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @api private
|
|
37
|
+
def __setup(type, sub, array, name)
|
|
38
|
+
@type = type
|
|
39
|
+
@sub = sub
|
|
40
|
+
@array = array
|
|
41
|
+
@name = name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @api private
|
|
45
|
+
def __array
|
|
46
|
+
@array
|
|
47
|
+
end
|
|
48
|
+
alias_method :__storage, :__array
|
|
49
|
+
|
|
50
|
+
# @api private
|
|
51
|
+
def __type
|
|
52
|
+
@type
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @api private
|
|
56
|
+
def __sub
|
|
57
|
+
@sub
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @api private
|
|
61
|
+
# @raise [TypeError] unless this list can be the field's value
|
|
62
|
+
def __check_field(fd)
|
|
63
|
+
unless FieldDescriptor::CTYPES.fetch(@type) == fd.__ctype
|
|
64
|
+
raise TypeError, "Repeated field array has wrong element type"
|
|
65
|
+
end
|
|
66
|
+
raise TypeError, "Repeated field array has wrong message/enum class" unless @sub.equal?(fd.subtype)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def each(&block)
|
|
70
|
+
return enum_for(:each) { size } unless block
|
|
71
|
+
@array.each(&block)
|
|
72
|
+
self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @overload [](index)
|
|
76
|
+
# @overload [](start, length)
|
|
77
|
+
# @overload [](range)
|
|
78
|
+
def [](*args)
|
|
79
|
+
if args.size == 1 && args[0].is_a?(Integer)
|
|
80
|
+
@array[args[0]]
|
|
81
|
+
else
|
|
82
|
+
@array[*args]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
alias_method :at, :[]
|
|
86
|
+
alias_method :slice, :[]
|
|
87
|
+
|
|
88
|
+
# Sets the element at the index, filling any gap with zero values
|
|
89
|
+
def []=(index, value)
|
|
90
|
+
check_frozen
|
|
91
|
+
count = @array.size
|
|
92
|
+
index += count if index < 0
|
|
93
|
+
return if index < 0
|
|
94
|
+
v = convert(value)
|
|
95
|
+
if index >= count
|
|
96
|
+
zero = Internal::Convert.zero(@type, @sub)
|
|
97
|
+
@array.fill(zero, count, index - count) if index > count
|
|
98
|
+
end
|
|
99
|
+
@array[index] = v
|
|
100
|
+
nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [self]
|
|
104
|
+
def push(*values)
|
|
105
|
+
check_frozen
|
|
106
|
+
converted = values.map { |v| convert(v) }
|
|
107
|
+
@array.concat(converted)
|
|
108
|
+
self
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @return [self]
|
|
112
|
+
def <<(value)
|
|
113
|
+
check_frozen
|
|
114
|
+
@array << convert(value)
|
|
115
|
+
self
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @return [self]
|
|
119
|
+
# @param list [Array]
|
|
120
|
+
# @return [Array] the list given
|
|
121
|
+
def replace(list)
|
|
122
|
+
check_frozen
|
|
123
|
+
raise ::TypeError, "wrong argument type #{list.class} (expected Array)" unless list.is_a?(Array)
|
|
124
|
+
converted = list.map { |v| convert(v) }
|
|
125
|
+
@array.replace(converted)
|
|
126
|
+
list
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# @return [self]
|
|
130
|
+
def clear
|
|
131
|
+
check_frozen
|
|
132
|
+
@array.clear
|
|
133
|
+
self
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def length
|
|
137
|
+
@array.length
|
|
138
|
+
end
|
|
139
|
+
alias_method :size, :length
|
|
140
|
+
|
|
141
|
+
def empty?
|
|
142
|
+
@array.empty?
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def first(n = nil)
|
|
146
|
+
return @array.first if n.nil?
|
|
147
|
+
raise ArgumentError, "negative array size" if n < 0
|
|
148
|
+
@array.first(n)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def last(n = nil)
|
|
152
|
+
return @array.last if n.nil?
|
|
153
|
+
raise ArgumentError, "negative array size" if n < 0
|
|
154
|
+
@array.last(n)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def pop(n = nil)
|
|
158
|
+
if n
|
|
159
|
+
results = []
|
|
160
|
+
n.times { results << pop_one }
|
|
161
|
+
results
|
|
162
|
+
else
|
|
163
|
+
pop_one
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# @return [Array] a copy of the elements
|
|
168
|
+
def to_ary
|
|
169
|
+
@array.dup
|
|
170
|
+
end
|
|
171
|
+
alias_method :to_a, :to_ary
|
|
172
|
+
|
|
173
|
+
# Equal to a RepeatedField of the same type and elements, or an Array of the same elements
|
|
174
|
+
def ==(other)
|
|
175
|
+
return true if equal?(other)
|
|
176
|
+
case other
|
|
177
|
+
when RepeatedField
|
|
178
|
+
FieldDescriptor::CTYPES.fetch(@type) == FieldDescriptor::CTYPES.fetch(other.__type) &&
|
|
179
|
+
@sub.equal?(other.__sub) && @array == other.__array
|
|
180
|
+
when Array then @array == other
|
|
181
|
+
else false
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def hash
|
|
186
|
+
@array.hash
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# @return [RepeatedField] a new list of the same elements; messages are shared
|
|
190
|
+
def dup
|
|
191
|
+
copy = self.class.allocate
|
|
192
|
+
copy.__setup(@type, @sub, @array.dup, @name)
|
|
193
|
+
copy
|
|
194
|
+
end
|
|
195
|
+
alias_method :clone, :dup
|
|
196
|
+
|
|
197
|
+
# @api private
|
|
198
|
+
def __deep_copy
|
|
199
|
+
copy = self.class.allocate
|
|
200
|
+
copy.__setup(@type, @sub, @array.map { |v| Internal.deep_copy_value(v) }, @name)
|
|
201
|
+
copy
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# @return [RepeatedField] a new list of this one's elements followed by the other's
|
|
205
|
+
def +(other)
|
|
206
|
+
case other
|
|
207
|
+
when RepeatedField
|
|
208
|
+
unless @type == other.__type && @sub.equal?(other.__sub)
|
|
209
|
+
raise ArgumentError, "Attempt to append RepeatedField with different element type."
|
|
210
|
+
end
|
|
211
|
+
copy = dup
|
|
212
|
+
copy.__array.concat(other.__array)
|
|
213
|
+
copy
|
|
214
|
+
when Enumerable
|
|
215
|
+
dup.push(*other.to_a)
|
|
216
|
+
else
|
|
217
|
+
raise ArgumentError, "Unknown type appending to RepeatedField"
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Appends every element of the Array
|
|
222
|
+
# @return [self]
|
|
223
|
+
def concat(other)
|
|
224
|
+
raise ::TypeError, "wrong argument type #{other.class} (expected Array)" unless other.is_a?(Array)
|
|
225
|
+
push(*other)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def frozen?
|
|
229
|
+
super || @array.frozen?
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Freezes the list, its storage and the messages in it
|
|
233
|
+
def freeze
|
|
234
|
+
return self if super_frozen?
|
|
235
|
+
unless @array.frozen?
|
|
236
|
+
@array.each { |v| v.freeze if v.is_a?(Protostar::Message) }
|
|
237
|
+
@array.freeze
|
|
238
|
+
end
|
|
239
|
+
super
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def inspect
|
|
243
|
+
@array.inspect
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def_delegators :to_ary,
|
|
247
|
+
:&, :*, :-, :<=>,
|
|
248
|
+
:assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
|
|
249
|
+
:cycle, :difference, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
|
|
250
|
+
:include?, :index, :intersection, :join,
|
|
251
|
+
:pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
|
|
252
|
+
:rassoc, :repeated_combination, :repeated_permutation, :reverse,
|
|
253
|
+
:rindex, :rotate, :sample, :shuffle, :shelljoin,
|
|
254
|
+
:to_s, :transpose, :union, :uniq, :|
|
|
255
|
+
|
|
256
|
+
alias_method :values_at, :select
|
|
257
|
+
alias_method :map, :collect
|
|
258
|
+
|
|
259
|
+
# Array methods that change the list: run on a copy, then written back
|
|
260
|
+
# through #replace so that every element is checked
|
|
261
|
+
class << self
|
|
262
|
+
private
|
|
263
|
+
|
|
264
|
+
def define_array_wrapper_method(method_name)
|
|
265
|
+
define_method(method_name) do |*args, &block|
|
|
266
|
+
arr = to_a
|
|
267
|
+
result = arr.send(method_name, *args)
|
|
268
|
+
replace(arr)
|
|
269
|
+
return result if result
|
|
270
|
+
block ? block.call : result
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def define_array_wrapper_with_result_method(method_name)
|
|
275
|
+
define_method(method_name) do |*args, &block|
|
|
276
|
+
result = to_a.send(method_name, *args, &block)
|
|
277
|
+
if result
|
|
278
|
+
new_arr = result.to_a
|
|
279
|
+
replace(new_arr)
|
|
280
|
+
if result.is_a?(Enumerator)
|
|
281
|
+
result = ProxyingEnumerator.new(self, new_arr.to_enum).to_enum
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
result
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
%w[delete delete_at shift slice! unshift].each { |m| define_array_wrapper_method(m) }
|
|
290
|
+
|
|
291
|
+
%w[collect! compact! delete_if each_index fill flatten! insert reverse!
|
|
292
|
+
rotate! select! shuffle! sort! sort_by! uniq!].each { |m| define_array_wrapper_with_result_method(m) }
|
|
293
|
+
alias_method :keep_if, :select!
|
|
294
|
+
alias_method :map!, :collect!
|
|
295
|
+
alias_method :reject!, :delete_if
|
|
296
|
+
|
|
297
|
+
# Writes changes made through an Enumerator from #sort! and the like back to the list
|
|
298
|
+
# @api private
|
|
299
|
+
class ProxyingEnumerator
|
|
300
|
+
def initialize(repeated_field, external_enumerator)
|
|
301
|
+
@repeated_field = repeated_field
|
|
302
|
+
@external_enumerator = external_enumerator
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def each(*)
|
|
306
|
+
results = []
|
|
307
|
+
@external_enumerator.each_with_index do |val, i|
|
|
308
|
+
result = yield(val)
|
|
309
|
+
results << result
|
|
310
|
+
@repeated_field[i] = result if result && result != val
|
|
311
|
+
end
|
|
312
|
+
results
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
private
|
|
317
|
+
|
|
318
|
+
def convert(value)
|
|
319
|
+
Internal::Convert.to_store(value, @type, @sub, @name)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def pop_one
|
|
323
|
+
check_frozen
|
|
324
|
+
@array.pop
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def check_frozen
|
|
328
|
+
raise FrozenError.new("can't modify frozen #{self.class}: #{inspect}", receiver: self) if frozen?
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def super_frozen?
|
|
332
|
+
Object.instance_method(:frozen?).bind_call(self)
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
module Internal
|
|
337
|
+
# The type names RepeatedField.new and Map.new take: C types, not field types
|
|
338
|
+
CONTAINER_TYPES = %i[int32 int64 uint32 uint64 bool float double string bytes message enum]
|
|
339
|
+
.to_h { |t| [t, true] }.freeze
|
|
340
|
+
|
|
341
|
+
# The element type of a RepeatedField or the value type of a Map from
|
|
342
|
+
# the arguments after the type: the class or module for :message and
|
|
343
|
+
# :enum, then the initial values
|
|
344
|
+
# @api private
|
|
345
|
+
# @return [Array(Descriptor, EnumDescriptor, nil), Object]
|
|
346
|
+
# @param before [Integer] how many arguments came before the type
|
|
347
|
+
def self.type_class(type, rest, before)
|
|
348
|
+
raise ArgumentError, "Expected symbol for field type." unless type.is_a?(Symbol)
|
|
349
|
+
raise ArgumentError, "Unknown field type." unless CONTAINER_TYPES.key?(type)
|
|
350
|
+
typed = type == :message || type == :enum
|
|
351
|
+
limit = typed ? 2 : 1
|
|
352
|
+
raise ArgumentError, "Expected a maximum of #{before + 1 + limit} arguments." if rest.size > limit
|
|
353
|
+
return [nil, rest[0]] unless typed
|
|
354
|
+
raise ArgumentError, "Expected at least #{before + 2} arguments for message/enum." if rest.empty?
|
|
355
|
+
klass = rest[0]
|
|
356
|
+
descriptor = klass.respond_to?(:descriptor) ? klass.descriptor : nil
|
|
357
|
+
unless descriptor.is_a?(Descriptor) || descriptor.is_a?(EnumDescriptor)
|
|
358
|
+
raise ArgumentError, "Type class has no descriptor. Please pass a class or enum as returned by the DescriptorPool."
|
|
359
|
+
end
|
|
360
|
+
expected = (type == :enum) ? EnumDescriptor : Descriptor
|
|
361
|
+
raise ::TypeError, "wrong argument type #{descriptor.class} (expected #{expected})" unless descriptor.is_a?(expected)
|
|
362
|
+
[descriptor, rest[1]]
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: google/protobuf/source_context.proto
|
|
4
|
+
|
|
5
|
+
require 'google/protobuf'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n$google/protobuf/source_context.proto\x12\x0fgoogle.protobuf\"\"\n\rSourceContext\x12\x11\n\tfile_name\x18\x01 \x01(\tB\x8a\x01\n\x13\x63om.google.protobufB\x12SourceContextProtoP\x01Z6google.golang.org/protobuf/types/known/sourcecontextpb\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
|
12
|
+
|
|
13
|
+
module Google
|
|
14
|
+
module Protobuf
|
|
15
|
+
SourceContext = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: google/protobuf/struct.proto
|
|
4
|
+
|
|
5
|
+
require 'google/protobuf'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n\x1cgoogle/protobuf/struct.proto\x12\x0fgoogle.protobuf\"\x84\x01\n\x06Struct\x12\x33\n\x06\x66ields\x18\x01 \x03(\x0b\x32#.google.protobuf.Struct.FieldsEntry\x1a\x45\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12%\n\x05value\x18\x02 \x01(\x0b\x32\x16.google.protobuf.Value:\x02\x38\x01\"\xea\x01\n\x05Value\x12\x30\n\nnull_value\x18\x01 \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00\x12\x16\n\x0cnumber_value\x18\x02 \x01(\x01H\x00\x12\x16\n\x0cstring_value\x18\x03 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x04 \x01(\x08H\x00\x12/\n\x0cstruct_value\x18\x05 \x01(\x0b\x32\x17.google.protobuf.StructH\x00\x12\x30\n\nlist_value\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00\x42\x06\n\x04kind\"3\n\tListValue\x12&\n\x06values\x18\x01 \x03(\x0b\x32\x16.google.protobuf.Value*\x1b\n\tNullValue\x12\x0e\n\nNULL_VALUE\x10\x00\x42\x7f\n\x13\x63om.google.protobufB\x0bStructProtoP\x01Z/google.golang.org/protobuf/types/known/structpb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
|
12
|
+
|
|
13
|
+
module Google
|
|
14
|
+
module Protobuf
|
|
15
|
+
Struct = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
|
|
16
|
+
Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
|
|
17
|
+
ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
|
|
18
|
+
NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: google/protobuf/timestamp.proto
|
|
4
|
+
|
|
5
|
+
require 'google/protobuf'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n\x1fgoogle/protobuf/timestamp.proto\x12\x0fgoogle.protobuf\"+\n\tTimestamp\x12\x0f\n\x07seconds\x18\x01 \x01(\x03\x12\r\n\x05nanos\x18\x02 \x01(\x05\x42\x85\x01\n\x13\x63om.google.protobufB\x0eTimestampProtoP\x01Z2google.golang.org/protobuf/types/known/timestamppb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
|
12
|
+
|
|
13
|
+
module Google
|
|
14
|
+
module Protobuf
|
|
15
|
+
Timestamp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: google/protobuf/type.proto
|
|
4
|
+
|
|
5
|
+
require 'google/protobuf'
|
|
6
|
+
|
|
7
|
+
require 'google/protobuf/any_pb'
|
|
8
|
+
require 'google/protobuf/source_context_pb'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
descriptor_data = "\n\x1agoogle/protobuf/type.proto\x12\x0fgoogle.protobuf\x1a\x19google/protobuf/any.proto\x1a$google/protobuf/source_context.proto\"\xe8\x01\n\x04Type\x12\x0c\n\x04name\x18\x01 \x01(\t\x12&\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x16.google.protobuf.Field\x12\x0e\n\x06oneofs\x18\x03 \x03(\t\x12(\n\x07options\x18\x04 \x03(\x0b\x32\x17.google.protobuf.Option\x12\x36\n\x0esource_context\x18\x05 \x01(\x0b\x32\x1e.google.protobuf.SourceContext\x12\'\n\x06syntax\x18\x06 \x01(\x0e\x32\x17.google.protobuf.Syntax\x12\x0f\n\x07\x65\x64ition\x18\x07 \x01(\t\"\xd5\x05\n\x05\x46ield\x12)\n\x04kind\x18\x01 \x01(\x0e\x32\x1b.google.protobuf.Field.Kind\x12\x37\n\x0b\x63\x61rdinality\x18\x02 \x01(\x0e\x32\".google.protobuf.Field.Cardinality\x12\x0e\n\x06number\x18\x03 \x01(\x05\x12\x0c\n\x04name\x18\x04 \x01(\t\x12\x10\n\x08type_url\x18\x06 \x01(\t\x12\x13\n\x0boneof_index\x18\x07 \x01(\x05\x12\x0e\n\x06packed\x18\x08 \x01(\x08\x12(\n\x07options\x18\t \x03(\x0b\x32\x17.google.protobuf.Option\x12\x11\n\tjson_name\x18\n \x01(\t\x12\x15\n\rdefault_value\x18\x0b \x01(\t\"\xc8\x02\n\x04Kind\x12\x10\n\x0cTYPE_UNKNOWN\x10\x00\x12\x0f\n\x0bTYPE_DOUBLE\x10\x01\x12\x0e\n\nTYPE_FLOAT\x10\x02\x12\x0e\n\nTYPE_INT64\x10\x03\x12\x0f\n\x0bTYPE_UINT64\x10\x04\x12\x0e\n\nTYPE_INT32\x10\x05\x12\x10\n\x0cTYPE_FIXED64\x10\x06\x12\x10\n\x0cTYPE_FIXED32\x10\x07\x12\r\n\tTYPE_BOOL\x10\x08\x12\x0f\n\x0bTYPE_STRING\x10\t\x12\x0e\n\nTYPE_GROUP\x10\n\x12\x10\n\x0cTYPE_MESSAGE\x10\x0b\x12\x0e\n\nTYPE_BYTES\x10\x0c\x12\x0f\n\x0bTYPE_UINT32\x10\r\x12\r\n\tTYPE_ENUM\x10\x0e\x12\x11\n\rTYPE_SFIXED32\x10\x0f\x12\x11\n\rTYPE_SFIXED64\x10\x10\x12\x0f\n\x0bTYPE_SINT32\x10\x11\x12\x0f\n\x0bTYPE_SINT64\x10\x12\"t\n\x0b\x43\x61rdinality\x12\x17\n\x13\x43\x41RDINALITY_UNKNOWN\x10\x00\x12\x18\n\x14\x43\x41RDINALITY_OPTIONAL\x10\x01\x12\x18\n\x14\x43\x41RDINALITY_REQUIRED\x10\x02\x12\x18\n\x14\x43\x41RDINALITY_REPEATED\x10\x03\"\xdf\x01\n\x04\x45num\x12\x0c\n\x04name\x18\x01 \x01(\t\x12-\n\tenumvalue\x18\x02 \x03(\x0b\x32\x1a.google.protobuf.EnumValue\x12(\n\x07options\x18\x03 \x03(\x0b\x32\x17.google.protobuf.Option\x12\x36\n\x0esource_context\x18\x04 \x01(\x0b\x32\x1e.google.protobuf.SourceContext\x12\'\n\x06syntax\x18\x05 \x01(\x0e\x32\x17.google.protobuf.Syntax\x12\x0f\n\x07\x65\x64ition\x18\x06 \x01(\t\"S\n\tEnumValue\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06number\x18\x02 \x01(\x05\x12(\n\x07options\x18\x03 \x03(\x0b\x32\x17.google.protobuf.Option\";\n\x06Option\x12\x0c\n\x04name\x18\x01 \x01(\t\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.google.protobuf.Any*C\n\x06Syntax\x12\x11\n\rSYNTAX_PROTO2\x10\x00\x12\x11\n\rSYNTAX_PROTO3\x10\x01\x12\x13\n\x0fSYNTAX_EDITIONS\x10\x02\x42{\n\x13\x63om.google.protobufB\tTypeProtoP\x01Z-google.golang.org/protobuf/types/known/typepb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
|
12
|
+
|
|
13
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
|
14
|
+
pool.add_serialized_file(descriptor_data)
|
|
15
|
+
|
|
16
|
+
module Google
|
|
17
|
+
module Protobuf
|
|
18
|
+
Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
|
|
19
|
+
Field = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
|
|
20
|
+
Field::Kind = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
|
|
21
|
+
Field::Cardinality = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
|
|
22
|
+
Enum = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
|
|
23
|
+
EnumValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
|
|
24
|
+
Option = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
|
|
25
|
+
Syntax = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "google/protobuf/any_pb"
|
|
4
|
+
require "google/protobuf/duration_pb"
|
|
5
|
+
require "google/protobuf/field_mask_pb"
|
|
6
|
+
require "google/protobuf/struct_pb"
|
|
7
|
+
require "google/protobuf/timestamp_pb"
|
|
8
|
+
|
|
9
|
+
# Timestamp (from_time, to_time, to_i, to_f) and Duration (to_f) have their
|
|
10
|
+
# helpers from Protostar::WellKnown, which protostar mixes into those classes
|
|
11
|
+
# however they are defined. Struct, Value and ListValue get the gem's from
|
|
12
|
+
# Google::Protobuf::Internal::WellKnown as their classes are set up, so they
|
|
13
|
+
# work without this file too. Any#pack is defined here, returning what the
|
|
14
|
+
# gem's does.
|
|
15
|
+
module Google
|
|
16
|
+
module Protobuf
|
|
17
|
+
Any.class_eval do
|
|
18
|
+
# @return [Any] a new Any holding the message
|
|
19
|
+
def self.pack(msg, type_url_prefix = "type.googleapis.com/")
|
|
20
|
+
any = new
|
|
21
|
+
any.pack(msg, type_url_prefix)
|
|
22
|
+
any
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Stores the message and a type URL of the prefix and its full name
|
|
26
|
+
# @return [String] the message's bytes
|
|
27
|
+
def pack(msg, type_url_prefix = "type.googleapis.com/")
|
|
28
|
+
self.type_url = if type_url_prefix.empty? || !type_url_prefix.end_with?("/")
|
|
29
|
+
"#{type_url_prefix}/#{msg.class.descriptor.name}"
|
|
30
|
+
else
|
|
31
|
+
"#{type_url_prefix}#{msg.class.descriptor.name}"
|
|
32
|
+
end
|
|
33
|
+
self.value = msg.to_proto
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: google/protobuf/wrappers.proto
|
|
4
|
+
|
|
5
|
+
require 'google/protobuf'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
descriptor_data = "\n\x1egoogle/protobuf/wrappers.proto\x12\x0fgoogle.protobuf\"\x1c\n\x0b\x44oubleValue\x12\r\n\x05value\x18\x01 \x01(\x01\"\x1b\n\nFloatValue\x12\r\n\x05value\x18\x01 \x01(\x02\"\x1b\n\nInt64Value\x12\r\n\x05value\x18\x01 \x01(\x03\"\x1c\n\x0bUInt64Value\x12\r\n\x05value\x18\x01 \x01(\x04\"\x1b\n\nInt32Value\x12\r\n\x05value\x18\x01 \x01(\x05\"\x1c\n\x0bUInt32Value\x12\r\n\x05value\x18\x01 \x01(\r\"\x1a\n\tBoolValue\x12\r\n\x05value\x18\x01 \x01(\x08\"\x1c\n\x0bStringValue\x12\r\n\x05value\x18\x01 \x01(\t\"\x1b\n\nBytesValue\x12\r\n\x05value\x18\x01 \x01(\x0c\x42\x83\x01\n\x13\x63om.google.protobufB\rWrappersProtoP\x01Z1google.golang.org/protobuf/types/known/wrapperspb\xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesb\x06proto3"
|
|
9
|
+
|
|
10
|
+
pool = ::Google::Protobuf::DescriptorPool.generated_pool
|
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
|
12
|
+
|
|
13
|
+
module Google
|
|
14
|
+
module Protobuf
|
|
15
|
+
DoubleValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
|
16
|
+
FloatValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
|
17
|
+
Int64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
|
18
|
+
UInt64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
|
19
|
+
Int32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
|
20
|
+
UInt32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
|
21
|
+
BoolValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
|
22
|
+
StringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
|
23
|
+
BytesValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "protostar"
|
|
4
|
+
require "google/protobuf/message_exts"
|
|
5
|
+
|
|
6
|
+
module Google
|
|
7
|
+
# google-protobuf's Ruby API on top of protostar. Generated `_pb.rb` files
|
|
8
|
+
# written by protoc (or `protostar compile --google_out`) load unchanged.
|
|
9
|
+
module Protobuf
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
class ParseError < Error; end
|
|
13
|
+
|
|
14
|
+
class TypeError < ::TypeError; end
|
|
15
|
+
|
|
16
|
+
# Raised by Struct, Value and ListValue for a Ruby value they cannot hold
|
|
17
|
+
class UnexpectedStructType < Error; end
|
|
18
|
+
|
|
19
|
+
# The gem chooses between its C extension and FFI here; there is only protostar
|
|
20
|
+
PREFER_FFI = false
|
|
21
|
+
|
|
22
|
+
# @return [Symbol] which implementation is loaded
|
|
23
|
+
IMPLEMENTATION = :PROTOSTAR
|
|
24
|
+
|
|
25
|
+
# descriptor.proto's classes, which descriptors' `options` and `to_proto`
|
|
26
|
+
# return, load on first use as the gem's C code requires them. The
|
|
27
|
+
# well-known types stay undefined until their files are required, as in the gem.
|
|
28
|
+
%i[
|
|
29
|
+
FileDescriptorSet FileDescriptorProto DescriptorProto ExtensionRangeOptions FieldDescriptorProto
|
|
30
|
+
OneofDescriptorProto EnumDescriptorProto EnumValueDescriptorProto ServiceDescriptorProto
|
|
31
|
+
MethodDescriptorProto FileOptions MessageOptions FieldOptions OneofOptions EnumOptions EnumValueOptions
|
|
32
|
+
ServiceOptions MethodOptions UninterpretedOption FeatureSet FeatureSetDefaults SourceCodeInfo
|
|
33
|
+
GeneratedCodeInfo Edition SymbolVisibility
|
|
34
|
+
].each { |name| autoload(name, ::File.expand_path("protobuf/descriptor_pb", __dir__)) }
|
|
35
|
+
|
|
36
|
+
# @return [String] the message's binary encoding
|
|
37
|
+
def self.encode(msg, options = {})
|
|
38
|
+
msg.to_proto(options)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [String] the message as JSON
|
|
42
|
+
def self.encode_json(msg, options = {})
|
|
43
|
+
msg.to_json(options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Message]
|
|
47
|
+
def self.decode(klass, proto, options = {})
|
|
48
|
+
klass.decode(proto, options)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Message]
|
|
52
|
+
def self.decode_json(klass, json, options = {})
|
|
53
|
+
klass.decode_json(json, options)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @param object [Message, RepeatedField, Map]
|
|
57
|
+
# @return [Message, RepeatedField, Map] a copy with every nested message copied too
|
|
58
|
+
def self.deep_copy(object)
|
|
59
|
+
case object
|
|
60
|
+
when RepeatedField, Map then object.__deep_copy
|
|
61
|
+
when MessageExts then object.__gdeep_copy
|
|
62
|
+
else raise ::TypeError, "wrong argument type #{object.class} (expected Google::Protobuf::Message)"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Drops the unknown fields of a message and of every message in it
|
|
67
|
+
# (extensions stay)
|
|
68
|
+
# @return [nil]
|
|
69
|
+
def self.discard_unknown(message)
|
|
70
|
+
raise FrozenError if message.frozen?
|
|
71
|
+
raise ArgumentError, "Expected message, got #{message.class} instead." unless message.is_a?(MessageExts)
|
|
72
|
+
Internal.discard_unknown(message)
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
module Internal
|
|
77
|
+
# @api private
|
|
78
|
+
def self.discard_unknown(message)
|
|
79
|
+
descriptor = message.class.descriptor.__schema
|
|
80
|
+
kept = message.unknown_fields.select { |u| descriptor.extension_number?(u.number) }
|
|
81
|
+
message.__greplace_unknown(kept) if kept.size != message.unknown_fields.size
|
|
82
|
+
message.class.__fields.each do |info|
|
|
83
|
+
next unless info.map ? info.value.message? : info.message?
|
|
84
|
+
v = message.__values[info.index]
|
|
85
|
+
case v
|
|
86
|
+
when nil then next
|
|
87
|
+
when Hash then v.each_value { |m| discard_unknown(m) }
|
|
88
|
+
when Array then v.each { |m| discard_unknown(m) }
|
|
89
|
+
else discard_unknown(v)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
require "google/protobuf/internal/convert"
|
|
98
|
+
require "google/protobuf/descriptors"
|
|
99
|
+
require "google/protobuf/descriptor_pool"
|
|
100
|
+
require "google/protobuf/internal/well_known"
|
|
101
|
+
require "google/protobuf/message"
|
|
102
|
+
require "google/protobuf/repeated_field"
|
|
103
|
+
require "google/protobuf/map"
|
|
104
|
+
require "google/protobuf/internal/extensions"
|
|
105
|
+
require "google/protobuf/internal/json"
|
|
106
|
+
|
|
107
|
+
Google::Protobuf::DescriptorPool.instance_variable_set(:@generated_pool, Google::Protobuf::DescriptorPool.new)
|