Compare commits

...

20 Commits

Author SHA1 Message Date
frsyuki
7a0acf2838 Merge branch 'master' of frsyuki@git.sourceforge.jp:/gitroot/msgpack/msgpack 2010-03-01 18:00:16 +09:00
frsyuki
27787505e0 strict-aliasing rule 2 2010-02-27 02:37:01 +09:00
frsyuki
2c8048115d Merge branch 'master' of frsyuki@git.sourceforge.jp:/gitroot/msgpack/msgpack 2010-02-18 14:31:41 +09:00
frsyuki
7df1780853 ruby: makegem.sh 2010-02-06 21:31:16 +09:00
frsyuki
d5609f3207 ruby: makegem.sh 2010-02-06 21:28:27 +09:00
frsyuki
cd10fbc1fe removed symbolic links 2010-02-06 20:09:41 +09:00
firewood
ca0b085d15 add a blanc after Japanese comment 2010-02-05 22:50:05 +09:00
firewood
9a034234d8 add vc2005 project file. 2010-02-05 22:49:28 +09:00
firewood
66ef6c9e4c undef after including winsock2.h. 2010-02-05 22:49:00 +09:00
frsyuki
7df60b259b MSVC2005 compatibility (@hotpepsi++) 2010-02-02 10:52:42 +09:00
frsyuki
34b3bbc883 ruby: add Unpacker#each 2010-01-29 17:23:48 +09:00
Naoki INADA
e02d20dd74 replace setup by setup_dev. 2010-01-25 20:52:48 +09:00
Naoki INADA
1a11608f1f cythoning *.pyx when sdist. 2010-01-25 20:51:55 +09:00
Naoki INADA
9e2c9d7812 Tiny fix in README 2010-01-25 12:21:46 +09:00
Kazuki Ohta
404a393315 c, cpp: fix test problem
- using LDADD instead of LDFLAGS
- fix include path in test.cpp
2010-01-21 21:55:06 +09:00
frsyuki
c69092e110 configure.in: fix message 2010-01-21 17:25:32 +09:00
frsyuki
ebc0eeac79 c,cpp: 0.4.1 2010-01-20 15:17:33 +09:00
frsyuki
2b72f35c32 configure.in: show error message if __sync_* atomic operations are not supported 2010-01-20 14:49:51 +09:00
frsyuki
d8212ad620 strict-aliasing rule 2010-01-20 14:46:54 +09:00
Kazuki Ohta
1066bb38a8 add tests for multi[map, set] and tr1::unordered_[multi][map, set] 2010-01-16 02:03:11 +09:00
58 changed files with 792 additions and 498 deletions

View File

@@ -1,4 +1,4 @@
Copyright (C) 2008-2009 FURUHASHI Sadayuki Copyright (C) 2008-2010 FURUHASHI Sadayuki
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

8
README
View File

@@ -19,12 +19,12 @@ Binary-based efficient data interchange format.
$ make $ make
$ sudo make install $ sudo make install
To install Ruby binding, run ./gengem.sh script on ruby/ directory and install To install Ruby binding, run ./makegem.sh script on ruby/ directory and install
generated gem package. generated gem package.
$ cd ruby $ cd ruby
$ ./gengem.sh $ ./makegem.sh
$ gem install gem/pkg/msgpack-*.gem $ gem install msgpack-*.gem
*Usage *Usage
@@ -54,7 +54,7 @@ Binary-based efficient data interchange format.
API Document is available at http://msgpack.sourceforge.jp/. API Document is available at http://msgpack.sourceforge.jp/.
Copyright (C) 2008-2009 FURUHASHI Sadayuki Copyright (C) 2008-2010 FURUHASHI Sadayuki
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@@ -23,6 +23,6 @@ check_PROGRAMS = \
msgpackc_test_SOURCES = test.cpp msgpackc_test_SOURCES = test.cpp
msgpackc_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c msgpackc_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c
msgpackc_test_LDFLAGS = libmsgpackc.la -lgtest_main msgpackc_test_LDADD = libmsgpackc.la -lgtest_main
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)

View File

@@ -1 +0,0 @@
.

View File

@@ -19,7 +19,6 @@
#define MSGPACK_OBJECT_H__ #define MSGPACK_OBJECT_H__
#include "msgpack/zone.h" #include "msgpack/zone.h"
#include "msgpack/sysdep.h"
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -18,6 +18,7 @@
#ifndef MSGPACK_ZONE_H__ #ifndef MSGPACK_ZONE_H__
#define MSGPACK_ZONE_H__ #define MSGPACK_ZONE_H__
#include "msgpack/sysdep.h"
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>

View File

@@ -30,7 +30,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
vbuf->chunk_size = chunk_size; vbuf->chunk_size = chunk_size;
vbuf->ref_size = ref_size; vbuf->ref_size = ref_size;
// glibcは72バイト以下のmallocが高速 // glibcは72バイト以下のmallocが高速
size_t nfirst = (sizeof(struct iovec) < 72/2) ? size_t nfirst = (sizeof(struct iovec) < 72/2) ?
72 / sizeof(struct iovec) : 8; 72 / sizeof(struct iovec) : 8;

View File

