msgpack 0.6.0pre1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +26 -0
  4. data/ChangeLog +117 -0
  5. data/Dockerfile +30 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +177 -0
  8. data/README.rdoc +129 -0
  9. data/Rakefile +114 -0
  10. data/bench/pack.rb +23 -0
  11. data/bench/pack_log.rb +33 -0
  12. data/bench/pack_log_long.rb +65 -0
  13. data/bench/run.sh +14 -0
  14. data/bench/run_long.sh +35 -0
  15. data/bench/unpack.rb +21 -0
  16. data/bench/unpack_log.rb +34 -0
  17. data/bench/unpack_log_long.rb +67 -0
  18. data/cross-build.sh +9 -0
  19. data/doclib/msgpack/buffer.rb +193 -0
  20. data/doclib/msgpack/core_ext.rb +101 -0
  21. data/doclib/msgpack/error.rb +14 -0
  22. data/doclib/msgpack/packer.rb +134 -0
  23. data/doclib/msgpack/unpacker.rb +146 -0
  24. data/doclib/msgpack.rb +77 -0
  25. data/ext/java/org/msgpack/jruby/Buffer.java +221 -0
  26. data/ext/java/org/msgpack/jruby/Decoder.java +201 -0
  27. data/ext/java/org/msgpack/jruby/Encoder.java +308 -0
  28. data/ext/java/org/msgpack/jruby/ExtensionValue.java +136 -0
  29. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +107 -0
  30. data/ext/java/org/msgpack/jruby/Packer.java +78 -0
  31. data/ext/java/org/msgpack/jruby/Types.java +37 -0
  32. data/ext/java/org/msgpack/jruby/Unpacker.java +170 -0
  33. data/ext/msgpack/buffer.c +695 -0
  34. data/ext/msgpack/buffer.h +447 -0
  35. data/ext/msgpack/buffer_class.c +507 -0
  36. data/ext/msgpack/buffer_class.h +32 -0
  37. data/ext/msgpack/compat.h +113 -0
  38. data/ext/msgpack/core_ext.c +129 -0
  39. data/ext/msgpack/core_ext.h +26 -0
  40. data/ext/msgpack/extconf.rb +28 -0
  41. data/ext/msgpack/packer.c +168 -0
  42. data/ext/msgpack/packer.h +441 -0
  43. data/ext/msgpack/packer_class.c +302 -0
  44. data/ext/msgpack/packer_class.h +30 -0
  45. data/ext/msgpack/rbinit.c +33 -0
  46. data/ext/msgpack/rmem.c +94 -0
  47. data/ext/msgpack/rmem.h +109 -0
  48. data/ext/msgpack/sysdep.h +115 -0
  49. data/ext/msgpack/sysdep_endian.h +50 -0
  50. data/ext/msgpack/sysdep_types.h +46 -0
  51. data/ext/msgpack/unpacker.c +771 -0
  52. data/ext/msgpack/unpacker.h +122 -0
  53. data/ext/msgpack/unpacker_class.c +405 -0
  54. data/ext/msgpack/unpacker_class.h +32 -0
  55. data/lib/msgpack/msgpack.so +0 -0
  56. data/lib/msgpack/version.rb +3 -0
  57. data/lib/msgpack.rb +13 -0
  58. data/msgpack.gemspec +31 -0
  59. data/msgpack.org.md +46 -0
  60. data/spec/cases.json +1 -0
  61. data/spec/cases.msg +0 -0
  62. data/spec/cases_compact.msg +0 -0
  63. data/spec/cases_spec.rb +39 -0
  64. data/spec/cruby/buffer_io_spec.rb +256 -0
  65. data/spec/cruby/buffer_packer.rb +29 -0
  66. data/spec/cruby/buffer_spec.rb +572 -0
  67. data/spec/cruby/buffer_unpacker.rb +19 -0
  68. data/spec/cruby/packer_spec.rb +120 -0
  69. data/spec/cruby/unpacker_spec.rb +305 -0
  70. data/spec/format_spec.rb +282 -0
  71. data/spec/jruby/benchmarks/shootout_bm.rb +73 -0
  72. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +25 -0
  73. data/spec/jruby/msgpack/unpacker_spec.rb +290 -0
  74. data/spec/jruby/msgpack_spec.rb +142 -0
  75. data/spec/pack_spec.rb +67 -0
  76. data/spec/random_compat.rb +24 -0
  77. data/spec/spec_helper.rb +27 -0
  78. data/spec/unpack_spec.rb +60 -0
  79. metadata +209 -0
