google-protobuf 3.21.2 → 4.29.1
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 +4 -4
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +67 -86
- data/ext/google/protobuf_c/convert.h +3 -28
- data/ext/google/protobuf_c/defs.c +538 -77
- data/ext/google/protobuf_c/defs.h +3 -28
- data/ext/google/protobuf_c/extconf.rb +4 -4
- data/ext/google/protobuf_c/glue.c +72 -0
- data/ext/google/protobuf_c/map.c +114 -85
- data/ext/google/protobuf_c/map.h +12 -30
- data/ext/google/protobuf_c/message.c +264 -238
- data/ext/google/protobuf_c/message.h +11 -33
- data/ext/google/protobuf_c/protobuf.c +63 -187
- data/ext/google/protobuf_c/protobuf.h +27 -39
- data/ext/google/protobuf_c/repeated_field.c +72 -38
- data/ext/google/protobuf_c/repeated_field.h +11 -29
- data/ext/google/protobuf_c/ruby-upb.c +13783 -8236
- data/ext/google/protobuf_c/ruby-upb.h +14077 -4495
- data/ext/google/protobuf_c/shared_convert.c +69 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +37 -0
- data/ext/google/protobuf_c/shared_message.h +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +20 -7
- data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
- data/lib/google/protobuf/any_pb.rb +6 -8
- data/lib/google/protobuf/api_pb.rb +6 -26
- data/lib/google/protobuf/descriptor_pb.rb +23 -226
- data/lib/google/protobuf/duration_pb.rb +6 -8
- data/lib/google/protobuf/empty_pb.rb +6 -6
- data/lib/google/protobuf/ffi/descriptor.rb +165 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +173 -0
- data/lib/google/protobuf/ffi/ffi.rb +215 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +330 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +49 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +296 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +433 -0
- data/lib/google/protobuf/ffi/message.rb +785 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +97 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
- data/lib/google/protobuf/field_mask_pb.rb +6 -7
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +8 -26
- data/lib/google/protobuf/plugin_pb.rb +25 -0
- data/lib/google/protobuf/repeated_field.rb +7 -31
- data/lib/google/protobuf/source_context_pb.rb +6 -7
- data/lib/google/protobuf/struct_pb.rb +6 -23
- data/lib/google/protobuf/timestamp_pb.rb +6 -8
- data/lib/google/protobuf/type_pb.rb +6 -71
- data/lib/google/protobuf/well_known_types.rb +5 -34
- data/lib/google/protobuf/wrappers_pb.rb +6 -31
- data/lib/google/protobuf.rb +27 -45
- data/lib/google/protobuf_ffi.rb +51 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +92 -16
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
- data/tests/basic.rb +0 -739
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348adc047870ec167a60d9eb6f1e6a908f7c9e853e14eb219bc20fa074a7061d
|
4
|
+
data.tar.gz: f496b9914e0e71ae82c3ca75efe7111ee8cb68bae54b71b051b28d09dc5ee6b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3e9a110007df61109ae34af8582b5333aa3b2f069377ff305f2acd8e540aaf50dc8930403eb72c777e4252fa82508559814977f0065cdbc34c099bf6a2e6d2
|
7
|
+
data.tar.gz: 2c1d7253020ee2bb238ef2a5b04fd722cfde1141a24ed41df6ac2906dff2a709eb1637d7053b4b5d22394dd8b03f7e26ff995f16c3573b86dc4b712d4eaee5f5
|
@@ -1,32 +1,9 @@
|
|
1
1
|
// Protocol Buffers - Google's data interchange format
|
2
2
|
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
4
3
|
//
|
5
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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.
|
4
|
+
// Use of this source code is governed by a BSD-style
|
5
|
+
// license that can be found in the LICENSE file or at
|
6
|
+
// https://developers.google.com/open-source/licenses/bsd
|
30
7
|
|
31
8
|
// -----------------------------------------------------------------------------
|
32
9
|
// Ruby <-> upb data conversion functions.
|
@@ -41,6 +18,7 @@
|
|
41
18
|
|
42
19
|
#include "message.h"
|
43
20
|
#include "protobuf.h"
|
21
|
+
#include "shared_convert.h"
|
44
22
|
|
45
23
|
static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
|
46
24
|
upb_StringView ret;
|
@@ -111,8 +89,7 @@ static int32_t Convert_ToEnum(VALUE value, const char* name,
|
|
111
89
|
case T_SYMBOL: {
|
112
90
|
const upb_EnumValueDef* ev =
|
113
91
|
upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value)));
|
114
|
-
if (!ev)
|
115
|
-
goto unknownval;
|
92
|
+
if (!ev) goto unknownval;
|
116
93
|
val = upb_EnumValueDef_Number(ev);
|
117
94
|
break;
|
118
95
|
}
|
@@ -127,6 +104,41 @@ unknownval:
|
|
127
104
|
rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
|
128
105
|
}
|
129
106
|
|
107
|
+
VALUE Convert_CheckStringUtf8(VALUE str) {
|
108
|
+
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
109
|
+
|
110
|
+
if (rb_obj_encoding(str) == utf8) {
|
111
|
+
// Note: Just because a string is marked as having UTF-8 encoding does
|
112
|
+
// not mean that it is *valid* UTF-8. We have to check separately
|
113
|
+
// whether it is valid.
|
114
|
+
if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
|
115
|
+
// TODO: For now
|
116
|
+
// we only warn for this case. We will remove the warning and throw an
|
117
|
+
// exception below in the 30.x release
|
118
|
+
|
119
|
+
rb_warn(
|
120
|
+
"String is invalid UTF-8. This will be an error in a future "
|
121
|
+
"version.");
|
122
|
+
// VALUE exc = rb_const_get_at(
|
123
|
+
// rb_cEncoding, rb_intern("InvalidByteSequenceError"));
|
124
|
+
// rb_raise(exc, "String is invalid UTF-8");
|
125
|
+
}
|
126
|
+
} else {
|
127
|
+
// Note: this will not duplicate underlying string data unless
|
128
|
+
// necessary.
|
129
|
+
//
|
130
|
+
// This will throw an exception if the conversion cannot be performed:
|
131
|
+
// - Encoding::UndefinedConversionError if certain characters cannot be
|
132
|
+
// converted to UTF-8.
|
133
|
+
// - Encoding::InvalidByteSequenceError if certain characters were invalid
|
134
|
+
// in the source encoding.
|
135
|
+
str = rb_str_encode(str, utf8, 0, Qnil);
|
136
|
+
PBRUBY_ASSERT(rb_enc_str_coderange(str) != ENC_CODERANGE_BROKEN);
|
137
|
+
}
|
138
|
+
|
139
|
+
return str;
|
140
|
+
}
|
141
|
+
|
130
142
|
upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
131
143
|
TypeInfo type_info, upb_Arena* arena) {
|
132
144
|
upb_MessageValue ret;
|
@@ -160,29 +172,18 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
160
172
|
}
|
161
173
|
break;
|
162
174
|
}
|
163
|
-
case kUpb_CType_String:
|
164
|
-
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
175
|
+
case kUpb_CType_String:
|
165
176
|
if (rb_obj_class(value) == rb_cSymbol) {
|
166
177
|
value = rb_funcall(value, rb_intern("to_s"), 0);
|
167
|
-
} else if (
|
178
|
+
} else if (!rb_obj_is_kind_of(value, rb_cString)) {
|
168
179
|
rb_raise(cTypeError,
|
169
180
|
"Invalid argument for string field '%s' (given %s).", name,
|
170
181
|
rb_class2name(CLASS_OF(value)));
|
171
182
|
}
|
172
183
|
|
173
|
-
|
174
|
-
// Note: this will not duplicate underlying string data unless
|
175
|
-
// necessary.
|
176
|
-
value = rb_str_encode(value, utf8, 0, Qnil);
|
177
|
-
|
178
|
-
if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
|
179
|
-
rb_raise(rb_eEncodingError, "String is invalid UTF-8");
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
184
|
+
value = Convert_CheckStringUtf8(value);
|
183
185
|
ret.str_val = Convert_StringData(value, arena);
|
184
186
|
break;
|
185
|
-
}
|
186
187
|
case kUpb_CType_Bytes: {
|
187
188
|
VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
|
188
189
|
if (rb_obj_class(value) != rb_cString) {
|
@@ -194,7 +195,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
194
195
|
if (rb_obj_encoding(value) != bytes) {
|
195
196
|
// Note: this will not duplicate underlying string data unless
|
196
197
|
// necessary.
|
197
|
-
// TODO
|
198
|
+
// TODO: is this really necessary to get raw bytes?
|
198
199
|
value = rb_str_encode(value, bytes, 0, Qnil);
|
199
200
|
}
|
200
201
|
|
@@ -227,11 +228,13 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
227
228
|
ret.uint64_val = NUM2ULL(value);
|
228
229
|
break;
|
229
230
|
default:
|
230
|
-
|
231
|
+
rb_raise(cTypeError, "Convert_RubyToUpb(): Unexpected type %d",
|
232
|
+
(int)type_info.type);
|
231
233
|
}
|
232
234
|
break;
|
233
235
|
default:
|
234
|
-
|
236
|
+
rb_raise(cTypeError,
|
237
|
+
"Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
|
235
238
|
}
|
236
239
|
|
237
240
|
return ret;
|
@@ -255,7 +258,7 @@ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
|
|
255
258
|
case kUpb_CType_UInt64:
|
256
259
|
return ULL2NUM(upb_val.int64_val);
|
257
260
|
case kUpb_CType_Enum: {
|
258
|
-
const upb_EnumValueDef
|
261
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
|
259
262
|
type_info.def.enumdef, upb_val.int32_val);
|
260
263
|
if (ev) {
|
261
264
|
return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
@@ -312,50 +315,28 @@ upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
|
|
312
315
|
|
313
316
|
bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
|
314
317
|
TypeInfo type_info) {
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
case kUpb_CType_Int64:
|
325
|
-
case kUpb_CType_UInt64:
|
326
|
-
return memcmp(&val1, &val2, 8) == 0;
|
327
|
-
case kUpb_CType_String:
|
328
|
-
case kUpb_CType_Bytes:
|
329
|
-
return val1.str_val.size == val2.str_val.size &&
|
330
|
-
memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
|
331
|
-
0;
|
332
|
-
case kUpb_CType_Message:
|
333
|
-
return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef);
|
334
|
-
default:
|
335
|
-
rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
|
318
|
+
upb_Status status;
|
319
|
+
upb_Status_Clear(&status);
|
320
|
+
bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
|
321
|
+
type_info.def.msgdef, &status);
|
322
|
+
if (upb_Status_IsOk(&status)) {
|
323
|
+
return return_value;
|
324
|
+
} else {
|
325
|
+
rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
|
326
|
+
upb_Status_ErrorMessage(&status));
|
336
327
|
}
|
337
328
|
}
|
338
329
|
|
339
330
|
uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
|
340
331
|
uint64_t seed) {
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
case kUpb_CType_Int64:
|
351
|
-
case kUpb_CType_UInt64:
|
352
|
-
return _upb_Hash(&val, 8, seed);
|
353
|
-
case kUpb_CType_String:
|
354
|
-
case kUpb_CType_Bytes:
|
355
|
-
return _upb_Hash(val.str_val.data, val.str_val.size, seed);
|
356
|
-
case kUpb_CType_Message:
|
357
|
-
return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
|
358
|
-
default:
|
359
|
-
rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
|
332
|
+
upb_Status status;
|
333
|
+
upb_Status_Clear(&status);
|
334
|
+
uint64_t return_value = shared_Msgval_GetHash(
|
335
|
+
val, type_info.type, type_info.def.msgdef, seed, &status);
|
336
|
+
if (upb_Status_IsOk(&status)) {
|
337
|
+
return return_value;
|
338
|
+
} else {
|
339
|
+
rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
|
340
|
+
upb_Status_ErrorMessage(&status));
|
360
341
|
}
|
361
342
|
}
|
@@ -1,38 +1,13 @@
|
|
1
1
|
// Protocol Buffers - Google's data interchange format
|
2
2
|
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
4
3
|
//
|
5
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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.
|
4
|
+
// Use of this source code is governed by a BSD-style
|
5
|
+
// license that can be found in the LICENSE file or at
|
6
|
+
// https://developers.google.com/open-source/licenses/bsd
|
30
7
|
|
31
8
|
#ifndef RUBY_PROTOBUF_CONVERT_H_
|
32
9
|
#define RUBY_PROTOBUF_CONVERT_H_
|
33
10
|
|
34
|
-
#include <ruby/ruby.h>
|
35
|
-
|
36
11
|
#include "protobuf.h"
|
37
12
|
#include "ruby-upb.h"
|
38
13
|
|