msgpack 0.4.7-x86-mingw32 → 0.5.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +17 -0
  2. data/ChangeLog +47 -0
  3. data/README.rdoc +102 -0
  4. data/Rakefile +88 -0
  5. data/doclib/msgpack.rb +55 -0
  6. data/doclib/msgpack/buffer.rb +193 -0
  7. data/doclib/msgpack/core_ext.rb +101 -0
  8. data/doclib/msgpack/error.rb +14 -0
  9. data/doclib/msgpack/packer.rb +131 -0
  10. data/doclib/msgpack/unpacker.rb +130 -0
  11. data/ext/msgpack/buffer.c +679 -0
  12. data/ext/msgpack/buffer.h +442 -0
  13. data/ext/msgpack/buffer_class.c +507 -0
  14. data/ext/msgpack/buffer_class.h +32 -0
  15. data/ext/msgpack/compat.h +112 -0
  16. data/ext/msgpack/core_ext.c +129 -0
  17. data/ext/{pack.h → msgpack/core_ext.h} +7 -7
  18. data/ext/msgpack/extconf.rb +17 -0
  19. data/ext/msgpack/packer.c +137 -0
  20. data/ext/msgpack/packer.h +319 -0
  21. data/ext/msgpack/packer_class.c +285 -0
  22. data/ext/{unpack.h → msgpack/packer_class.h} +11 -7
  23. data/ext/msgpack/rbinit.c +33 -0
  24. data/ext/msgpack/rmem.c +110 -0
  25. data/ext/msgpack/rmem.h +100 -0
  26. data/ext/msgpack/sysdep.h +115 -0
  27. data/ext/msgpack/sysdep_endian.h +50 -0
  28. data/ext/msgpack/sysdep_types.h +46 -0
  29. data/ext/msgpack/unpacker.c +669 -0
  30. data/ext/msgpack/unpacker.h +112 -0
  31. data/ext/msgpack/unpacker_class.c +376 -0
  32. data/{msgpack/pack_define.h → ext/msgpack/unpacker_class.h} +12 -8
  33. data/lib/msgpack.rb +10 -1
  34. data/{ext → lib/msgpack}/version.rb +1 -1
  35. data/msgpack.gemspec +25 -0
  36. data/spec/buffer_io_spec.rb +237 -0
  37. data/spec/buffer_spec.rb +572 -0
  38. data/{test → spec}/cases.json +0 -0
  39. data/{test/cases.mpac → spec/cases.msg} +0 -0
  40. data/{test/cases_compact.mpac → spec/cases_compact.msg} +0 -0
  41. data/spec/cases_spec.rb +39 -0
  42. data/spec/format_spec.rb +225 -0
  43. data/spec/packer_spec.rb +127 -0
  44. data/spec/random_compat.rb +24 -0
  45. data/spec/spec_helper.rb +21 -0
  46. data/spec/unpacker_spec.rb +128 -0
  47. metadata +157 -39
  48. data/ext/compat.h +0 -99
  49. data/ext/extconf.rb +0 -7
  50. data/ext/pack.c +0 -314
  51. data/ext/rbinit.c +0 -66
  52. data/ext/unpack.c +0 -1001
  53. data/lib/1.8/msgpack.so +0 -0
  54. data/lib/1.9/msgpack.so +0 -0
  55. data/msgpack/pack_template.h +0 -771
  56. data/msgpack/sysdep.h +0 -195
  57. data/msgpack/unpack_define.h +0 -93
  58. data/msgpack/unpack_template.h +0 -413
  59. data/test/test_cases.rb +0 -46
  60. data/test/test_encoding.rb +0 -68
  61. data/test/test_helper.rb +0 -10
  62. data/test/test_pack_unpack.rb +0 -308
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 11
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 4
8
- - 7
9
- version: 0.4.7
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
10
11
  platform: x86-mingw32
11
12
  authors:
12
13
  - FURUHASHI Sadayuki