@@ -0,0 +1,129 @@
1
+ /*
2
+ * MessagePack for Ruby
3
+ *
4
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "core_ext.h"
20
+ #include "packer.h"
21
+ #include "packer_class.h"
22
+
23
+ static inline VALUE delegete_to_pack(int argc, VALUE* argv, VALUE self)
24
+ {
25
+ if(argc == 0) {
26
+ return MessagePack_pack(1, &self);
27
+ } else if(argc == 1) {
28
+ /* write to io */
29
+ VALUE argv2[2];
30
+ argv2[0] = self;
31
+ argv2[1] = argv[0];
32
+ return MessagePack_pack(2, argv2);
33
+ } else {
34
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
35
+ }
36
+ }
37
+
38
+ #define ENSURE_PACKER(argc, argv, packer, pk) \
39
+ if(argc != 1 || rb_class_of(argv[0]) != cMessagePack_Packer) { \
40
+ return delegete_to_pack(argc, argv, self); \
41
+ } \
42
+ VALUE packer = argv[0]; \
43
+ msgpack_packer_t *pk; \
44
+ Data_Get_Struct(packer, msgpack_packer_t, pk);
45
+
46
+ static VALUE NilClass_to_msgpack(int argc, VALUE* argv, VALUE self)
47
+ {
48
+ ENSURE_PACKER(argc, argv, packer, pk);
49
+ msgpack_packer_write_nil(pk);
50
+ return packer;
51
+ }
52
+
53
+ static VALUE TrueClass_to_msgpack(int argc, VALUE* argv, VALUE self)
54
+ {
55
+ ENSURE_PACKER(argc, argv, packer, pk);
56
+ msgpack_packer_write_true(pk);
57
+ return packer;
58
+ }
59
+
60
+ static VALUE FalseClass_to_msgpack(int argc, VALUE* argv, VALUE self)
61
+ {
62
+ ENSURE_PACKER(argc, argv, packer, pk);
63
+ msgpack_packer_write_false(pk);
64
+ return packer;
65
+ }
66
+
67
+ static VALUE Fixnum_to_msgpack(int argc, VALUE* argv, VALUE self)
68
+ {
69
+ ENSURE_PACKER(argc, argv, packer, pk);
70
+ msgpack_packer_write_fixnum_value(pk, self);
71
+ return packer;
72
+ }
73
+
74
+ static VALUE Bignum_to_msgpack(int argc, VALUE* argv, VALUE self)
75
+ {
76
+ ENSURE_PACKER(argc, argv, packer, pk);
77
+ msgpack_packer_write_bignum_value(pk, self);
78
+ return packer;
79
+ }
80
+
81
+ static VALUE Float_to_msgpack(int argc, VALUE* argv, VALUE self)
82
+ {
83
+ ENSURE_PACKER(argc, argv, packer, pk);
84
+ msgpack_packer_write_float_value(pk, self);
85
+ return packer;
86
+ }
87
+
88
+ static VALUE String_to_msgpack(int argc, VALUE* argv, VALUE self)
89
+ {
90
+ ENSURE_PACKER(argc, argv, packer, pk);
91
+ msgpack_packer_write_string_value(pk, self);
92
+ return packer;
93
+ }
94
+
95
+ static VALUE Array_to_msgpack(int argc, VALUE* argv, VALUE self)
96
+ {
97
+ ENSURE_PACKER(argc, argv, packer, pk);
98
+ msgpack_packer_write_array_value(pk, self);
99
+ return packer;
100
+ }
101
+
102
+ static VALUE Hash_to_msgpack(int argc, VALUE* argv, VALUE self)
103
+ {
104
+ ENSURE_PACKER(argc, argv, packer, pk);
105
+ msgpack_packer_write_hash_value(pk, self);
106
+ return packer;
107
+ }
108
+
109
+ static VALUE Symbol_to_msgpack(int argc, VALUE* argv, VALUE self)
110
+ {
111
+ ENSURE_PACKER(argc, argv, packer, pk);
112
+ msgpack_packer_write_symbol_value(pk, self);
113
+ return packer;
114
+ }
115
+
116
+ void MessagePack_core_ext_module_init()
117
+ {
118
+ rb_define_method(rb_cNilClass, "to_msgpack", NilClass_to_msgpack, -1);
119
+ rb_define_method(rb_cTrueClass, "to_msgpack", TrueClass_to_msgpack, -1);
120
+ rb_define_method(rb_cFalseClass, "to_msgpack", FalseClass_to_msgpack, -1);
121
+ rb_define_method(rb_cFixnum, "to_msgpack", Fixnum_to_msgpack, -1);
122
+ rb_define_method(rb_cBignum, "to_msgpack", Bignum_to_msgpack, -1);
123
+ rb_define_method(rb_cFloat, "to_msgpack", Float_to_msgpack, -1);
124
+ rb_define_method(rb_cString, "to_msgpack", String_to_msgpack, -1);
125
+ rb_define_method(rb_cArray, "to_msgpack", Array_to_msgpack, -1);
126
+ rb_define_method(rb_cHash, "to_msgpack", Hash_to_msgpack, -1);
127
+ rb_define_method(rb_cSymbol, "to_msgpack", Symbol_to_msgpack, -1);
128
+ }
129
+
@@ -0,0 +1,26 @@
1
+ /*
2
+ * MessagePack for Ruby
3
+ *
4
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #ifndef MSGPACK_RUBY_CORE_EXT_H__
19
+ #define MSGPACK_RUBY_CORE_EXT_H__
20
+
21
+ #include "compat.h"
22
+
23
+ void MessagePack_core_ext_module_init();
24
+
25
+ #endif
26
+
@@ -0,0 +1,28 @@
1
+ require 'mkmf'
2
+
3
+ have_header("ruby/st.h")
4
+ have_header("st.h")
5
+ have_func("rb_str_replace", ["ruby.h"])
6
+ have_func("rb_intern_str", ["ruby.h"])
7
+ have_func("rb_sym2str", ["ruby.h"])
8
+ have_func("rb_str_intern", ["ruby.h"])
9
+
10
+ $CFLAGS << %[ -I.. -Wall -O3 -g -std=c99]
11
+ #$CFLAGS << %[ -DDISABLE_RMEM]
12
+ #$CFLAGS << %[ -DDISABLE_RMEM_REUSE_INTERNAL_FRAGMENT]
13
+ #$CFLAGS << %[ -DDISABLE_BUFFER_READ_REFERENCE_OPTIMIZE]
14
+ #$CFLAGS << %[ -DDISABLE_BUFFER_READ_TO_S_OPTIMIZE]
15
+
16
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
17
+ # msgpack-ruby doesn't modify data came from RSTRING_PTR(str)
18
+ $CFLAGS << %[ -DRSTRING_NOT_MODIFIED]
19
+ # Rubinius C extensions don't grab GVL while rmem is not thread safe
20
+ $CFLAGS << %[ -DDISABLE_RMEM]
21
+ end
22
+
23
+ if warnflags = CONFIG['warnflags']
24
+ warnflags.slice!(/ -Wdeclaration-after-statement/)
25
+ end
26
+
27
+ create_makefile('msgpack/msgpack')
28
+
@@ -0,0 +1,168 @@
1
+ /*
2
+ * MessagePack for Ruby
3
+ *
4
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "packer.h"
20
+
21
+ #ifdef RUBINIUS
22
+ static ID s_to_iter;
23
+ static ID s_next;
24
+ static ID s_key;
25
+ static ID s_value;
26
+ #endif
27
+
28
+ void msgpack_packer_static_init()
29
+ {
30
+ #ifdef RUBINIUS
31
+ s_to_iter = rb_intern("to_iter");
32
+ s_next = rb_intern("next");
33
+ s_key = rb_intern("key");
34
+ s_value = rb_intern("value");
35
+ #endif
36
+ }
37
+
38
+ void msgpack_packer_static_destroy()
39
+ { }
40
+
41
+ void msgpack_packer_init(msgpack_packer_t* pk)
42
+ {
43
+ memset(pk, 0, sizeof(msgpack_packer_t));
44
+
45
+ msgpack_buffer_init(PACKER_BUFFER_(pk));
46
+
47
+ pk->io = Qnil;
48
+ }
49
+
50
+ void msgpack_packer_destroy(msgpack_packer_t* pk)
51
+ {
52
+ msgpack_buffer_destroy(PACKER_BUFFER_(pk));
53
+ }
54
+
55
+ void msgpack_packer_mark(msgpack_packer_t* pk)
56
+ {
57
+ rb_gc_mark(pk->io);
58
+
59
+ /* See MessagePack_Buffer_wrap */
60
+ /* msgpack_buffer_mark(PACKER_BUFFER_(pk)); */
61
+ rb_gc_mark(pk->buffer_ref);
62
+ }
63
+
64
+ void msgpack_packer_reset(msgpack_packer_t* pk)
65
+ {
66
+ msgpack_buffer_clear(PACKER_BUFFER_(pk));
67
+
68
+ pk->io = Qnil;
69
+ pk->io_write_all_method = 0;
70
+ pk->buffer_ref = Qnil;
71
+ }
72
+
73
+
74
+ void msgpack_packer_write_array_value(msgpack_packer_t* pk, VALUE v)
75
+ {
76
+ /* actual return type of RARRAY_LEN is long */
77
+ unsigned long len = RARRAY_LEN(v);
78
+ if(len > 0xffffffffUL) {
79
+ rb_raise(rb_eArgError, "size of array is too long to pack: %lu bytes should be <= %lu", len, 0xffffffffUL);
80
+ }
81
+ unsigned int len32 = (unsigned int)len;
82
+ msgpack_packer_write_array_header(pk, len32);
83
+
84
+ unsigned int i;
85
+ for(i=0; i < len32; ++i) {
86
+ VALUE e = rb_ary_entry(v, i);
87
+ msgpack_packer_write_value(pk, e);
88
+ }
89
+ }
90
+
91
+ static int write_hash_foreach(VALUE key, VALUE value, VALUE pk_value)
92
+ {
93
+ if (key == Qundef) {
94
+ return ST_CONTINUE;
95
+ }
96
+ msgpack_packer_t* pk = (msgpack_packer_t*) pk_value;
97
+ msgpack_packer_write_value(pk, key);
98
+ msgpack_packer_write_value(pk, value);
99
+ return ST_CONTINUE;
100
+ }
101
+
102
+ void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v)
103
+ {
104
+ /* actual return type of RHASH_SIZE is long (if SIZEOF_LONG == SIZEOF_VOIDP
105
+ * or long long (if SIZEOF_LONG_LONG == SIZEOF_VOIDP. See st.h. */
106
+ unsigned long len = RHASH_SIZE(v);
107
+ if(len > 0xffffffffUL) {
108
+ rb_raise(rb_eArgError, "size of array is too long to pack: %ld bytes should be <= %lu", len, 0xffffffffUL);
109
+ }
110
+ unsigned int len32 = (unsigned int)len;
111
+ msgpack_packer_write_map_header(pk, len32);
112
+
113
+ #ifdef RUBINIUS
114
+ VALUE iter = rb_funcall(v, s_to_iter, 0);
115
+ VALUE entry = Qnil;
116
+ while(RTEST(entry = rb_funcall(iter, s_next, 1, entry))) {
117
+ VALUE key = rb_funcall(entry, s_key, 0);
118
+ VALUE val = rb_funcall(entry, s_value, 0);
119
+ write_hash_foreach(key, val, (VALUE) pk);
120
+ }
121
+ #else
122
+ rb_hash_foreach(v, write_hash_foreach, (VALUE) pk);
123
+ #endif
124
+ }
125
+
126
+ static void _msgpack_packer_write_other_value(msgpack_packer_t* pk, VALUE v)
127
+ {
128
+ rb_funcall(v, pk->to_msgpack_method, 1, pk->to_msgpack_arg);
129
+ }
130
+
131
+ void msgpack_packer_write_value(msgpack_packer_t* pk, VALUE v)
132
+ {
133
+ switch(rb_type(v)) {
134
+ case T_NIL:
135
+ msgpack_packer_write_nil(pk);
136
+ break;
137
+ case T_TRUE:
138
+ msgpack_packer_write_true(pk);
139
+ break;
140
+ case T_FALSE:
141
+ msgpack_packer_write_false(pk);
142
+ break;
143
+ case T_FIXNUM:
144
+ msgpack_packer_write_fixnum_value(pk, v);
145
+ break;
146
+ case T_SYMBOL:
147
+ msgpack_packer_write_symbol_value(pk, v);
148
+ break;
149
+ case T_STRING:
150
+ msgpack_packer_write_string_value(pk, v);
151
+ break;
152
+ case T_ARRAY:
153
+ msgpack_packer_write_array_value(pk, v);
154
+ break;
155
+ case T_HASH:
156
+ msgpack_packer_write_hash_value(pk, v);
157
+ break;
158
+ case T_BIGNUM:
159
+ msgpack_packer_write_bignum_value(pk, v);
160
+ break;
161
+ case T_FLOAT:
162
+ msgpack_packer_write_float_value(pk, v);
163
+ break;
164
+ default:
165
+ _msgpack_packer_write_other_value(pk, v);
166
+ }
167
+ }
168
+