google-protobuf 3.19.4 → 3.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +121 -155
  4. data/ext/google/protobuf_c/convert.h +15 -37
  5. data/ext/google/protobuf_c/defs.c +223 -239
  6. data/ext/google/protobuf_c/defs.h +22 -47
  7. data/ext/google/protobuf_c/extconf.rb +13 -5
  8. data/ext/google/protobuf_c/glue.c +21 -0
  9. data/ext/google/protobuf_c/map.c +109 -137
  10. data/ext/google/protobuf_c/map.h +10 -36
  11. data/ext/google/protobuf_c/message.c +445 -386
  12. data/ext/google/protobuf_c/message.h +25 -47
  13. data/ext/google/protobuf_c/protobuf.c +101 -228
  14. data/ext/google/protobuf_c/protobuf.h +37 -42
  15. data/ext/google/protobuf_c/repeated_field.c +91 -113
  16. data/ext/google/protobuf_c/repeated_field.h +9 -34
  17. data/ext/google/protobuf_c/ruby-upb.c +12236 -6993
  18. data/ext/google/protobuf_c/ruby-upb.h +12127 -3787
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  25. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  26. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  27. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
  28. data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
  29. data/lib/google/protobuf/any_pb.rb +24 -5
  30. data/lib/google/protobuf/api_pb.rb +26 -23
  31. data/lib/google/protobuf/descriptor_dsl.rb +8 -1
  32. data/lib/google/protobuf/descriptor_pb.rb +43 -225
  33. data/lib/google/protobuf/duration_pb.rb +24 -5
  34. data/lib/google/protobuf/empty_pb.rb +24 -3
  35. data/lib/google/protobuf/ffi/descriptor.rb +154 -0
  36. data/lib/google/protobuf/ffi/descriptor_pool.rb +70 -0
  37. data/lib/google/protobuf/ffi/enum_descriptor.rb +161 -0
  38. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  39. data/lib/google/protobuf/ffi/field_descriptor.rb +309 -0
  40. data/lib/google/protobuf/ffi/file_descriptor.rb +48 -0
  41. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  42. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  43. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  44. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  45. data/lib/google/protobuf/ffi/map.rb +396 -0
  46. data/lib/google/protobuf/ffi/message.rb +641 -0
  47. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  48. data/lib/google/protobuf/ffi/oneof_descriptor.rb +88 -0
  49. data/lib/google/protobuf/ffi/repeated_field.rb +503 -0
  50. data/lib/google/protobuf/field_mask_pb.rb +24 -4
  51. data/lib/google/protobuf/message_exts.rb +10 -28
  52. data/lib/google/protobuf/object_cache.rb +97 -0
  53. data/lib/google/protobuf/plugin_pb.rb +47 -0
  54. data/lib/google/protobuf/repeated_field.rb +18 -28
  55. data/lib/google/protobuf/source_context_pb.rb +24 -4
  56. data/lib/google/protobuf/struct_pb.rb +24 -20
  57. data/lib/google/protobuf/timestamp_pb.rb +24 -5
  58. data/lib/google/protobuf/type_pb.rb +26 -68
  59. data/lib/google/protobuf/well_known_types.rb +16 -40
  60. data/lib/google/protobuf/wrappers_pb.rb +24 -28
  61. data/lib/google/protobuf.rb +32 -50
  62. data/lib/google/protobuf_ffi.rb +50 -0
  63. data/lib/google/protobuf_native.rb +20 -0
  64. data/lib/google/tasks/ffi.rake +102 -0
  65. metadata +82 -14
  66. data/tests/basic.rb +0 -648
  67. data/tests/generated_code_test.rb +0 -23
  68. data/tests/stress.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b2d8d23ee73555093c96e12a9915ae2d827fa93916ec1c2f13b1410b213ae3b
4
- data.tar.gz: 8b915c10d1817642f5d3427e88285b03df6251de4b35b40683fc57625c7ab600
3
+ metadata.gz: f07b3e363c6a69664f352f94158f1c150d11fc6947fd8aafe1d06decbed0a545
4
+ data.tar.gz: dd3bb39d53484b82469238a0fd009d2049d4c1ce5732b1c141e73a1f5b23c8bb
5
5
  SHA512:
