msgpack 0.2.2-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/Makefile +156 -0
- data/ext/extconf.rb +4 -0
- data/ext/msgpack.so +0 -0
- data/ext/pack.c +165 -0
- data/ext/pack.h +26 -0
- data/ext/pack.o +0 -0
- data/ext/rbinit.c +29 -0
- data/ext/rbinit.o +0 -0
- data/ext/unpack.c +302 -0
- data/ext/unpack.h +26 -0
- data/ext/unpack.o +0 -0
- data/lib/msgpack/version.rb +9 -0
- metadata +66 -0
data/ext/Makefile
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = c:/MinGW/lib/ruby/1.8/i386-mingw32
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir);$(topdir);$(hdrdir)
|
10
|
+
|
11
|
+
DESTDIR = c:
|
12
|
+
exec_prefix = $(prefix)
|
13
|
+
prefix = $(DESTDIR)/MinGW
|
14
|
+
sharedstatedir = $(prefix)/com
|
15
|
+
mandir = $(datarootdir)/man
|
16
|
+
psdir = $(docdir)
|
17
|
+
oldincludedir = $(DESTDIR)/usr/include
|
18
|
+
localedir = $(datarootdir)/locale
|
19
|
+
bindir = $(exec_prefix)/bin
|
20
|
+
libexecdir = $(exec_prefix)/libexec
|
21
|
+
sitedir = $(libdir)/ruby/site_ruby
|
22
|
+
htmldir = $(docdir)
|
23
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
24
|
+
includedir = $(prefix)/include
|
25
|
+
infodir = $(datarootdir)/info
|
26
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
27
|
+
sysconfdir = $(prefix)/etc
|
28
|
+
libdir = $(exec_prefix)/lib
|
29
|
+
sbindir = $(exec_prefix)/sbin
|
30
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
31
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
32
|
+
dvidir = $(docdir)
|
33
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
34
|
+
datarootdir = $(prefix)/share
|
35
|
+
pdfdir = $(docdir)
|
36
|
+
archdir = $(rubylibdir)/$(arch)
|
37
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
38
|
+
datadir = $(datarootdir)
|
39
|
+
localstatedir = $(prefix)/var
|
40
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
41
|
+
|
42
|
+
CC = gcc
|
43
|
+
LIBRUBY = lib$(LIBRUBY_SO).a
|
44
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
45
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
46
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
47
|
+
|
48
|
+
RUBY_EXTCONF_H =
|
49
|
+
CFLAGS = -g -O2 $(cflags) -I.. -Wall -O4
|
50
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
51
|
+
DEFS =
|
52
|
+
CPPFLAGS = $(DEFS) $(cppflags)
|
53
|
+
CXXFLAGS = $(CFLAGS)
|
54
|
+
ldflags = -L.
|
55
|
+
dldflags = -Wl,--enable-auto-image-base,--enable-auto-import,--export-all
|
56
|
+
archflag =
|
57
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
58
|
+
LDSHARED = gcc -shared -s
|
59
|
+
AR = ar
|
60
|
+
EXEEXT = .exe
|
61
|
+
|
62
|
+
RUBY_INSTALL_NAME = ruby
|
63
|
+
RUBY_SO_NAME = msvcrt-ruby18
|
64
|
+
arch = i386-mingw32
|
65
|
+
sitearch = i386-msvcrt
|
66
|
+
ruby_version = 1.8
|
67
|
+
ruby = c:/MinGW/bin/ruby
|
68
|
+
RUBY = $(ruby)
|
69
|
+
RM = rm -f
|
70
|
+
MAKEDIRS = mkdir -p
|
71
|
+
INSTALL = /bin/install -c
|
72
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
73
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
74
|
+
COPY = cp
|
75
|
+
|
76
|
+
#### End of system configuration section. ####
|
77
|
+
|
78
|
+
preload =
|
79
|
+
|
80
|
+
libpath = . $(libdir)
|
81
|
+
LIBPATH = -L. -L$(libdir)
|
82
|
+
DEFFILE =
|
83
|
+
|
84
|
+
CLEANFILES = mkmf.log
|
85
|
+
DISTCLEANFILES =
|
86
|
+
|
87
|
+
extout =
|
88
|
+
extout_prefix =
|
89
|
+
target_prefix =
|
90
|
+
LOCAL_LIBS =
|
91
|
+
LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lwsock32
|
92
|
+
SRCS = pack.c rbinit.c unpack.c
|
93
|
+
OBJS = pack.o rbinit.o unpack.o
|
94
|
+
TARGET = msgpack
|
95
|
+
DLLIB = $(TARGET).so
|
96
|
+
EXTSTATIC =
|
97
|
+
STATIC_LIB =
|
98
|
+
|
99
|
+
BINDIR = $(bindir)
|
100
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
101
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
102
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
103
|
+
|
104
|
+
TARGET_SO = $(DLLIB)
|
105
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
106
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
107
|
+
|
108
|
+
all: $(DLLIB)
|
109
|
+
static: $(STATIC_LIB)
|
110
|
+
|
111
|
+
clean:
|
112
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
113
|
+
|
114
|
+
distclean: clean
|
115
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
116
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
117
|
+
|
118
|
+
realclean: distclean
|
119
|
+
install: install-so install-rb
|
120
|
+
|
121
|
+
install-so: $(RUBYARCHDIR)
|
122
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
123
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
124
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
125
|
+
install-rb: pre-install-rb install-rb-default
|
126
|
+
install-rb-default: pre-install-rb-default
|
127
|
+
pre-install-rb: Makefile
|
128
|
+
pre-install-rb-default: Makefile
|
129
|
+
$(RUBYARCHDIR):
|
130
|
+
$(MAKEDIRS) $@
|
131
|
+
|
132
|
+
site-install: site-install-so site-install-rb
|
133
|
+
site-install-so: install-so
|
134
|
+
site-install-rb: install-rb
|
135
|
+
|
136
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .o
|
137
|
+
|
138
|
+
.cc.o:
|
139
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
140
|
+
|
141
|
+
.cxx.o:
|
142
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
143
|
+
|
144
|
+
.cpp.o:
|
145
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
146
|
+
|
147
|
+
.c.o:
|
148
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
149
|
+
|
150
|
+
$(DLLIB): $(OBJS)
|
151
|
+
@-$(RM) $@
|
152
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
$(OBJS): ruby.h defines.h
|
data/ext/extconf.rb
ADDED
data/ext/msgpack.so
ADDED
Binary file
|
data/ext/pack.c
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack packing routine for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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
|
+
#include "ruby.h"
|
19
|
+
#include "msgpack/pack_define.h"
|
20
|
+
|
21
|
+
#define msgpack_pack_inline_func(name) \
|
22
|
+
static inline void msgpack_pack_##name
|
23
|
+
|
24
|
+
#define msgpack_pack_inline_func_cint(name) \
|
25
|
+
static inline void msgpack_pack_##name
|
26
|
+
|
27
|
+
#define msgpack_pack_user VALUE
|
28
|
+
|
29
|
+
#define msgpack_pack_append_buffer(user, buf, len) \
|
30
|
+
rb_str_buf_cat(user, (const void*)buf, len)
|
31
|
+
|
32
|
+
#include "msgpack/pack_template.h"
|
33
|
+
|
34
|
+
|
35
|
+
#ifndef RUBY_VM
|
36
|
+
#include "st.h" // ruby hash
|
37
|
+
#endif
|
38
|
+
|
39
|
+
static ID s_to_msgpack;
|
40
|
+
|
41
|
+
#define ARG_BUFFER(name, argc, argv) \
|
42
|
+
VALUE name; \
|
43
|
+
if(argc == 1) { \
|
44
|
+
name = argv[0]; \
|
45
|
+
} else if(argc == 0) { \
|
46
|
+
name = rb_str_buf_new(0); \
|
47
|
+
} else { \
|
48
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); \
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE MessagePack_NilClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
52
|
+
{
|
53
|
+
ARG_BUFFER(out, argc, argv);
|
54
|
+
msgpack_pack_nil(out);
|
55
|
+
return out;
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE MessagePack_TrueClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
59
|
+
{
|
60
|
+
ARG_BUFFER(out, argc, argv);
|
61
|
+
msgpack_pack_true(out);
|
62
|
+
return out;
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
66
|
+
{
|
67
|
+
ARG_BUFFER(out, argc, argv);
|
68
|
+
msgpack_pack_false(out);
|
69
|
+
return out;
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
74
|
+
{
|
75
|
+
ARG_BUFFER(out, argc, argv);
|
76
|
+
msgpack_pack_long(out, FIX2LONG(self));
|
77
|
+
return out;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
#ifndef RBIGNUM_SIGN // Ruby 1.8
|
82
|
+
#define RBIGNUM_SIGN(b) (RBIGNUM(b)->sign)
|
83
|
+
#endif
|
84
|
+
|
85
|
+
static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
86
|
+
{
|
87
|
+
ARG_BUFFER(out, argc, argv);
|
88
|
+
// FIXME bignum
|
89
|
+
if(RBIGNUM_SIGN(self)) { // positive
|
90
|
+
msgpack_pack_uint64(out, rb_big2ull(self));
|
91
|
+
} else { // negative
|
92
|
+
msgpack_pack_int64(out, rb_big2ll(self));
|
93
|
+
}
|
94
|
+
return out;
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
|
98
|
+
{
|
99
|
+
ARG_BUFFER(out, argc, argv);
|
100
|
+
msgpack_pack_double(out, rb_num2dbl(self));
|
101
|
+
return out;
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
|
105
|
+
{
|
106
|
+
ARG_BUFFER(out, argc, argv);
|
107
|
+
msgpack_pack_raw(out, RSTRING_LEN(self));
|
108
|
+
msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
|
109
|
+
return out;
|
110
|
+
}
|
111
|
+
|
112
|
+
static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
|
113
|
+
{
|
114
|
+
ARG_BUFFER(out, argc, argv);
|
115
|
+
msgpack_pack_array(out, RARRAY_LEN(self));
|
116
|
+
VALUE* p = RARRAY_PTR(self);
|
117
|
+
VALUE* const pend = p + RARRAY_LEN(self);
|
118
|
+
for(;p != pend; ++p) {
|
119
|
+
rb_funcall(*p, s_to_msgpack, 1, out);
|
120
|
+
}
|
121
|
+
return out;
|
122
|
+
}
|
123
|
+
|
124
|
+
#ifndef RHASH_SIZE // Ruby 1.8
|
125
|
+
#define RHASH_SIZE(h) (RHASH(h)->tbl ? RHASH(h)->tbl->num_entries : 0)
|
126
|
+
#endif
|
127
|
+
|
128
|
+
static int MessagePack_Hash_to_msgpack_foreach(VALUE key, VALUE value, VALUE out)
|
129
|
+
{
|
130
|
+
if (key == Qundef) { return ST_CONTINUE; }
|
131
|
+
rb_funcall(key, s_to_msgpack, 1, out);
|
132
|
+
rb_funcall(value, s_to_msgpack, 1, out);
|
133
|
+
return ST_CONTINUE;
|
134
|
+
}
|
135
|
+
|
136
|
+
static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
|
137
|
+
{
|
138
|
+
ARG_BUFFER(out, argc, argv);
|
139
|
+
msgpack_pack_map(out, RHASH_SIZE(self));
|
140
|
+
rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
|
141
|
+
return out;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
static VALUE MessagePack_pack(VALUE self, VALUE data)
|
146
|
+
{
|
147
|
+
return rb_funcall(data, s_to_msgpack, 0);
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
void Init_msgpack_pack(VALUE mMessagePack)
|
152
|
+
{
|
153
|
+
s_to_msgpack = rb_intern("to_msgpack");
|
154
|
+
rb_define_method_id(rb_cNilClass, s_to_msgpack, MessagePack_NilClass_to_msgpack, -1);
|
155
|
+
rb_define_method_id(rb_cTrueClass, s_to_msgpack, MessagePack_TrueClass_to_msgpack, -1);
|
156
|
+
rb_define_method_id(rb_cFalseClass, s_to_msgpack, MessagePack_FalseClass_to_msgpack, -1);
|
157
|
+
rb_define_method_id(rb_cFixnum, s_to_msgpack, MessagePack_Fixnum_to_msgpack, -1);
|
158
|
+
rb_define_method_id(rb_cBignum, s_to_msgpack, MessagePack_Bignum_to_msgpack, -1);
|
159
|
+
rb_define_method_id(rb_cFloat, s_to_msgpack, MessagePack_Float_to_msgpack, -1);
|
160
|
+
rb_define_method_id(rb_cString, s_to_msgpack, MessagePack_String_to_msgpack, -1);
|
161
|
+
rb_define_method_id(rb_cArray, s_to_msgpack, MessagePack_Array_to_msgpack, -1);
|
162
|
+
rb_define_method_id(rb_cHash, s_to_msgpack, MessagePack_Hash_to_msgpack, -1);
|
163
|
+
rb_define_module_function(mMessagePack, "pack", MessagePack_pack, 1);
|
164
|
+
}
|
165
|
+
|
data/ext/pack.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack packing routine for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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 PACK_H__
|
19
|
+
#define PACK_H__
|
20
|
+
|
21
|
+
#include "ruby.h"
|
22
|
+
|
23
|
+
void Init_msgpack_pack(VALUE mMessagePack);
|
24
|
+
|
25
|
+
#endif /* pack.h */
|
26
|
+
|
data/ext/pack.o
ADDED
Binary file
|
data/ext/rbinit.c
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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
|
+
#include "pack.h"
|
19
|
+
#include "unpack.h"
|
20
|
+
|
21
|
+
static VALUE mMessagePack;
|
22
|
+
|
23
|
+
void Init_msgpack(void)
|
24
|
+
{
|
25
|
+
mMessagePack = rb_define_module("MessagePack");
|
26
|
+
Init_msgpack_unpack(mMessagePack);
|
27
|
+
Init_msgpack_pack(mMessagePack);
|
28
|
+
}
|
29
|
+
|
data/ext/rbinit.o
ADDED
Binary file
|
data/ext/unpack.c
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack unpacking routine for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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
|
+
#include "ruby.h"
|
19
|
+
#include "msgpack/unpack_define.h"
|
20
|
+
|
21
|
+
|
22
|
+
typedef struct {
|
23
|
+
int finished;
|
24
|
+
VALUE origstr;
|
25
|
+
} msgpack_unpack_context;
|
26
|
+
|
27
|
+
|
28
|
+
#define msgpack_unpack_struct(name) \
|
29
|
+
struct msgpack_unpacker_##name
|
30
|
+
|
31
|
+
#define msgpack_unpack_func(ret, name) \
|
32
|
+
ret msgpack_unpacker_##name
|
33
|
+
|
34
|
+
#define msgpack_unpack_callback(name) \
|
35
|
+
template_callback_##name
|
36
|
+
|
37
|
+
#define msgpack_unpack_object VALUE
|
38
|
+
|
39
|
+
#define msgpack_unpack_user msgpack_unpack_context
|
40
|
+
|
41
|
+
|
42
|
+
struct msgpack_unpacker_context;
|
43
|
+
typedef struct msgpack_unpacker_context msgpack_unpacker;
|
44
|
+
|
45
|
+
static void msgpack_unpacker_init(msgpack_unpacker* ctx);
|
46
|
+
|
47
|
+
static VALUE msgpack_unpacker_data(msgpack_unpacker* ctx);
|
48
|
+
|
49
|
+
static int msgpack_unpacker_execute(msgpack_unpacker* ctx,
|
50
|
+
const char* data, size_t len, size_t* off);
|
51
|
+
|
52
|
+
|
53
|
+
static inline VALUE template_callback_init(msgpack_unpack_context* x)
|
54
|
+
{ return Qnil; }
|
55
|
+
|
56
|
+
static inline VALUE template_callback_uint8(msgpack_unpack_context* x, uint8_t d)
|
57
|
+
{ return INT2FIX(d); }
|
58
|
+
|
59
|
+
static inline VALUE template_callback_uint16(msgpack_unpack_context* x, uint16_t d)
|
60
|
+
{ return INT2FIX(d); }
|
61
|
+
|
62
|
+
static inline VALUE template_callback_uint32(msgpack_unpack_context* x, uint32_t d)
|
63
|
+
{ return UINT2NUM(d); }
|
64
|
+
|
65
|
+
static inline VALUE template_callback_uint64(msgpack_unpack_context* x, uint64_t d)
|
66
|
+
{ return rb_ull2inum(d); }
|
67
|
+
|
68
|
+
static inline VALUE template_callback_int8(msgpack_unpack_context* x, int8_t d)
|
69
|
+
{ return INT2FIX((long)d); }
|
70
|
+
|
71
|
+
static inline VALUE template_callback_int16(msgpack_unpack_context* x, int16_t d)
|
72
|
+
{ return INT2FIX((long)d); }
|
73
|
+
|
74
|
+
static inline VALUE template_callback_int32(msgpack_unpack_context* x, int32_t d)
|
75
|
+
{ return INT2NUM((long)d); }
|
76
|
+
|
77
|
+
static inline VALUE template_callback_int64(msgpack_unpack_context* x, int64_t d)
|
78
|
+
{ return rb_ll2inum(d); }
|
79
|
+
|
80
|
+
static inline VALUE template_callback_float(msgpack_unpack_context* x, float d)
|
81
|
+
{ return rb_float_new(d); }
|
82
|
+
|
83
|
+
static inline VALUE template_callback_double(msgpack_unpack_context* x, double d)
|
84
|
+
{ return rb_float_new(d); }
|
85
|
+
|
86
|
+
static inline VALUE template_callback_nil(msgpack_unpack_context* x)
|
87
|
+
{ return Qnil; }
|
88
|
+
|
89
|
+
static inline VALUE template_callback_true(msgpack_unpack_context* x)
|
90
|
+
{ return Qtrue; }
|
91
|
+
|
92
|
+
static inline VALUE template_callback_false(msgpack_unpack_context* x)
|
93
|
+
{ return Qfalse; }
|
94
|
+
|
95
|
+
static inline VALUE template_callback_array(msgpack_unpack_context* x, unsigned int n)
|
96
|
+
{ return rb_ary_new2(n); }
|
97
|
+
|
98
|
+
static inline void template_callback_array_item(msgpack_unpack_context* x, VALUE* c, VALUE o)
|
99
|
+
{ rb_ary_push(*c, o); } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
|
100
|
+
|
101
|
+
static inline VALUE template_callback_map(msgpack_unpack_context* x, unsigned int n)
|
102
|
+
{ return rb_hash_new(); }
|
103
|
+
|
104
|
+
static inline void template_callback_map_item(msgpack_unpack_context* x, VALUE* c, VALUE k, VALUE v)
|
105
|
+
{ rb_hash_aset(*c, k, v); }
|
106
|
+
|
107
|
+
static inline VALUE template_callback_raw(msgpack_unpack_context* x, const char* b, const char* p, unsigned int l)
|
108
|
+
{ return l == 0 ? rb_str_new(0,0) : rb_str_substr(x->origstr, p - b, l); }
|
109
|
+
|
110
|
+
|
111
|
+
#include "msgpack/unpack_template.h"
|
112
|
+
|
113
|
+
|
114
|
+
#define UNPACKER(from, name) \
|
115
|
+
msgpack_unpacker *name = NULL; \
|
116
|
+
Data_Get_Struct(from, msgpack_unpacker, name); \
|
117
|
+
if(name == NULL) { \
|
118
|
+
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
|
119
|
+
}
|
120
|
+
|
121
|
+
#define CHECK_STRING_TYPE(value) \
|
122
|
+
value = rb_check_string_type(value); \
|
123
|
+
if( NIL_P(value) ) { \
|
124
|
+
rb_raise(rb_eTypeError, "instance of String needed"); \
|
125
|
+
}
|
126
|
+
|
127
|
+
static VALUE cUnpacker;
|
128
|
+
static VALUE eUnpackError;
|
129
|
+
|
130
|
+
static void MessagePack_Unpacker_free(void* data)
|
131
|
+
{
|
132
|
+
if(data) { free(data); }
|
133
|
+
}
|
134
|
+
|
135
|
+
static void MessagePack_Unpacker_mark(msgpack_unpacker *mp)
|
136
|
+
{
|
137
|
+
unsigned int i;
|
138
|
+
for(i=0; i < mp->top; ++i) {
|
139
|
+
rb_gc_mark(mp->stack[i].obj);
|
140
|
+
rb_gc_mark(mp->stack[i].map_key);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
static VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
145
|
+
{
|
146
|
+
VALUE obj;
|
147
|
+
msgpack_unpacker* mp = ALLOC_N(msgpack_unpacker, 1);
|
148
|
+
obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark,
|
149
|
+
MessagePack_Unpacker_free, mp);
|
150
|
+
return obj;
|
151
|
+
}
|
152
|
+
|
153
|
+
static VALUE MessagePack_Unpacker_reset(VALUE self)
|
154
|
+
{
|
155
|
+
UNPACKER(self, mp);
|
156
|
+
msgpack_unpacker_init(mp);
|
157
|
+
msgpack_unpack_context ctx = {0, Qnil};
|
158
|
+
mp->user = ctx;
|
159
|
+
return self;
|
160
|
+
}
|
161
|
+
|
162
|
+
static VALUE MessagePack_Unpacker_initialize(VALUE self)
|
163
|
+
{
|
164
|
+
return MessagePack_Unpacker_reset(self);
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
|
169
|
+
{
|
170
|
+
VALUE self = ((VALUE*)args)[0];
|
171
|
+
VALUE data = ((VALUE*)args)[1];
|
172
|
+
VALUE off = ((VALUE*)args)[2];
|
173
|
+
|
174
|
+
UNPACKER(self, mp);
|
175
|
+
size_t from = NUM2UINT(off);
|
176
|
+
char* dptr = RSTRING_PTR(data);
|
177
|
+
long dlen = RSTRING_LEN(data);
|
178
|
+
int ret;
|
179
|
+
|
180
|
+
if(from >= dlen) {
|
181
|
+
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
|
182
|
+
}
|
183
|
+
|
184
|
+
mp->user.origstr = data;
|
185
|
+
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
|
186
|
+
mp->user.origstr = Qnil;
|
187
|
+
|
188
|
+
if(ret < 0) {
|
189
|
+
rb_raise(eUnpackError, "parse error.");
|
190
|
+
} else if(ret > 0) {
|
191
|
+
mp->user.finished = 1;
|
192
|
+
return ULONG2NUM(from);
|
193
|
+
} else {
|
194
|
+
mp->user.finished = 0;
|
195
|
+
return ULONG2NUM(from);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
|
200
|
+
{
|
201
|
+
rb_gc_enable();
|
202
|
+
#ifdef RUBY_VM
|
203
|
+
rb_exc_raise(rb_errinfo());
|
204
|
+
#else
|
205
|
+
rb_exc_raise(ruby_errinfo);
|
206
|
+
#endif
|
207
|
+
}
|
208
|
+
|
209
|
+
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
210
|
+
{
|
211
|
+
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
212
|
+
rb_gc_disable();
|
213
|
+
VALUE args[3] = {self, data, off};
|
214
|
+
VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
|
215
|
+
MessagePack_Unpacker_execute_rescue, Qnil);
|
216
|
+
rb_gc_enable();
|
217
|
+
return ret;
|
218
|
+
}
|
219
|
+
|
220
|
+
static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
221
|
+
{
|
222
|
+
UNPACKER(self, mp);
|
223
|
+
if(mp->user.finished) {
|
224
|
+
return Qtrue;
|
225
|
+
}
|
226
|
+
return Qfalse;
|
227
|
+
}
|
228
|
+
|
229
|
+
static VALUE MessagePack_Unpacker_data(VALUE self)
|
230
|
+
{
|
231
|
+
UNPACKER(self, mp);
|
232
|
+
return msgpack_unpacker_data(mp);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
static VALUE MessagePack_unpack_impl(VALUE args)
|
237
|
+
{
|
238
|
+
msgpack_unpacker* mp = (msgpack_unpacker*)((VALUE*)args)[0];
|
239
|
+
VALUE data = ((VALUE*)args)[1];
|
240
|
+
|
241
|
+
size_t from = 0;
|
242
|
+
char* dptr = RSTRING_PTR(data);
|
243
|
+
long dlen = RSTRING_LEN(data);
|
244
|
+
int ret;
|
245
|
+
|
246
|
+
mp->user.origstr = data;
|
247
|
+
ret = msgpack_unpacker_execute(mp, dptr, (size_t)dlen, &from);
|
248
|
+
mp->user.origstr = Qnil;
|
249
|
+
|
250
|
+
if(ret < 0) {
|
251
|
+
rb_raise(eUnpackError, "parse error.");
|
252
|
+
} else if(ret == 0) {
|
253
|
+
rb_raise(eUnpackError, "insufficient bytes.");
|
254
|
+
} else {
|
255
|
+
if(from < dlen) {
|
256
|
+
rb_raise(eUnpackError, "extra bytes.");
|
257
|
+
}
|
258
|
+
return msgpack_unpacker_data(mp);
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
static VALUE MessagePack_unpack_rescue(VALUE args)
|
263
|
+
{
|
264
|
+
rb_gc_enable();
|
265
|
+
#ifdef RUBY_VM
|
266
|
+
rb_exc_raise(rb_errinfo());
|
267
|
+
#else
|
268
|
+
rb_exc_raise(ruby_errinfo);
|
269
|
+
#endif
|
270
|
+
}
|
271
|
+
|
272
|
+
static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
273
|
+
{
|
274
|
+
CHECK_STRING_TYPE(data);
|
275
|
+
msgpack_unpacker mp;
|
276
|
+
msgpack_unpacker_init(&mp);
|
277
|
+
msgpack_unpack_context ctx = {0, Qnil};
|
278
|
+
mp.user = ctx;
|
279
|
+
|
280
|
+
rb_gc_disable();
|
281
|
+
VALUE args[2] = {(VALUE)&mp, data};
|
282
|
+
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
283
|
+
MessagePack_unpack_rescue, Qnil);
|
284
|
+
rb_gc_enable();
|
285
|
+
return ret;
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
void Init_msgpack_unpack(VALUE mMessagePack)
|
290
|
+
{
|
291
|
+
eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
|
292
|
+
cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
|
293
|
+
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
294
|
+
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
|
295
|
+
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
|
296
|
+
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
|
297
|
+
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
|
298
|
+
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
|
299
|
+
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
|
300
|
+
}
|
301
|
+
|
302
|
+
|
data/ext/unpack.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack unpacking routine for Ruby
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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 UNPACK_H__
|
19
|
+
#define UNPACK_H__
|
20
|
+
|
21
|
+
#include "ruby.h"
|
22
|
+
|
23
|
+
void Init_msgpack_unpack(VALUE mMessagePack);
|
24
|
+
|
25
|
+
#endif /* unpack.h */
|
26
|
+
|
data/ext/unpack.o
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: msgpack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: mswin32
|
6
|
+
authors:
|
7
|
+
- FURUHASHI Sadayuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-11 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: frsyuki@users.sourceforge.jp
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/msgpack
|
26
|
+
- lib/msgpack/version.rb
|
27
|
+
- ext/extconf.rb
|
28
|
+
- ext/Makefile
|
29
|
+
- ext/msgpack.so
|
30
|
+
- ext/pack.c
|
31
|
+
- ext/pack.h
|
32
|
+
- ext/pack.o
|
33
|
+
- ext/rbinit.c
|
34
|
+
- ext/rbinit.o
|
35
|
+
- ext/unpack.c
|
36
|
+
- ext/unpack.h
|
37
|
+
- ext/unpack.o
|
38
|
+
has_rdoc: false
|
39
|
+
homepage: https://launchpad.net/msgpack/
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
- ext
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: MessagePack
|
65
|
+
test_files: []
|
66
|
+
|