@@ -14,11 +15,104 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2012-05-06 00:00:00 Z
18
- dependencies: []
19
-
20
- description:
21
- email: frsyuki@users.sourceforge.jp
18
+ date: 2012-12-21 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ name: bundler
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 63
44
+ segments:
45
+ - 0
46
+ - 9
47
+ - 2
48
+ version: 0.9.2
49
+ name: rake
50
+ version_requirements: *id002
51
+ prerelease: false
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 61
60
+ segments:
61
+ - 0
62
+ - 8
63
+ - 1
64
+ version: 0.8.1
65
+ name: rake-compiler
66
+ version_requirements: *id003
67
+ prerelease: false
68
+ - !ruby/object:Gem::Dependency
69
+ type: :development
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 21
76
+ segments:
77
+ - 2
78
+ - 11
79
+ version: "2.11"
80
+ name: rspec
81
+ version_requirements: *id004
82
+ prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 1
91
+ segments:
92
+ - 1
93
+ - 7
94
+ version: "1.7"
95
+ name: json
96
+ version_requirements: *id005
97
+ prerelease: false
98
+ - !ruby/object:Gem::Dependency
99
+ type: :development
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ hash: 59
106
+ segments:
107
+ - 0
108
+ - 8
109
+ - 2
110
+ version: 0.8.2
111
+ name: yard
112
+ version_requirements: *id006
113
+ prerelease: false
114
+ description: MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.
115
+ email: frsyuki@gmail.com
22
116
  executables: []
23
117
 
24
118
  extensions: []
@@ -26,35 +120,62 @@ extensions: []
26
120
  extra_rdoc_files: []
27
121
 
28
122
  files:
29
- - ext/compat.h
30
- - ext/extconf.rb
31
- - ext/pack.c
32
- - ext/pack.h
33
- - ext/rbinit.c
34
- - ext/unpack.c
35
- - ext/unpack.h
36
- - ext/version.rb
37
- - lib/1.8/msgpack.so
38
- - lib/1.9/msgpack.so
123
+ - .gitignore
124
+ - ChangeLog
125
+ - Gemfile
126
+ - README.rdoc
127
+ - Rakefile
128
+ - doclib/msgpack.rb
129
+ - doclib/msgpack/buffer.rb
130
+ - doclib/msgpack/core_ext.rb
131
+ - doclib/msgpack/error.rb
132
+ - doclib/msgpack/packer.rb
133
+ - doclib/msgpack/unpacker.rb
134
+ - ext/msgpack/buffer.c
135
+ - ext/msgpack/buffer.h
136
+ - ext/msgpack/buffer_class.c
137
+ - ext/msgpack/buffer_class.h
138
+ - ext/msgpack/compat.h
139
+ - ext/msgpack/core_ext.c
140
+ - ext/msgpack/core_ext.h
141
+ - ext/msgpack/extconf.rb
142
+ - ext/msgpack/packer.c
143
+ - ext/msgpack/packer.h
144
+ - ext/msgpack/packer_class.c
145
+ - ext/msgpack/packer_class.h
146
+ - ext/msgpack/rbinit.c
147
+ - ext/msgpack/rmem.c
148
+ - ext/msgpack/rmem.h
149
+ - ext/msgpack/sysdep.h
150
+ - ext/msgpack/sysdep_endian.h
151
+ - ext/msgpack/sysdep_types.h
152
+ - ext/msgpack/unpacker.c
153
+ - ext/msgpack/unpacker.h
154
+ - ext/msgpack/unpacker_class.c
155
+ - ext/msgpack/unpacker_class.h
39
156
  - lib/msgpack.rb
40
- - msgpack/pack_define.h
41
- - msgpack/pack_template.h
42
- - msgpack/sysdep.h
43
- - msgpack/unpack_define.h
44
- - msgpack/unpack_template.h
45
- - test/cases.json
46
- - test/cases.mpac
47
- - test/cases_compact.mpac
48
- - test/test_cases.rb
49
- - test/test_encoding.rb
50
- - test/test_helper.rb
51
- - test/test_pack_unpack.rb
157
+ - lib/msgpack/version.rb
158
+ - msgpack.gemspec
159
+ - spec/buffer_io_spec.rb
160
+ - spec/buffer_spec.rb
161
+ - spec/cases.json
162
+ - spec/cases.msg
163
+ - spec/cases_compact.msg
164
+ - spec/cases_spec.rb
165
+ - spec/format_spec.rb
166
+ - spec/packer_spec.rb
167
+ - spec/random_compat.rb
168
+ - spec/spec_helper.rb
169
+ - spec/unpacker_spec.rb
170
+ - lib/msgpack/1.8/msgpack.so
171
+ - lib/msgpack/1.9/msgpack.so
172
+ has_rdoc: true
52
173
  homepage: http://msgpack.org/
