google-protobuf 3.0.0.alpha.5.0.5-x86-linux → 3.0.0-x86-linux
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/encode_decode.c +42 -11
- data/ext/google/protobuf_c/map.c +11 -9
- data/ext/google/protobuf_c/protobuf.h +2 -1
- data/ext/google/protobuf_c/repeated_field.c +5 -0
- data/ext/google/protobuf_c/storage.c +51 -21
- data/ext/google/protobuf_c/upb.c +1 -1
- data/ext/google/protobuf_c/upb.h +1 -1
- data/lib/google/2.0/protobuf_c.so +0 -0
- data/lib/google/2.1/protobuf_c.so +0 -0
- data/lib/google/2.2/protobuf_c.so +0 -0
- data/lib/google/2.3/protobuf_c.so +0 -0
- data/lib/google/protobuf/{any.rb → any_pb.rb} +0 -0
- data/lib/google/protobuf/{api.rb → api_pb.rb} +2 -2
- data/lib/google/protobuf/{duration.rb → duration_pb.rb} +0 -0
- data/lib/google/protobuf/{empty.rb → empty_pb.rb} +0 -0
- data/lib/google/protobuf/{field_mask.rb → field_mask_pb.rb} +0 -0
- data/lib/google/protobuf/repeated_field.rb +3 -3
- data/lib/google/protobuf/{source_context.rb → source_context_pb.rb} +0 -0
- data/lib/google/protobuf/{struct.rb → struct_pb.rb} +0 -0
- data/lib/google/protobuf/{timestamp.rb → timestamp_pb.rb} +0 -0
- data/lib/google/protobuf/{type.rb → type_pb.rb} +2 -2
- data/lib/google/protobuf/{wrappers.rb → wrappers_pb.rb} +0 -0
- data/tests/basic.rb +45 -37
- data/tests/generated_code_test.rb +3 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe7168a154abbcb7d78704c952ab1896bf12b20
|
4
|
+
data.tar.gz: 8d8f2fdd5b71a20818e51f4156da8227e57026ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2854c00f4745af1081fdb1932c26e16f76121a0443e5f2913c695b0d761c4ae35fb04ab7ff4a4a9a451b0d5660b4a0119a13f36a82f119c96716d1a85f26a198
|
7
|
+
data.tar.gz: 9eae2f03ebe7b74ea2ec885a808c0c1f42dcfc9f565a864249f47317f6c29c7f742baedc59ba78a17200d5928d81201aadb26594ecaee64af1dd11e3be03b093
|
@@ -54,7 +54,7 @@ VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len) {
|
|
54
54
|
static const void* newhandlerdata(upb_handlers* h, uint32_t ofs) {
|
55
55
|
size_t* hd_ofs = ALLOC(size_t);
|
56
56
|
*hd_ofs = ofs;
|
57
|
-
upb_handlers_addcleanup(h, hd_ofs,
|
57
|
+
upb_handlers_addcleanup(h, hd_ofs, xfree);
|
58
58
|
return hd_ofs;
|
59
59
|
}
|
60
60
|
|
@@ -69,7 +69,7 @@ static const void *newsubmsghandlerdata(upb_handlers* h, uint32_t ofs,
|
|
69
69
|
submsg_handlerdata_t *hd = ALLOC(submsg_handlerdata_t);
|
70
70
|
hd->ofs = ofs;
|
71
71
|
hd->md = upb_fielddef_msgsubdef(f);
|
72
|
-
upb_handlers_addcleanup(h, hd,
|
72
|
+
upb_handlers_addcleanup(h, hd, xfree);
|
73
73
|
return hd;
|
74
74
|
}
|
75
75
|
|
@@ -99,7 +99,7 @@ static const void *newoneofhandlerdata(upb_handlers *h,
|
|
99
99
|
} else {
|
100
100
|
hd->md = NULL;
|
101
101
|
}
|
102
|
-
upb_handlers_addcleanup(h, hd,
|
102
|
+
upb_handlers_addcleanup(h, hd, xfree);
|
103
103
|
return hd;
|
104
104
|
}
|
105
105
|
|
@@ -135,7 +135,7 @@ static void* appendstr_handler(void *closure,
|
|
135
135
|
VALUE ary = (VALUE)closure;
|
136
136
|
VALUE str = rb_str_new2("");
|
137
137
|
rb_enc_associate(str, kRubyStringUtf8Encoding);
|
138
|
-
|
138
|
+
RepeatedField_push_native(ary, &str);
|
139
139
|
return (void*)str;
|
140
140
|
}
|
141
141
|
|
@@ -146,7 +146,7 @@ static void* appendbytes_handler(void *closure,
|
|
146
146
|
VALUE ary = (VALUE)closure;
|
147
147
|
VALUE str = rb_str_new2("");
|
148
148
|
rb_enc_associate(str, kRubyString8bitEncoding);
|
149
|
-
|
149
|
+
RepeatedField_push_native(ary, &str);
|
150
150
|
return (void*)str;
|
151
151
|
}
|
152
152
|
|
@@ -182,6 +182,23 @@ static size_t stringdata_handler(void* closure, const void* hd,
|
|
182
182
|
return len;
|
183
183
|
}
|
184
184
|
|
185
|
+
static bool stringdata_end_handler(void* closure, const void* hd) {
|
186
|
+
MessageHeader* msg = closure;
|
187
|
+
const size_t *ofs = hd;
|
188
|
+
VALUE rb_str = DEREF(msg, *ofs, VALUE);
|
189
|
+
rb_obj_freeze(rb_str);
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
|
193
|
+
static bool appendstring_end_handler(void* closure, const void* hd) {
|
194
|
+
VALUE ary = (VALUE)closure;
|
195
|
+
int size = RepeatedField_size(ary);
|
196
|
+
VALUE* last = RepeatedField_index_native(ary, size - 1);
|
197
|
+
VALUE rb_str = *last;
|
198
|
+
rb_obj_freeze(rb_str);
|
199
|
+
return true;
|
200
|
+
}
|
201
|
+
|
185
202
|
// Appends a submessage to a repeated field (a regular Ruby array for now).
|
186
203
|
static void *appendsubmsg_handler(void *closure, const void *hd) {
|
187
204
|
VALUE ary = (VALUE)closure;
|
@@ -281,7 +298,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) {
|
|
281
298
|
&frame->value_storage);
|
282
299
|
|
283
300
|
Map_index_set(frame->map, key, value);
|
284
|
-
|
301
|
+
xfree(frame);
|
285
302
|
|
286
303
|
return true;
|
287
304
|
}
|
@@ -360,6 +377,13 @@ static void *oneofbytes_handler(void *closure,
|
|
360
377
|
return (void*)str;
|
361
378
|
}
|
362
379
|
|
380
|
+
static bool oneofstring_end_handler(void* closure, const void* hd) {
|
381
|
+
MessageHeader* msg = closure;
|
382
|
+
const oneof_handlerdata_t *oneofdata = hd;
|
383
|
+
rb_obj_freeze(DEREF(msg, oneofdata->ofs, VALUE));
|
384
|
+
return true;
|
385
|
+
}
|
386
|
+
|
363
387
|
// Handler for a submessage field in a oneof.
|
364
388
|
static void *oneofsubmsg_handler(void *closure,
|
365
389
|
const void *hd) {
|
@@ -426,6 +450,7 @@ static void add_handlers_for_repeated_field(upb_handlers *h,
|
|
426
450
|
appendbytes_handler : appendstr_handler,
|
427
451
|
NULL);
|
428
452
|
upb_handlers_setstring(h, f, stringdata_handler, NULL);
|
453
|
+
upb_handlers_setendstr(h, f, appendstring_end_handler, NULL);
|
429
454
|
break;
|
430
455
|
}
|
431
456
|
case UPB_TYPE_MESSAGE: {
|
@@ -462,6 +487,7 @@ static void add_handlers_for_singular_field(upb_handlers *h,
|
|
462
487
|
is_bytes ? bytes_handler : str_handler,
|
463
488
|
&attr);
|
464
489
|
upb_handlers_setstring(h, f, stringdata_handler, &attr);
|
490
|
+
upb_handlers_setendstr(h, f, stringdata_end_handler, &attr);
|
465
491
|
upb_handlerattr_uninit(&attr);
|
466
492
|
break;
|
467
493
|
}
|
@@ -484,7 +510,7 @@ static void add_handlers_for_mapfield(upb_handlers* h,
|
|
484
510
|
map_handlerdata_t* hd = new_map_handlerdata(offset, map_msgdef, desc);
|
485
511
|
upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
|
486
512
|
|
487
|
-
upb_handlers_addcleanup(h, hd,
|
513
|
+
upb_handlers_addcleanup(h, hd, xfree);
|
488
514
|
upb_handlerattr_sethandlerdata(&attr, hd);
|
489
515
|
upb_handlers_setstartsubmsg(h, fielddef, startmapentry_handler, &attr);
|
490
516
|
upb_handlerattr_uninit(&attr);
|
@@ -499,7 +525,7 @@ static void add_handlers_for_mapentry(const upb_msgdef* msgdef,
|
|
499
525
|
map_handlerdata_t* hd = new_map_handlerdata(0, msgdef, desc);
|
500
526
|
upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
|
501
527
|
|
502
|
-
upb_handlers_addcleanup(h, hd,
|
528
|
+
upb_handlers_addcleanup(h, hd, xfree);
|
503
529
|
upb_handlerattr_sethandlerdata(&attr, hd);
|
504
530
|
upb_handlers_setendmsg(h, endmap_handler, &attr);
|
505
531
|
|
@@ -546,6 +572,7 @@ static void add_handlers_for_oneof_field(upb_handlers *h,
|
|
546
572
|
oneofbytes_handler : oneofstr_handler,
|
547
573
|
&attr);
|
548
574
|
upb_handlers_setstring(h, f, stringdata_handler, NULL);
|
575
|
+
upb_handlers_setendstr(h, f, oneofstring_end_handler, &attr);
|
549
576
|
break;
|
550
577
|
}
|
551
578
|
case UPB_TYPE_MESSAGE: {
|
@@ -863,9 +890,13 @@ static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink) {
|
|
863
890
|
|
864
891
|
assert(BUILTIN_TYPE(str) == RUBY_T_STRING);
|
865
892
|
|
866
|
-
//
|
867
|
-
//
|
868
|
-
|
893
|
+
// We should be guaranteed that the string has the correct encoding because
|
894
|
+
// we ensured this at assignment time and then froze the string.
|
895
|
+
if (upb_fielddef_type(f) == UPB_TYPE_STRING) {
|
896
|
+
assert(rb_enc_from_index(ENCODING_GET(value)) == kRubyStringUtf8Encoding);
|
897
|
+
} else {
|
898
|
+
assert(rb_enc_from_index(ENCODING_GET(value)) == kRubyString8bitEncoding);
|
899
|
+
}
|
869
900
|
|
870
901
|
upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), RSTRING_LEN(str),
|
871
902
|
&subsink);
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -63,16 +63,16 @@
|
|
63
63
|
// construct a key byte sequence if needed. |out_key| and |out_length| provide
|
64
64
|
// the resulting key data/length.
|
65
65
|
#define TABLE_KEY_BUF_LENGTH 8 // sizeof(uint64_t)
|
66
|
-
static
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
static VALUE table_key(Map* self, VALUE key,
|
67
|
+
char* buf,
|
68
|
+
const char** out_key,
|
69
|
+
size_t* out_length) {
|
70
70
|
switch (self->key_type) {
|
71
71
|
case UPB_TYPE_BYTES:
|
72
72
|
case UPB_TYPE_STRING:
|
73
73
|
// Strings: use string content directly.
|
74
74
|
Check_Type(key, T_STRING);
|
75
|
-
|
75
|
+
key = native_slot_encode_and_freeze_string(self->key_type, key);
|
76
76
|
*out_key = RSTRING_PTR(key);
|
77
77
|
*out_length = RSTRING_LEN(key);
|
78
78
|
break;
|
@@ -93,6 +93,8 @@ static void table_key(Map* self, VALUE key,
|
|
93
93
|
assert(false);
|
94
94
|
break;
|
95
95
|
}
|
96
|
+
|
97
|
+
return key;
|
96
98
|
}
|
97
99
|
|
98
100
|
static VALUE table_key_to_ruby(Map* self, const char* buf, size_t length) {
|
@@ -357,7 +359,7 @@ VALUE Map_index(VALUE _self, VALUE key) {
|
|
357
359
|
const char* keyval = NULL;
|
358
360
|
size_t length = 0;
|
359
361
|
upb_value v;
|
360
|
-
table_key(self, key, keybuf, &keyval, &length);
|
362
|
+
key = table_key(self, key, keybuf, &keyval, &length);
|
361
363
|
|
362
364
|
if (upb_strtable_lookup2(&self->table, keyval, length, &v)) {
|
363
365
|
void* mem = value_memory(&v);
|
@@ -383,7 +385,7 @@ VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
|
|
383
385
|
size_t length = 0;
|
384
386
|
upb_value v;
|
385
387
|
void* mem;
|
386
|
-
table_key(self, key, keybuf, &keyval, &length);
|
388
|
+
key = table_key(self, key, keybuf, &keyval, &length);
|
387
389
|
|
388
390
|
mem = value_memory(&v);
|
389
391
|
native_slot_set(self->value_type, self->value_type_class, mem, value);
|
@@ -411,7 +413,7 @@ VALUE Map_has_key(VALUE _self, VALUE key) {
|
|
411
413
|
char keybuf[TABLE_KEY_BUF_LENGTH];
|
412
414
|
const char* keyval = NULL;
|
413
415
|
size_t length = 0;
|
414
|
-
table_key(self, key, keybuf, &keyval, &length);
|
416
|
+
key = table_key(self, key, keybuf, &keyval, &length);
|
415
417
|
|
416
418
|
if (upb_strtable_lookup2(&self->table, keyval, length, NULL)) {
|
417
419
|
return Qtrue;
|
@@ -434,7 +436,7 @@ VALUE Map_delete(VALUE _self, VALUE key) {
|
|
434
436
|
const char* keyval = NULL;
|
435
437
|
size_t length = 0;
|
436
438
|
upb_value v;
|
437
|
-
table_key(self, key, keybuf, &keyval, &length);
|
439
|
+
key = table_key(self, key, keybuf, &keyval, &length);
|
438
440
|
|
439
441
|
if (upb_strtable_remove2(&self->table, keyval, length, &v)) {
|
440
442
|
void* mem = value_memory(&v);
|
@@ -313,7 +313,7 @@ void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
|
|
313
313
|
void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from);
|
314
314
|
bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2);
|
315
315
|
|
316
|
-
|
316
|
+
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value);
|
317
317
|
void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE value);
|
318
318
|
|
319
319
|
extern rb_encoding* kRubyStringUtf8Encoding;
|
@@ -366,6 +366,7 @@ RepeatedField* ruby_to_RepeatedField(VALUE value);
|
|
366
366
|
VALUE RepeatedField_each(VALUE _self);
|
367
367
|
VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self);
|
368
368
|
void* RepeatedField_index_native(VALUE _self, int index);
|
369
|
+
int RepeatedField_size(VALUE _self);
|
369
370
|
VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
|
370
371
|
void RepeatedField_reserve(RepeatedField* self, int new_size);
|
371
372
|
VALUE RepeatedField_push(VALUE _self, VALUE val);
|
@@ -244,6 +244,11 @@ void* RepeatedField_index_native(VALUE _self, int index) {
|
|
244
244
|
return RepeatedField_memoryat(self, index, element_size);
|
245
245
|
}
|
246
246
|
|
247
|
+
int RepeatedField_size(VALUE _self) {
|
248
|
+
RepeatedField* self = ruby_to_RepeatedField(_self);
|
249
|
+
return self->size;
|
250
|
+
}
|
251
|
+
|
247
252
|
/*
|
248
253
|
* Private ruby method, used by RepeatedField.pop
|
249
254
|
*/
|
@@ -57,6 +57,37 @@ size_t native_slot_size(upb_fieldtype_t type) {
|
|
57
57
|
}
|
58
58
|
}
|
59
59
|
|
60
|
+
static VALUE value_from_default(const upb_fielddef *field) {
|
61
|
+
switch (upb_fielddef_type(field)) {
|
62
|
+
case UPB_TYPE_FLOAT: return DBL2NUM(upb_fielddef_defaultfloat(field));
|
63
|
+
case UPB_TYPE_DOUBLE: return DBL2NUM(upb_fielddef_defaultdouble(field));
|
64
|
+
case UPB_TYPE_BOOL:
|
65
|
+
return upb_fielddef_defaultbool(field) ? Qtrue : Qfalse;
|
66
|
+
case UPB_TYPE_MESSAGE: return Qnil;
|
67
|
+
case UPB_TYPE_ENUM: {
|
68
|
+
const upb_enumdef *enumdef = upb_fielddef_enumsubdef(field);
|
69
|
+
int32_t num = upb_fielddef_defaultint32(field);
|
70
|
+
const char *label = upb_enumdef_iton(enumdef, num);
|
71
|
+
if (label) {
|
72
|
+
return ID2SYM(rb_intern(label));
|
73
|
+
} else {
|
74
|
+
return INT2NUM(num);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
case UPB_TYPE_INT32: return INT2NUM(upb_fielddef_defaultint32(field));
|
78
|
+
case UPB_TYPE_INT64: return LL2NUM(upb_fielddef_defaultint64(field));;
|
79
|
+
case UPB_TYPE_UINT32: return UINT2NUM(upb_fielddef_defaultuint32(field));
|
80
|
+
case UPB_TYPE_UINT64: return ULL2NUM(upb_fielddef_defaultuint64(field));
|
81
|
+
case UPB_TYPE_STRING:
|
82
|
+
case UPB_TYPE_BYTES: {
|
83
|
+
size_t size;
|
84
|
+
const char *str = upb_fielddef_defaultstr(field, &size);
|
85
|
+
return rb_str_new(str, size);
|
86
|
+
}
|
87
|
+
default: return Qnil;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
60
91
|
static bool is_ruby_num(VALUE value) {
|
61
92
|
return (TYPE(value) == T_FLOAT ||
|
62
93
|
TYPE(value) == T_FIXNUM ||
|
@@ -86,25 +117,24 @@ void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE val) {
|
|
86
117
|
}
|
87
118
|
}
|
88
119
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
// Check that encoding is UTF-8 or ASCII (for string fields) or ASCII-8BIT
|
101
|
-
// (for bytes fields).
|
102
|
-
if (bad_encoding) {
|
103
|
-
rb_raise(rb_eTypeError, "Encoding for '%s' fields must be %s (was %s)",
|
104
|
-
(type == UPB_TYPE_STRING) ? "string" : "bytes",
|
105
|
-
(type == UPB_TYPE_STRING) ? "UTF-8 or ASCII" : "ASCII-8BIT",
|
106
|
-
rb_enc_name(string_encoding));
|
120
|
+
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value) {
|
121
|
+
rb_encoding* desired_encoding = (type == UPB_TYPE_STRING) ?
|
122
|
+
kRubyStringUtf8Encoding : kRubyString8bitEncoding;
|
123
|
+
VALUE desired_encoding_value = rb_enc_from_encoding(desired_encoding);
|
124
|
+
|
125
|
+
// Note: this will not duplicate underlying string data unless necessary.
|
126
|
+
value = rb_str_encode(value, desired_encoding_value, 0, Qnil);
|
127
|
+
|
128
|
+
if (type == UPB_TYPE_STRING &&
|
129
|
+
rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
|
130
|
+
rb_raise(rb_eEncodingError, "String is invalid UTF-8");
|
107
131
|
}
|
132
|
+
|
133
|
+
// Ensure the data remains valid. Since we called #encode a moment ago,
|
134
|
+
// this does not freeze the string the user assigned.
|
135
|
+
rb_obj_freeze(value);
|
136
|
+
|
137
|
+
return value;
|
108
138
|
}
|
109
139
|
|
110
140
|
void native_slot_set(upb_fieldtype_t type, VALUE type_class,
|
@@ -150,8 +180,8 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class,
|
|
150
180
|
if (CLASS_OF(value) != rb_cString) {
|
151
181
|
rb_raise(rb_eTypeError, "Invalid argument for string field.");
|
152
182
|
}
|
153
|
-
|
154
|
-
DEREF(memory, VALUE) = value;
|
183
|
+
|
184
|
+
DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value);
|
155
185
|
break;
|
156
186
|
}
|
157
187
|
case UPB_TYPE_MESSAGE: {
|
@@ -537,7 +567,7 @@ VALUE layout_get(MessageLayout* layout,
|
|
537
567
|
|
538
568
|
if (upb_fielddef_containingoneof(field)) {
|
539
569
|
if (*oneof_case != upb_fielddef_number(field)) {
|
540
|
-
return
|
570
|
+
return value_from_default(field);
|
541
571
|
}
|
542
572
|
return native_slot_get(upb_fielddef_type(field),
|
543
573
|
field_type_class(field),
|
data/ext/google/protobuf_c/upb.c
CHANGED
@@ -11076,8 +11076,8 @@ static bool end_stringval(upb_json_parser *p) {
|
|
11076
11076
|
|
11077
11077
|
case UPB_TYPE_STRING: {
|
11078
11078
|
upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
|
11079
|
-
upb_sink_endstr(&p->top->sink, sel);
|
11080
11079
|
p->top--;
|
11080
|
+
upb_sink_endstr(&p->top->sink, sel);
|
11081
11081
|
break;
|
11082
11082
|
}
|
11083
11083
|
|
data/ext/google/protobuf_c/upb.h
CHANGED
@@ -55,7 +55,7 @@
|
|
55
55
|
** store pointers or integers of at least 32 bits (upb isn't really useful on
|
56
56
|
** systems where sizeof(void*) < 4).
|
57
57
|
**
|
58
|
-
** The table must be
|
58
|
+
** The table must be homogeneous (all values of the same type). In debug
|
59
59
|
** mode, we check this on insert and lookup.
|
60
60
|
*/
|
61
61
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -3,8 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
|
-
require 'google/protobuf/
|
7
|
-
require 'google/protobuf/
|
6
|
+
require 'google/protobuf/source_context_pb'
|
7
|
+
require 'google/protobuf/type_pb'
|
8
8
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
9
|
add_message "google.protobuf.Api" do
|
10
10
|
optional :name, :string, 1
|
File without changes
|
File without changes
|
File without changes
|
@@ -69,8 +69,8 @@ module Google
|
|
69
69
|
# relationship explicit instead of implicit
|
70
70
|
def_delegators :to_ary,
|
71
71
|
:&, :*, :-, :'<=>',
|
72
|
-
:assoc, :bsearch, :combination, :compact, :count,
|
73
|
-
:drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
|
72
|
+
:assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
|
73
|
+
:cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
|
74
74
|
:include?, :index, :inspect, :join,
|
75
75
|
:pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
|
76
76
|
:rassoc, :repeated_combination, :repeated_permutation, :reverse,
|
@@ -173,7 +173,7 @@ module Google
|
|
173
173
|
external_enumerator.each_with_index do |val, i|
|
174
174
|
result = yield(val)
|
175
175
|
results << result
|
176
|
-
#nil means no change
|
176
|
+
#nil means no change occurred from yield; usually occurs when #to_a is called
|
177
177
|
if result
|
178
178
|
repeated_field[i] = result if result != val
|
179
179
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -3,8 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
|
-
require 'google/protobuf/
|
7
|
-
require 'google/protobuf/
|
6
|
+
require 'google/protobuf/any_pb'
|
7
|
+
require 'google/protobuf/source_context_pb'
|
8
8
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
9
|
add_message "google.protobuf.Type" do
|
10
10
|
optional :name, :string, 1
|
File without changes
|
data/tests/basic.rb
CHANGED
@@ -255,14 +255,17 @@ module BasicTest
|
|
255
255
|
m = TestMessage.new
|
256
256
|
|
257
257
|
# Assigning a normal (ASCII or UTF8) string to a bytes field, or
|
258
|
-
# ASCII-8BIT to a string field
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
258
|
+
# ASCII-8BIT to a string field will convert to the proper encoding.
|
259
|
+
m.optional_bytes = "Test string ASCII".encode!('ASCII')
|
260
|
+
assert m.optional_bytes.frozen?
|
261
|
+
assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding
|
262
|
+
assert_equal "Test string ASCII", m.optional_bytes
|
263
|
+
|
264
|
+
assert_raise Encoding::UndefinedConversionError do
|
263
265
|
m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8')
|
264
266
|
end
|
265
|
-
|
267
|
+
|
268
|
+
assert_raise Encoding::UndefinedConversionError do
|
266
269
|
m.optional_string = ["FFFF"].pack('H*')
|
267
270
|
end
|
268
271
|
|
@@ -270,11 +273,10 @@ module BasicTest
|
|
270
273
|
m.optional_bytes = ["FFFF"].pack('H*')
|
271
274
|
m.optional_string = "\u0100"
|
272
275
|
|
273
|
-
# strings are
|
276
|
+
# strings are immutable so we can't do this, but serialize should catch it.
|
274
277
|
m.optional_string = "asdf".encode!('UTF-8')
|
275
|
-
|
276
|
-
|
277
|
-
data = TestMessage.encode(m)
|
278
|
+
assert_raise RuntimeError do
|
279
|
+
m.optional_string.encode!('ASCII-8BIT')
|
278
280
|
end
|
279
281
|
end
|
280
282
|
|
@@ -558,7 +560,7 @@ module BasicTest
|
|
558
560
|
assert_raise TypeError do
|
559
561
|
m[1] = 1
|
560
562
|
end
|
561
|
-
assert_raise
|
563
|
+
assert_raise Encoding::UndefinedConversionError do
|
562
564
|
bytestring = ["FFFF"].pack("H*")
|
563
565
|
m[bytestring] = 1
|
564
566
|
end
|
@@ -566,9 +568,8 @@ module BasicTest
|
|
566
568
|
m = Google::Protobuf::Map.new(:bytes, :int32)
|
567
569
|
bytestring = ["FFFF"].pack("H*")
|
568
570
|
m[bytestring] = 1
|
569
|
-
|
570
|
-
|
571
|
-
end
|
571
|
+
# Allowed -- we will automatically convert to ASCII-8BIT.
|
572
|
+
m["asdf"] = 1
|
572
573
|
assert_raise TypeError do
|
573
574
|
m[1] = 1
|
574
575
|
end
|
@@ -703,36 +704,36 @@ module BasicTest
|
|
703
704
|
|
704
705
|
def test_oneof
|
705
706
|
d = OneofMessage.new
|
706
|
-
assert d.a ==
|
707
|
-
assert d.b ==
|
707
|
+
assert d.a == ""
|
708
|
+
assert d.b == 0
|
708
709
|
assert d.c == nil
|
709
|
-
assert d.d ==
|
710
|
+
assert d.d == :Default
|
710
711
|
assert d.my_oneof == nil
|
711
712
|
|
712
713
|
d.a = "hi"
|
713
714
|
assert d.a == "hi"
|
714
|
-
assert d.b ==
|
715
|
+
assert d.b == 0
|
715
716
|
assert d.c == nil
|
716
|
-
assert d.d ==
|
717
|
+
assert d.d == :Default
|
717
718
|
assert d.my_oneof == :a
|
718
719
|
|
719
720
|
d.b = 42
|
720
|
-
assert d.a ==
|
721
|
+
assert d.a == ""
|
721
722
|
assert d.b == 42
|
722
723
|
assert d.c == nil
|
723
|
-
assert d.d ==
|
724
|
+
assert d.d == :Default
|
724
725
|
assert d.my_oneof == :b
|
725
726
|
|
726
727
|
d.c = TestMessage2.new(:foo => 100)
|
727
|
-
assert d.a ==
|
728
|
-
assert d.b ==
|
728
|
+
assert d.a == ""
|
729
|
+
assert d.b == 0
|
729
730
|
assert d.c.foo == 100
|
730
|
-
assert d.d ==
|
731
|
+
assert d.d == :Default
|
731
732
|
assert d.my_oneof == :c
|
732
733
|
|
733
734
|
d.d = :C
|
734
|
-
assert d.a ==
|
735
|
-
assert d.b ==
|
735
|
+
assert d.a == ""
|
736
|
+
assert d.b == 0
|
736
737
|
assert d.c == nil
|
737
738
|
assert d.d == :C
|
738
739
|
assert d.my_oneof == :d
|
@@ -748,23 +749,23 @@ module BasicTest
|
|
748
749
|
|
749
750
|
d3 = OneofMessage.decode(
|
750
751
|
encoded_field_c + encoded_field_a + encoded_field_d)
|
751
|
-
assert d3.a ==
|
752
|
-
assert d3.b ==
|
752
|
+
assert d3.a == ""
|
753
|
+
assert d3.b == 0
|
753
754
|
assert d3.c == nil
|
754
755
|
assert d3.d == :B
|
755
756
|
|
756
757
|
d4 = OneofMessage.decode(
|
757
758
|
encoded_field_c + encoded_field_a + encoded_field_d +
|
758
759
|
encoded_field_c)
|
759
|
-
assert d4.a ==
|
760
|
-
assert d4.b ==
|
760
|
+
assert d4.a == ""
|
761
|
+
assert d4.b == 0
|
761
762
|
assert d4.c.foo == 1
|
762
|
-
assert d4.d ==
|
763
|
+
assert d4.d == :Default
|
763
764
|
|
764
765
|
d5 = OneofMessage.new(:a => "hello")
|
765
|
-
assert d5.a
|
766
|
+
assert d5.a == "hello"
|
766
767
|
d5.a = nil
|
767
|
-
assert d5.a ==
|
768
|
+
assert d5.a == ""
|
768
769
|
assert OneofMessage.encode(d5) == ''
|
769
770
|
assert d5.my_oneof == nil
|
770
771
|
end
|
@@ -853,15 +854,22 @@ module BasicTest
|
|
853
854
|
|
854
855
|
def test_encode_decode_helpers
|
855
856
|
m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
|
857
|
+
assert_equal 'foo', m.optional_string
|
858
|
+
assert_equal ['bar1', 'bar2'], m.repeated_string
|
859
|
+
|
856
860
|
json = m.to_json
|
857
861
|
m2 = TestMessage.decode_json(json)
|
858
|
-
|
859
|
-
|
862
|
+
assert_equal 'foo', m2.optional_string
|
863
|
+
assert_equal ['bar1', 'bar2'], m2.repeated_string
|
864
|
+
if RUBY_PLATFORM != "java"
|
865
|
+
assert m2.optional_string.frozen?
|
866
|
+
assert m2.repeated_string[0].frozen?
|
867
|
+
end
|
860
868
|
|
861
869
|
proto = m.to_proto
|
862
870
|
m2 = TestMessage.decode(proto)
|
863
|
-
|
864
|
-
|
871
|
+
assert_equal 'foo', m2.optional_string
|
872
|
+
assert_equal ['bar1', 'bar2'], m2.repeated_string
|
865
873
|
end
|
866
874
|
|
867
875
|
def test_protobuf_encode_decode_helpers
|
@@ -3,7 +3,8 @@
|
|
3
3
|
# generated_code.rb is in the same directory as this test.
|
4
4
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'generated_code_pb'
|
7
|
+
require 'test_import_pb'
|
7
8
|
require 'test/unit'
|
8
9
|
|
9
10
|
class GeneratedCodeTest < Test::Unit::TestCase
|
@@ -13,5 +14,6 @@ class GeneratedCodeTest < Test::Unit::TestCase
|
|
13
14
|
# successfully creates message definitions and classes, not to test every
|
14
15
|
# aspect of the extension (basic.rb is for that).
|
15
16
|
m = A::B::C::TestMessage.new()
|
17
|
+
m2 = FooBar::TestImportedMessage.new()
|
16
18
|
end
|
17
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0
|
4
|
+
version: 3.0.0
|
5
5
|
platform: x86-linux
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
@@ -88,18 +88,18 @@ files:
|
|
88
88
|
- lib/google/2.2/protobuf_c.so
|
89
89
|
- lib/google/2.3/protobuf_c.so
|
90
90
|
- lib/google/protobuf.rb
|
91
|
-
- lib/google/protobuf/
|
92
|
-
- lib/google/protobuf/
|
93
|
-
- lib/google/protobuf/
|
94
|
-
- lib/google/protobuf/
|
95
|
-
- lib/google/protobuf/
|
91
|
+
- lib/google/protobuf/any_pb.rb
|
92
|
+
- lib/google/protobuf/api_pb.rb
|
93
|
+
- lib/google/protobuf/duration_pb.rb
|
94
|
+
- lib/google/protobuf/empty_pb.rb
|
95
|
+
- lib/google/protobuf/field_mask_pb.rb
|
96
96
|
- lib/google/protobuf/message_exts.rb
|
97
97
|
- lib/google/protobuf/repeated_field.rb
|
98
|
-
- lib/google/protobuf/
|
99
|
-
- lib/google/protobuf/
|
100
|
-
- lib/google/protobuf/
|
101
|
-
- lib/google/protobuf/
|
102
|
-
- lib/google/protobuf/
|
98
|
+
- lib/google/protobuf/source_context_pb.rb
|
99
|
+
- lib/google/protobuf/struct_pb.rb
|
100
|
+
- lib/google/protobuf/timestamp_pb.rb
|
101
|
+
- lib/google/protobuf/type_pb.rb
|
102
|
+
- lib/google/protobuf/wrappers_pb.rb
|
103
103
|
- tests/basic.rb
|
104
104
|
- tests/generated_code_test.rb
|
105
105
|
- tests/stress.rb
|
@@ -118,9 +118,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - "
|
121
|
+
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
123
|
+
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
126
|
rubygems_version: 2.5.1
|