google-protobuf 3.19.1 → 4.30.2
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 +153 -166
- data/ext/google/protobuf_c/convert.h +15 -37
- data/ext/google/protobuf_c/defs.c +867 -251
- data/ext/google/protobuf_c/defs.h +22 -47
- data/ext/google/protobuf_c/extconf.rb +25 -5
- data/ext/google/protobuf_c/glue.c +135 -0
- data/ext/google/protobuf_c/map.c +182 -145
- data/ext/google/protobuf_c/map.h +16 -35
- data/ext/google/protobuf_c/message.c +534 -437
- data/ext/google/protobuf_c/message.h +30 -49
- data/ext/google/protobuf_c/protobuf.c +125 -238
- data/ext/google/protobuf_c/protobuf.h +40 -49
- data/ext/google/protobuf_c/repeated_field.c +152 -120
- data/ext/google/protobuf_c/repeated_field.h +16 -34
- data/ext/google/protobuf_c/ruby-upb.c +15827 -7228
- data/ext/google/protobuf_c/ruby-upb.h +15075 -3866
- 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 +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
- 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 +24 -225
- 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 +175 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +183 -0
- data/lib/google/protobuf/ffi/ffi.rb +214 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +340 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +292 -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 +783 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +107 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -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 +10 -28
- data/lib/google/protobuf/plugin_pb.rb +25 -0
- data/lib/google/protobuf/repeated_field.rb +22 -33
- 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 +16 -40
- data/lib/google/protobuf/wrappers_pb.rb +6 -31
- data/lib/google/protobuf.rb +32 -50
- data/lib/google/protobuf_ffi.rb +52 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +97 -20
- data/lib/google/protobuf/descriptor_dsl.rb +0 -458
- data/tests/basic.rb +0 -640
- 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: b5125cc8af8296e8ccc158044588e8aa997acb0a4dfc12b8f70207c4b6e0e312
|
4
|
+
data.tar.gz: 9aaaeb8e9c9b0ced47d7c14a5d3d2da37e43c6b12fd32177d87fa055b59426d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc4490fe009fdf955ac03163cde61170975faba127c6987819321d6c45ef9d20823f44d25b883881c5bb2faab630c01e8a0519a20466abc624d018a759a73b33
|
7
|
+
data.tar.gz: 7b2364e5c5a7056df7684eed5be81b03f4806a53e8f8f9e381f879b8c11e640e191ab72e1abbf7db56f1aae8e299d4f260b2138367f657911542ad87174f031a
|
@@ -1,37 +1,14 @@
|
|
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.
|
33
10
|
//
|
34
|
-
// This file Also contains a few other assorted algorithms on
|
11
|
+
// This file Also contains a few other assorted algorithms on upb_MessageValue.
|
35
12
|
//
|
36
13
|
// None of the algorithms in this file require any access to the internal
|
37
14
|
// representation of Ruby or upb objects.
|
@@ -41,11 +18,12 @@
|
|
41
18
|
|
42
19
|
#include "message.h"
|
43
20
|
#include "protobuf.h"
|
21
|
+
#include "shared_convert.h"
|
44
22
|
|
45
|
-
static
|
46
|
-
|
23
|
+
static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
|
24
|
+
upb_StringView ret;
|
47
25
|
if (arena) {
|
48
|
-
char
|
26
|
+
char* ptr = upb_Arena_Malloc(arena, RSTRING_LEN(str));
|
49
27
|
memcpy(ptr, RSTRING_PTR(str), RSTRING_LEN(str));
|
50
28
|
ret.data = ptr;
|
51
29
|
} else {
|
@@ -57,13 +35,11 @@ static upb_strview Convert_StringData(VALUE str, upb_arena *arena) {
|
|
57
35
|
}
|
58
36
|
|
59
37
|
static bool is_ruby_num(VALUE value) {
|
60
|
-
return (TYPE(value) == T_FLOAT ||
|
61
|
-
TYPE(value) == T_FIXNUM ||
|
38
|
+
return (TYPE(value) == T_FLOAT || TYPE(value) == T_FIXNUM ||
|
62
39
|
TYPE(value) == T_BIGNUM);
|
63
40
|
}
|
64
41
|
|
65
|
-
static void Convert_CheckInt(const char* name,
|
66
|
-
VALUE val) {
|
42
|
+
static void Convert_CheckInt(const char* name, upb_CType type, VALUE val) {
|
67
43
|
if (!is_ruby_num(val)) {
|
68
44
|
rb_raise(cTypeError,
|
69
45
|
"Expected number type for integral field '%s' (given %s).", name,
|
@@ -82,7 +58,7 @@ static void Convert_CheckInt(const char* name, upb_fieldtype_t type,
|
|
82
58
|
name, rb_class2name(CLASS_OF(val)));
|
83
59
|
}
|
84
60
|
}
|
85
|
-
if (type ==
|
61
|
+
if (type == kUpb_CType_UInt32 || type == kUpb_CType_UInt64) {
|
86
62
|
if (NUM2DBL(val) < 0) {
|
87
63
|
rb_raise(
|
88
64
|
rb_eRangeError,
|
@@ -93,26 +69,30 @@ static void Convert_CheckInt(const char* name, upb_fieldtype_t type,
|
|
93
69
|
}
|
94
70
|
|
95
71
|
static int32_t Convert_ToEnum(VALUE value, const char* name,
|
96
|
-
const
|
72
|
+
const upb_EnumDef* e) {
|
97
73
|
int32_t val;
|
98
74
|
|
99
75
|
switch (TYPE(value)) {
|
100
76
|
case T_FLOAT:
|
101
77
|
case T_FIXNUM:
|
102
78
|
case T_BIGNUM:
|
103
|
-
Convert_CheckInt(name,
|
79
|
+
Convert_CheckInt(name, kUpb_CType_Int32, value);
|
104
80
|
val = NUM2INT(value);
|
105
81
|
break;
|
106
|
-
case T_STRING:
|
107
|
-
|
108
|
-
|
109
|
-
|
82
|
+
case T_STRING: {
|
83
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize(
|
84
|
+
e, RSTRING_PTR(value), RSTRING_LEN(value));
|
85
|
+
if (!ev) goto unknownval;
|
86
|
+
val = upb_EnumValueDef_Number(ev);
|
110
87
|
break;
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
88
|
+
}
|
89
|
+
case T_SYMBOL: {
|
90
|
+
const upb_EnumValueDef* ev =
|
91
|
+
upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value)));
|
92
|
+
if (!ev) goto unknownval;
|
93
|
+
val = upb_EnumValueDef_Number(ev);
|
115
94
|
break;
|
95
|
+
}
|
116
96
|
default:
|
117
97
|
rb_raise(cTypeError,
|
118
98
|
"Expected number or symbol type for enum field '%s'.", name);
|
@@ -124,148 +104,175 @@ unknownval:
|
|
124
104
|
rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
|
125
105
|
}
|
126
106
|
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
+
VALUE exc = rb_const_get_at(
|
116
|
+
rb_cEncoding, rb_intern("InvalidByteSequenceError"));
|
117
|
+
rb_raise(exc, "String is invalid UTF-8");
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
// Note: this will not duplicate underlying string data unless
|
121
|
+
// necessary.
|
122
|
+
//
|
123
|
+
// This will throw an exception if the conversion cannot be performed:
|
124
|
+
// - Encoding::UndefinedConversionError if certain characters cannot be
|
125
|
+
// converted to UTF-8.
|
126
|
+
// - Encoding::InvalidByteSequenceError if certain characters were invalid
|
127
|
+
// in the source encoding.
|
128
|
+
str = rb_str_encode(str, utf8, 0, Qnil);
|
129
|
+
PBRUBY_ASSERT(rb_enc_str_coderange(str) != ENC_CODERANGE_BROKEN);
|
130
|
+
}
|
131
|
+
|
132
|
+
return str;
|
133
|
+
}
|
134
|
+
|
135
|
+
upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
136
|
+
TypeInfo type_info, upb_Arena* arena) {
|
137
|
+
upb_MessageValue ret;
|
130
138
|
|
131
139
|
switch (type_info.type) {
|
132
|
-
case
|
140
|
+
case kUpb_CType_Float:
|
133
141
|
if (!is_ruby_num(value)) {
|
134
|
-
rb_raise(cTypeError,
|
135
|
-
|
142
|
+
rb_raise(cTypeError,
|
143
|
+
"Expected number type for float field '%s' (given %s).", name,
|
144
|
+
rb_class2name(CLASS_OF(value)));
|
136
145
|
}
|
137
146
|
ret.float_val = NUM2DBL(value);
|
138
147
|
break;
|
139
|
-
case
|
148
|
+
case kUpb_CType_Double:
|
140
149
|
if (!is_ruby_num(value)) {
|
141
|
-
rb_raise(cTypeError,
|
142
|
-
|
150
|
+
rb_raise(cTypeError,
|
151
|
+
"Expected number type for double field '%s' (given %s).", name,
|
152
|
+
rb_class2name(CLASS_OF(value)));
|
143
153
|
}
|
144
154
|
ret.double_val = NUM2DBL(value);
|
145
155
|
break;
|
146
|
-
case
|
156
|
+
case kUpb_CType_Bool: {
|
147
157
|
if (value == Qtrue) {
|
148
158
|
ret.bool_val = 1;
|
149
159
|
} else if (value == Qfalse) {
|
150
160
|
ret.bool_val = 0;
|
151
161
|
} else {
|
152
|
-
rb_raise(cTypeError,
|
153
|
-
|
162
|
+
rb_raise(cTypeError,
|
163
|
+
"Invalid argument for boolean field '%s' (given %s).", name,
|
164
|
+
rb_class2name(CLASS_OF(value)));
|
154
165
|
}
|
155
166
|
break;
|
156
167
|
}
|
157
|
-
case
|
158
|
-
|
159
|
-
if (CLASS_OF(value) == rb_cSymbol) {
|
168
|
+
case kUpb_CType_String:
|
169
|
+
if (rb_obj_class(value) == rb_cSymbol) {
|
160
170
|
value = rb_funcall(value, rb_intern("to_s"), 0);
|
161
|
-
} else if (
|
162
|
-
rb_raise(cTypeError,
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
if (rb_obj_encoding(value) != utf8) {
|
167
|
-
// Note: this will not duplicate underlying string data unless necessary.
|
168
|
-
value = rb_str_encode(value, utf8, 0, Qnil);
|
169
|
-
|
170
|
-
if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
|
171
|
-
rb_raise(rb_eEncodingError, "String is invalid UTF-8");
|
172
|
-
}
|
171
|
+
} else if (!rb_obj_is_kind_of(value, rb_cString)) {
|
172
|
+
rb_raise(cTypeError,
|
173
|
+
"Invalid argument for string field '%s' (given %s).", name,
|
174
|
+
rb_class2name(CLASS_OF(value)));
|
173
175
|
}
|
174
176
|
|
177
|
+
value = Convert_CheckStringUtf8(value);
|
175
178
|
ret.str_val = Convert_StringData(value, arena);
|
176
179
|
break;
|
177
|
-
|
178
|
-
case UPB_TYPE_BYTES: {
|
180
|
+
case kUpb_CType_Bytes: {
|
179
181
|
VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
|
180
|
-
if (
|
181
|
-
rb_raise(cTypeError,
|
182
|
-
|
182
|
+
if (rb_obj_class(value) != rb_cString) {
|
183
|
+
rb_raise(cTypeError,
|
184
|
+
"Invalid argument for bytes field '%s' (given %s).", name,
|
185
|
+
rb_class2name(CLASS_OF(value)));
|
183
186
|
}
|
184
187
|
|
185
188
|
if (rb_obj_encoding(value) != bytes) {
|
186
|
-
// Note: this will not duplicate underlying string data unless
|
187
|
-
//
|
189
|
+
// Note: this will not duplicate underlying string data unless
|
190
|
+
// necessary.
|
191
|
+
// TODO: is this really necessary to get raw bytes?
|
188
192
|
value = rb_str_encode(value, bytes, 0, Qnil);
|
189
193
|
}
|
190
194
|
|
191
195
|
ret.str_val = Convert_StringData(value, arena);
|
192
196
|
break;
|
193
197
|
}
|
194
|
-
case
|
198
|
+
case kUpb_CType_Message:
|
195
199
|
ret.msg_val =
|
196
200
|
Message_GetUpbMessage(value, type_info.def.msgdef, name, arena);
|
197
201
|
break;
|
198
|
-
case
|
202
|
+
case kUpb_CType_Enum:
|
199
203
|
ret.int32_val = Convert_ToEnum(value, name, type_info.def.enumdef);
|
200
204
|
break;
|
201
|
-
case
|
202
|
-
case
|
203
|
-
case
|
204
|
-
case
|
205
|
+
case kUpb_CType_Int32:
|
206
|
+
case kUpb_CType_Int64:
|
207
|
+
case kUpb_CType_UInt32:
|
208
|
+
case kUpb_CType_UInt64:
|
205
209
|
Convert_CheckInt(name, type_info.type, value);
|
206
210
|
switch (type_info.type) {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
211
|
+
case kUpb_CType_Int32:
|
212
|
+
ret.int32_val = NUM2INT(value);
|
213
|
+
break;
|
214
|
+
case kUpb_CType_Int64:
|
215
|
+
ret.int64_val = NUM2LL(value);
|
216
|
+
break;
|
217
|
+
case kUpb_CType_UInt32:
|
218
|
+
ret.uint32_val = NUM2UINT(value);
|
219
|
+
break;
|
220
|
+
case kUpb_CType_UInt64:
|
221
|
+
ret.uint64_val = NUM2ULL(value);
|
222
|
+
break;
|
223
|
+
default:
|
224
|
+
rb_raise(cTypeError, "Convert_RubyToUpb(): Unexpected type %d",
|
225
|
+
(int)type_info.type);
|
221
226
|
}
|
222
227
|
break;
|
223
228
|
default:
|
224
|
-
|
229
|
+
rb_raise(cTypeError,
|
230
|
+
"Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
|
225
231
|
}
|
226
232
|
|
227
233
|
return ret;
|
228
234
|
}
|
229
235
|
|
230
|
-
VALUE Convert_UpbToRuby(
|
236
|
+
VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
|
237
|
+
VALUE arena) {
|
231
238
|
switch (type_info.type) {
|
232
|
-
case
|
239
|
+
case kUpb_CType_Float:
|
233
240
|
return DBL2NUM(upb_val.float_val);
|
234
|
-
case
|
241
|
+
case kUpb_CType_Double:
|
235
242
|
return DBL2NUM(upb_val.double_val);
|
236
|
-
case
|
243
|
+
case kUpb_CType_Bool:
|
237
244
|
return upb_val.bool_val ? Qtrue : Qfalse;
|
238
|
-
case
|
245
|
+
case kUpb_CType_Int32:
|
239
246
|
return INT2NUM(upb_val.int32_val);
|
240
|
-
case
|
247
|
+
case kUpb_CType_Int64:
|
241
248
|
return LL2NUM(upb_val.int64_val);
|
242
|
-
case
|
249
|
+
case kUpb_CType_UInt32:
|
243
250
|
return UINT2NUM(upb_val.uint32_val);
|
244
|
-
case
|
251
|
+
case kUpb_CType_UInt64:
|
245
252
|
return ULL2NUM(upb_val.int64_val);
|
246
|
-
case
|
247
|
-
const
|
248
|
-
|
249
|
-
if (
|
250
|
-
return ID2SYM(rb_intern(
|
253
|
+
case kUpb_CType_Enum: {
|
254
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
|
255
|
+
type_info.def.enumdef, upb_val.int32_val);
|
256
|
+
if (ev) {
|
257
|
+
return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
251
258
|
} else {
|
252
259
|
return INT2NUM(upb_val.int32_val);
|
253
260
|
}
|
254
261
|
}
|
255
|
-
case
|
262
|
+
case kUpb_CType_String: {
|
256
263
|
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size);
|
257
264
|
rb_enc_associate(str_rb, rb_utf8_encoding());
|
258
265
|
rb_obj_freeze(str_rb);
|
259
266
|
return str_rb;
|
260
267
|
}
|
261
|
-
case
|
268
|
+
case kUpb_CType_Bytes: {
|
262
269
|
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size);
|
263
270
|
rb_enc_associate(str_rb, rb_ascii8bit_encoding());
|
264
271
|
rb_obj_freeze(str_rb);
|
265
272
|
return str_rb;
|
266
273
|
}
|
267
|
-
case
|
268
|
-
return Message_GetRubyWrapper((
|
274
|
+
case kUpb_CType_Message:
|
275
|
+
return Message_GetRubyWrapper((upb_Message*)upb_val.msg_val,
|
269
276
|
type_info.def.msgdef, arena);
|
270
277
|
default:
|
271
278
|
rb_raise(rb_eRuntimeError, "Convert_UpbToRuby(): Unexpected type %d",
|
@@ -273,24 +280,24 @@ VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena) {
|
|
273
280
|
}
|
274
281
|
}
|
275
282
|
|
276
|
-
|
277
|
-
|
278
|
-
|
283
|
+
upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
|
284
|
+
upb_Arena* arena) {
|
285
|
+
upb_MessageValue new_msgval;
|
279
286
|
|
280
287
|
switch (type_info.type) {
|
281
288
|
default:
|
282
289
|
memcpy(&new_msgval, &msgval, sizeof(msgval));
|
283
290
|
break;
|
284
|
-
case
|
285
|
-
case
|
291
|
+
case kUpb_CType_String:
|
292
|
+
case kUpb_CType_Bytes: {
|
286
293
|
size_t n = msgval.str_val.size;
|
287
|
-
char
|
294
|
+
char* mem = upb_Arena_Malloc(arena, n);
|
288
295
|
new_msgval.str_val.data = mem;
|
289
296
|
new_msgval.str_val.size = n;
|
290
297
|
memcpy(mem, msgval.str_val.data, n);
|
291
298
|
break;
|
292
299
|
}
|
293
|
-
case
|
300
|
+
case kUpb_CType_Message:
|
294
301
|
new_msgval.msg_val =
|
295
302
|
Message_deep_copy(msgval.msg_val, type_info.def.msgdef, arena);
|
296
303
|
break;
|
@@ -299,50 +306,30 @@ upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info,
|
|
299
306
|
return new_msgval;
|
300
307
|
}
|
301
308
|
|
302
|
-
bool Msgval_IsEqual(
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
case UPB_TYPE_UINT64:
|
314
|
-
return memcmp(&val1, &val2, 8) == 0;
|
315
|
-
case UPB_TYPE_STRING:
|
316
|
-
case UPB_TYPE_BYTES:
|
317
|
-
return val1.str_val.size == val2.str_val.size &&
|
318
|
-
memcmp(val1.str_val.data, val2.str_val.data,
|
319
|
-
val1.str_val.size) == 0;
|
320
|
-
case UPB_TYPE_MESSAGE:
|
321
|
-
return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef);
|
322
|
-
default:
|
323
|
-
rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
|
309
|
+
bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
|
310
|
+
TypeInfo type_info) {
|
311
|
+
upb_Status status;
|
312
|
+
upb_Status_Clear(&status);
|
313
|
+
bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
|
314
|
+
type_info.def.msgdef, &status);
|
315
|
+
if (upb_Status_IsOk(&status)) {
|
316
|
+
return return_value;
|
317
|
+
} else {
|
318
|
+
rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
|
319
|
+
upb_Status_ErrorMessage(&status));
|
324
320
|
}
|
325
321
|
}
|
326
322
|
|
327
|
-
uint64_t Msgval_GetHash(
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
case UPB_TYPE_UINT64:
|
339
|
-
return Wyhash(&val, 8, seed, kWyhashSalt);
|
340
|
-
case UPB_TYPE_STRING:
|
341
|
-
case UPB_TYPE_BYTES:
|
342
|
-
return Wyhash(val.str_val.data, val.str_val.size, seed, kWyhashSalt);
|
343
|
-
case UPB_TYPE_MESSAGE:
|
344
|
-
return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
|
345
|
-
default:
|
346
|
-
rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
|
323
|
+
uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
|
324
|
+
uint64_t seed) {
|
325
|
+
upb_Status status;
|
326
|
+
upb_Status_Clear(&status);
|
327
|
+
uint64_t return_value = shared_Msgval_GetHash(
|
328
|
+
val, type_info.type, type_info.def.msgdef, seed, &status);
|
329
|
+
if (upb_Status_IsOk(&status)) {
|
330
|
+
return return_value;
|
331
|
+
} else {
|
332
|
+
rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
|
333
|
+
upb_Status_ErrorMessage(&status));
|
347
334
|
}
|
348
335
|
}
|
@@ -1,42 +1,17 @@
|
|
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
|
|
39
|
-
// Converts |ruby_val| to a
|
14
|
+
// Converts |ruby_val| to a upb_MessageValue according to |type_info|.
|
40
15
|
//
|
41
16
|
// The |arena| parameter indicates the lifetime of the container where this
|
42
17
|
// value will be assigned. It is used as follows:
|
@@ -47,8 +22,8 @@
|
|
47
22
|
// - If type is message and the Ruby value is a message instance, we will fuse
|
48
23
|
// the message's arena into |arena|, to ensure that this message outlives the
|
49
24
|
// container.
|
50
|
-
|
51
|
-
|
25
|
+
upb_MessageValue Convert_RubyToUpb(VALUE ruby_val, const char *name,
|
26
|
+
TypeInfo type_info, upb_Arena *arena);
|
52
27
|
|
53
28
|
// Converts |upb_val| to a Ruby VALUE according to |type_info|. This may involve
|
54
29
|
// creating a Ruby wrapper object.
|
@@ -56,17 +31,20 @@ upb_msgval Convert_RubyToUpb(VALUE ruby_val, const char *name,
|
|
56
31
|
// The |arena| parameter indicates the arena that owns the lifetime of
|
57
32
|
// |upb_val|. Any Ruby wrapper object that is created will reference |arena|
|
58
33
|
// and ensure it outlives the wrapper.
|
59
|
-
VALUE Convert_UpbToRuby(
|
34
|
+
VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
|
35
|
+
VALUE arena);
|
60
36
|
|
61
37
|
// Creates a deep copy of |msgval| in |arena|.
|
62
|
-
|
63
|
-
|
38
|
+
upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
|
39
|
+
upb_Arena *arena);
|
64
40
|
|
65
41
|
// Returns true if |val1| and |val2| are equal. Their type is given by
|
66
42
|
// |type_info|.
|
67
|
-
bool Msgval_IsEqual(
|
43
|
+
bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
|
44
|
+
TypeInfo type_info);
|
68
45
|
|
69
|
-
// Returns a hash value for the given
|
70
|
-
uint64_t Msgval_GetHash(
|
46
|
+
// Returns a hash value for the given upb_MessageValue.
|
47
|
+
uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
|
48
|
+
uint64_t seed);
|
71
49
|
|
72
50
|
#endif // RUBY_PROTOBUF_CONVERT_H_
|