google-protobuf 3.19.1 → 3.25.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.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +121 -155
- data/ext/google/protobuf_c/convert.h +15 -37
- data/ext/google/protobuf_c/defs.c +362 -243
- data/ext/google/protobuf_c/defs.h +22 -47
- data/ext/google/protobuf_c/extconf.rb +13 -5
- data/ext/google/protobuf_c/glue.c +56 -0
- data/ext/google/protobuf_c/map.c +129 -137
- data/ext/google/protobuf_c/map.h +13 -36
- data/ext/google/protobuf_c/message.c +486 -389
- data/ext/google/protobuf_c/message.h +32 -47
- data/ext/google/protobuf_c/protobuf.c +101 -228
- data/ext/google/protobuf_c/protobuf.h +37 -42
- data/ext/google/protobuf_c/repeated_field.c +110 -113
- data/ext/google/protobuf_c/repeated_field.h +12 -34
- data/ext/google/protobuf_c/ruby-upb.c +12236 -6993
- data/ext/google/protobuf_c/ruby-upb.h +12127 -3787
- data/ext/google/protobuf_c/shared_convert.c +64 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +65 -0
- data/ext/google/protobuf_c/shared_message.h +25 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -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 +21 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
- data/lib/google/protobuf/any_pb.rb +24 -5
- data/lib/google/protobuf/api_pb.rb +26 -23
- data/lib/google/protobuf/descriptor_dsl.rb +8 -1
- data/lib/google/protobuf/descriptor_pb.rb +43 -225
- data/lib/google/protobuf/duration_pb.rb +24 -5
- data/lib/google/protobuf/empty_pb.rb +24 -3
- data/lib/google/protobuf/ffi/descriptor.rb +165 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
- data/lib/google/protobuf/ffi/ffi.rb +213 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +305 -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 +407 -0
- data/lib/google/protobuf/ffi/message.rb +662 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
- data/lib/google/protobuf/field_mask_pb.rb +24 -4
- data/lib/google/protobuf/message_exts.rb +10 -28
- data/lib/google/protobuf/object_cache.rb +97 -0
- data/lib/google/protobuf/plugin_pb.rb +47 -0
- data/lib/google/protobuf/repeated_field.rb +18 -28
- data/lib/google/protobuf/source_context_pb.rb +24 -4
- data/lib/google/protobuf/struct_pb.rb +24 -20
- data/lib/google/protobuf/timestamp_pb.rb +24 -5
- data/lib/google/protobuf/type_pb.rb +26 -68
- data/lib/google/protobuf/well_known_types.rb +16 -40
- data/lib/google/protobuf/wrappers_pb.rb +24 -28
- data/lib/google/protobuf.rb +32 -50
- data/lib/google/protobuf_ffi.rb +50 -0
- data/lib/google/protobuf_native.rb +20 -0
- data/lib/google/tasks/ffi.rake +102 -0
- metadata +82 -20
- 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: 6470f48584a738af5306675fc774c061991dfae0483670b4125312e0db687eac
|
4
|
+
data.tar.gz: 9333f9654f114712ad3a2e02a6256b1fd6b8b2b5c92a7361013e4edb83a9a242
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01a7ec92451f2dbb1f1749e3c9f08036298e7c6bda73e592a523e47f1229492ff8f1f43474e0edd8f40ae361946e27e210d1ca533a14580fb83689129be5bb8c
|
7
|
+
data.tar.gz: 90693ba6ea735332943ee1d3f0d444488cf0508ee08cf755e007bfd72acb5b36d9306762f1a3689e499058b97a0364d55eb2b20ccd07564c1fba8f56516410fb
|
@@ -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,47 +104,52 @@ unknownval:
|
|
124
104
|
rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
|
125
105
|
}
|
126
106
|
|
127
|
-
|
128
|
-
|
129
|
-
|
107
|
+
upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
108
|
+
TypeInfo type_info, upb_Arena* arena) {
|
109
|
+
upb_MessageValue ret;
|
130
110
|
|
131
111
|
switch (type_info.type) {
|
132
|
-
case
|
112
|
+
case kUpb_CType_Float:
|
133
113
|
if (!is_ruby_num(value)) {
|
134
|
-
rb_raise(cTypeError,
|
135
|
-
|
114
|
+
rb_raise(cTypeError,
|
115
|
+
"Expected number type for float field '%s' (given %s).", name,
|
116
|
+
rb_class2name(CLASS_OF(value)));
|
136
117
|
}
|
137
118
|
ret.float_val = NUM2DBL(value);
|
138
119
|
break;
|
139
|
-
case
|
120
|
+
case kUpb_CType_Double:
|
140
121
|
if (!is_ruby_num(value)) {
|
141
|
-
rb_raise(cTypeError,
|
142
|
-
|
122
|
+
rb_raise(cTypeError,
|
123
|
+
"Expected number type for double field '%s' (given %s).", name,
|
124
|
+
rb_class2name(CLASS_OF(value)));
|
143
125
|
}
|
144
126
|
ret.double_val = NUM2DBL(value);
|
145
127
|
break;
|
146
|
-
case
|
128
|
+
case kUpb_CType_Bool: {
|
147
129
|
if (value == Qtrue) {
|
148
130
|
ret.bool_val = 1;
|
149
131
|
} else if (value == Qfalse) {
|
150
132
|
ret.bool_val = 0;
|
151
133
|
} else {
|
152
|
-
rb_raise(cTypeError,
|
153
|
-
|
134
|
+
rb_raise(cTypeError,
|
135
|
+
"Invalid argument for boolean field '%s' (given %s).", name,
|
136
|
+
rb_class2name(CLASS_OF(value)));
|
154
137
|
}
|
155
138
|
break;
|
156
139
|
}
|
157
|
-
case
|
140
|
+
case kUpb_CType_String: {
|
158
141
|
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
159
|
-
if (
|
142
|
+
if (rb_obj_class(value) == rb_cSymbol) {
|
160
143
|
value = rb_funcall(value, rb_intern("to_s"), 0);
|
161
|
-
} else if (
|
162
|
-
rb_raise(cTypeError,
|
163
|
-
|
144
|
+
} else if (rb_obj_class(value) != rb_cString) {
|
145
|
+
rb_raise(cTypeError,
|
146
|
+
"Invalid argument for string field '%s' (given %s).", name,
|
147
|
+
rb_class2name(CLASS_OF(value)));
|
164
148
|
}
|
165
149
|
|
166
150
|
if (rb_obj_encoding(value) != utf8) {
|
167
|
-
// Note: this will not duplicate underlying string data unless
|
151
|
+
// Note: this will not duplicate underlying string data unless
|
152
|
+
// necessary.
|
168
153
|
value = rb_str_encode(value, utf8, 0, Qnil);
|
169
154
|
|
170
155
|
if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
|
@@ -175,49 +160,51 @@ upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info,
|
|
175
160
|
ret.str_val = Convert_StringData(value, arena);
|
176
161
|
break;
|
177
162
|
}
|
178
|
-
case
|
163
|
+
case kUpb_CType_Bytes: {
|
179
164
|
VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
|
180
|
-
if (
|
181
|
-
rb_raise(cTypeError,
|
182
|
-
|
165
|
+
if (rb_obj_class(value) != rb_cString) {
|
166
|
+
rb_raise(cTypeError,
|
167
|
+
"Invalid argument for bytes field '%s' (given %s).", name,
|
168
|
+
rb_class2name(CLASS_OF(value)));
|
183
169
|
}
|
184
170
|
|
185
171
|
if (rb_obj_encoding(value) != bytes) {
|
186
|
-
// Note: this will not duplicate underlying string data unless
|
187
|
-
//
|
172
|
+
// Note: this will not duplicate underlying string data unless
|
173
|
+
// necessary.
|
174
|
+
// TODO: is this really necessary to get raw bytes?
|
188
175
|
value = rb_str_encode(value, bytes, 0, Qnil);
|
189
176
|
}
|
190
177
|
|
191
178
|
ret.str_val = Convert_StringData(value, arena);
|
192
179
|
break;
|
193
180
|
}
|
194
|
-
case
|
181
|
+
case kUpb_CType_Message:
|
195
182
|
ret.msg_val =
|
196
183
|
Message_GetUpbMessage(value, type_info.def.msgdef, name, arena);
|
197
184
|
break;
|
198
|
-
case
|
185
|
+
case kUpb_CType_Enum:
|
199
186
|
ret.int32_val = Convert_ToEnum(value, name, type_info.def.enumdef);
|
200
187
|
break;
|
201
|
-
case
|
202
|
-
case
|
203
|
-
case
|
204
|
-
case
|
188
|
+
case kUpb_CType_Int32:
|
189
|
+
case kUpb_CType_Int64:
|
190
|
+
case kUpb_CType_UInt32:
|
191
|
+
case kUpb_CType_UInt64:
|
205
192
|
Convert_CheckInt(name, type_info.type, value);
|
206
193
|
switch (type_info.type) {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
194
|
+
case kUpb_CType_Int32:
|
195
|
+
ret.int32_val = NUM2INT(value);
|
196
|
+
break;
|
197
|
+
case kUpb_CType_Int64:
|
198
|
+
ret.int64_val = NUM2LL(value);
|
199
|
+
break;
|
200
|
+
case kUpb_CType_UInt32:
|
201
|
+
ret.uint32_val = NUM2UINT(value);
|
202
|
+
break;
|
203
|
+
case kUpb_CType_UInt64:
|
204
|
+
ret.uint64_val = NUM2ULL(value);
|
205
|
+
break;
|
206
|
+
default:
|
207
|
+
break;
|
221
208
|
}
|
222
209
|
break;
|
223
210
|
default:
|
@@ -227,45 +214,46 @@ upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info,
|
|
227
214
|
return ret;
|
228
215
|
}
|
229
216
|
|
230
|
-
VALUE Convert_UpbToRuby(
|
217
|
+
VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
|
218
|
+
VALUE arena) {
|
231
219
|
switch (type_info.type) {
|
232
|
-
case
|
220
|
+
case kUpb_CType_Float:
|
233
221
|
return DBL2NUM(upb_val.float_val);
|
234
|
-
case
|
222
|
+
case kUpb_CType_Double:
|
235
223
|
return DBL2NUM(upb_val.double_val);
|
236
|
-
case
|
224
|
+
case kUpb_CType_Bool:
|
237
225
|
return upb_val.bool_val ? Qtrue : Qfalse;
|
238
|
-
case
|
226
|
+
case kUpb_CType_Int32:
|
239
227
|
return INT2NUM(upb_val.int32_val);
|
240
|
-
case
|
228
|
+
case kUpb_CType_Int64:
|
241
229
|
return LL2NUM(upb_val.int64_val);
|
242
|
-
case
|
230
|
+
case kUpb_CType_UInt32:
|
243
231
|
return UINT2NUM(upb_val.uint32_val);
|
244
|
-
case
|
232
|
+
case kUpb_CType_UInt64:
|
245
233
|
return ULL2NUM(upb_val.int64_val);
|
246
|
-
case
|
247
|
-
const
|
248
|
-
|
249
|
-
if (
|
250
|
-
return ID2SYM(rb_intern(
|
234
|
+
case kUpb_CType_Enum: {
|
235
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
|
236
|
+
type_info.def.enumdef, upb_val.int32_val);
|
237
|
+
if (ev) {
|
238
|
+
return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
251
239
|
} else {
|
252
240
|
return INT2NUM(upb_val.int32_val);
|
253
241
|
}
|
254
242
|
}
|
255
|
-
case
|
243
|
+
case kUpb_CType_String: {
|
256
244
|
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size);
|
257
245
|
rb_enc_associate(str_rb, rb_utf8_encoding());
|
258
246
|
rb_obj_freeze(str_rb);
|
259
247
|
return str_rb;
|
260
248
|
}
|
261
|
-
case
|
249
|
+
case kUpb_CType_Bytes: {
|
262
250
|
VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size);
|
263
251
|
rb_enc_associate(str_rb, rb_ascii8bit_encoding());
|
264
252
|
rb_obj_freeze(str_rb);
|
265
253
|
return str_rb;
|
266
254
|
}
|
267
|
-
case
|
268
|
-
return Message_GetRubyWrapper((
|
255
|
+
case kUpb_CType_Message:
|
256
|
+
return Message_GetRubyWrapper((upb_Message*)upb_val.msg_val,
|
269
257
|
type_info.def.msgdef, arena);
|
270
258
|
default:
|
271
259
|
rb_raise(rb_eRuntimeError, "Convert_UpbToRuby(): Unexpected type %d",
|
@@ -273,24 +261,24 @@ VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena) {
|
|
273
261
|
}
|
274
262
|
}
|
275
263
|
|
276
|
-
|
277
|
-
|
278
|
-
|
264
|
+
upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
|
265
|
+
upb_Arena* arena) {
|
266
|
+
upb_MessageValue new_msgval;
|
279
267
|
|
280
268
|
switch (type_info.type) {
|
281
269
|
default:
|
282
270
|
memcpy(&new_msgval, &msgval, sizeof(msgval));
|
283
271
|
break;
|
284
|
-
case
|
285
|
-
case
|
272
|
+
case kUpb_CType_String:
|
273
|
+
case kUpb_CType_Bytes: {
|
286
274
|
size_t n = msgval.str_val.size;
|
287
|
-
char
|
275
|
+
char* mem = upb_Arena_Malloc(arena, n);
|
288
276
|
new_msgval.str_val.data = mem;
|
289
277
|
new_msgval.str_val.size = n;
|
290
278
|
memcpy(mem, msgval.str_val.data, n);
|
291
279
|
break;
|
292
280
|
}
|
293
|
-
case
|
281
|
+
case kUpb_CType_Message:
|
294
282
|
new_msgval.msg_val =
|
295
283
|
Message_deep_copy(msgval.msg_val, type_info.def.msgdef, arena);
|
296
284
|
break;
|
@@ -299,50 +287,28 @@ upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info,
|
|
299
287
|
return new_msgval;
|
300
288
|
}
|
301
289
|
|
302
|
-
bool Msgval_IsEqual(
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
case UPB_TYPE_INT64:
|
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");
|
290
|
+
bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
|
291
|
+
TypeInfo type_info) {
|
292
|
+
upb_Status status;
|
293
|
+
upb_Status_Clear(&status);
|
294
|
+
bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
|
295
|
+
type_info.def.msgdef, &status);
|
296
|
+
if (upb_Status_IsOk(&status)) {
|
297
|
+
return return_value;
|
298
|
+
} else {
|
299
|
+
rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
|
324
300
|
}
|
325
301
|
}
|
326
302
|
|
327
|
-
uint64_t Msgval_GetHash(
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
case UPB_TYPE_INT64:
|
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");
|
303
|
+
uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
|
304
|
+
uint64_t seed) {
|
305
|
+
upb_Status status;
|
306
|
+
upb_Status_Clear(&status);
|
307
|
+
uint64_t return_value = shared_Msgval_GetHash(
|
308
|
+
val, type_info.type, type_info.def.msgdef, seed, &status);
|
309
|
+
if (upb_Status_IsOk(&status)) {
|
310
|
+
return return_value;
|
311
|
+
} else {
|
312
|
+
rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
|
347
313
|
}
|
348
314
|
}
|
@@ -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_
|