6
- metadata.gz: 55d7d59cf630737bfd96c705af5877ec7bdd08c4bca5da7f3d701cc7e0fac4f258cba73b14aee68eef5c1f9406f7228c27a2f0a75365720ee1744caa9e8a5e8e
7
- data.tar.gz: a26bf9e6f8faeffe2b74901f7bd85b63b9afecab6426fde9fa2aa77ac1ca502faa3635bdd01b5289531fc3827065575ab5cc46356ef2ec57476a0621e416be63
6
+ metadata.gz: '028e14308853bce11c830bd55735df413954ac79a986e46375964907ca984f5f93bf4cf0ed8632c175b5fe9946724d270a999733778e735f568fa215018275f9'
7
+ data.tar.gz: 3f6832e092254e27ca64fdf11367cb3a4e4a0e8f34d6e824044a8e701bcea5e88e4b8aaeba81ea8b83ab5e5a834969c074ba034e056cdc26484822064c0403f6
@@ -0,0 +1,3 @@
1
+ import '../../../lib/google/tasks/ffi.rake'
2
+
3
+ task default: ['ffi-protobuf:default']
@@ -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
- // 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.
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 upb_msgval.
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 upb_strview Convert_StringData(VALUE str, upb_arena *arena) {
46
- upb_strview ret;
23
+ static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
24
+ upb_StringView ret;
47
25
  if (arena) {
48
- char *ptr = upb_arena_malloc(arena, RSTRING_LEN(str));
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, upb_fieldtype_t type,
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 == UPB_TYPE_UINT32 || type == UPB_TYPE_UINT64) {
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 upb_enumdef* e) {
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, UPB_TYPE_INT32, value);
79
+ Convert_CheckInt(name, kUpb_CType_Int32, value);
104
80
  val = NUM2INT(value);
105
81
  break;
106
- case T_STRING:
107
- if (!upb_enumdef_ntoi(e, RSTRING_PTR(value), RSTRING_LEN(value), &val)) {
108
- goto unknownval;
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
- case T_SYMBOL:
112
- if (!upb_enumdef_ntoiz(e, rb_id2name(SYM2ID(value)), &val)) {
113
- goto unknownval;
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
- upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info,
128
- upb_arena* arena) {
129
- upb_msgval ret;
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 UPB_TYPE_FLOAT:
112
+ case kUpb_CType_Float:
133
113
  if (!is_ruby_num(value)) {
134
- rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).",
135
- name, rb_class2name(CLASS_OF(value)));
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 UPB_TYPE_DOUBLE:
120
+ case kUpb_CType_Double:
140
121
  if (!is_ruby_num(value)) {
141
- rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).",
142
- name, rb_class2name(CLASS_OF(value)));
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 UPB_TYPE_BOOL: {
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, "Invalid argument for boolean field '%s' (given %s).",
153
- name, rb_class2name(CLASS_OF(value)));
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 UPB_TYPE_STRING: {
140
+ case kUpb_CType_String: {
158
141
  VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
159
- if (CLASS_OF(value) == rb_cSymbol) {
142
+ if (rb_obj_class(value) == rb_cSymbol) {
160
143
  value = rb_funcall(value, rb_intern("to_s"), 0);
161
- } else if (CLASS_OF(value) != rb_cString) {
162
- rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).",
163
- name, rb_class2name(CLASS_OF(value)));
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 necessary.
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 UPB_TYPE_BYTES: {
163
+ case kUpb_CType_Bytes: {
179
164
  VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
180
- if (CLASS_OF(value) != rb_cString) {
181
- rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).",
182
- name, rb_class2name(CLASS_OF(value)));
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 necessary.
187
- // TODO(haberman): is this really necessary to get raw bytes?
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 UPB_TYPE_MESSAGE:
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 UPB_TYPE_ENUM:
185
+ case kUpb_CType_Enum:
199
186
  ret.int32_val = Convert_ToEnum(value, name, type_info.def.enumdef);
200
187
  break;
201
- case UPB_TYPE_INT32:
202
- case UPB_TYPE_INT64:
203
- case UPB_TYPE_UINT32:
204
- case UPB_TYPE_UINT64:
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
- case UPB_TYPE_INT32:
208
- ret.int32_val = NUM2INT(value);
209
- break;
210
- case UPB_TYPE_INT64:
211
- ret.int64_val = NUM2LL(value);
212
- break;
213
- case UPB_TYPE_UINT32:
214
- ret.uint32_val = NUM2UINT(value);
215
- break;
216
- case UPB_TYPE_UINT64:
217
- ret.uint64_val = NUM2ULL(value);
218
- break;
219
- default:
220
- break;
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(upb_msgval upb_val, TypeInfo type_info, VALUE arena) {
217
+ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
218
+ VALUE arena) {
231
219
  switch (type_info.type) {
232
- case UPB_TYPE_FLOAT:
220
+ case kUpb_CType_Float:
233
221
  return DBL2NUM(upb_val.float_val);
234
- case UPB_TYPE_DOUBLE:
222
+ case kUpb_CType_Double:
235
223
  return DBL2NUM(upb_val.double_val);
236
- case UPB_TYPE_BOOL:
224
+ case kUpb_CType_Bool:
237
225
  return upb_val.bool_val ? Qtrue : Qfalse;
238
- case UPB_TYPE_INT32:
226
+ case kUpb_CType_Int32:
239
227
  return INT2NUM(upb_val.int32_val);
240
- case UPB_TYPE_INT64:
228
+ case kUpb_CType_Int64:
241
229
  return LL2NUM(upb_val.int64_val);
242
- case UPB_TYPE_UINT32:
230
+ case kUpb_CType_UInt32:
243
231
  return UINT2NUM(upb_val.uint32_val);
244
- case UPB_TYPE_UINT64:
232
+ case kUpb_CType_UInt64:
245
233
  return ULL2NUM(upb_val.int64_val);
246
- case UPB_TYPE_ENUM: {
247
- const char* name =
248
- upb_enumdef_iton(type_info.def.enumdef, upb_val.int32_val);
249
- if (name) {
250
- return ID2SYM(rb_intern(name));
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 UPB_TYPE_STRING: {
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 UPB_TYPE_BYTES: {
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 UPB_TYPE_MESSAGE:
268
- return Message_GetRubyWrapper((upb_msg*)upb_val.msg_val,
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
- upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info,
277
- upb_arena* arena) {
278
- upb_msgval new_msgval;
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 UPB_TYPE_STRING:
285
- case UPB_TYPE_BYTES: {
272
+ case kUpb_CType_String:
273
+ case kUpb_CType_Bytes: {
286
274
  size_t n = msgval.str_val.size;
287
- char *mem = upb_arena_malloc(arena, n);
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 UPB_TYPE_MESSAGE:
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(upb_msgval val1, upb_msgval val2, TypeInfo type_info) {
303
- switch (type_info.type) {
304
- case UPB_TYPE_BOOL:
305
- return memcmp(&val1, &val2, 1) == 0;
306
- case UPB_TYPE_FLOAT:
307
- case UPB_TYPE_INT32:
308
- case UPB_TYPE_UINT32:
309
- case UPB_TYPE_ENUM:
310
- return memcmp(&val1, &val2, 4) == 0;
311
- case UPB_TYPE_DOUBLE:
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(upb_msgval val, TypeInfo type_info, uint64_t seed) {
328
- switch (type_info.type) {
329
- case UPB_TYPE_BOOL:
330
- return Wyhash(&val, 1, seed, kWyhashSalt);
331
- case UPB_TYPE_FLOAT:
332
- case UPB_TYPE_INT32:
333
- case UPB_TYPE_UINT32:
334
- case UPB_TYPE_ENUM:
335
- return Wyhash(&val, 4, seed, kWyhashSalt);
336
- case UPB_TYPE_DOUBLE:
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
- // 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.
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 upb_msgval according to |type_info|.
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
- upb_msgval Convert_RubyToUpb(VALUE ruby_val, const char *name,
51
- TypeInfo type_info, upb_arena *arena);
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(upb_msgval upb_val, TypeInfo type_info, VALUE arena);
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
- upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info,
63
- upb_arena *arena);
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(upb_msgval val1, upb_msgval val2, TypeInfo type_info);
43
+ bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
44
+ TypeInfo type_info);
68
45
 
69
- // Returns a hash value for the given upb_msgval.
70
- uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed);
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_