msgpack 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/ChangeLog +0 -0
- data/README +29 -0
- data/Rakefile +133 -4
- data/ext/pack.c +4 -4
- data/ext/pack.h +2 -2
- data/ext/rbinit.c +1 -1
- data/ext/unpack.c +94 -78
- data/ext/unpack.h +2 -2
- data/msgpack/pack_define.h +1 -1
- data/msgpack/pack_template.h +40 -38
- data/msgpack/unpack_define.h +1 -1
- data/msgpack/unpack_template.h +49 -48
- data/test/msgpack_test.rb +150 -0
- data/test/test_helper.rb +3 -0
- metadata +33 -43
- data/License.txt +0 -13
- data/Manifest.txt +0 -23
- data/README.txt +0 -23
- data/config/hoe.rb +0 -75
- data/config/requirements.rb +0 -15
- data/lib/msgpack/version.rb +0 -9
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
FURUHASHI Sadayuki <frsyuki _at_ users.sourceforge.jp>
|
data/ChangeLog
ADDED
File without changes
|
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
= MessagePack
|
3
|
+
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
=== Archive Installation
|
11
|
+
|
12
|
+
rake install
|
13
|
+
|
14
|
+
=== Gem Installation
|
15
|
+
|
16
|
+
gem install msgpack
|
17
|
+
|
18
|
+
|
19
|
+
== Features/Problems
|
20
|
+
|
21
|
+
|
22
|
+
== Synopsis
|
23
|
+
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Author:: frsyuki <frsyuki@users.sourceforge.jp>
|
28
|
+
Copyright:: Copyright (c) 2008-2009 frsyuki
|
29
|
+
License:: Apache License, Version 2.0
|
data/Rakefile
CHANGED
@@ -1,4 +1,133 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'rake/contrib/sshpublisher'
|
10
|
+
require 'fileutils'
|
11
|
+
include FileUtils
|
12
|
+
|
13
|
+
NAME = "msgpack"
|
14
|
+
AUTHOR = "FURUHASHI Sadayuki"
|
15
|
+
EMAIL = "frsyuki _at_ users.sourceforge.jp"
|
16
|
+
DESCRIPTION = "Binary-based efficient data interchange format."
|
17
|
+
RUBYFORGE_PROJECT = "msgpack"
|
18
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
19
|
+
BIN_FILES = %w( )
|
20
|
+
VERS = "0.3.0"
|
21
|
+
|
22
|
+
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
|
+
REV = nil
|
24
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
|
+
RDOC_OPTS = [
|
26
|
+
'--title', "#{NAME} documentation",
|
27
|
+
"--charset", "utf-8",
|
28
|
+
"--opname", "index.html",
|
29
|
+
"--line-numbers",
|
30
|
+
"--main", "README",
|
31
|
+
"--inline-source",
|
32
|
+
]
|
33
|
+
|
34
|
+
task :default => [:test]
|
35
|
+
task :package => [:clean]
|
36
|
+
|
37
|
+
Rake::TestTask.new("test") do |t|
|
38
|
+
t.libs << "test"
|
39
|
+
t.pattern = "test/**/*_test.rb"
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
spec = Gem::Specification.new do |s|
|
44
|
+
s.name = NAME
|
45
|
+
s.version = VERS
|
46
|
+
s.platform = Gem::Platform::RUBY
|
47
|
+
s.has_rdoc = true
|
48
|
+
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
|
49
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
50
|
+
s.summary = DESCRIPTION
|
51
|
+
s.description = DESCRIPTION
|
52
|
+
s.author = AUTHOR
|
53
|
+
s.email = EMAIL
|
54
|
+
s.homepage = HOMEPATH
|
55
|
+
s.executables = BIN_FILES
|
56
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
57
|
+
s.bindir = "bin"
|
58
|
+
s.require_path = "ext"
|
59
|
+
s.autorequire = ""
|
60
|
+
s.test_files = Dir["test/test_*.rb"]
|
61
|
+
|
62
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
63
|
+
#s.required_ruby_version = '>= 1.8.2'
|
64
|
+
|
65
|
+
s.files = %w(README ChangeLog Rakefile) +
|
66
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
67
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
68
|
+
Dir.glob("examples/**/*.rb") +
|
69
|
+
Dir.glob("tools/*.rb") +
|
70
|
+
Dir.glob("msgpack/*.h")
|
71
|
+
|
72
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
73
|
+
end
|
74
|
+
|
75
|
+
Rake::GemPackageTask.new(spec) do |p|
|
76
|
+
p.need_tar = true
|
77
|
+
p.gem_spec = spec
|
78
|
+
end
|
79
|
+
|
80
|
+
task :install do
|
81
|
+
name = "#{NAME}-#{VERS}.gem"
|
82
|
+
sh %{rake package}
|
83
|
+
sh %{sudo gem install pkg/#{name}}
|
84
|
+
end
|
85
|
+
|
86
|
+
task :uninstall => [:clean] do
|
87
|
+
sh %{sudo gem uninstall #{NAME}}
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
#Rake::RDocTask.new do |rdoc|
|
92
|
+
# rdoc.rdoc_dir = 'html'
|
93
|
+
# rdoc.options += RDOC_OPTS
|
94
|
+
# rdoc.template = "resh"
|
95
|
+
# #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
96
|
+
# if ENV['DOC_FILES']
|
97
|
+
# rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
98
|
+
# else
|
99
|
+
# rdoc.rdoc_files.include('README', 'ChangeLog')
|
100
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
101
|
+
# rdoc.rdoc_files.include('ext/**/*.c')
|
102
|
+
# end
|
103
|
+
#end
|
104
|
+
|
105
|
+
desc "Publish to RubyForge"
|
106
|
+
task :rubyforge => [:rdoc, :package] do
|
107
|
+
require 'rubyforge'
|
108
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'frsyuki').upload
|
109
|
+
end
|
110
|
+
|
111
|
+
desc 'Package and upload the release to rubyforge.'
|
112
|
+
task :release => [:clean, :package] do |t|
|
113
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
114
|
+
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
115
|
+
pkg = "pkg/#{NAME}-#{VERS}"
|
116
|
+
|
117
|
+
rf = RubyForge.new
|
118
|
+
puts "Logging in"
|
119
|
+
rf.login
|
120
|
+
|
121
|
+
c = rf.userconfig
|
122
|
+
# c["release_notes"] = description if description
|
123
|
+
# c["release_changes"] = changes if changes
|
124
|
+
c["preformatted"] = true
|
125
|
+
|
126
|
+
files = [
|
127
|
+
"#{pkg}.tgz",
|
128
|
+
"#{pkg}.gem"
|
129
|
+
].compact
|
130
|
+
|
131
|
+
puts "Releasing #{NAME} v. #{VERS}"
|
132
|
+
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
133
|
+
end
|
data/ext/pack.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
|
-
* MessagePack packing routine
|
2
|
+
* MessagePack for Ruby packing routine
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008 FURUHASHI Sadayuki
|
4
|
+
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -19,10 +19,10 @@
|
|
19
19
|
#include "msgpack/pack_define.h"
|
20
20
|
|
21
21
|
#define msgpack_pack_inline_func(name) \
|
22
|
-
static inline void
|
22
|
+
static inline void msgpack_pack ## name
|
23
23
|
|
24
24
|
#define msgpack_pack_inline_func_cint(name) \
|
25
|
-
static inline void
|
25
|
+
static inline void msgpack_pack ## name
|
26
26
|
|
27
27
|
#define msgpack_pack_user VALUE
|
28
28
|
|
data/ext/pack.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
|
-
* MessagePack packing routine
|
2
|
+
* MessagePack for Ruby packing routine
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008 FURUHASHI Sadayuki
|
4
|
+
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
data/ext/rbinit.c
CHANGED
data/ext/unpack.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
|
-
* MessagePack unpacking routine
|
2
|
+
* MessagePack for Ruby unpacking routine
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008 FURUHASHI Sadayuki
|
4
|
+
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -21,99 +21,99 @@
|
|
21
21
|
|
22
22
|
typedef struct {
|
23
23
|
int finished;
|
24
|
-
VALUE
|
25
|
-
}
|
24
|
+
VALUE source;
|
25
|
+
} unpack_user;
|
26
26
|
|
27
27
|
|
28
28
|
#define msgpack_unpack_struct(name) \
|
29
|
-
struct
|
29
|
+
struct template ## name
|
30
30
|
|
31
31
|
#define msgpack_unpack_func(ret, name) \
|
32
|
-
ret
|
32
|
+
ret template ## name
|
33
33
|
|
34
34
|
#define msgpack_unpack_callback(name) \
|
35
|
-
|
35
|
+
template_callback ## name
|
36
36
|
|
37
37
|
#define msgpack_unpack_object VALUE
|
38
38
|
|
39
|
-
#define msgpack_unpack_user
|
39
|
+
#define msgpack_unpack_user unpack_user
|
40
40
|
|
41
41
|
|
42
|
-
struct
|
43
|
-
typedef struct
|
42
|
+
struct template_context;
|
43
|
+
typedef struct template_context msgpack_unpack_t;
|
44
44
|
|
45
|
-
static void
|
45
|
+
static void template_init(msgpack_unpack_t* u);
|
46
46
|
|
47
|
-
static VALUE
|
47
|
+
static VALUE template_data(msgpack_unpack_t* u);
|
48
48
|
|
49
|
-
static int
|
49
|
+
static int template_execute(msgpack_unpack_t* u,
|
50
50
|
const char* data, size_t len, size_t* off);
|
51
51
|
|
52
52
|
|
53
|
-
static inline VALUE
|
53
|
+
static inline VALUE template_callback_root(unpack_user* u)
|
54
54
|
{ return Qnil; }
|
55
55
|
|
56
|
-
static inline
|
57
|
-
{
|
56
|
+
static inline int template_callback_uint8(unpack_user* u, uint8_t d, VALUE* o)
|
57
|
+
{ *o = INT2FIX(d); return 0; }
|
58
58
|
|
59
|
-
static inline
|
60
|
-
{
|
59
|
+
static inline int template_callback_uint16(unpack_user* u, uint16_t d, VALUE* o)
|
60
|
+
{ *o = INT2FIX(d); return 0; }
|
61
61
|
|
62
|
-
static inline
|
63
|
-
{
|
62
|
+
static inline int template_callback_uint32(unpack_user* u, uint32_t d, VALUE* o)
|
63
|
+
{ *o = UINT2NUM(d); return 0; }
|
64
64
|
|
65
|
-
static inline
|
66
|
-
{
|
65
|
+
static inline int template_callback_uint64(unpack_user* u, uint64_t d, VALUE* o)
|
66
|
+
{ *o = rb_ull2inum(d); return 0; }
|
67
67
|
|
68
|
-
static inline
|
69
|
-
{
|
68
|
+
static inline int template_callback_int8(unpack_user* u, int8_t d, VALUE* o)
|
69
|
+
{ *o = INT2FIX((long)d); return 0; }
|
70
70
|
|
71
|
-
static inline
|
72
|
-
{
|
71
|
+
static inline int template_callback_int16(unpack_user* u, int16_t d, VALUE* o)
|
72
|
+
{ *o = INT2FIX((long)d); return 0; }
|
73
73
|
|
74
|
-
static inline
|
75
|
-
{
|
74
|
+
static inline int template_callback_int32(unpack_user* u, int32_t d, VALUE* o)
|
75
|
+
{ *o = INT2NUM((long)d); return 0; }
|
76
76
|
|
77
|
-
static inline
|
78
|
-
{
|
77
|
+
static inline int template_callback_int64(unpack_user* u, int64_t d, VALUE* o)
|
78
|
+
{ *o = rb_ll2inum(d); return 0; }
|
79
79
|
|
80
|
-
static inline
|
81
|
-
{
|
80
|
+
static inline int template_callback_float(unpack_user* u, float d, VALUE* o)
|
81
|
+
{ *o = rb_float_new(d); return 0; }
|
82
82
|
|
83
|
-
static inline
|
84
|
-
{
|
83
|
+
static inline int template_callback_double(unpack_user* u, double d, VALUE* o)
|
84
|
+
{ *o = rb_float_new(d); return 0; }
|
85
85
|
|
86
|
-
static inline
|
87
|
-
{
|
86
|
+
static inline int template_callback_nil(unpack_user* u, VALUE* o)
|
87
|
+
{ *o = Qnil; return 0; }
|
88
88
|
|
89
|
-
static inline
|
90
|
-
{
|
89
|
+
static inline int template_callback_true(unpack_user* u, VALUE* o)
|
90
|
+
{ *o = Qtrue; return 0; }
|
91
91
|
|
92
|
-
static inline
|
93
|
-
{
|
92
|
+
static inline int template_callback_false(unpack_user* u, VALUE* o)
|
93
|
+
{ *o = Qfalse; return 0;}
|
94
94
|
|
95
|
-
static inline
|
96
|
-
{
|
95
|
+
static inline int template_callback_array(unpack_user* u, unsigned int n, VALUE* o)
|
96
|
+
{ *o = rb_ary_new2(n); return 0; }
|
97
97
|
|
98
|
-
static inline
|
99
|
-
{ rb_ary_push(*c, o); } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
|
98
|
+
static inline int template_callback_array_item(unpack_user* u, VALUE* c, VALUE o)
|
99
|
+
{ rb_ary_push(*c, o); return 0; } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
|
100
100
|
|
101
|
-
static inline
|
102
|
-
{
|
101
|
+
static inline int template_callback_map(unpack_user* u, unsigned int n, VALUE* o)
|
102
|
+
{ *o = rb_hash_new(); return 0; }
|
103
103
|
|
104
|
-
static inline
|
105
|
-
{ rb_hash_aset(*c, k, v); }
|
104
|
+
static inline int template_callback_map_item(unpack_user* u, VALUE* c, VALUE k, VALUE v)
|
105
|
+
{ rb_hash_aset(*c, k, v); return 0; }
|
106
106
|
|
107
|
-
static inline
|
108
|
-
{
|
107
|
+
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, VALUE* o)
|
108
|
+
{ *o = (l == 0) ? rb_str_new(0,0) : rb_str_substr(u->source, p - b, l); return 0; }
|
109
109
|
|
110
110
|
|
111
111
|
#include "msgpack/unpack_template.h"
|
112
112
|
|
113
113
|
|
114
114
|
#define UNPACKER(from, name) \
|
115
|
-
|
116
|
-
Data_Get_Struct(from,
|
115
|
+
msgpack_unpack_t *name = NULL; \
|
116
|
+
Data_Get_Struct(from, msgpack_unpack_t, name); \
|
117
117
|
if(name == NULL) { \
|
118
118
|
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
|
119
119
|
}
|
@@ -132,7 +132,7 @@ static void MessagePack_Unpacker_free(void* data)
|
|
132
132
|
if(data) { free(data); }
|
133
133
|
}
|
134
134
|
|
135
|
-
static void MessagePack_Unpacker_mark(
|
135
|
+
static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
|
136
136
|
{
|
137
137
|
unsigned int i;
|
138
138
|
for(i=0; i < mp->top; ++i) {
|
@@ -144,7 +144,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpacker *mp)
|
|
144
144
|
static VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
145
145
|
{
|
146
146
|
VALUE obj;
|
147
|
-
|
147
|
+
msgpack_unpack_t* mp = ALLOC_N(msgpack_unpack_t, 1);
|
148
148
|
obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark,
|
149
149
|
MessagePack_Unpacker_free, mp);
|
150
150
|
return obj;
|
@@ -153,9 +153,9 @@ static VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
|
153
153
|
static VALUE MessagePack_Unpacker_reset(VALUE self)
|
154
154
|
{
|
155
155
|
UNPACKER(self, mp);
|
156
|
-
|
157
|
-
|
158
|
-
mp->user =
|
156
|
+
template_init(mp);
|
157
|
+
unpack_user u = {0, Qnil};
|
158
|
+
mp->user = u;
|
159
159
|
return self;
|
160
160
|
}
|
161
161
|
|
@@ -169,21 +169,20 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
|
|
169
169
|
{
|
170
170
|
VALUE self = ((VALUE*)args)[0];
|
171
171
|
VALUE data = ((VALUE*)args)[1];
|
172
|
-
VALUE off = ((VALUE*)args)[2];
|
173
172
|
|
174
173
|
UNPACKER(self, mp);
|
175
|
-
size_t from = NUM2UINT(
|
174
|
+
size_t from = NUM2UINT(((VALUE*)args)[2]);
|
176
175
|
char* dptr = RSTRING_PTR(data);
|
177
|
-
long dlen =
|
176
|
+
long dlen = FIX2LONG(((VALUE*)args)[3]);
|
178
177
|
int ret;
|
179
178
|
|
180
179
|
if(from >= dlen) {
|
181
180
|
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
|
182
181
|
}
|
183
182
|
|
184
|
-
mp->user.
|
185
|
-
ret =
|
186
|
-
mp->user.
|
183
|
+
mp->user.source = data;
|
184
|
+
ret = template_execute(mp, dptr, (size_t)dlen, &from);
|
185
|
+
mp->user.source = Qnil;
|
187
186
|
|
188
187
|
if(ret < 0) {
|
189
188
|
rb_raise(eUnpackError, "parse error.");
|
@@ -206,17 +205,24 @@ static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
|
|
206
205
|
#endif
|
207
206
|
}
|
208
207
|
|
209
|
-
static VALUE
|
208
|
+
static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
|
209
|
+
VALUE off, VALUE limit)
|
210
210
|
{
|
211
211
|
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
212
212
|
rb_gc_disable();
|
213
|
-
VALUE args[
|
213
|
+
VALUE args[4] = {self, data, off, limit};
|
214
214
|
VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
|
215
215
|
MessagePack_Unpacker_execute_rescue, Qnil);
|
216
216
|
rb_gc_enable();
|
217
217
|
return ret;
|
218
218
|
}
|
219
219
|
|
220
|
+
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
221
|
+
{
|
222
|
+
return MessagePack_Unpacker_execute_limit(self, data, off,
|
223
|
+
LONG2FIX(RSTRING_LEN(data)));
|
224
|
+
}
|
225
|
+
|
220
226
|
static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
221
227
|
{
|
222
228
|
UNPACKER(self, mp);
|
@@ -229,23 +235,23 @@ static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
|
229
235
|
static VALUE MessagePack_Unpacker_data(VALUE self)
|
230
236
|
{
|
231
237
|
UNPACKER(self, mp);
|
232
|
-
return
|
238
|
+
return template_data(mp);
|
233
239
|
}
|
234
240
|
|
235
241
|
|
236
242
|
static VALUE MessagePack_unpack_impl(VALUE args)
|
237
243
|
{
|
238
|
-
|
244
|
+
msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
|
239
245
|
VALUE data = ((VALUE*)args)[1];
|
240
246
|
|
241
247
|
size_t from = 0;
|
242
248
|
char* dptr = RSTRING_PTR(data);
|
243
|
-
long dlen =
|
249
|
+
long dlen = FIX2LONG(((VALUE*)args)[2]);
|
244
250
|
int ret;
|
245
251
|
|
246
|
-
mp->user.
|
247
|
-
ret =
|
248
|
-
mp->user.
|
252
|
+
mp->user.source = data;
|
253
|
+
ret = template_execute(mp, dptr, (size_t)dlen, &from);
|
254
|
+
mp->user.source = Qnil;
|
249
255
|
|
250
256
|
if(ret < 0) {
|
251
257
|
rb_raise(eUnpackError, "parse error.");
|
@@ -255,7 +261,7 @@ static VALUE MessagePack_unpack_impl(VALUE args)
|
|
255
261
|
if(from < dlen) {
|
256
262
|
rb_raise(eUnpackError, "extra bytes.");
|
257
263
|
}
|
258
|
-
return
|
264
|
+
return template_data(mp);
|
259
265
|
}
|
260
266
|
}
|
261
267
|
|
@@ -269,22 +275,30 @@ static VALUE MessagePack_unpack_rescue(VALUE args)
|
|
269
275
|
#endif
|
270
276
|
}
|
271
277
|
|
272
|
-
static VALUE
|
278
|
+
static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
|
273
279
|
{
|
274
280
|
CHECK_STRING_TYPE(data);
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
281
|
+
|
282
|
+
msgpack_unpack_t mp;
|
283
|
+
template_init(&mp);
|
284
|
+
unpack_user u = {0, Qnil};
|
285
|
+
mp.user = u;
|
279
286
|
|
280
287
|
rb_gc_disable();
|
281
|
-
VALUE args[
|
288
|
+
VALUE args[3] = {(VALUE)&mp, data, limit};
|
282
289
|
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
283
290
|
MessagePack_unpack_rescue, Qnil);
|
284
291
|
rb_gc_enable();
|
292
|
+
|
285
293
|
return ret;
|
286
294
|
}
|
287
295
|
|
296
|
+
static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
297
|
+
{
|
298
|
+
return MessagePack_unpack_limit(self, data,
|
299
|
+
LONG2FIX(RSTRING_LEN(data)));
|
300
|
+
}
|
301
|
+
|
288
302
|
|
289
303
|
void Init_msgpack_unpack(VALUE mMessagePack)
|
290
304
|
{
|
@@ -293,10 +307,12 @@ void Init_msgpack_unpack(VALUE mMessagePack)
|
|
293
307
|
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
294
308
|
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
|
295
309
|
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
|
310
|
+
rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
|
296
311
|
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
|
297
312
|
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
|
298
313
|
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
|
299
314
|
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
|
315
|
+
rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
|
300
316
|
}
|
301
317
|
|
302
318
|
|