msgpack 0.4.7 → 0.5.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.
Files changed (60) 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 -0
  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 +171 -34
  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/msgpack/pack_template.h +0 -771
  54. data/msgpack/sysdep.h +0 -195
  55. data/msgpack/unpack_define.h +0 -93
  56. data/msgpack/unpack_template.h +0 -413
  57. data/test/test_cases.rb +0 -46
  58. data/test/test_encoding.rb +0 -68
  59. data/test/test_helper.rb +0 -10
  60. data/test/test_pack_unpack.rb +0 -308
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,164 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-06 00:00:00.000000000Z
13
- dependencies: []
14
- description:
15
- email: frsyuki@users.sourceforge.jp
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake-compiler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.11'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.11'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.7'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.7'
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.2
110
+ description: MessagePack is a binary-based efficient object serialization library.
111
+ It enables to exchange structured objects between many languages like JSON. But
112
+ unlike JSON, it is very fast and small.
113
+ email: frsyuki@gmail.com
16
114
  executables: []
17
115
  extensions:
18
- - ext/extconf.rb
116
+ - ext/msgpack/extconf.rb
19
117
  extra_rdoc_files: []
20
118
  files:
21
- - ext/compat.h
22
- - ext/extconf.rb
23
- - ext/pack.c
24
- - ext/pack.h
25
- - ext/rbinit.c
26
- - ext/unpack.c
27
- - ext/unpack.h
28
- - ext/version.rb
29
- - msgpack/pack_define.h
30
- - msgpack/pack_template.h
31
- - msgpack/sysdep.h
32
- - msgpack/unpack_define.h
33
- - msgpack/unpack_template.h
34
- - test/cases.json
35
- - test/cases.mpac
36
- - test/cases_compact.mpac
37
- - test/test_cases.rb
38
- - test/test_encoding.rb
39
- - test/test_helper.rb
40
- - test/test_pack_unpack.rb
119
+ - .gitignore
120
+ - ChangeLog
121
+ - Gemfile
122
+ - README.rdoc
123
+ - Rakefile
124
+ - doclib/msgpack.rb
125
+ - doclib/msgpack/buffer.rb
126
+ - doclib/msgpack/core_ext.rb
127
+ - doclib/msgpack/error.rb
128
+ - doclib/msgpack/packer.rb
129
+ - doclib/msgpack/unpacker.rb
130
+ - ext/msgpack/buffer.c
131
+ - ext/msgpack/buffer.h
132
+ - ext/msgpack/buffer_class.c
133
+ - ext/msgpack/buffer_class.h
134
+ - ext/msgpack/compat.h
135
+ - ext/msgpack/core_ext.c
136
+ - ext/msgpack/core_ext.h
137
+ - ext/msgpack/extconf.rb
138
+ - ext/msgpack/packer.c
139
+ - ext/msgpack/packer.h
140
+ - ext/msgpack/packer_class.c
141
+ - ext/msgpack/packer_class.h
142
+ - ext/msgpack/rbinit.c
143
+ - ext/msgpack/rmem.c
144
+ - ext/msgpack/rmem.h
145
+ - ext/msgpack/sysdep.h
146
+ - ext/msgpack/sysdep_endian.h
147
+ - ext/msgpack/sysdep_types.h
148
+ - ext/msgpack/unpacker.c
149
+ - ext/msgpack/unpacker.h
150
+ - ext/msgpack/unpacker_class.c
151
+ - ext/msgpack/unpacker_class.h
152
+ - lib/msgpack.rb
153
+ - lib/msgpack/version.rb
154
+ - msgpack.gemspec
155
+ - spec/buffer_io_spec.rb
156
+ - spec/buffer_spec.rb
157
+ - spec/cases.json
158
+ - spec/cases.msg
159
+ - spec/cases_compact.msg
160
+ - spec/cases_spec.rb
161
+ - spec/format_spec.rb
162
+ - spec/packer_spec.rb
163
+ - spec/random_compat.rb
164
+ - spec/spec_helper.rb
165
+ - spec/unpacker_spec.rb
41
166
  homepage: http://msgpack.org/
42
167
  licenses: []
43
168
  post_install_message:
44
- rdoc_options:
45
- - ext
169
+ rdoc_options: []
46
170
  require_paths:
47
171
  - lib
48
172
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -51,21 +175,34 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
175
  - - ! '>='
52
176
  - !ruby/object:Gem::Version
53
177
  version: '0'
178
+ segments:
179
+ - 0
180
+ hash: -2311966328594479476
54
181
  required_rubygems_version: !ruby/object:Gem::Requirement
55
182
  none: false
56
183
  requirements:
57
184
  - - ! '>='
58
185
  - !ruby/object:Gem::Version
59
186
  version: '0'
187
+ segments:
188
+ - 0
189
+ hash: -2311966328594479476
60
190
  requirements: []
61
191
  rubyforge_project: msgpack
62
- rubygems_version: 1.8.12
192
+ rubygems_version: 1.8.23
63
193
  signing_key:
64
194
  specification_version: 3
65
195
  summary: MessagePack, a binary-based efficient data interchange format.
66
196
  test_files:
67
- - test/test_cases.rb
68
- - test/test_encoding.rb
69
- - test/test_helper.rb
70
- - test/test_pack_unpack.rb
71
- has_rdoc: true
197
+ - spec/buffer_io_spec.rb
198
+ - spec/buffer_spec.rb
199
+ - spec/cases.json
200
+ - spec/cases.msg
201
+ - spec/cases_compact.msg
202
+ - spec/cases_spec.rb
203
+ - spec/format_spec.rb
204
+ - spec/packer_spec.rb
205
+ - spec/random_compat.rb
206
+ - spec/spec_helper.rb
207
+ - spec/unpacker_spec.rb
208
+ has_rdoc: false
@@ -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
-