google-protobuf 3.0.0 → 3.20.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/ext/google/protobuf_c/convert.c +361 -0
- data/ext/google/protobuf_c/convert.h +75 -0
- data/ext/google/protobuf_c/defs.c +760 -1243
- data/ext/google/protobuf_c/defs.h +107 -0
- data/ext/google/protobuf_c/extconf.rb +22 -4
- data/ext/google/protobuf_c/map.c +342 -450
- data/ext/google/protobuf_c/map.h +66 -0
- data/ext/google/protobuf_c/message.c +1108 -284
- data/ext/google/protobuf_c/message.h +104 -0
- data/ext/google/protobuf_c/protobuf.c +416 -51
- data/ext/google/protobuf_c/protobuf.h +53 -472
- data/ext/google/protobuf_c/repeated_field.c +318 -317
- data/ext/google/protobuf_c/repeated_field.h +63 -0
- data/ext/google/protobuf_c/ruby-upb.c +11115 -0
- data/ext/google/protobuf_c/ruby-upb.h +5612 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +52 -0
- data/lib/google/protobuf/any_pb.rb +6 -4
- data/lib/google/protobuf/api_pb.rb +27 -24
- data/lib/google/protobuf/descriptor_dsl.rb +465 -0
- data/lib/google/protobuf/descriptor_pb.rb +269 -0
- data/lib/google/protobuf/duration_pb.rb +6 -4
- data/lib/google/protobuf/empty_pb.rb +4 -2
- data/lib/google/protobuf/field_mask_pb.rb +5 -3
- data/lib/google/protobuf/message_exts.rb +4 -4
- data/lib/google/protobuf/repeated_field.rb +4 -4
- data/lib/google/protobuf/source_context_pb.rb +5 -3
- data/lib/google/protobuf/struct_pb.rb +23 -21
- data/lib/google/protobuf/timestamp_pb.rb +6 -4
- data/lib/google/protobuf/type_pb.rb +77 -74
- data/lib/google/protobuf/well_known_types.rb +240 -0
- data/lib/google/protobuf/wrappers_pb.rb +37 -35
- data/lib/google/protobuf.rb +12 -9
- data/tests/basic.rb +489 -1001
- data/tests/generated_code_test.rb +6 -2
- data/tests/stress.rb +1 -1
- metadata +39 -34
- data/ext/google/protobuf_c/encode_decode.c +0 -1264
- data/ext/google/protobuf_c/storage.c +0 -893
- data/ext/google/protobuf_c/upb.c +0 -12812
- data/ext/google/protobuf_c/upb.h +0 -8569
@@ -0,0 +1,240 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# Protocol Buffers - Google's data interchange format
|
3
|
+
# Copyright 2008 Google Inc. All rights reserved.
|
4
|
+
# https://developers.google.com/protocol-buffers/
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are
|
8
|
+
# met:
|
9
|
+
#
|
10
|
+
# * Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
# * Redistributions in binary form must reproduce the above
|
13
|
+
# copyright notice, this list of conditions and the following disclaimer
|
14
|
+
# in the documentation and/or other materials provided with the
|
15
|
+
# distribution.
|
16
|
+
# * Neither the name of Google Inc. nor the names of its
|
17
|
+
# contributors may be used to endorse or promote products derived from
|
18
|
+
# this software without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
require 'google/protobuf/any_pb'
|
33
|
+
require 'google/protobuf/duration_pb'
|
34
|
+
require 'google/protobuf/field_mask_pb'
|
35
|
+
require 'google/protobuf/struct_pb'
|
36
|
+
require 'google/protobuf/timestamp_pb'
|
37
|
+
|
38
|
+
module Google
|
39
|
+
module Protobuf
|
40
|
+
|
41
|
+
Any.class_eval do
|
42
|
+
def self.pack(msg, type_url_prefix='type.googleapis.com/')
|
43
|
+
any = self.new
|
44
|
+
any.pack(msg, type_url_prefix)
|
45
|
+
any
|
46
|
+
end
|
47
|
+
|
48
|
+
def pack(msg, type_url_prefix='type.googleapis.com/')
|
49
|
+
if type_url_prefix.empty? or type_url_prefix[-1] != '/' then
|
50
|
+
self.type_url = "#{type_url_prefix}/#{msg.class.descriptor.name}"
|
51
|
+
else
|
52
|
+
self.type_url = "#{type_url_prefix}#{msg.class.descriptor.name}"
|
53
|
+
end
|
54
|
+
self.value = msg.to_proto
|
55
|
+
end
|
56
|
+
|
57
|
+
def unpack(klass)
|
58
|
+
if self.is(klass) then
|
59
|
+
klass.decode(self.value)
|
60
|
+
else
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def type_name
|
66
|
+
return self.type_url.split("/")[-1]
|
67
|
+
end
|
68
|
+
|
69
|
+
def is(klass)
|
70
|
+
return self.type_name == klass.descriptor.name
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Timestamp.class_eval do
|
75
|
+
if RUBY_VERSION < "2.5"
|
76
|
+
def to_time
|
77
|
+
Time.at(self.to_f)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
def to_time
|
81
|
+
Time.at(seconds, nanos, :nanosecond)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.from_time(time)
|
86
|
+
new.from_time(time)
|
87
|
+
end
|
88
|
+
|
89
|
+
def from_time(time)
|
90
|
+
self.seconds = time.to_i
|
91
|
+
self.nanos = time.nsec
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_i
|
96
|
+
self.seconds
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_f
|
100
|
+
self.seconds + (self.nanos.quo(1_000_000_000))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
Duration.class_eval do
|
105
|
+
def to_f
|
106
|
+
self.seconds + (self.nanos.to_f / 1_000_000_000)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class UnexpectedStructType < Google::Protobuf::Error; end
|
111
|
+
|
112
|
+
Value.class_eval do
|
113
|
+
def to_ruby(recursive = false)
|
114
|
+
case self.kind
|
115
|
+
when :struct_value
|
116
|
+
if recursive
|
117
|
+
self.struct_value.to_h
|
118
|
+
else
|
119
|
+
self.struct_value
|
120
|
+
end
|
121
|
+
when :list_value
|
122
|
+
if recursive
|
123
|
+
self.list_value.to_a
|
124
|
+
else
|
125
|
+
self.list_value
|
126
|
+
end
|
127
|
+
when :null_value
|
128
|
+
nil
|
129
|
+
when :number_value
|
130
|
+
self.number_value
|
131
|
+
when :string_value
|
132
|
+
self.string_value
|
133
|
+
when :bool_value
|
134
|
+
self.bool_value
|
135
|
+
else
|
136
|
+
raise UnexpectedStructType
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.from_ruby(value)
|
141
|
+
self.new.from_ruby(value)
|
142
|
+
end
|
143
|
+
|
144
|
+
def from_ruby(value)
|
145
|
+
case value
|
146
|
+
when NilClass
|
147
|
+
self.null_value = :NULL_VALUE
|
148
|
+
when Numeric
|
149
|
+
self.number_value = value
|
150
|
+
when String
|
151
|
+
self.string_value = value
|
152
|
+
when TrueClass
|
153
|
+
self.bool_value = true
|
154
|
+
when FalseClass
|
155
|
+
self.bool_value = false
|
156
|
+
when Struct
|
157
|
+
self.struct_value = value
|
158
|
+
when Hash
|
159
|
+
self.struct_value = Struct.from_hash(value)
|
160
|
+
when ListValue
|
161
|
+
self.list_value = value
|
162
|
+
when Array
|
163
|
+
self.list_value = ListValue.from_a(value)
|
164
|
+
else
|
165
|
+
raise UnexpectedStructType
|
166
|
+
end
|
167
|
+
|
168
|
+
self
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
Struct.class_eval do
|
173
|
+
def [](key)
|
174
|
+
self.fields[key].to_ruby
|
175
|
+
rescue NoMethodError
|
176
|
+
nil
|
177
|
+
end
|
178
|
+
|
179
|
+
def []=(key, value)
|
180
|
+
unless key.is_a?(String)
|
181
|
+
raise UnexpectedStructType, "Struct keys must be strings."
|
182
|
+
end
|
183
|
+
self.fields[key] ||= Google::Protobuf::Value.new
|
184
|
+
self.fields[key].from_ruby(value)
|
185
|
+
end
|
186
|
+
|
187
|
+
def to_h
|
188
|
+
ret = {}
|
189
|
+
self.fields.each { |key, val| ret[key] = val.to_ruby(true) }
|
190
|
+
ret
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.from_hash(hash)
|
194
|
+
ret = Struct.new
|
195
|
+
hash.each { |key, val| ret[key] = val }
|
196
|
+
ret
|
197
|
+
end
|
198
|
+
|
199
|
+
def has_key?(key)
|
200
|
+
self.fields.has_key?(key)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
ListValue.class_eval do
|
205
|
+
include Enumerable
|
206
|
+
|
207
|
+
def length
|
208
|
+
self.values.length
|
209
|
+
end
|
210
|
+
|
211
|
+
def [](index)
|
212
|
+
self.values[index].to_ruby
|
213
|
+
end
|
214
|
+
|
215
|
+
def []=(index, value)
|
216
|
+
self.values[index].from_ruby(value)
|
217
|
+
end
|
218
|
+
|
219
|
+
def <<(value)
|
220
|
+
wrapper = Google::Protobuf::Value.new
|
221
|
+
wrapper.from_ruby(value)
|
222
|
+
self.values << wrapper
|
223
|
+
end
|
224
|
+
|
225
|
+
def each
|
226
|
+
self.values.each { |x| yield(x.to_ruby) }
|
227
|
+
end
|
228
|
+
|
229
|
+
def to_a
|
230
|
+
self.values.map { |x| x.to_ruby(true) }
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.from_a(arr)
|
234
|
+
ret = ListValue.new
|
235
|
+
arr.each { |val| ret << val }
|
236
|
+
ret
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -4,45 +4,47 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
7
|
+
add_file("google/protobuf/wrappers.proto", :syntax => :proto3) do
|
8
|
+
add_message "google.protobuf.DoubleValue" do
|
9
|
+
optional :value, :double, 1
|
10
|
+
end
|
11
|
+
add_message "google.protobuf.FloatValue" do
|
12
|
+
optional :value, :float, 1
|
13
|
+
end
|
14
|
+
add_message "google.protobuf.Int64Value" do
|
15
|
+
optional :value, :int64, 1
|
16
|
+
end
|
17
|
+
add_message "google.protobuf.UInt64Value" do
|
18
|
+
optional :value, :uint64, 1
|
19
|
+
end
|
20
|
+
add_message "google.protobuf.Int32Value" do
|
21
|
+
optional :value, :int32, 1
|
22
|
+
end
|
23
|
+
add_message "google.protobuf.UInt32Value" do
|
24
|
+
optional :value, :uint32, 1
|
25
|
+
end
|
26
|
+
add_message "google.protobuf.BoolValue" do
|
27
|
+
optional :value, :bool, 1
|
28
|
+
end
|
29
|
+
add_message "google.protobuf.StringValue" do
|
30
|
+
optional :value, :string, 1
|
31
|
+
end
|
32
|
+
add_message "google.protobuf.BytesValue" do
|
33
|
+
optional :value, :bytes, 1
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
module Google
|
37
39
|
module Protobuf
|
38
|
-
DoubleValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
39
|
-
FloatValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
40
|
-
Int64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
41
|
-
UInt64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
42
|
-
Int32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
43
|
-
UInt32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
44
|
-
BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
45
|
-
StringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
46
|
-
BytesValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
40
|
+
DoubleValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
41
|
+
FloatValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
42
|
+
Int64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
43
|
+
UInt64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
44
|
+
Int32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
45
|
+
UInt32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
46
|
+
BoolValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
47
|
+
StringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
48
|
+
BytesValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
47
49
|
end
|
48
50
|
end
|
data/lib/google/protobuf.rb
CHANGED
@@ -37,6 +37,7 @@ module Google
|
|
37
37
|
module Protobuf
|
38
38
|
class Error < StandardError; end
|
39
39
|
class ParseError < Error; end
|
40
|
+
class TypeError < ::TypeError; end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -45,31 +46,33 @@ if RUBY_PLATFORM == "java"
|
|
45
46
|
require 'google/protobuf_java'
|
46
47
|
else
|
47
48
|
begin
|
48
|
-
require "google/#{RUBY_VERSION.sub(/\.\d
|
49
|
+
require "google/#{RUBY_VERSION.sub(/\.\d+$/, '')}/protobuf_c"
|
49
50
|
rescue LoadError
|
50
51
|
require 'google/protobuf_c'
|
51
52
|
end
|
53
|
+
|
52
54
|
end
|
53
55
|
|
56
|
+
require 'google/protobuf/descriptor_dsl'
|
54
57
|
require 'google/protobuf/repeated_field'
|
55
58
|
|
56
59
|
module Google
|
57
60
|
module Protobuf
|
58
61
|
|
59
|
-
def self.encode(msg)
|
60
|
-
msg.to_proto
|
62
|
+
def self.encode(msg, options = {})
|
63
|
+
msg.to_proto(options)
|
61
64
|
end
|
62
65
|
|
63
|
-
def self.encode_json(msg)
|
64
|
-
msg.to_json
|
66
|
+
def self.encode_json(msg, options = {})
|
67
|
+
msg.to_json(options)
|
65
68
|
end
|
66
69
|
|
67
|
-
def self.decode(klass, proto)
|
68
|
-
klass.decode(proto)
|
70
|
+
def self.decode(klass, proto, options = {})
|
71
|
+
klass.decode(proto, options)
|
69
72
|
end
|
70
73
|
|
71
|
-
def self.decode_json(klass, json)
|
72
|
-
klass.decode_json(json)
|
74
|
+
def self.decode_json(klass, json, options = {})
|
75
|
+
klass.decode_json(json, options)
|
73
76
|
end
|
74
77
|
|
75
78
|
end
|