53
174
  licenses: []
54
175
 
55
176
  post_install_message:
56
- rdoc_options:
57
- - ext
177
+ rdoc_options: []
178
+
58
179
  require_paths:
59
180
  - lib
60
181
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -78,12 +199,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
199
  requirements: []
79
200
 
80
201
  rubyforge_project: msgpack
81
- rubygems_version: 1.8.16
202
+ rubygems_version: 1.6.2
82
203
  signing_key:
83
204
  specification_version: 3
84
205
  summary: MessagePack, a binary-based efficient data interchange format.
85
- test_files:
86
- - test/test_cases.rb
87
- - test/test_encoding.rb
88
- - test/test_helper.rb
89
- - test/test_pack_unpack.rb
206
+ test_files: []
207
+
@@ -1,99 +0,0 @@
1
- /*
2
- * MessagePack for Ruby
3
- *
4
- * Copyright (C) 2008-2010 FURUHASHI Sadayuki
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 COMPAT_H__
19
- #define COMPAT_H__
20
-
21
-
22
- #ifdef HAVE_RUBY_ENCODING_H
23
- #include "ruby/encoding.h"
24
- #define COMPAT_HAVE_ENCODING
25
- extern int s_enc_utf8;
26
- extern int s_enc_ascii8bit;
27
- extern int s_enc_usascii;
28
- extern VALUE s_enc_utf8_value;
29
- #endif
30
-
31
- /* MRI 1.9 */
32
- #if defined(RUBY_VM)
33
- #define COMPAT_RERAISE rb_exc_raise(rb_errinfo())
34
-
35
- /* JRuby */
36
- #elif defined(JRUBY)
37
- #define COMPAT_RERAISE rb_exc_raise(rb_gv_get("$!"))
38
-
39
- /* MRI 1.8 and Rubinius */
40
- #else
41
- #define COMPAT_RERAISE rb_exc_raise(ruby_errinfo)
42
- #endif
43
-
44
-
45
- #ifndef RBIGNUM_POSITIVE_P
46
-
47
- /* Rubinius */
48
- #if defined(RUBINIUS)
49
- #define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
50
-
51
- /* JRuby */
52
- #elif defined(JRUBY)
53
- #define RBIGNUM_POSITIVE_P(b) (rb_funcall(b, rb_intern(">="), 1, INT2FIX(0)) == Qtrue)
54
- #define rb_big2ull(b) rb_num2ull(b)
55
- /*#define rb_big2ll(b) rb_num2ll(b)*/
56
-
57
- /* MRI 1.8 */
58
- #else
59
- #define RBIGNUM_POSITIVE_P(b) (RBIGNUM(b)->sign)
60
-
61
- #endif
62
- #endif
63
-
64
-
65
- /* Rubinius */
66
- #if defined(RUBINIUS)
67
- static inline void rb_gc_enable() { return; }
68
- static inline void rb_gc_disable() { return; }
69
-
70
- /* JRuby */
71
- #elif defined(JRUBY)
72
- static inline void rb_gc_enable() { return; }
73
- static inline void rb_gc_disable() { return; }
74
- #endif
75
-
76
-
77
- /* MRI 1.8.5 */
78
- #ifndef RSTRING_PTR
79
- #define RSTRING_PTR(s) (RSTRING(s)->ptr)
80
- #endif
81
-
82
- /* MRI 1.8.5 */
83
- #ifndef RSTRING_LEN
84
- #define RSTRING_LEN(s) (RSTRING(s)->len)
85
- #endif
86
-
87
- /* MRI 1.8.5 */
88
- #ifndef RARRAY_PTR
89
- #define RARRAY_PTR(s) (RARRAY(s)->ptr)
90
- #endif
91
-
92
- /* MRI 1.8.5 */
93
- #ifndef RARRAY_LEN
94
- #define RARRAY_LEN(s) (RARRAY(s)->len)
95
- #endif
96
-
97
-
98
- #endif /* compat.h */
99
-
@@ -1,7 +0,0 @@
1
- require 'mkmf'
2
- require './version.rb'
3
- $CFLAGS << %[ -I.. -Wall -O3 -DMESSAGEPACK_VERSION=\\"#{MessagePack::VERSION}\\" -g]
4
- have_header("ruby/st.h")
5
- have_header("st.h")
6
- create_makefile('msgpack')
7
-
data/ext/pack.c DELETED
@@ -1,314 +0,0 @@
1
- /*
2
- * MessagePack for Ruby packing routine
3
- *
4
- * Copyright (C) 2008-2010 FURUHASHI Sadayuki
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
- #define RSTRING_NOT_MODIFIED
19
- #include "ruby.h"
20
- #include "compat.h"
21
-
22
- #include "msgpack/pack_define.h"
23
-
24
- static ID s_to_msgpack;
25
- static ID s_append;
26
-
27
- #define msgpack_pack_inline_func(name) \
28
- static inline void msgpack_pack ## name
29
-
30
- #define msgpack_pack_inline_func_cint(name) \
31
- static inline void msgpack_pack ## name
32
-
33
- #define msgpack_pack_user VALUE
34
-
35
- #define msgpack_pack_append_buffer(user, buf, len) \
36
- ((TYPE(user) == T_STRING) ? \
37
- rb_str_buf_cat(user, (const void*)buf, len) : \
38
- rb_funcall(user, s_append, 1, rb_str_new((const void*)buf,len)))
39
-
40
- #include "msgpack/pack_template.h"
41
-
42
-
43
- #if defined(HAVE_RUBY_ST_H)
44
- #include "ruby/st.h" // ruby hash on Ruby 1.9
45
- #elif defined(HAVE_ST_H)
46
- #include "st.h" // ruby hash on Ruby 1.8
47
- #endif
48
-
49
- #define ARG_BUFFER(name, argc, argv) \
50
- VALUE name; \
51
- if(argc == 1) { \
52
- name = argv[0]; \
53
- } else if(argc == 0) { \
54
- name = rb_str_buf_new(0); \
55
- } else { \
56
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); \
57
- }
58
-
59
-
60
- /*
61
- * Document-method: NilClass#to_msgpack
62
- *
63
- * call-seq:
64
- * nil.to_msgpack(out = '') -> String
65
- *
66
- * Serializes the nil into raw bytes.
67
- */
68
- static VALUE MessagePack_NilClass_to_msgpack(int argc, VALUE *argv, VALUE self)
69
- {
70
- ARG_BUFFER(out, argc, argv);
71
- msgpack_pack_nil(out);
72
- return out;
73
- }
74
-
75
-
76
- /*
77
- * Document-method: TrueClass#to_msgpack
78
- *
79
- * call-seq:
80
- * true.to_msgpack(out = '') -> String
81
- *
82
- * Serializes the true into raw bytes.
83
- */
84
- static VALUE MessagePack_TrueClass_to_msgpack(int argc, VALUE *argv, VALUE self)
85
- {
86
- ARG_BUFFER(out, argc, argv);
87
- msgpack_pack_true(out);
88
- return out;
89
- }
90
-
91
-
92
- /*
93
- * Document-method: FalseClass#to_msgpack
94
- *
95
- * call-seq:
96
- * false.to_msgpack(out = '') -> String
97
- *
98
- * Serializes false into raw bytes.
99
- */
100
- static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self)
101
- {
102
- ARG_BUFFER(out, argc, argv);
103
- msgpack_pack_false(out);
104
- return out;
105
- }
106
-
107
-
108
- /*
109
- * Document-method: Fixnum#to_msgpack
110
- *
111
- * call-seq:
112
- * fixnum.to_msgpack(out = '') -> String
113
- *
114
- * Serializes the Fixnum into raw bytes.
115
- */
116
- static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
117
- {
118
- ARG_BUFFER(out, argc, argv);
119
- #ifdef JRUBY
120
- msgpack_pack_long(out, FIXNUM_P(self) ? FIX2LONG(self) : rb_num2ll(self));
121
- #else
122
- msgpack_pack_long(out, FIX2LONG(self));
123
- #endif
124
- return out;
125
- }
126
-
127
-
128
- /*
129
- * Document-method: Bignum#to_msgpack
130
- *
131
- * call-seq:
132
- * bignum.to_msgpack(out = '') -> String
133
- *
134
- * Serializes the Bignum into raw bytes.
135
- */
136
- static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self)
137
- {
138
- ARG_BUFFER(out, argc, argv);
139
- if(RBIGNUM_POSITIVE_P(self)) {
140
- msgpack_pack_uint64(out, rb_big2ull(self));
141
- } else {
142
- msgpack_pack_int64(out, rb_big2ll(self));
143
- }
144
- return out;
145
- }
146
-
147
-
148
- /*
149
- * Document-method: Float#to_msgpack
150
- *
151
- * call-seq:
152
- * float.to_msgpack(out = '') -> String
153
- *
154
- * Serializes the Float into raw bytes.
155
- */
156
- static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
157
- {
158
- ARG_BUFFER(out, argc, argv);
159
- msgpack_pack_double(out, rb_num2dbl(self));
160
- return out;
161
- }
162
-
163
-
164
- /*
165
- * Document-method: String#to_msgpack
166
- *
167
- * call-seq:
168
- * string.to_msgpack(out = '') -> String
169
- *
170
- * Serializes the String into raw bytes.
171
- */
172
- static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
173
- {
174
- ARG_BUFFER(out, argc, argv);
175
- #ifdef COMPAT_HAVE_ENCODING
176
- int enc = ENCODING_GET(self);
177
- if(enc != s_enc_utf8 && enc != s_enc_ascii8bit && enc != s_enc_usascii) {
178
- if(!ENC_CODERANGE_ASCIIONLY(self)) {
179
- self = rb_str_encode(self, s_enc_utf8_value, 0, Qnil);
180
- }
181
- }
182
- #endif
183
- msgpack_pack_raw(out, RSTRING_LEN(self));
184
- msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
185
- return out;
186
- }
187
-
188
-
189
- /*
190
- * Document-method: Symbol#to_msgpack
191
- *
192
- * call-seq:
193
- * symbol.to_msgpack(out = '') -> String
194
- *
195
- * Serializes the Symbol into raw bytes.
196
- */
197
- static VALUE MessagePack_Symbol_to_msgpack(int argc, VALUE *argv, VALUE self)
198
- {
199
- #ifdef COMPAT_HAVE_ENCODING
200
- return MessagePack_String_to_msgpack(argc, argv, rb_id2str(SYM2ID(self)));
201
- #else
202
- ARG_BUFFER(out, argc, argv);
203
- const char* name = rb_id2name(SYM2ID(self));
204
- size_t len = strlen(name);
205
- msgpack_pack_raw(out, len);
206
- msgpack_pack_raw_body(out, name, len);
207
- return out;
208
- #endif
209
- }
210
-
211
-
212
- /*
213
- * Document-method: Array#to_msgpack
214
- *
215
- * call-seq:
216
- * array.to_msgpack(out = '') -> String
217
- *
218
- * Serializes the Array into raw bytes.
219
- * This calls to_msgpack method reflectively for internal elements.
220
- */
221
- static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
222
- {
223
- ARG_BUFFER(out, argc, argv);
224
- // FIXME check sizeof(long) > sizeof(unsigned int) && RARRAY_LEN(self) > UINT_MAX
225
- unsigned int ary_length = (unsigned int)RARRAY_LEN(self);
226
- unsigned int i = 0;
227
- msgpack_pack_array(out, ary_length);
228
- for(; i < ary_length; ++i) {
229
- VALUE p = rb_ary_entry(self, i);
230
- rb_funcall(p, s_to_msgpack, 1, out);
231
- }
232
- return out;
233
- }
234
-
235
-
236
- #ifndef RHASH_SIZE // Ruby 1.8
237
- #define RHASH_SIZE(h) (RHASH(h)->tbl ? RHASH(h)->tbl->num_entries : 0)
238
- #endif
239
-
240
- static int MessagePack_Hash_to_msgpack_foreach(VALUE key, VALUE value, VALUE out)
241
- {
242
- if (key == Qundef) { return ST_CONTINUE; }
243
- rb_funcall(key, s_to_msgpack, 1, out);
244
- rb_funcall(value, s_to_msgpack, 1, out);
245
- return ST_CONTINUE;
246
- }
247
-
248
- /*
249
- * Document-method: Hash#to_msgpack
250
- *
251
- * call-seq:
252
- * hash.to_msgpack(out = '') -> String
253
- *
254
- * Serializes the Hash into raw bytes.
255
- * This calls to_msgpack method reflectively for internal keys and values.
256
- */
257
- static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
258
- {
259
- ARG_BUFFER(out, argc, argv);
260
- // FIXME check sizeof(st_index_t) > sizeof(unsigned int) && RARRAY_LEN(self) > UINT_MAX
261
- msgpack_pack_map(out, (unsigned int)RHASH_SIZE(self));
262
- rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
263
- return out;
264
- }
265
-
266
-
267
- /**
268
- * Document-method: MessagePack.pack
269
- *
270
- * call-seq:
271
- * MessagePack.pack(object, out = '') -> String
272
- *
273
- * Serializes the object into raw bytes. The encoding of the string is ASCII-8BIT on Ruby 1.9.
274
- * This method is same as object.to_msgpack(out = '').
275
- *
276
- * _out_ is an object that implements *<<* method like String or IO.
277
- */
278
- static VALUE MessagePack_pack(int argc, VALUE* argv, VALUE self)
279
- {
280
- VALUE out;
281
- if(argc == 1) {
282
- out = rb_str_buf_new(0);
283
- } else if(argc == 2) {
284
- out = argv[1];
285
- } else {
286
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
287
- }
288
- return rb_funcall(argv[0], s_to_msgpack, 1, out);
289
- }
290
-
291
-
292
- void Init_msgpack_pack(VALUE mMessagePack)
293
- {
294
- s_to_msgpack = rb_intern("to_msgpack");
295
- s_append = rb_intern("<<");
296
-
297
- rb_define_method(rb_cNilClass, "to_msgpack", MessagePack_NilClass_to_msgpack, -1);
298
- rb_define_method(rb_cTrueClass, "to_msgpack", MessagePack_TrueClass_to_msgpack, -1);
299
- rb_define_method(rb_cFalseClass, "to_msgpack", MessagePack_FalseClass_to_msgpack, -1);
300
- rb_define_method(rb_cFixnum, "to_msgpack", MessagePack_Fixnum_to_msgpack, -1);
301
- rb_define_method(rb_cBignum, "to_msgpack", MessagePack_Bignum_to_msgpack, -1);
302
- rb_define_method(rb_cFloat, "to_msgpack", MessagePack_Float_to_msgpack, -1);
303
- rb_define_method(rb_cString, "to_msgpack", MessagePack_String_to_msgpack, -1);
304
- rb_define_method(rb_cArray, "to_msgpack", MessagePack_Array_to_msgpack, -1);
305
- rb_define_method(rb_cHash, "to_msgpack", MessagePack_Hash_to_msgpack, -1);
306
- rb_define_method(rb_cSymbol, "to_msgpack", MessagePack_Symbol_to_msgpack, -1);
307
-
308
- /**
309
- * MessagePack module is defined in rbinit.c file.
310
- * mMessagePack = rb_define_module("MessagePack");
311
- */
312
- rb_define_module_function(mMessagePack, "pack", MessagePack_pack, -1);
313
- }
314
-