google-protobuf 3.2.0 → 3.9.1
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/defs.c +575 -81
- data/ext/google/protobuf_c/encode_decode.c +456 -149
- data/ext/google/protobuf_c/extconf.rb +15 -2
- data/ext/google/protobuf_c/map.c +47 -3
- data/ext/google/protobuf_c/message.c +308 -82
- data/ext/google/protobuf_c/protobuf.c +7 -3
- data/ext/google/protobuf_c/protobuf.h +86 -12
- data/ext/google/protobuf_c/repeated_field.c +10 -4
- data/ext/google/protobuf_c/storage.c +286 -117
- data/ext/google/protobuf_c/upb.c +14482 -10935
- data/ext/google/protobuf_c/upb.h +2401 -613
- data/ext/google/protobuf_c/wrap_memcpy.c +51 -0
- data/lib/google/protobuf.rb +5 -4
- data/lib/google/protobuf/any_pb.rb +5 -3
- data/lib/google/protobuf/api_pb.rb +23 -21
- data/lib/google/protobuf/duration_pb.rb +5 -3
- data/lib/google/protobuf/empty_pb.rb +3 -1
- data/lib/google/protobuf/field_mask_pb.rb +4 -2
- data/lib/google/protobuf/message_exts.rb +2 -2
- data/lib/google/protobuf/repeated_field.rb +3 -3
- data/lib/google/protobuf/source_context_pb.rb +4 -2
- data/lib/google/protobuf/struct_pb.rb +19 -17
- data/lib/google/protobuf/timestamp_pb.rb +5 -3
- data/lib/google/protobuf/type_pb.rb +68 -66
- data/lib/google/protobuf/well_known_types.rb +13 -1
- data/lib/google/protobuf/wrappers_pb.rb +28 -26
- data/tests/basic.rb +206 -1023
- data/tests/generated_code_test.rb +6 -2
- metadata +5 -5
@@ -0,0 +1,51 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2017 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
|
+
#include <string.h>
|
32
|
+
|
33
|
+
// On x86-64 Linux with glibc, we link against the 2.2.5 version of memcpy so
|
34
|
+
// that we avoid depending on the 2.14 version of the symbol. This way,
|
35
|
+
// distributions that are using pre-2.14 versions of glibc can successfully use
|
36
|
+
// the gem we distribute (https://github.com/protocolbuffers/protobuf/issues/2783).
|
37
|
+
//
|
38
|
+
// This wrapper is enabled by passing the linker flags -Wl,-wrap,memcpy in
|
39
|
+
// extconf.rb.
|
40
|
+
#ifdef __linux__
|
41
|
+
#if defined(__x86_64__) && defined(__GNU_LIBRARY__)
|
42
|
+
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
|
43
|
+
void *__wrap_memcpy(void *dest, const void *src, size_t n) {
|
44
|
+
return memcpy(dest, src, n);
|
45
|
+
}
|
46
|
+
#else
|
47
|
+
void *__wrap_memcpy(void *dest, const void *src, size_t n) {
|
48
|
+
return memmove(dest, src, n);
|
49
|
+
}
|
50
|
+
#endif
|
51
|
+
#endif
|
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
|
|
@@ -60,16 +61,16 @@ module Google
|
|
60
61
|
msg.to_proto
|
61
62
|
end
|
62
63
|
|
63
|
-
def self.encode_json(msg)
|
64
|
-
msg.to_json
|
64
|
+
def self.encode_json(msg, options = {})
|
65
|
+
msg.to_json(options)
|
65
66
|
end
|
66
67
|
|
67
68
|
def self.decode(klass, proto)
|
68
69
|
klass.decode(proto)
|
69
70
|
end
|
70
71
|
|
71
|
-
def self.decode_json(klass, json)
|
72
|
-
klass.decode_json(json)
|
72
|
+
def self.decode_json(klass, json, options = {})
|
73
|
+
klass.decode_json(json, options)
|
73
74
|
end
|
74
75
|
|
75
76
|
end
|
@@ -4,9 +4,11 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
add_file("google/protobuf/any.proto", :syntax => :proto3) do
|
8
|
+
add_message "google.protobuf.Any" do
|
9
|
+
optional :type_url, :string, 1
|
10
|
+
optional :value, :bytes, 2
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -6,27 +6,29 @@ require 'google/protobuf'
|
|
6
6
|
require 'google/protobuf/source_context_pb'
|
7
7
|
require 'google/protobuf/type_pb'
|
8
8
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
9
|
+
add_file("google/protobuf/api.proto", :syntax => :proto3) do
|
10
|
+
add_message "google.protobuf.Api" do
|
11
|
+
optional :name, :string, 1
|
12
|
+
repeated :methods, :message, 2, "google.protobuf.Method"
|
13
|
+
repeated :options, :message, 3, "google.protobuf.Option"
|
14
|
+
optional :version, :string, 4
|
15
|
+
optional :source_context, :message, 5, "google.protobuf.SourceContext"
|
16
|
+
repeated :mixins, :message, 6, "google.protobuf.Mixin"
|
17
|
+
optional :syntax, :enum, 7, "google.protobuf.Syntax"
|
18
|
+
end
|
19
|
+
add_message "google.protobuf.Method" do
|
20
|
+
optional :name, :string, 1
|
21
|
+
optional :request_type_url, :string, 2
|
22
|
+
optional :request_streaming, :bool, 3
|
23
|
+
optional :response_type_url, :string, 4
|
24
|
+
optional :response_streaming, :bool, 5
|
25
|
+
repeated :options, :message, 6, "google.protobuf.Option"
|
26
|
+
optional :syntax, :enum, 7, "google.protobuf.Syntax"
|
27
|
+
end
|
28
|
+
add_message "google.protobuf.Mixin" do
|
29
|
+
optional :name, :string, 1
|
30
|
+
optional :root, :string, 2
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -4,9 +4,11 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -4,8 +4,10 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
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
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -79,7 +79,7 @@ module Google
|
|
79
79
|
|
80
80
|
|
81
81
|
def first(n=nil)
|
82
|
-
n ? self[0
|
82
|
+
n ? self[0...n] : self[0]
|
83
83
|
end
|
84
84
|
|
85
85
|
|
@@ -150,12 +150,12 @@ module Google
|
|
150
150
|
end
|
151
151
|
|
152
152
|
|
153
|
-
%w(delete delete_at
|
153
|
+
%w(delete delete_at shift slice! unshift).each do |method_name|
|
154
154
|
define_array_wrapper_method(method_name)
|
155
155
|
end
|
156
156
|
|
157
157
|
|
158
|
-
%w(collect! compact! fill flatten! insert reverse!
|
158
|
+
%w(collect! compact! delete_if fill flatten! insert reverse!
|
159
159
|
rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
|
160
160
|
define_array_wrapper_with_result_method(method_name)
|
161
161
|
end
|
@@ -4,8 +4,10 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
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
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -4,24 +4,26 @@
|
|
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
|
-
|
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
|
18
26
|
end
|
19
|
-
end
|
20
|
-
add_message "google.protobuf.ListValue" do
|
21
|
-
repeated :values, :message, 1, "google.protobuf.Value"
|
22
|
-
end
|
23
|
-
add_enum "google.protobuf.NullValue" do
|
24
|
-
value :NULL_VALUE, 0
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -4,9 +4,11 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
@@ -6,72 +6,74 @@ require 'google/protobuf'
|
|
6
6
|
require 'google/protobuf/any_pb'
|
7
7
|
require 'google/protobuf/source_context_pb'
|
8
8
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
9
|
+
add_file("google/protobuf/type.proto", :syntax => :proto3) do
|
10
|
+
add_message "google.protobuf.Type" do
|
11
|
+
optional :name, :string, 1
|
12
|
+
repeated :fields, :message, 2, "google.protobuf.Field"
|
13
|
+
repeated :oneofs, :string, 3
|
14
|
+
repeated :options, :message, 4, "google.protobuf.Option"
|
15
|
+
optional :source_context, :message, 5, "google.protobuf.SourceContext"
|
16
|
+
optional :syntax, :enum, 6, "google.protobuf.Syntax"
|
17
|
+
end
|
18
|
+
add_message "google.protobuf.Field" do
|
19
|
+
optional :kind, :enum, 1, "google.protobuf.Field.Kind"
|
20
|
+
optional :cardinality, :enum, 2, "google.protobuf.Field.Cardinality"
|
21
|
+
optional :number, :int32, 3
|
22
|
+
optional :name, :string, 4
|
23
|
+
optional :type_url, :string, 6
|
24
|
+
optional :oneof_index, :int32, 7
|
25
|
+
optional :packed, :bool, 8
|
26
|
+
repeated :options, :message, 9, "google.protobuf.Option"
|
27
|
+
optional :json_name, :string, 10
|
28
|
+
optional :default_value, :string, 11
|
29
|
+
end
|
30
|
+
add_enum "google.protobuf.Field.Kind" do
|
31
|
+
value :TYPE_UNKNOWN, 0
|
32
|
+
value :TYPE_DOUBLE, 1
|
33
|
+
value :TYPE_FLOAT, 2
|
34
|
+
value :TYPE_INT64, 3
|
35
|
+
value :TYPE_UINT64, 4
|
36
|
+
value :TYPE_INT32, 5
|
37
|
+
value :TYPE_FIXED64, 6
|
38
|
+
value :TYPE_FIXED32, 7
|
39
|
+
value :TYPE_BOOL, 8
|
40
|
+
value :TYPE_STRING, 9
|
41
|
+
value :TYPE_GROUP, 10
|
42
|
+
value :TYPE_MESSAGE, 11
|
43
|
+
value :TYPE_BYTES, 12
|
44
|
+
value :TYPE_UINT32, 13
|
45
|
+
value :TYPE_ENUM, 14
|
46
|
+
value :TYPE_SFIXED32, 15
|
47
|
+
value :TYPE_SFIXED64, 16
|
48
|
+
value :TYPE_SINT32, 17
|
49
|
+
value :TYPE_SINT64, 18
|
50
|
+
end
|
51
|
+
add_enum "google.protobuf.Field.Cardinality" do
|
52
|
+
value :CARDINALITY_UNKNOWN, 0
|
53
|
+
value :CARDINALITY_OPTIONAL, 1
|
54
|
+
value :CARDINALITY_REQUIRED, 2
|
55
|
+
value :CARDINALITY_REPEATED, 3
|
56
|
+
end
|
57
|
+
add_message "google.protobuf.Enum" do
|
58
|
+
optional :name, :string, 1
|
59
|
+
repeated :enumvalue, :message, 2, "google.protobuf.EnumValue"
|
60
|
+
repeated :options, :message, 3, "google.protobuf.Option"
|
61
|
+
optional :source_context, :message, 4, "google.protobuf.SourceContext"
|
62
|
+
optional :syntax, :enum, 5, "google.protobuf.Syntax"
|
63
|
+
end
|
64
|
+
add_message "google.protobuf.EnumValue" do
|
65
|
+
optional :name, :string, 1
|
66
|
+
optional :number, :int32, 2
|
67
|
+
repeated :options, :message, 3, "google.protobuf.Option"
|
68
|
+
end
|
69
|
+
add_message "google.protobuf.Option" do
|
70
|
+
optional :name, :string, 1
|
71
|
+
optional :value, :message, 2, "google.protobuf.Any"
|
72
|
+
end
|
73
|
+
add_enum "google.protobuf.Syntax" do
|
74
|
+
value :SYNTAX_PROTO2, 0
|
75
|
+
value :SYNTAX_PROTO3, 1
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
@@ -39,6 +39,12 @@ module Google
|
|
39
39
|
module Protobuf
|
40
40
|
|
41
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
|
+
|
42
48
|
def pack(msg, type_url_prefix='type.googleapis.com/')
|
43
49
|
if type_url_prefix.empty? or type_url_prefix[-1] != '/' then
|
44
50
|
self.type_url = "#{type_url_prefix}/#{msg.class.descriptor.name}"
|
@@ -80,7 +86,7 @@ module Google
|
|
80
86
|
end
|
81
87
|
|
82
88
|
def to_f
|
83
|
-
self.seconds + (self.nanos.
|
89
|
+
self.seconds + (self.nanos.quo(1_000_000_000))
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
@@ -149,6 +155,8 @@ module Google
|
|
149
155
|
Struct.class_eval do
|
150
156
|
def [](key)
|
151
157
|
self.fields[key].to_ruby
|
158
|
+
rescue NoMethodError
|
159
|
+
nil
|
152
160
|
end
|
153
161
|
|
154
162
|
def []=(key, value)
|
@@ -170,6 +178,10 @@ module Google
|
|
170
178
|
hash.each { |key, val| ret[key] = val }
|
171
179
|
ret
|
172
180
|
end
|
181
|
+
|
182
|
+
def has_key?(key)
|
183
|
+
self.fields.has_key?(key)
|
184
|
+
end
|
173
185
|
end
|
174
186
|
|
175
187
|
ListValue.class_eval do
|