@@ -104,7 +104,6 @@ static inline void init_finalizer_array(msgpack_zone_finalizer_array* fa)
static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa) static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa)
{ {
// 逆順に呼び出し
msgpack_zone_finalizer* fin = fa->tail; msgpack_zone_finalizer* fin = fa->tail;
for(; fin != fa->array; --fin) { for(; fin != fa->array; --fin) {
(*(fin-1)->func)((fin-1)->data); (*(fin-1)->func)((fin-1)->data);
@@ -132,9 +131,6 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
size_t nnext; size_t nnext;
if(nused == 0) { if(nused == 0) {
// 初回の呼び出しfa->tail == fa->end == fa->array == NULL
// glibcは72バイト以下のmallocが高速
nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ? nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
72 / sizeof(msgpack_zone_finalizer) : 8; 72 / sizeof(msgpack_zone_finalizer) : 8;

View File

@@ -1,6 +1,6 @@
AC_INIT(msgpack/unpack_template.h) AC_INIT(msgpack/unpack_template.h)
AC_CONFIG_AUX_DIR(ac) AC_CONFIG_AUX_DIR(ac)
AM_INIT_AUTOMAKE(msgpack, 0.4.0) AM_INIT_AUTOMAKE(msgpack, 0.4.1)
AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS) AC_SUBST(CFLAGS)
@@ -12,7 +12,6 @@ AC_PROG_CC
CFLAGS="-O4 -Wall $CFLAGS -I.." CFLAGS="-O4 -Wall $CFLAGS -I.."
AC_MSG_CHECKING([if c++ api is enabled]) AC_MSG_CHECKING([if c++ api is enabled])
AC_ARG_ENABLE(cxx, AC_ARG_ENABLE(cxx,
AS_HELP_STRING([--disable-cxx], AS_HELP_STRING([--disable-cxx],
@@ -25,11 +24,34 @@ if test "$enable_cxx" != "no"; then
fi fi
fi fi
# FIXME # FIXME enable_cxx
AC_PROG_CXX AC_PROG_CXX
CXXFLAGS="-O4 -Wall $CXXFLAGS -I.. -I../c" CXXFLAGS="-O4 -Wall $CXXFLAGS -I.. -I../c"
# FIXME enable_cxx
AC_LANG_PUSH([C++])
AC_CHECK_HEADERS(tr1/unordered_map)
AC_CHECK_HEADERS(tr1/unordered_set)
AC_LANG_POP([C++])
AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [
AC_TRY_LINK([
int atomic_sub(int i) { return __sync_sub_and_fetch(&i, 1); }
int atomic_add(int i) { return __sync_add_and_fetch(&i, 1); }
], [], msgpack_cv_atomic_ops="yes")
])
if test "$msgpack_cv_atomic_ops" != "yes"; then
AC_MSG_ERROR([__sync_* atomic operations are not supported.
Note that gcc < 4.1 is not supported.
If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to
add CFLAGS="--march=i686" and CXXFLAGS="-march=i668" options to ./configure as follows:
$ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686"
])
fi
AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no") AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no")

View File

@@ -39,6 +39,6 @@ check_PROGRAMS = \
msgpack_test_SOURCES = test.cpp msgpack_test_SOURCES = test.cpp
msgpack_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c -I$(top_srcdir)/cpp msgpack_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c -I$(top_srcdir)/cpp
msgpack_test_LDFLAGS = libmsgpack.la -lgtest_main msgpack_test_LDADD = libmsgpack.la -lgtest_main
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)

View File

@@ -1 +0,0 @@
.

View File

@@ -29,11 +29,15 @@ inline std::vector<T>& operator>> (object o, std::vector<T>& v)
{ {
if(o.type != type::ARRAY) { throw type_error(); } if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.array.size); v.resize(o.via.array.size);
object* p = o.via.array.ptr; if(o.via.array.size > 0) {
object* const pend = o.via.array.ptr + o.via.array.size; object* p = o.via.array.ptr;
T* it = &v.front(); object* const pend = o.via.array.ptr + o.via.array.size;
for(; p < pend; ++p, ++it) { T* it = &v[0];
p->convert(it); do {
p->convert(it);
++p;
++it;
} while(p < pend);
} }
return v; return v;
} }

View File

@@ -10,6 +10,10 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
using namespace std; using namespace std;
const unsigned int kLoop = 10000; const unsigned int kLoop = 10000;
@@ -227,6 +231,8 @@ TEST(MSGPACK, simple_buffer_false)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// STL
TEST(MSGPACK_STL, simple_buffer_string) TEST(MSGPACK_STL, simple_buffer_string)
{ {
for (unsigned int k = 0; k < kLoop; k++) { for (unsigned int k = 0; k < kLoop; k++) {
@@ -365,6 +371,190 @@ TEST(MSGPACK_STL, simple_buffer_pair)
} }
} }
TEST(MSGPACK_STL, simple_buffer_multimap)
{
for (unsigned int k = 0; k < kLoop; k++) {
multimap<int, int> val1;
for (unsigned int i = 0; i < kElements; i++) {
int i1 = rand();
val1.insert(make_pair(i1, rand()));
val1.insert(make_pair(i1, rand()));
}
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
multimap<int, int> val2;
obj.convert(&val2);
vector<pair<int, int> > v1, v2;
multimap<int, int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(make_pair(it->first, it->second));
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(make_pair(it->first, it->second));
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
TEST(MSGPACK_STL, simple_buffer_multiset)
{
for (unsigned int k = 0; k < kLoop; k++) {
multiset<int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1.insert(rand());
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
multiset<int> val2;
obj.convert(&val2);
vector<int> v1, v2;
multiset<int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(*it);
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(*it);
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
// TR1
#ifdef HAVE_TR1_UNORDERED_MAP
#include <tr1/unordered_map>
#include "cpp/msgpack/type/tr1/unordered_map.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_map)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_map<int, int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1[rand()] = rand();
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
tr1::unordered_map<int, int> val2;
obj.convert(&val2);
EXPECT_EQ(val1.size(), val2.size());
tr1::unordered_map<int, int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it) {
EXPECT_TRUE(val2.find(it->first) != val2.end());
EXPECT_EQ(it->second, val2.find(it->first)->second);
}
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_multimap<int, int> val1;
for (unsigned int i = 0; i < kElements; i++) {
int i1 = rand();
val1.insert(make_pair(i1, rand()));
val1.insert(make_pair(i1, rand()));
}
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
tr1::unordered_multimap<int, int> val2;
obj.convert(&val2);
vector<pair<int, int> > v1, v2;
tr1::unordered_multimap<int, int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(make_pair(it->first, it->second));
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(make_pair(it->first, it->second));
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
#endif
#ifdef HAVE_TR1_UNORDERED_SET
#include <tr1/unordered_set>
#include "cpp/msgpack/type/tr1/unordered_set.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_set)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_set<int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1.insert(rand());
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
tr1::unordered_set<int> val2;
obj.convert(&val2);
EXPECT_EQ(val1.size(), val2.size());
tr1::unordered_set<int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
EXPECT_TRUE(val2.find(*it) != val2.end());
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_multiset<int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1.insert(rand());
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
tr1::unordered_multiset<int> val2;
obj.convert(&val2);
vector<int> v1, v2;
tr1::unordered_multiset<int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(*it);
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(*it);
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
#endif
// User-Defined Structures
class TestClass class TestClass
{ {
public: public:

View File

@@ -1,7 +1,7 @@
/* /*
* MessagePack unpacking routine template * MessagePack unpacking routine template
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
#include "msgpack/sysdep.h" #include "msgpack/sysdep.h"
#include <limits.h> #include <limits.h>
#include <string.h>
#endif /* msgpack/pack_define.h */ #endif /* msgpack/pack_define.h */

View File

@@ -1,7 +1,7 @@
/* /*
* MessagePack packing routine template * MessagePack packing routine template
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} while(0) } while(0)
@@ -89,12 +89,12 @@ do { \
if(d < (1<<16)) { \ if(d < (1<<16)) { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} \ } \
@@ -115,17 +115,17 @@ do { \
if(d < (1ULL<<16)) { \ if(d < (1ULL<<16)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else if(d < (1ULL<<32)) { \ } else if(d < (1ULL<<32)) { \
/* signed 32 */ \ /* signed 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else { \ } else { \
/* signed 64 */ \ /* signed 64 */ \
unsigned char buf[9]; \ unsigned char buf[9]; \
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \ msgpack_pack_append_buffer(x, buf, 9); \
} \ } \
} \ } \
@@ -149,7 +149,7 @@ do { \
if(d < -(1<<7)) { \ if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@@ -167,7 +167,7 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} \ } \
@@ -179,12 +179,12 @@ do { \
if(d < -(1<<15)) { \ if(d < -(1<<15)) { \
/* signed 32 */ \ /* signed 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else if(d < -(1<<7)) { \ } else if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@@ -202,12 +202,12 @@ do { \
} else if(d < (1<<16)) { \ } else if(d < (1<<16)) { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} \ } \
@@ -220,19 +220,19 @@ do { \
if(d < -(1LL<<31)) { \ if(d < -(1LL<<31)) { \
/* signed 64 */ \ /* signed 64 */ \
unsigned char buf[9]; \ unsigned char buf[9]; \
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d); \ buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \ msgpack_pack_append_buffer(x, buf, 9); \
} else { \ } else { \
/* signed 32 */ \ /* signed 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} \ } \
} else { \ } else { \
if(d < -(1<<7)) { \ if(d < -(1<<7)) { \
/* signed 16 */ \ /* signed 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} else { \ } else { \
/* signed 8 */ \ /* signed 8 */ \
@@ -252,19 +252,19 @@ do { \
} else { \ } else { \
/* unsigned 16 */ \ /* unsigned 16 */ \
unsigned char buf[3]; \ unsigned char buf[3]; \
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \ msgpack_pack_append_buffer(x, buf, 3); \
} \ } \
} else { \ } else { \
if(d < (1LL<<32)) { \ if(d < (1LL<<32)) { \
/* unsigned 32 */ \ /* unsigned 32 */ \
unsigned char buf[5]; \ unsigned char buf[5]; \
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \ msgpack_pack_append_buffer(x, buf, 5); \
} else { \ } else { \
/* unsigned 64 */ \ /* unsigned 64 */ \
unsigned char buf[9]; \ unsigned char buf[9]; \
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \ msgpack_pack_append_buffer(x, buf, 9); \
} \ } \
} \ } \
@@ -283,21 +283,21 @@ msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d) msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
{ {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} }
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d) msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
{ {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); buf[0] = 0xce; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d) msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
{ {
unsigned char buf[9]; unsigned char buf[9];
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9); msgpack_pack_append_buffer(x, buf, 9);
} }
@@ -310,21 +310,21 @@ msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d) msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
{ {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} }
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d) msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
{ {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d) msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
{ {
unsigned char buf[9]; unsigned char buf[9];
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d); buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9); msgpack_pack_append_buffer(x, buf, 9);
} }
@@ -554,19 +554,19 @@ if(sizeof(unsigned long long) == 2) {
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
{ {
union { char buf[4]; uint32_t num; } f; union { float f; uint32_t i; } mem;
*((float*)&f.buf) = d; // FIXME mem.f = d;
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(f.num); buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
{ {
union { char buf[8]; uint64_t num; } f; union { double f; uint64_t i; } mem;
*((double*)&f.buf) = d; // FIXME mem.f = d;
unsigned char buf[9]; unsigned char buf[9];
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(f.num); buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 9); msgpack_pack_append_buffer(x, buf, 9);
} }
@@ -610,11 +610,11 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
msgpack_pack_append_buffer(x, &d, 1); msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) { } else if(n < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xdc; *(uint16_t*)&buf[1] = _msgpack_be16(n); buf[0] = 0xdc; _msgpack_store16(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdd; *(uint32_t*)&buf[1] = _msgpack_be32(n); buf[0] = 0xdd; _msgpack_store32(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }
@@ -631,11 +631,11 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) { } else if(n < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xde; *(uint16_t*)&buf[1] = _msgpack_be16(n); buf[0] = 0xde; _msgpack_store16(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdf; *(uint32_t*)&buf[1] = _msgpack_be32(n); buf[0] = 0xdf; _msgpack_store32(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }
@@ -652,11 +652,11 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 65536) { } else if(l < 65536) {
unsigned char buf[3]; unsigned char buf[3];
buf[0] = 0xda; *(uint16_t*)&buf[1] = _msgpack_be16(l); buf[0] = 0xda; _msgpack_store16(&buf[1], l);
msgpack_pack_append_buffer(x, buf, 3); msgpack_pack_append_buffer(x, buf, 3);
} else { } else {
unsigned char buf[5]; unsigned char buf[5];
buf[0] = 0xdb; *(uint32_t*)&buf[1] = _msgpack_be32(l); buf[0] = 0xdb; _msgpack_store32(&buf[1], l);
msgpack_pack_append_buffer(x, buf, 5); msgpack_pack_append_buffer(x, buf, 5);
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
* MessagePack system dependencies * MessagePack system dependencies
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -48,6 +48,17 @@ typedef unsigned int _msgpack_atomic_counter_t;
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#ifdef __cplusplus
/* numeric_limits<T>::min,max */
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#endif
#else #else
#include <arpa/inet.h> /* __BYTE_ORDER */ #include <arpa/inet.h> /* __BYTE_ORDER */
#endif #endif
@@ -90,5 +101,18 @@ typedef unsigned int _msgpack_atomic_counter_t;
#endif #endif
#define _msgpack_store16(to, num) \
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0);
#define _msgpack_store32(to, num) \
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0);
#define _msgpack_store64(to, num) \
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0);
#define _msgpack_load16(cast, from) ((cast)_msgpack_be16(*(uint16_t*)from))
#define _msgpack_load32(cast, from) ((cast)_msgpack_be32(*(uint32_t*)from))
#define _msgpack_load64(cast, from) ((cast)_msgpack_be64(*(uint64_t*)from))
#endif /* msgpack/sysdep.h */ #endif /* msgpack/sysdep.h */

View File

@@ -1,7 +1,7 @@
/* /*
* MessagePack unpacking routine template * MessagePack unpacking routine template
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
/* /*
* MessagePack unpacking routine template * MessagePack unpacking routine template
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -130,11 +130,6 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
#define NEXT_CS(p) \ #define NEXT_CS(p) \
((unsigned int)*p & 0x1f) ((unsigned int)*p & 0x1f)
#define PTR_CAST_8(ptr) (*(uint8_t*)ptr)
#define PTR_CAST_16(ptr) _msgpack_be16(*(uint16_t*)ptr)
#define PTR_CAST_32(ptr) _msgpack_be32(*(uint32_t*)ptr)
#define PTR_CAST_64(ptr) _msgpack_be64(*(uint64_t*)ptr)
#ifdef USE_CASE_RANGE #ifdef USE_CASE_RANGE
#define SWITCH_RANGE_BEGIN switch(*p) { #define SWITCH_RANGE_BEGIN switch(*p) {
#define SWITCH_RANGE(FROM, TO) case FROM ... TO: #define SWITCH_RANGE(FROM, TO) case FROM ... TO:
@@ -222,70 +217,70 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
//case CS_ //case CS_
//case CS_ //case CS_
case CS_FLOAT: { case CS_FLOAT: {
union { uint32_t num; char buf[4]; } f; union { uint32_t i; float f; } mem;
f.num = PTR_CAST_32(n); // FIXME mem.i = _msgpack_load32(uint32_t,n);
push_fixed_value(_float, *((float*)f.buf)); } push_fixed_value(_float, mem.f); }
case CS_DOUBLE: { case CS_DOUBLE: {
union { uint64_t num; char buf[8]; } f; union { uint64_t i; double f; } mem;
f.num = PTR_CAST_64(n); // FIXME mem.i = _msgpack_load64(uint64_t,n);
push_fixed_value(_double, *((double*)f.buf)); } push_fixed_value(_double, mem.f); }
case CS_UINT_8: case CS_UINT_8:
push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n)); push_fixed_value(_uint8, *(uint8_t*)n);
case CS_UINT_16: case CS_UINT_16:
push_fixed_value(_uint16, (uint16_t)PTR_CAST_16(n)); push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
case CS_UINT_32: case CS_UINT_32:
push_fixed_value(_uint32, (uint32_t)PTR_CAST_32(n)); push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
case CS_UINT_64: case CS_UINT_64:
push_fixed_value(_uint64, (uint64_t)PTR_CAST_64(n)); push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
case CS_INT_8: case CS_INT_8:
push_fixed_value(_int8, (int8_t)PTR_CAST_8(n)); push_fixed_value(_int8, *(int8_t*)n);
case CS_INT_16: case CS_INT_16:
push_fixed_value(_int16, (int16_t)PTR_CAST_16(n)); push_fixed_value(_int16, _msgpack_load16(int16_t,n));
case CS_INT_32: case CS_INT_32:
push_fixed_value(_int32, (int32_t)PTR_CAST_32(n)); push_fixed_value(_int32, _msgpack_load32(int32_t,n));
case CS_INT_64: case CS_INT_64:
push_fixed_value(_int64, (int64_t)PTR_CAST_64(n)); push_fixed_value(_int64, _msgpack_load64(int64_t,n));
//case CS_ //case CS_
//case CS_ //case CS_
//case CS_BIG_INT_16: //case CS_BIG_INT_16:
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint16_t)PTR_CAST_16(n), _big_int_zero); // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
//case CS_BIG_INT_32: //case CS_BIG_INT_32:
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint32_t)PTR_CAST_32(n), _big_int_zero); // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
//case ACS_BIG_INT_VALUE: //case ACS_BIG_INT_VALUE:
//_big_int_zero: //_big_int_zero:
// // FIXME // // FIXME
// push_variable_value(_big_int, data, n, trail); // push_variable_value(_big_int, data, n, trail);
//case CS_BIG_FLOAT_16: //case CS_BIG_FLOAT_16:
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero); // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
//case CS_BIG_FLOAT_32: //case CS_BIG_FLOAT_32:
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint32_t)PTR_CAST_32(n), _big_float_zero); // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
//case ACS_BIG_FLOAT_VALUE: //case ACS_BIG_FLOAT_VALUE:
//_big_float_zero: //_big_float_zero:
// // FIXME // // FIXME
// push_variable_value(_big_float, data, n, trail); // push_variable_value(_big_float, data, n, trail);
case CS_RAW_16: case CS_RAW_16:
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero); again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
case CS_RAW_32: case CS_RAW_32:
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero); again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
case ACS_RAW_VALUE: case ACS_RAW_VALUE:
_raw_zero: _raw_zero:
push_variable_value(_raw, data, n, trail); push_variable_value(_raw, data, n, trail);
case CS_ARRAY_16: case CS_ARRAY_16:
start_container(_array, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM); start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
case CS_ARRAY_32: case CS_ARRAY_32:
/* FIXME security guard */ /* FIXME security guard */
start_container(_array, (uint32_t)PTR_CAST_32(n), CT_ARRAY_ITEM); start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
case CS_MAP_16: case CS_MAP_16:
start_container(_map, (uint16_t)PTR_CAST_16(n), CT_MAP_KEY); start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
case CS_MAP_32: case CS_MAP_32:
/* FIXME security guard */ /* FIXME security guard */
start_container(_map, (uint32_t)PTR_CAST_32(n), CT_MAP_KEY); start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
default: default:
goto _failed; goto _failed;
@@ -371,8 +366,4 @@ _end:
#undef start_container #undef start_container
#undef NEXT_CS #undef NEXT_CS
#undef PTR_CAST_8
#undef PTR_CAST_16
#undef PTR_CAST_32
#undef PTR_CAST_64

275
msgpack_vc8.vcproj Normal file
View File

@@ -0,0 +1,275 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="MessagePack"
ProjectGUID="{122A2EA4-B283-4241-9655-786DE78283B2}"
RootNamespace="MessagePack"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="cpp;c;."
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="1"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="cpp;c;."
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="<22>\<5C>[<5B>X <20>t<EFBFBD>@<40>C<EFBFBD><43>"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\c\object.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\$(InputName)1.obj"
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\$(InputName)1.obj"
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\cpp\object.cpp"
>
</File>
<File
RelativePath=".\c\unpack.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\c\vrefbuffer.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\c\zone.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="<22>w<EFBFBD>b<EFBFBD>_<EFBFBD>[ <20>t<EFBFBD>@<40>C<EFBFBD><43>"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\msgpack\pack_define.h"
>
</File>
<File
RelativePath=".\msgpack\pack_template.h"
>
</File>
<File
RelativePath=".\msgpack\sysdep.h"
>
</File>
<File
RelativePath=".\msgpack\unpack_define.h"
>
</File>
<File
RelativePath=".\msgpack\unpack_template.h"
>
</File>
</Filter>
<Filter
Name="<22><><EFBFBD>\<5C>[<5B>X <20>t<EFBFBD>@<40>C<EFBFBD><43>"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -2,7 +2,7 @@
MessagePack Python Binding MessagePack Python Binding
=========================== ===========================
:author: Naoki INADA :author: INADA Naoki
:version: 0.1.0 :version: 0.1.0
:date: 2009-07-12 :date: 2009-07-12
@@ -32,7 +32,11 @@ MinGW GCC.
TEST TEST
---- ----
MessagePack uses nosetest for testing. MessagePack uses `nosetest` for testing.
Run test with following command: Run test with following command:
$ nosetests test $ nosetests test
..
vim: filetype=rst

View File

@@ -1,16 +1,41 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
from distutils.core import setup, Extension
#from Cython.Distutils import build_ext
import os import os
from glob import glob
from distutils.core import setup, Extension
from distutils.command.sdist import sdist
try:
from Cython.Distutils import build_ext
import Cython.Compiler.Main as cython_compiler
have_cython = True
except ImportError:
from distutils.command.build_ext import build_ext
have_cython = False
version = '0.2.0dev' version = '0.2.0dev'
# take care of extension modules.
if have_cython:
sources = ['msgpack/_msgpack.pyx']
class Sdist(sdist):
def __init__(self, *args, **kwargs):
for src in glob('msgpack/*.pyx'):
cython_compiler.compile(glob('msgpack/*.pyx'),
cython_compiler.default_options)
sdist.__init__(self, *args, **kwargs)
else:
sources = ['msgpack/_msgpack.c']
Sdist = sdist
msgpack_mod = Extension('msgpack._msgpack', msgpack_mod = Extension('msgpack._msgpack',
#sources=['msgpack/_msgpack.pyx'] sources=sources,
sources=['msgpack/_msgpack.c']
) )
del sources
desc = 'MessagePack (de)serializer.' desc = 'MessagePack (de)serializer.'
long_desc = desc + """ long_desc = desc + """
@@ -26,14 +51,15 @@ What's MessagePack? (from http://msgpack.sourceforge.jp/)
""" """
setup(name='msgpack', setup(name='msgpack',
author='Naoki INADA', author='INADA Naoki',
author_email='songofacandy@gmail.com', author_email='songofacandy@gmail.com',
version=version, version=version,
#cmdclass={'build_ext': build_ext}, cmdclass={'build_ext': build_ext, 'sdist': Sdist},
ext_modules=[msgpack_mod], ext_modules=[msgpack_mod],
packages=['msgpack'], packages=['msgpack'],
description=desc, description=desc,
long_description=long_desc, long_description=long_desc,
url="http://msgpack.sourceforge.jp/",
classifiers=[ classifiers=[
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'Intended Audience :: Developers', 'Intended Audience :: Developers',

View File

@@ -1,41 +0,0 @@
#!/usr/bin/env python
# coding: utf-8
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
import os
version = '0.2.0dev'
msgpack_mod = Extension('msgpack._msgpack',
sources=['msgpack/_msgpack.pyx']
)
desc = 'MessagePack (de)serializer.'
long_desc = desc + """
MessagePack_ (de)serializer for Python.
.. _MessagePack: http://msgpack.sourceforge.jp/
What's MessagePack? (from http://msgpack.sourceforge.jp/)
MessagePack is a binary-based efficient data interchange format that is
focused on high performance. It is like JSON, but very fast and small.
"""
setup(name='msgpack',
author='Naoki INADA',
author_email='songofacandy@gmail.com',
version=version,
cmdclass={'build_ext': build_ext},
ext_modules=[msgpack_mod],
packages=['msgpack'],
description=desc,
long_description=long_desc,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
]
)

View File

@@ -1,133 +0,0 @@
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/contrib/rubyforgepublisher'
require 'rake/contrib/sshpublisher'
require 'fileutils'
include FileUtils
NAME = "msgpack"
AUTHOR = "FURUHASHI Sadayuki"
EMAIL = "frsyuki _at_ users.sourceforge.jp"
DESCRIPTION = "Binary-based efficient data interchange format."
RUBYFORGE_PROJECT = "msgpack"
HOMEPATH = "http://msgpack.sourceforge.jp/"
BIN_FILES = %w( )
VERS = "0.3.2"
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
REV = nil
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
RDOC_OPTS = [
'--title', "#{NAME} documentation",
"--charset", "utf-8",
"--opname", "index.html",
"--line-numbers",
"--main", "README",
"--inline-source",
]
task :default => [:test]
task :package => [:clean]
Rake::TestTask.new("test") do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = true
end
spec = Gem::Specification.new do |s|
s.name = NAME
s.version = VERS
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
s.summary = DESCRIPTION
s.description = DESCRIPTION
s.author = AUTHOR
s.email = EMAIL
s.homepage = HOMEPATH
s.executables = BIN_FILES
s.rubyforge_project = RUBYFORGE_PROJECT
s.bindir = "bin"
s.require_path = "ext"
s.autorequire = ""
s.test_files = Dir["test/test_*.rb"]
#s.add_dependency('activesupport', '>=1.3.1')
#s.required_ruby_version = '>= 1.8.2'
s.files = %w(README ChangeLog Rakefile) +
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
Dir.glob("ext/**/*.{h,c,rb}") +
Dir.glob("examples/**/*.rb") +
Dir.glob("tools/*.rb") +
Dir.glob("msgpack/*.h")
s.extensions = FileList["ext/**/extconf.rb"].to_a
end
Rake::GemPackageTask.new(spec) do |p|
p.need_tar = true
p.gem_spec = spec
end
task :install do
name = "#{NAME}-#{VERS}.gem"
sh %{rake package}
sh %{sudo gem install pkg/#{name}}
end
task :uninstall => [:clean] do
sh %{sudo gem uninstall #{NAME}}
end
#Rake::RDocTask.new do |rdoc|
# rdoc.rdoc_dir = 'html'
# rdoc.options += RDOC_OPTS
# rdoc.template = "resh"
# #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
# if ENV['DOC_FILES']
# rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
# else
# rdoc.rdoc_files.include('README', 'ChangeLog')
# rdoc.rdoc_files.include('lib/**/*.rb')
# rdoc.rdoc_files.include('ext/**/*.c')
# end
#end
desc "Publish to RubyForge"
task :rubyforge => [:rdoc, :package] do
require 'rubyforge'
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'frsyuki').upload
end
desc 'Package and upload the release to rubyforge.'
task :release => [:clean, :package] do |t|
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
pkg = "pkg/#{NAME}-#{VERS}"
rf = RubyForge.new
puts "Logging in"
rf.login
c = rf.userconfig
# c["release_notes"] = description if description
# c["release_changes"] = changes if changes
c["preformatted"] = true
files = [
"#{pkg}.tgz",
"#{pkg}.gem"
].compact
puts "Releasing #{NAME} v. #{VERS}"
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
end

View File

@@ -1,21 +0,0 @@
#!/bin/sh
mkdir -p gem/ext
mkdir -p gem/msgpack
cp extconf.rb gem/ext/
cp pack.c gem/ext/
cp pack.h gem/ext/
cp rbinit.c gem/ext/
cp unpack.c gem/ext/
cp unpack.h gem/ext/
cat test_case.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > gem/test/msgpack_test.rb
cp ../AUTHORS gem/AUTHORS
cp ../ChangeLog gem/ChangeLog
cp ../msgpack/pack_define.h gem/msgpack/
cp ../msgpack/pack_template.h gem/msgpack/
cp ../msgpack/unpack_define.h gem/msgpack/
cp ../msgpack/unpack_template.h gem/msgpack/
cp ../msgpack/sysdep.h gem/msgpack/
cd gem && rake --trace package

21
ruby/makegem.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
mkdir -p ext
mkdir -p msgpack
cp extconf.rb ext/
cp pack.c ext/
cp pack.h ext/
cp rbinit.c ext/
cp unpack.c ext/
cp unpack.h ext/
cp ../AUTHORS ./
cp ../ChangeLog ./
cp ../msgpack/pack_define.h msgpack/
cp ../msgpack/pack_template.h msgpack/
cp ../msgpack/unpack_define.h msgpack/
cp ../msgpack/unpack_template.h msgpack/
cp ../msgpack/sysdep.h msgpack/
cat msgpack_test.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > test/msgpack_test.rb
gem build msgpack.gemspec

26
ruby/msgpack.gemspec Executable file → Normal file
View File

@@ -1,12 +1,16 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.platform = Gem::Platform::CURRENT s.platform = Gem::Platform::RUBY
s.name = "msgpack" s.name = "msgpack"
s.version = "0.3.2" s.version = "0.3.3"
s.summary = "MessagePack" s.summary = "MessagePack, a binary-based efficient data interchange format."
s.author = "FURUHASHI Sadayuki" s.author = "FURUHASHI Sadayuki"
s.email = "frsyuki@users.sourceforge.jp" s.email = "frsyuki@users.sourceforge.jp"
s.homepage = "http://msgpack.sourceforge.jp/" s.homepage = "http://msgpack.sourceforge.jp/"
s.rubyforge_project = "msgpack" s.rubyforge_project = "msgpack"
s.require_paths = ["lib", "ext"] s.has_rdoc = false
s.files = ["lib/**/*", "ext/**/*"].map {|g| Dir.glob(g) }.flatten s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
s.require_paths = ["lib", "ext"]
s.files = Dir["lib/**/*", "ext/**/*", "msgpack/**/*", "test/**/*"]
s.test_files = Dir["test/test_*.rb"]
s.extensions = Dir["ext/**/extconf.rb"]
end end

View File

@@ -1,122 +0,0 @@
require 'msgpack'
@up = MessagePack::Unpacker.new
def check(bytes, should)
puts "----"
@up.reset
src = bytes.pack('C*')
ret = @up.execute(src, 0)
if ret != src.length
puts "** EXTRA BYTES **"
end
puts bytes.map{|x|"%x"%x}.join(' ')
data = @up.data
p data
if data != should
puts "** TEST FAILED **"
p should
end
end
# SimpleValue
check([
0x93, 0xc0, 0xc2, 0xc3,
], [nil,false,true])
# Fixnum
check([
0x92,
0x93, 0x00, 0x40, 0x7f,
0x93, 0xe0, 0xf0, 0xff,
], [[0,64,127], [-32,-16,-1]])
# FixArray
check([
0x92,
0x90,
0x91,
0x91, 0xc0,
], [[],[[nil]]])
# FixRaw
check([
0x94,
0xa0,
0xa1, ?a,
0xa2, ?b, ?c,
0xa3, ?d, ?e, ?f,
], ["","a","bc","def"])
# FixMap
check([
0x82,
0xc2, 0x81,
0xc0, 0xc0,
0xc3, 0x81,
0xc0, 0x80,
], {false=>{nil=>nil}, true=>{nil=>{}}})
# unsigned int
check([
0x99,
0xcc, 0,
0xcc, 128,
0xcc, 255,
0xcd, 0x00, 0x00,
0xcd, 0x80, 0x00,
0xcd, 0xff, 0xff,
0xce, 0x00, 0x00, 0x00, 0x00,
0xce, 0x80, 0x00, 0x00, 0x00,
0xce, 0xff, 0xff, 0xff, 0xff,
], [0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295])
# signed int
check([
0x99,
0xd0, 0,
0xd0, 128,
0xd0, 255,
0xd1, 0x00, 0x00,
0xd1, 0x80, 0x00,
0xd1, 0xff, 0xff,
0xd2, 0x00, 0x00, 0x00, 0x00,
0xd2, 0x80, 0x00, 0x00, 0x00,
0xd2, 0xff, 0xff, 0xff, 0xff,
], [0, -128, -1, 0, -32768, -1, 0, -2147483648, -1])
# raw
check([
0x96,
0xda, 0x00, 0x00,
0xda, 0x00, 0x01, ?a,
0xda, 0x00, 0x02, ?a, ?b,
0xdb, 0x00, 0x00, 0x00, 0x00,
0xdb, 0x00, 0x00, 0x00, 0x01, ?a,
0xdb, 0x00, 0x00, 0x00, 0x02, ?a, ?b,
], ["", "a", "ab", "", "a", "ab"])
# array
check([
0x96,
0xdc, 0x00, 0x00,
0xdc, 0x00, 0x01, 0xc0,
0xdc, 0x00, 0x02, 0xc2, 0xc3,
0xdd, 0x00, 0x00, 0x00, 0x00,
0xdd, 0x00, 0x00, 0x00, 0x01, 0xc0,
0xdd, 0x00, 0x00, 0x00, 0x02, 0xc2, 0xc3
], [[], [nil], [false,true], [], [nil], [false,true]])
# map
check([
0x96,
0xde, 0x00, 0x00,
0xde, 0x00, 0x01, 0xc0, 0xc2,
0xde, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
0xdf, 0x00, 0x00, 0x00, 0x00,
0xdf, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xc2,
0xdf, 0x00, 0x00, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
], [{}, {nil=>false}, {true=>false, nil=>false}, {}, {nil=>false}, {true=>false, nil=>false}])

View File

@@ -1,58 +0,0 @@
require 'msgpack'
def check(data)
puts "---"
pack = data.to_msgpack
p data
puts pack.unpack('C*').map{|x|"%02x"%x}.join(' ')
re = MessagePack::unpack(pack)
if re != data
p re
puts "** TEST FAILED **"
end
end
check 0
check 1
check 127
check 128
check 255
check 256
check 65535
check 65536
check -1
check -32
check -33
check -128
check -129
check -32768
check -32769
check 1.0
check ""
check "a"
check "a"*31
check "a"*32
check nil
check true
check false
check []
check [[]]
check [[], nil]
check( {nil=>0} )
check (1<<23)
__END__
ary = []
i = 0
while i < (1<<16)
ary << i
i += 1
end
check ary

View File

@@ -18,10 +18,16 @@
#include "ruby.h" #include "ruby.h"
#include "msgpack/unpack_define.h" #include "msgpack/unpack_define.h"
static ID s_sysread;
typedef struct { typedef struct {
int finished; int finished;
VALUE source; VALUE source;
size_t offset;
size_t parsed;
VALUE buffer;
VALUE stream;
VALUE streambuf;
} unpack_user; } unpack_user;
@@ -144,6 +150,9 @@ static void MessagePack_Unpacker_free(void* data)
static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp) static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
{ {
unsigned int i; unsigned int i;
rb_gc_mark(mp->user.buffer);
rb_gc_mark(mp->user.stream);
rb_gc_mark(mp->user.streambuf);
for(i=0; i < mp->top; ++i) { for(i=0; i < mp->top; ++i) {
rb_gc_mark(mp->stack[i].obj); rb_gc_mark(mp->stack[i].obj);
rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */ rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */
@@ -164,14 +173,32 @@ static VALUE MessagePack_Unpacker_reset(VALUE self)
UNPACKER(self, mp); UNPACKER(self, mp);
template_init(mp); template_init(mp);
init_stack(mp); init_stack(mp);
unpack_user u = {0, Qnil}; mp->user.finished = 0;
mp->user = u;
return self; return self;
} }
static VALUE MessagePack_Unpacker_initialize(VALUE self) static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
{ {
return MessagePack_Unpacker_reset(self); VALUE stream;
switch(argc) {
case 0:
stream = Qnil;
break;
case 1:
stream = argv[0];
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
MessagePack_Unpacker_reset(self);
UNPACKER(self, mp);
mp->user.offset = 0;
mp->user.parsed = 0;
mp->user.buffer = rb_str_new("",0);
mp->user.stream = stream;
mp->user.streambuf = rb_str_new("",0);
return self;
} }
@@ -249,6 +276,87 @@ static VALUE MessagePack_Unpacker_data(VALUE self)
} }
static VALUE MessagePack_Unpacker_feed(VALUE self, VALUE data)
{
UNPACKER(self, mp);
StringValue(data);
rb_str_cat(mp->user.buffer, RSTRING_PTR(data), RSTRING_LEN(data));
return Qnil;
}
static VALUE MessagePack_Unpacker_stream_get(VALUE self)
{
UNPACKER(self, mp);
return mp->user.stream;
}
static VALUE MessagePack_Unpacker_stream_set(VALUE self, VALUE val)
{
UNPACKER(self, mp);
return mp->user.stream = val;
}
static VALUE MessagePack_Unpacker_fill(VALUE self)
{
UNPACKER(self, mp);
if(mp->user.stream == Qnil) {
return Qnil;
}
size_t len;
if(RSTRING_LEN(mp->user.buffer) == 0) {
rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.buffer);
len = RSTRING_LEN(mp->user.buffer);
} else {
rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.streambuf);
len = RSTRING_LEN(mp->user.streambuf);
rb_str_cat(mp->user.buffer, RSTRING_PTR(mp->user.streambuf), RSTRING_LEN(mp->user.streambuf));
}
return LONG2FIX(len);
}
static VALUE MessagePack_Unpacker_each(VALUE self)
{
UNPACKER(self, mp);
int ret;
#ifdef RETURN_ENUMERATOR
RETURN_ENUMERATOR(self, 0, 0);
#endif
while(1) {
if(RSTRING_LEN(mp->user.buffer) <= mp->user.offset) {
do_fill:
{
VALUE len = MessagePack_Unpacker_fill(self);
if(len == Qnil || FIX2LONG(len) == 0) {
break;
}
}
}
mp->user.source = mp->user.buffer;
ret = template_execute(mp, RSTRING_PTR(mp->user.buffer), RSTRING_LEN(mp->user.buffer), &mp->user.offset);
mp->user.source = Qnil;
if(ret < 0) {
rb_raise(eUnpackError, "parse error.");
} else if(ret > 0) {
VALUE data = template_data(mp);
template_init(mp);
init_stack(mp);
rb_yield(data);
} else {
goto do_fill;
}
}
return Qnil;
}
static VALUE MessagePack_unpack_impl(VALUE args) static VALUE MessagePack_unpack_impl(VALUE args)
{ {
msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0]; msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
@@ -292,7 +400,7 @@ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
msgpack_unpack_t mp; msgpack_unpack_t mp;
template_init(&mp); template_init(&mp);
init_stack(&mp); init_stack(&mp);
unpack_user u = {0, Qnil}; unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil};
mp.user = u; mp.user = u;
rb_gc_disable(); rb_gc_disable();
@@ -313,17 +421,22 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
void Init_msgpack_unpack(VALUE mMessagePack) void Init_msgpack_unpack(VALUE mMessagePack)
{ {
s_sysread = rb_intern("sysread");
eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError); eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject); cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc); rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0); rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, -1);
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2); rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3); rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0); rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0); rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0); rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
rb_define_method(cUnpacker, "feed", MessagePack_Unpacker_feed, 1);
rb_define_method(cUnpacker, "fill", MessagePack_Unpacker_fill, 0);
rb_define_method(cUnpacker, "each", MessagePack_Unpacker_each, 0);
rb_define_method(cUnpacker, "stream", MessagePack_Unpacker_stream_get, 0);
rb_define_method(cUnpacker, "stream=", MessagePack_Unpacker_stream_set, 1);
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1); rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2); rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
} }