google-protobuf 3.2.0 → 3.3.0
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/extconf.rb +8 -1
- data/ext/google/protobuf_c/map.c +31 -0
- data/ext/google/protobuf_c/message.c +12 -2
- data/ext/google/protobuf_c/protobuf.h +2 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +51 -0
- data/tests/basic.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab3368a432715f4e921518757a25d977584aeff5
|
4
|
+
data.tar.gz: 45949b282302bc58f9fcd05bc88a385580d5d352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e55b826b563d58eefcec951ac912b2fb4b988aae3e655f7759163c0b8ee1db6f8932ec0485c7cf6f8a4188bfa2584ce33dd5670dab43fb21eaf8fc7f86a5e819
|
7
|
+
data.tar.gz: bccb6b6299c91554bf0f69123af98fdd3926f073d591e6c62c219b01430078c5ae0bd1139d6dec239ab0ee5254ac2d04c1cf23647aabaedd4e9956937e6d18c4
|
@@ -4,7 +4,14 @@ require 'mkmf'
|
|
4
4
|
|
5
5
|
$CFLAGS += " -std=c99 -O3 -DNDEBUG"
|
6
6
|
|
7
|
+
|
8
|
+
if RUBY_PLATFORM =~ /linux/
|
9
|
+
# Instruct the linker to point memcpy calls at our __wrap_memcpy wrapper.
|
10
|
+
$LDFLAGS += " -Wl,-wrap,memcpy"
|
11
|
+
end
|
12
|
+
|
7
13
|
$objs = ["protobuf.o", "defs.o", "storage.o", "message.o",
|
8
|
-
"repeated_field.o", "map.o", "encode_decode.o", "upb.o"
|
14
|
+
"repeated_field.o", "map.o", "encode_decode.o", "upb.o",
|
15
|
+
"wrap_memcpy.o"]
|
9
16
|
|
10
17
|
create_makefile("google/protobuf_c")
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -652,6 +652,35 @@ VALUE Map_hash(VALUE _self) {
|
|
652
652
|
return INT2FIX(h);
|
653
653
|
}
|
654
654
|
|
655
|
+
/*
|
656
|
+
* call-seq:
|
657
|
+
* Map.to_h => {}
|
658
|
+
*
|
659
|
+
* Returns a Ruby Hash object containing all the values within the map
|
660
|
+
*/
|
661
|
+
VALUE Map_to_h(VALUE _self) {
|
662
|
+
Map* self = ruby_to_Map(_self);
|
663
|
+
VALUE hash = rb_hash_new();
|
664
|
+
upb_strtable_iter it;
|
665
|
+
for (upb_strtable_begin(&it, &self->table);
|
666
|
+
!upb_strtable_done(&it);
|
667
|
+
upb_strtable_next(&it)) {
|
668
|
+
VALUE key = table_key_to_ruby(
|
669
|
+
self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
|
670
|
+
upb_value v = upb_strtable_iter_value(&it);
|
671
|
+
void* mem = value_memory(&v);
|
672
|
+
VALUE value = native_slot_get(self->value_type,
|
673
|
+
self->value_type_class,
|
674
|
+
mem);
|
675
|
+
|
676
|
+
if (self->value_type == UPB_TYPE_MESSAGE) {
|
677
|
+
value = Message_to_h(value);
|
678
|
+
}
|
679
|
+
rb_hash_aset(hash, key, value);
|
680
|
+
}
|
681
|
+
return hash;
|
682
|
+
}
|
683
|
+
|
655
684
|
/*
|
656
685
|
* call-seq:
|
657
686
|
* Map.inspect => string
|
@@ -804,6 +833,8 @@ void Map_register(VALUE module) {
|
|
804
833
|
rb_define_method(klass, "dup", Map_dup, 0);
|
805
834
|
rb_define_method(klass, "==", Map_eq, 1);
|
806
835
|
rb_define_method(klass, "hash", Map_hash, 0);
|
836
|
+
rb_define_method(klass, "to_hash", Map_to_h, 0);
|
837
|
+
rb_define_method(klass, "to_h", Map_to_h, 0);
|
807
838
|
rb_define_method(klass, "inspect", Map_inspect, 0);
|
808
839
|
rb_define_method(klass, "merge", Map_merge, 1);
|
809
840
|
rb_include_module(klass, rb_mEnumerable);
|
@@ -394,7 +394,12 @@ VALUE Message_inspect(VALUE _self) {
|
|
394
394
|
return str;
|
395
395
|
}
|
396
396
|
|
397
|
-
|
397
|
+
/*
|
398
|
+
* call-seq:
|
399
|
+
* Message.to_h => {}
|
400
|
+
*
|
401
|
+
* Returns the message as a Ruby Hash object, with keys as symbols.
|
402
|
+
*/
|
398
403
|
VALUE Message_to_h(VALUE _self) {
|
399
404
|
MessageHeader* self;
|
400
405
|
VALUE hash;
|
@@ -410,8 +415,13 @@ VALUE Message_to_h(VALUE _self) {
|
|
410
415
|
VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self),
|
411
416
|
field);
|
412
417
|
VALUE msg_key = ID2SYM(rb_intern(upb_fielddef_name(field)));
|
413
|
-
if (
|
418
|
+
if (upb_fielddef_ismap(field)) {
|
419
|
+
msg_value = Map_to_h(msg_value);
|
420
|
+
} else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
|
414
421
|
msg_value = RepeatedField_to_ary(msg_value);
|
422
|
+
} else if (msg_value != Qnil &&
|
423
|
+
upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
|
424
|
+
msg_value = Message_to_h(msg_value);
|
415
425
|
}
|
416
426
|
rb_hash_aset(hash, msg_key, msg_value);
|
417
427
|
}
|
@@ -424,6 +424,7 @@ VALUE Map_dup(VALUE _self);
|
|
424
424
|
VALUE Map_deep_copy(VALUE _self);
|
425
425
|
VALUE Map_eq(VALUE _self, VALUE _other);
|
426
426
|
VALUE Map_hash(VALUE _self);
|
427
|
+
VALUE Map_to_h(VALUE _self);
|
427
428
|
VALUE Map_inspect(VALUE _self);
|
428
429
|
VALUE Map_merge(VALUE _self, VALUE hashmap);
|
429
430
|
VALUE Map_merge_into_self(VALUE _self, VALUE hashmap);
|
@@ -496,6 +497,7 @@ VALUE Message_deep_copy(VALUE _self);
|
|
496
497
|
VALUE Message_eq(VALUE _self, VALUE _other);
|
497
498
|
VALUE Message_hash(VALUE _self);
|
498
499
|
VALUE Message_inspect(VALUE _self);
|
500
|
+
VALUE Message_to_h(VALUE _self);
|
499
501
|
VALUE Message_index(VALUE _self, VALUE field_name);
|
500
502
|
VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
|
501
503
|
VALUE Message_descriptor(VALUE klass);
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2017 Google Inc. All rights reserved.
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
4
|
+
//
|
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.
|
30
|
+
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
// On x86-64 Linux with glibc, we link against the 2.2.5 version of memcpy so
|
34
|
+
// that we avoid depending on the 2.14 version of the symbol. This way,
|
35
|
+
// distributions that are using pre-2.14 versions of glibc can successfully use
|
36
|
+
// the gem we distribute (https://github.com/google/protobuf/issues/2783).
|
37
|
+
//
|
38
|
+
// This wrapper is enabled by passing the linker flags -Wl,-wrap,memcpy in
|
39
|
+
// extconf.rb.
|
40
|
+
#ifdef __linux__
|
41
|
+
#if defined(__x86_64__) && defined(__GNU_LIBRARY__)
|
42
|
+
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
|
43
|
+
void *__wrap_memcpy(void *dest, const void *src, size_t n) {
|
44
|
+
return memcpy(dest, src, n);
|
45
|
+
}
|
46
|
+
#else
|
47
|
+
void *__wrap_memcpy(void *dest, const void *src, size_t n) {
|
48
|
+
return memmove(dest, src, n);
|
49
|
+
}
|
50
|
+
#endif
|
51
|
+
#endif
|
data/tests/basic.rb
CHANGED
@@ -927,6 +927,16 @@ module BasicTest
|
|
927
927
|
:repeated_uint64=>[]
|
928
928
|
}
|
929
929
|
assert_equal expected_result, m.to_h
|
930
|
+
|
931
|
+
m = MapMessage.new(
|
932
|
+
:map_string_int32 => {"a" => 1, "b" => 2},
|
933
|
+
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
934
|
+
"b" => TestMessage2.new(:foo => 2)})
|
935
|
+
expected_result = {
|
936
|
+
:map_string_int32 => {"a" => 1, "b" => 2},
|
937
|
+
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
|
938
|
+
}
|
939
|
+
assert_equal expected_result, m.to_h
|
930
940
|
end
|
931
941
|
|
932
942
|
|
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.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ext/google/protobuf_c/storage.c
|
91
91
|
- ext/google/protobuf_c/upb.c
|
92
92
|
- ext/google/protobuf_c/upb.h
|
93
|
+
- ext/google/protobuf_c/wrap_memcpy.c
|
93
94
|
- lib/google/protobuf.rb
|
94
95
|
- lib/google/protobuf/any_pb.rb
|
95
96
|
- lib/google/protobuf/api_pb.rb
|