Compare commits

..

229 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
frsyuki
2bf3f1856f c,cpp: configure.in: version 0.4.0 2010-01-15 14:45:52 +09:00
frsyuki
f145129f6e c,cpp: optimize msgpack_vrefbuffer 2010-01-15 05:29:41 +09:00
frsyuki
8d365458d5 c,cpp: optimize msgpack_zone: variable-length array of chunk -> list of chunk 2010-01-15 05:27:44 +09:00
frsyuki
55cfbf378e cpp: add msgpack/type/tr1/unordered_{map,set}.hpp 2010-01-14 21:20:32 +09:00
frsyuki
d76093b148 import MessagePack for Java 2010-01-08 17:34:14 +09:00
tokuhirom
7873e41e00 Perl: change for release Data-MessagePack-0.09 2010-01-04 12:10:46 +09:00
tokuhirom
9817e9b18d Perl: support NVTYPE=="long double" or IVTYPE="long long" environment. 2010-01-04 11:59:52 +09:00
tokuhirom
519716bbe4 Merge branch 'master' of git://git.sourceforge.jp/gitroot/msgpack/msgpack 2010-01-04 11:23:40 +09:00
frsyuki
c2dd22ec10 c,cpp: add msgpack_vrefbuffer_migrate, msgpack::vrefbuffer::migrate 2009-12-19 22:09:29 +09:00
Naoki INADA
232aced926 Update gitignore. 2009-12-17 18:03:33 +09:00
Naoki INADA
63b9a876b0 Fix tests. 2009-12-17 17:58:41 +09:00
inada-n
5cf85a82d3 Add .gitignore for Python. 2009-12-17 15:20:20 +09:00
inada-n
b9f78821d4 Make tuple default. 2009-12-17 15:19:18 +09:00
Naoki INADA
f4c5b15cc6 Add use_tuple option that returns tuple for array object to Unpacker. 2009-12-17 11:13:47 +09:00
Naoki INADA
4d33bd456c Update new headers. 2009-12-17 10:43:22 +09:00
Naoki INADA
3a5f7f53ff Start 0.2.0 2009-12-17 10:43:01 +09:00
inada-n
1ed4236bcf Make new Python release. 2009-12-16 22:18:17 +09:00
inada-n
5ff2c6be74 Fix bug come from previous commit 2009-12-16 22:14:13 +09:00
inada-n
dd18402737 Fix stream unpacker broken. 2009-12-16 22:05:31 +09:00
frsyuki
686e8ca0f0 c,cpp: fix unpacker 2009-12-16 04:08:36 +09:00
frsyuki
5aa47d6677 cpp: zone::push_finalizer supports std::auto_ptr<T> 2009-12-16 03:52:14 +09:00
frsyuki
0d44348c7d ruby: version 0.3.2 2009-12-11 04:13:24 +09:00
frsyuki
35929b46ae add msgpack/sysdep.h 2009-12-10 07:22:39 +09:00
frsyuki
ba3ba0367c msgpack template: macros for compilers that doesn't not support Case Ranges 2009-12-10 06:40:29 +09:00
frsyuki
7ce866ad7c msgpack template: architecture specific endian conversion 2009-12-10 06:19:53 +09:00
frsyuki
0ae1965f6b ruby: fixes MessagePack_Unpacker_mark marks uninitialized map_key 2009-12-10 04:32:33 +09:00
frsyuki
eb9e892491 import MessagePack for Java implementation plan 3 2009-11-26 11:22:08 +09:00
frsyuki
e39e1d4f60 import MessagePack for Java implementation plan 2 2009-11-12 01:10:36 +09:00
Naoki INADA
93a95725fc Fix Makefile 2009-11-05 14:26:12 +09:00
Naoki INADA
4758d9f04b Fix to use MANIEFST.in. 2009-11-05 14:24:47 +09:00
frsyuki
d39c016e1d java: fix streaming de/serializer 2009-10-25 02:41:55 +09:00
frsyuki
5393a0df16 import MessagePack for Java implementation plan 1 2009-10-25 01:27:09 +09:00
Tokuhiro Matsuno
68176e10f5 added some pattern to MANIFEST.SKIP 2009-10-22 14:34:53 +09:00
Tokuhiro Matsuno
c6a2569af8 - generate README automatically
- added LICENSE term
2009-10-22 14:32:39 +09:00
frsyuki
3424dc916c cpp: add missing type::tuple::tuple(object o) 2009-10-09 17:49:30 +09:00
frsyuki
c8ad32a39e cpp: preprocess.sh: more verbose 2009-10-05 23:31:08 +09:00
Kazuki Ohta
d0b76814b0 cpp: add tests for stream unpacker api 2009-09-12 03:12:53 +09:00
frsyuki
bf3cb63d46 cpp: version 0.3.8 2009-09-10 13:53:12 +09:00
frsyuki
8da7b692f6 cpp: define, type::tuple: GENERATION_LIMIT = 31 2009-09-10 13:50:19 +09:00
Kazuki Ohta
320c79db49 c++: add vrefbuffer test 2009-09-04 16:20:29 +09:00
frsyuki
ebf64d9892 cpp: test.cpp: fixes EXPECT_EQ rule 2009-08-26 12:28:08 +09:00
frsyuki
c12d5b8461 c: test.cpp: add msgpack_sbuffer_destroy and msgpack_zone_destroy 2009-08-26 12:27:28 +09:00
Kazuki Ohta
7186edc45e C: more strict tests for float, double
C++: more strict tests for float, double & enum, union member
2009-08-26 11:52:12 +09:00
Kazuki Ohta
c94772104d C: add test for map
C++: add tests for primitive types, stl types, user-defined type
2009-08-26 11:28:54 +09:00
Kazuki Ohta
9374571056 C: add more tests (float, double, nil, true, false, array, raw) 2009-08-26 09:24:07 +09:00
Kazuki Ohta
c232e91f83 c: fix bugs in c/test.cpp and add more tests 2009-08-25 19:26:54 +09:00
Kazuki Ohta
5b8777026a c: add sometests for serialization 2009-08-25 19:04:21 +09:00
Kazuki Ohta
51e435d46c fix build 2009-08-25 18:40:06 +09:00
frsyuki
d3f9ab7dec add c/test.cpp cpp/test.cpp 2009-08-25 18:35:26 +09:00
frsyuki
1ba330c473 fix cpp/preprocess.sh 2009-08-25 18:25:58 +09:00
frsyuki
dba7f480ed cpp: add missing preprocess.sh file 2009-08-19 17:50:15 +09:00
frsyuki
3a39accb0b cpp: preprocess eruby templates on ./bootstrap; released package doesn't require erb 2009-08-19 17:47:22 +09:00
frsyuki
387eca6fbf cpp-0.3.7 2009-08-19 17:36:05 +09:00
frsyuki
b2381d0513 cpp: fix overflow check for minimum number of signed integer type 2009-08-19 15:10:10 +09:00
frsyuki
92952f6566 c++: fix object >> std::string 2009-08-10 22:16:44 +09:00
frsyuki
a62a5d6c69 c++: fix type.hpp 2009-08-10 18:33:35 +09:00
frsyuki
0627324da6 c++: rebuild type/*.hpp 2009-08-10 18:26:01 +09:00
frsyuki
394331cd4e c++: add std::pair and std::set serializer 2009-08-10 17:34:21 +09:00
frsyuki
0491768fb2 c++: fix Makefile.am 2009-08-10 15:58:43 +09:00
frsyuki
a5705183d6 0.3.5 2009-08-07 13:32:32 +09:00
frsyuki
95a6316cc7 cpp: fix msgpack::type::make_define() 2009-08-07 13:32:07 +09:00
frsyuki
be32e3b1fb cpp: add missing msgpack::type::make_tuple() 2009-08-07 13:31:42 +09:00
frsyuki
b4cb5e23c0 fix Makefile.am 2009-08-07 11:28:23 +09:00
frsyuki
1375732c80 add 2009-08-07 11:15:33 +09:00
frsyuki
7fbe845434 cpp: msgpack::define is obsolete 2009-08-06 13:59:48 +09:00
frsyuki
3afa9f265e cpp: add msgpack::type::define 2009-08-06 13:51:49 +09:00
frsyuki
ec8932d6a1 fix missing tuple<>::value_type 2009-08-06 13:28:41 +09:00
frsyuki
f7a9805f7b operator>> (object, std::vector<T>): return reference; don't copy 2009-08-06 13:26:34 +09:00
frsyuki
aaef612a05 Makefile.am: don't package perl and ruby files 2009-08-06 13:20:43 +09:00
Tokuhiro Matsuno
da9b75f553 Checking in changes prior to tagging of version 0.08. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 4e7f1d7..c6e370c 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.08
+
+    - fixed PVNV issue...
+
 0.07

     - do not use switch (SvTYPE(val)).
2009-07-30 16:52:13 +09:00
Tokuhiro Matsuno
d3906bd1ab Perl: use M::I::XSUtil 2009-07-30 16:38:03 +09:00
Tokuhiro Matsuno
4db90d23ac - fixed SVt_PVNV issue. 2009-07-30 16:22:00 +09:00
Tokuhiro Matsuno
bb455c1f71 perl: display module version 2009-07-30 13:29:24 +09:00
Tokuhiro Matsuno
3275eee281 Perl: display original data 2009-07-30 13:24:38 +09:00
Tokuhiro Matsuno
0fe79a7752 Perl: added benchmark script for memroy-usage 2009-07-30 13:19:49 +09:00
Tokuhiro Matsuno
794adf9469 Checking in changes prior to tagging of version 0.07. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 1a51ddf..4e7f1d7 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.07
+
+    - do not use switch (SvTYPE(val)).
+
 0.06

     - use SvNOK.
2009-07-22 16:42:12 +09:00
Tokuhiro Matsuno
718227bc2c Perl: do not use switch (SvTYPE) 2009-07-22 16:40:15 +09:00
Tokuhiro Matsuno
390c5ad8a0 added test case. 2009-07-22 13:41:31 +09:00
Tokuhiro Matsuno
2da4b17d0b Merge branch 'master' of tokuhirom@git.sourceforge.jp:/gitroot/msgpack/msgpack 2009-07-22 13:28:27 +09:00
inada-n
d19c488929 version: python-0.1.1 2009-07-13 15:52:25 +09:00
inada-n
0db5e0439d Fix: Unpacker.unpack() may raise StopIteration before unpacking large object when deserializing from file. 2009-07-13 15:49:38 +09:00
inada-n
6083bad5ff Fix wrong MANIFEST. 2009-07-13 14:46:53 +09:00
inada-n
63a507a123 merge python binding from bzr. 2009-07-13 14:40:02 +09:00
Naoki INADA
294e3fe7ab Add setup script for distribution. 2009-07-13 14:27:57 +09:00
Naoki INADA
e5c49dae13 Release 0.1.0 2009-07-12 20:02:21 +09:00
Naoki INADA
900785e1aa Clean up 2009-07-12 09:29:11 +09:00
Naoki INADA
979efbb950 Support MinGW. 2009-07-09 13:41:04 +09:00
Tokuhiro Matsuno
7da1a9b3cf Checking in changes prior to tagging of version 0.06. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 15603ea..1a51ddf 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.06
+
+    - use SvNOK.
+
 0.05

     - change type detection for old perl
2009-07-03 18:19:29 +09:00
Tokuhiro Matsuno
661f273481 Perl: use SvNOK. 2009-07-03 18:18:40 +09:00
Tokuhiro Matsuno
cb5c878b77 Checking in changes prior to tagging of version 0.05. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 33fb36c..15603ea 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.05
+
+    - change type detection for old perl
+
 0.04

     - check SvROK first(reported by yappo++)
2009-07-03 18:15:45 +09:00
Tokuhiro Matsuno
34ed3bc9e3 Perl: check IV by SvIOK 2009-07-03 18:09:38 +09:00
Tokuhiro Matsuno
ad7cf12128 perl: added test case for "the flag is working?" 2009-07-03 17:27:44 +09:00
Tokuhiro Matsuno
6fb6283463 Checking in changes prior to tagging of version 0.04. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 0c170a3..33fb36c 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,11 @@
+0.04
+
+    - check SvROK first(reported by yappo++)
+    - PreferInteger: faster string to integer conversion; support negative value
+      (frsyuki++)
+    - make PreferInteger variable magical and remove get_sv from _msgpack_pack_sv
+      (frsyuki++)
+
 0.03

     - performance tuning for too long string
2009-07-03 15:23:50 +09:00
Tokuhiro Matsuno
b45dc8db61 check SvROK first 2009-07-03 15:14:31 +09:00
Tokuhiro Matsuno
3397d261d8 Merge branch 'master' of tokuhirom@git.sourceforge.jp:/gitroot/msgpack/msgpack
Conflicts:
	perl/lib/Data/MessagePack.pm
2009-07-03 11:39:34 +09:00
frsyuki
eaa8be8ddd perl: PreferInteger: faster string to integer conversion; support negative value 2009-07-03 02:08:22 +09:00
frsyuki
0f9dcb8610 perl: make PreferInteger variable magical and remove get_sv from _msgpack_pack_sv 2009-07-03 01:49:37 +09:00
Tokuhiro Matsuno
3446c475d7 Checking in changes prior to tagging of version 0.03. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index fb31a69..0c170a3 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.03
+
+    - performance tuning for too long string
+    - fixed memory leaks in stream unpacker
+
 0.02

     - added $Data::MessagePack::PreferInteger
2009-07-02 17:43:58 +09:00
Tokuhiro Matsuno
ffef0a0b6f oops. fixed memory leaks in stream unpacker. 2009-07-02 17:42:28 +09:00
Tokuhiro Matsuno
580fbe77e9 do not check the string longer than 10. 2009-07-02 16:40:41 +09:00
Tokuhiro Matsuno
e92e99c4d1 Perl: I don't need CCFLAGS 2009-07-02 14:43:22 +09:00
Tokuhiro Matsuno
c3f793aa09 Checking in changes prior to tagging of version 0.02. Changelog diff is:
diff --git a/perl/Changes b/perl/Changes
index 18041d4..fb31a69 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.02
+
+    - added $Data::MessagePack::PreferInteger
+      (requested by yappo++)
+
 0.01

     - initial release to CPAN
2009-07-02 14:37:54 +09:00
Tokuhiro Matsuno
3d9908c8e5 Merge branch 'master' of git://git.sourceforge.jp/gitroot/msgpack/msgpack
Conflicts:
	perl/pack.c
2009-07-02 14:31:52 +09:00
Tokuhiro Matsuno
7b198d5966 s/Preferred/Prefer/g suggested by kazuho++ 2009-07-02 14:29:49 +09:00
Tokuhiro Matsuno
601209c83c support $Data::MessagePack::PreferredInteger for Data::Model 2009-07-02 14:25:48 +09:00
Naoki INADA
78db826a75 Fix memory leak. Remove stream packing feature. Add errorcheck in packing. 2009-07-01 20:55:24 +09:00
Tokuhiro Matsuno
c2a63b2c54 Checking in changes prior to tagging of version 0.01. Changelog diff is: 2009-07-01 18:40:14 +09:00
Tokuhiro Matsuno
7c27624161 added .shipit file 2009-07-01 18:34:27 +09:00
Tokuhiro Matsuno
d86b90e663 added Changes file 2009-07-01 18:34:11 +09:00
Tokuhiro Matsuno
d72bef9f9a added MANIFEST.SKIP files 2009-07-01 18:33:56 +09:00
Tokuhiro Matsuno
37972dfe3e copy files into this dir. 2009-07-01 18:20:14 +09:00
Tokuhiro Matsuno
c6496ddf13 added .gitignore file 2009-07-01 18:08:39 +09:00
Tokuhiro Matsuno
a95e8c790c this module requires perl 5.8 2009-07-01 17:45:18 +09:00
Naoki INADA
03942a1b90 Major speedup on packing. 2009-07-01 00:57:46 +09:00
Naoki INADA
d4317fdc85 Some optimization on packing. 2009-06-30 23:03:33 +09:00
Naoki INADA
b5010c71a9 Fix tests. 2009-06-29 11:21:28 +09:00
Naoki INADA
9015bd4ecf Fix error on packing unsigned long long. 2009-06-29 10:09:04 +09:00
Naoki INADA
fe2421275d Add some test cases. 2009-06-29 09:31:43 +09:00
Naoki INADA
257270c1eb Refactor packing code. 2009-06-29 08:23:49 +09:00
Naoki INADA
0b33a634a6 Update test_format. 2009-06-29 08:23:27 +09:00
Naoki INADA
3e396ef146 Don't use C++. 2009-06-28 21:24:16 +09:00
Naoki INADA
1b07b61c04 Ues more suitable type when packing. 2009-06-28 21:24:02 +09:00
Naoki INADA
fa2efcdb5b Rename test files. 2009-06-27 12:04:11 +09:00
Naoki INADA
a345131aaa Add: README 2009-06-27 12:03:00 +09:00
Naoki INADA
ffc16736ba merge to git master 2009-06-27 10:35:07 +09:00
Naoki INADA
3c3df3133c Implement streaming deserializer. 2009-06-26 14:10:20 +09:00
Naoki INADA
16a208243b merge 2009-06-26 14:09:15 +09:00
frsyuki
dd407410d2 version 0.3.3 2009-06-24 16:01:13 +09:00
frsyuki
8f52ed26c7 version 0.3.3 2009-06-24 16:01:13 +09:00
Naoki INADA
479263989b Stop unnecessary caching. 2009-06-24 14:58:02 +09:00
Tokuhiro Matsuno
87e1adcb40 works correctly under Perl5.8.x. Perl5.8.x makes "a" as PVIV in {"a", 0}. 2009-06-24 14:46:28 +09:00
Tokuhiro Matsuno
8e166de1d1 works correctly under Perl5.8.x. Perl5.8.x makes "a" as PVIV in {"a", 0}. 2009-06-24 14:46:28 +09:00
Tokuhiro Matsuno
3aef3edbad works correctly under Perl5.8.x.
Perl5.8.x makes "a" as PVIV in {"a", 0}.
2009-06-24 14:36:37 +09:00
Tokuhiro Matsuno
b2fdaac99e update ppport.h 2009-06-24 14:11:06 +09:00
Tokuhiro Matsuno
9a342ab7f8 update ppport.h 2009-06-24 14:11:06 +09:00
frsyuki
8596d36d02 perl package 2009-06-24 13:53:12 +09:00
Naoki INADA
423e5132a1 merge 2009-06-24 08:49:48 +09:00
Naoki INADA
1581acfd14 Make setup.py executable. 2009-06-24 14:33:36 +09:00
Naoki INADA
5d4189306a Check return value of c-api. 2009-06-24 04:25:05 +09:00
Naoki INADA
f61b282886 Reduce memory footprint. 2009-06-24 01:54:47 +09:00
Naoki INADA
3fd28d0792 Remove duplicated values. 2009-06-24 01:38:48 +09:00
Naoki INADA
dd53b141ef Remove unneccessary value. 2009-06-24 01:13:39 +09:00
Naoki INADA
99d0a41ec6 Fix setup script bug. 2009-06-24 01:13:22 +09:00
Naoki INADA
b8e5b918a3 Update manifest. 2009-06-22 22:50:05 +09:00
Naoki INADA
71af62c1df merge to master. 2009-06-22 20:08:17 +09:00
Naoki INADA
7d5f04917e Update manifest. 2009-06-22 19:55:46 +09:00
Naoki INADA
46d7c65621 Fix compile error. 2009-06-22 19:49:02 +09:00
Naoki INADA
87f5df1503 Use std::stack. 2009-06-22 15:59:02 +09:00
Naoki INADA
9a77ab57f6 merge document fix. 2009-06-22 14:55:46 +09:00
Naoki INADA
20a7ff0be8 Make msgpack package instead of module. and using Cython in setup script. 2009-06-22 14:38:36 +09:00
Naoki INADA
075081a521 Fix manifest. 2009-06-22 14:28:04 +09:00
Naoki INADA
f4387e9746 merge changing include path 2009-06-22 13:26:41 +09:00
Naoki INADA
0d14239c21 Optimize to parsing data that has a number of same short raw field. 2009-06-22 09:51:24 +09:00
Naoki INADA
2475187c7d Fix refcount leak and optimize list initialization. 2009-06-17 13:45:08 +09:00
Naoki INADA
4d6e9ffaa2 Fix can't pack float values. 2009-06-16 01:58:07 +09:00
Naoki INADA
6184e17a42 Increase stack size. 2009-06-16 01:56:04 +09:00
Naoki INADA
e814986b4e Fix document miss. 2009-06-10 13:33:42 +09:00
Naoki INADA
3a9f74e79c Make msgpack package instead of module. 2009-06-10 10:58:09 +09:00
Naoki INADA
a1fb1507d4 Refactor include path. 2009-06-10 10:45:07 +09:00
Naoki INADA
85ca594118 free buffer when packer deleted. 2009-06-09 13:12:29 +09:00
Naoki INADA
9c9393bff9 Fix setup script doesn't work. 2009-06-08 13:21:38 +09:00
Naoki INADA
560bd901f8 Fix double INCREF-ing when unpacking. 2009-06-08 12:46:02 +09:00
Naoki INADA
114ef92d42 Merge branch 'master' of git://git.sourceforge.jp/gitroot/msgpack/msgpack 2009-06-08 04:43:25 +09:00
Naoki INADA
1840ef70ae merge to trunk 2009-06-08 04:38:20 +09:00
Naoki INADA
935db853f0 add test. 2009-06-08 04:33:58 +09:00
Naoki INADA
17d2ca2d63 Fix unpacking True, False and True. 2009-06-08 04:33:47 +09:00
Naoki INADA
c930f5367b add cythoned source and setup script. 2009-06-08 01:43:50 +09:00
Naoki INADA
d8a3bc920c refactoring 2009-06-08 01:30:43 +09:00
Naoki INADA
711e4817a5 support packing long and tuple. add missing files. 2009-06-08 00:23:38 +09:00
frsyuki
7cd359c1fd add msgpack_vrefbuffer, msgpack::vrefbuffer 2009-06-07 14:59:50 +09:00
frsyuki
2598d98922 Merge branch 'master' of frsyuki@git.sourceforge.jp:/gitroot/msgpack/msgpack 2009-06-07 13:33:22 +09:00
frsyuki
8617213149 cpp: fix map<K, V> converter 2009-06-03 22:01:27 +09:00
Naoki INADA
3628ea22d4 add pyx 2009-05-22 14:31:20 +09:00
frsyuki
6a0729ea91 cpp: const 2009-05-13 17:53:27 +09:00
Tokuhiro Matsuno
b0062a7f6f perl: oops. this doens't needed. 2009-04-15 23:14:56 +09:00
Tokuhiro Matsuno
b140b27b9a perl: added argument check 2009-04-15 23:11:26 +09:00
Tokuhiro Matsuno
e0bd2a2911 perl: added benchmark script for deserialization 2009-04-15 23:06:47 +09:00
Tokuhiro Matsuno
ea41db4cc7 perl: renamed benchmark script 2009-04-15 23:02:27 +09:00
Tokuhiro Matsuno
5a201be844 perl: use more efficent strategy for memory allocation.this code taken from JSON::XS. thanks to mlehmann++ 2009-04-15 22:43:59 +09:00
Tokuhiro Matsuno
28e113fd00 oops. remove debugging code. 2009-04-15 22:43:16 +09:00
Tokuhiro Matsuno
5710b87b06 perl: enhancement portability 2009-04-15 13:09:05 +09:00
Tokuhiro Matsuno
8c62d93bca added perl support 2009-04-15 12:55:41 +09:00
frsyuki
b8cc8b72bd version 0.3.1 2009-03-04 01:54:07 +09:00
frsyuki
cc7379d532 more test caces 2009-03-04 01:36:56 +09:00
frsyuki
163fc6f589 fix serialization bug on BigEndian environment 3 2009-03-04 01:15:22 +09:00
frsyuki
c7f193e441 fix serialization bug on BigEndian environment 2009-03-04 01:04:43 +09:00
frsyuki
09978e500a update ruby/msgpack.gemspec 2009-03-01 18:32:50 +09:00
frsyuki
2fad10ca3f zone::base 2009-03-01 16:40:02 +09:00
frsyuki
e707b7a600 zone::push_finalizer reverts memory allocation on exception 2009-03-01 15:49:24 +09:00
frsyuki
e7403013e5 msgpack_zone: sizeof(int) bytes alignment 2009-03-01 14:59:13 +09:00
frsyuki
c3f9696268 fix packaging problem 2009-03-01 13:46:20 +09:00
frsyuki
cb24a0c24f fix msgpack_unpacker_expand_buffer 2009-03-01 03:39:34 +09:00
frsyuki
0efb8160b9 msgpack_zone_clear, msgpack::zone::clear 2009-03-01 02:55:45 +09:00
frsyuki
bf13ba72b5 fix unpacker 2009-03-01 02:27:04 +09:00
frsyuki
6fc38d1669 msgpack::pack is not obsolete 2009-03-01 01:31:12 +09:00
frsyuki
879c70f93a fix msgpack_sbuffer_release 2009-03-01 01:13:31 +09:00
frsyuki
6fda01111e msgpack::sbuffer::data() const 2009-03-01 01:06:16 +09:00
frsyuki
4f4fa39cd5 c: msgpack_sbuffer; cpp: msgpack::sbuffer 2009-03-01 00:59:15 +09:00
frsyuki (none)
c60b6be548 add NOTICE file 2009-02-26 18:37:13 +09:00
frsyuki (none)
9b4b49a6a8 example: limit message size 2009-02-26 01:33:34 +09:00
frsyuki (none)
c0baf9b873 add msgpack_unpacker_message_size 2009-02-26 01:27:00 +09:00
frsyuki (none)
65ef9cab66 remove msgpack_unpacker_buffered_size, add msgpack_unpacker_parsed_size 2009-02-26 01:15:14 +09:00
frsyuki (none)
6ffee9e54a c: msgpack_unpacker_buffered_size; c++: unpacker::buffered_size 2009-02-25 23:31:53 +09:00
frsyuki (none)
43360e3786 fix msgpack::unpack_return 2009-02-25 18:55:56 +09:00
frsyuki (none)
4d708aa4da c: msgpack_pack_object 2009-02-24 16:37:47 +09:00
frsyuki (none)
5d51129e65 add example/simple.c 2009-02-24 16:37:01 +09:00
frsyuki (none)
a0b82e39e1 AC_CONFIG_AUX_DIR(ac) 2009-02-22 15:47:06 +09:00
frsyuki (none)
9642368835 type conversion operator msgpack_object <-> msgpack::object 2009-02-22 15:36:02 +09:00
frsyuki (none)
cbf7afc1cc c and c++: rewritten and integrated 2009-02-22 15:14:21 +09:00
138 changed files with 10501 additions and 8204 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");
you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,4 @@
if ENABLE_CXX
export ERB
SUBDIRS = c cpp
else
SUBDIRS = c
@@ -9,40 +8,6 @@ nobase_include_HEADERS = \
msgpack/pack_define.h \
msgpack/pack_template.h \
msgpack/unpack_define.h \
msgpack/unpack_template.h
EXTRA_DIST = \
ruby/bench.rb \
ruby/extconf.rb \
ruby/gem/README \
ruby/gem/Rakefile \
ruby/gem/test/test_helper.rb \
ruby/gengem.sh \
ruby/msgpack.gemspec \
ruby/pack.c \
ruby/pack.h \
ruby/rbinit.c \
ruby/test_case.rb \
ruby/test_format.rb \
ruby/test_pack.rb \
ruby/unpack.c \
ruby/unpack.h \
perl/Makefile.PL \
perl/MessagePack.c \
perl/benchmark/deserialize.pl \
perl/benchmark/serialize.pl \
perl/lib/Data/MessagePack.pm \
perl/lib/Data/MessagePack \
perl/lib/Data/MessagePack/Unpacker.pod \
perl/pack.c \
perl/ppport.h \
perl/t/00_compile.t \
perl/t/01_pack.t \
perl/t/02_unpack.t \
perl/t/03_stream_unpack.t \
perl/t/04_invert.t \
perl/t/Util.pm \
perl/t/data.pl \
perl/unpack.c \
perl/xt/99_pod.t
msgpack/unpack_template.h \
msgpack/sysdep.h

12
README
View File

@@ -8,9 +8,7 @@ Binary-based efficient data interchange format.
MessagePack is only tested on Linux and Mac OS X, but it may run on other
UNIX-like platforms.
Following programs are required to build:
- gcc >= 4.1 with C++ support
- ruby >= 1.8 (ruby is used as a preprocessor)
gcc >= 4.1 is required to build.
*Installation
@@ -21,12 +19,12 @@ Binary-based efficient data interchange format.
$ make
$ 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.
$ cd ruby
$ ./gengem.sh
$ gem install gem/pkg/msgpack-*.gem
$ ./makegem.sh
$ gem install msgpack-*.gem
*Usage
@@ -56,7 +54,7 @@ Binary-based efficient data interchange format.
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");
you may not use this file except in compliance with the License.

View File

@@ -31,11 +31,8 @@ if test x"$1" = x"--help"; then
fi
#if [ -z "$NO_NEST" ];then
# cd c && ./bootstrap $@; cd ..
# cd cpp && ./bootstrap $@; cd ..
#fi
mkdir -p ac
(cd cpp && ./preprocess.sh $@; cd ..)
ACLOCAL="aclocal"

View File

@@ -16,5 +16,13 @@ nobase_include_HEADERS = \
msgpack/zone.h
# -version-info CURRENT:REVISION:AGE
libmsgpackc_la_LDFLAGS = -version-info 1:0:0
libmsgpackc_la_LDFLAGS = -version-info 2:0:0
check_PROGRAMS = \
msgpackc_test
msgpackc_test_SOURCES = test.cpp
msgpackc_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c
msgpackc_test_LDADD = libmsgpackc.la -lgtest_main
TESTS = $(check_PROGRAMS)

View File

@@ -1 +0,0 @@
.

View File

@@ -19,9 +19,6 @@
#define MSGPACK_OBJECT_H__
#include "msgpack/zone.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#ifdef __cplusplus

View File

@@ -18,11 +18,9 @@
#ifndef MSGPACK_PACK_H__
#define MSGPACK_PACK_H__
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "msgpack/pack_define.h"
#include "msgpack/object.h"
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -15,13 +15,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef msgpack_unpacker_H__
#define msgpack_unpacker_H__
#ifndef MSGPACK_UNPACKER_H__
#define MSGPACK_UNPACKER_H__
#include "msgpack/zone.h"
#include "msgpack/object.h"
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {

View File

@@ -19,7 +19,16 @@
#define MSGPACK_VREFBUFFER_H__
#include "msgpack/zone.h"
#ifndef _WIN32
#include <sys/uio.h>
#else
struct iovec {
void *iov_base;
size_t iov_len;
};
#endif
#ifdef __cplusplus
extern "C" {
@@ -31,24 +40,27 @@ extern "C" {
#endif
#ifndef MSGPACK_VREFBUFFER_CHUNK_SIZE
#define MSGPACK_VREFBUFFER_CHUNK_SIZE 2048
#define MSGPACK_VREFBUFFER_CHUNK_SIZE 8192
#endif
typedef struct msgpack_vrefbuffer_chunk {
struct msgpack_vrefbuffer_chunk;
typedef struct msgpack_vrefbuffer_chunk msgpack_vrefbuffer_chunk;
typedef struct msgpack_vrefbuffer_inner_buffer {
size_t free;
struct msgpack_vrefbuffer_chunk* next;
/* data ... */
} msgpack_vrefbuffer_chunk;
char* ptr;
msgpack_vrefbuffer_chunk* head;
} msgpack_vrefbuffer_inner_buffer;
typedef struct msgpack_vrefbuffer {
size_t chunk_size;
size_t ref_size;
struct iovec* tail;
struct iovec* end;
struct iovec* array;
msgpack_vrefbuffer_chunk* chunk;
size_t chunk_size;
size_t ref_size;
msgpack_vrefbuffer_inner_buffer inner_buffer;
} msgpack_vrefbuffer;
@@ -67,6 +79,7 @@ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
const char* buf, unsigned int len);
int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to);
int msgpack_vrefbuffer_write(void* data, const char* buf, unsigned int len)
{

View File

@@ -18,6 +18,7 @@
#ifndef MSGPACK_ZONE_H__
#define MSGPACK_ZONE_H__
#include "msgpack/sysdep.h"
#include <stddef.h>
#include <stdbool.h>
@@ -26,37 +27,34 @@ extern "C" {
#endif
typedef struct msgpack_zone_chunk {
size_t free;
char* ptr;
void* alloc;
} msgpack_zone_chunk;
typedef struct msgpack_zone_finalizer {
void (*func)(void* data);
void* data;
} msgpack_zone_finalizer;
typedef struct msgpack_zone_chunk_array {
msgpack_zone_chunk* tail;
msgpack_zone_chunk* end;
msgpack_zone_chunk* array;
} msgpack_zone_chunk_array;
typedef struct msgpack_zone_finalizer_array {
msgpack_zone_finalizer* tail;
msgpack_zone_finalizer* end;
msgpack_zone_finalizer* array;
} msgpack_zone_finalizer_array;
struct msgpack_zone_chunk;
typedef struct msgpack_zone_chunk msgpack_zone_chunk;
typedef struct msgpack_zone_chunk_list {
size_t free;
char* ptr;
msgpack_zone_chunk* head;
} msgpack_zone_chunk_list;
typedef struct msgpack_zone {
msgpack_zone_chunk_array chunk_array;
msgpack_zone_chunk_list chunk_list;
msgpack_zone_finalizer_array finalizer_array;
size_t chunk_size;
} msgpack_zone;
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 2048
#define MSGPACK_ZONE_CHUNK_SIZE 8192
#endif
bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size);
@@ -85,15 +83,15 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size);
void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size)
{
msgpack_zone_chunk* chunk = zone->chunk_array.tail;
msgpack_zone_chunk_list* cl = &zone->chunk_list;
if(chunk->free < size) {
if(zone->chunk_list.free < size) {
return msgpack_zone_malloc_expand(zone, size);
}
char* ptr = chunk->ptr;
chunk->ptr += size;
chunk->free -= size;
char* ptr = cl->ptr;
cl->free -= size;
cl->ptr += size;
return ptr;
}

View File

@@ -18,7 +18,17 @@
#include "msgpack/object.h"
#include "msgpack/pack.h"
#include <stdio.h>
#ifndef _MSC_VER
#include <inttypes.h>
#else
#ifndef PRIu64
#define PRIu64 "I64u"
#endif
#ifndef PRIi64
#define PRIi64 "I64d"
#endif
#endif
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d)

424
c/test.cpp Normal file
View File

@@ -0,0 +1,424 @@
#include "msgpack.h"
#include <math.h>
#include <vector>
#include <limits>
#include <gtest/gtest.h>
using namespace std;
const unsigned int kLoop = 10000;
const double kEPS = 1e-10;
#define GEN_TEST_SIGNED(test_type, func_type) \
do { \
vector<test_type> v; \
v.push_back(0); \
v.push_back(1); \
v.push_back(-1); \
v.push_back(numeric_limits<test_type>::min()); \
v.push_back(numeric_limits<test_type>::max()); \
for (unsigned int i = 0; i < kLoop; i++) \
v.push_back(rand()); \
for (unsigned int i = 0; i < v.size() ; i++) { \
test_type val = v[i]; \
msgpack_sbuffer sbuf; \
msgpack_sbuffer_init(&sbuf); \
msgpack_packer pk; \
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); \
msgpack_pack_##func_type(&pk, val); \
msgpack_zone z; \
msgpack_zone_init(&z, 2048); \
msgpack_object obj; \
msgpack_unpack_return ret = \
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); \
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); \
if (val < 0) { \
EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, obj.type); \
EXPECT_EQ(val, obj.via.i64); \
} else { \
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); \
EXPECT_EQ(val, obj.via.u64); \
} \
msgpack_zone_destroy(&z); \
msgpack_sbuffer_destroy(&sbuf); \
} \
} while(0)
#define GEN_TEST_UNSIGNED(test_type, func_type) \
do { \
vector<test_type> v; \
v.push_back(0); \
v.push_back(1); \
v.push_back(2); \
v.push_back(numeric_limits<test_type>::min()); \
v.push_back(numeric_limits<test_type>::max()); \
for (unsigned int i = 0; i < kLoop; i++) \
v.push_back(rand()); \
for (unsigned int i = 0; i < v.size() ; i++) { \
test_type val = v[i]; \
msgpack_sbuffer sbuf; \
msgpack_sbuffer_init(&sbuf); \
msgpack_packer pk; \
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write); \
msgpack_pack_##func_type(&pk, val); \
msgpack_zone z; \
msgpack_zone_init(&z, 2048); \
msgpack_object obj; \
msgpack_unpack_return ret = \
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj); \
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret); \
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type); \
EXPECT_EQ(val, obj.via.u64); \
msgpack_zone_destroy(&z); \
msgpack_sbuffer_destroy(&sbuf); \
} \
} while(0)
TEST(MSGPACKC, simple_buffer_short)
{
GEN_TEST_SIGNED(short, short);
}
TEST(MSGPACKC, simple_buffer_int)
{
GEN_TEST_SIGNED(int, int);
}
TEST(MSGPACKC, simple_buffer_long)
{
GEN_TEST_SIGNED(long, long);
}
TEST(MSGPACKC, simple_buffer_long_long)
{
GEN_TEST_SIGNED(long long, long_long);
}
TEST(MSGPACKC, simple_buffer_unsigned_short)
{
GEN_TEST_UNSIGNED(unsigned short, unsigned_short);
}
TEST(MSGPACKC, simple_buffer_unsigned_int)
{
GEN_TEST_UNSIGNED(unsigned int, unsigned_int);
}
TEST(MSGPACKC, simple_buffer_unsigned_long)
{
GEN_TEST_UNSIGNED(unsigned long, unsigned_long);
}
TEST(MSGPACKC, simple_buffer_unsigned_long_long)
{
GEN_TEST_UNSIGNED(unsigned long long, unsigned_long_long);
}
TEST(MSGPACKC, simple_buffer_uint8)
{
GEN_TEST_UNSIGNED(uint8_t, uint8);
}
TEST(MSGPACKC, simple_buffer_uint16)
{
GEN_TEST_UNSIGNED(uint16_t, uint16);
}
TEST(MSGPACKC, simple_buffer_uint32)
{
GEN_TEST_UNSIGNED(uint32_t, uint32);
}
TEST(MSGPACKC, simple_buffer_uint64)
{
GEN_TEST_UNSIGNED(uint64_t, uint64);
}
TEST(MSGPACKC, simple_buffer_int8)
{
GEN_TEST_SIGNED(int8_t, int8);
}
TEST(MSGPACKC, simple_buffer_int16)
{
GEN_TEST_SIGNED(int16_t, int16);
}
TEST(MSGPACKC, simple_buffer_int32)
{
GEN_TEST_SIGNED(int32_t, int32);
}
TEST(MSGPACKC, simple_buffer_int64)
{
GEN_TEST_SIGNED(int64_t, int64);
}
TEST(MSGPACKC, simple_buffer_float)
{
vector<float> v;
v.push_back(0.0);
v.push_back(1.0);
v.push_back(-1.0);
v.push_back(numeric_limits<float>::min());
v.push_back(numeric_limits<float>::max());
v.push_back(nanf("tag"));
v.push_back(1.0/0.0); // inf
v.push_back(-(1.0/0.0)); // -inf
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(drand48());
v.push_back(-drand48());
}
for (unsigned int i = 0; i < v.size() ; i++) {
float val = v[i];
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_float(&pk, val);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret =
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, obj.type);
if (isnan(val))
EXPECT_TRUE(isnan(obj.via.dec));
else if (isinf(val))
EXPECT_TRUE(isinf(obj.via.dec));
else
EXPECT_TRUE(fabs(obj.via.dec - val) <= kEPS);
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
}
TEST(MSGPACKC, simple_buffer_double)
{
vector<double> v;
v.push_back(0.0);
v.push_back(-0.0);
v.push_back(1.0);
v.push_back(-1.0);
v.push_back(numeric_limits<double>::min());
v.push_back(numeric_limits<double>::max());
v.push_back(nan("tag"));
v.push_back(1.0/0.0); // inf
v.push_back(-(1.0/0.0)); // -inf
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(drand48());
v.push_back(-drand48());
}
for (unsigned int i = 0; i < v.size() ; i++) {
double val = v[i];
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_double(&pk, val);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret =
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, obj.type);
if (isnan(val))
EXPECT_TRUE(isnan(obj.via.dec));
else if (isinf(val))
EXPECT_TRUE(isinf(obj.via.dec));
else
EXPECT_TRUE(fabs(obj.via.dec - val) <= kEPS);
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
}
TEST(MSGPACKC, simple_buffer_nil)
{
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_nil(&pk);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret =
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_NIL, obj.type);
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
TEST(MSGPACKC, simple_buffer_true)
{
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_true(&pk);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret =
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type);
EXPECT_EQ(true, obj.via.boolean);
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
TEST(MSGPACKC, simple_buffer_false)
{
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_false(&pk);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret =
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, obj.type);
EXPECT_EQ(false, obj.via.boolean);
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
TEST(MSGPACKC, simple_buffer_array)
{
unsigned int array_size = 5;
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_array(&pk, array_size);
msgpack_pack_nil(&pk);
msgpack_pack_true(&pk);
msgpack_pack_false(&pk);
msgpack_pack_int(&pk, 10);
msgpack_pack_int(&pk, -10);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret;
ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type);
EXPECT_EQ(array_size, obj.via.array.size);
for (unsigned int i = 0; i < obj.via.array.size; i++) {
msgpack_object o = obj.via.array.ptr[i];
switch (i) {
case 0:
EXPECT_EQ(MSGPACK_OBJECT_NIL, o.type);
break;
case 1:
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, o.type);
EXPECT_EQ(true, o.via.boolean);
break;
case 2:
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, o.type);
EXPECT_EQ(false, o.via.boolean);
break;
case 3:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, o.type);
EXPECT_EQ(10, o.via.u64);
break;
case 4:
EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, o.type);
EXPECT_EQ(-10, o.via.i64);
break;
}
}
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
TEST(MSGPACKC, simple_buffer_map)
{
unsigned int map_size = 2;
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_map(&pk, map_size);
msgpack_pack_true(&pk);
msgpack_pack_false(&pk);
msgpack_pack_int(&pk, 10);
msgpack_pack_int(&pk, -10);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret;
ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type);
EXPECT_EQ(map_size, obj.via.map.size);
for (unsigned int i = 0; i < map_size; i++) {
msgpack_object key = obj.via.map.ptr[i].key;
msgpack_object val = obj.via.map.ptr[i].val;
switch (i) {
case 0:
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, key.type);
EXPECT_EQ(true, key.via.boolean);
EXPECT_EQ(MSGPACK_OBJECT_BOOLEAN, val.type);
EXPECT_EQ(false, val.via.boolean);
break;
case 1:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, key.type);
EXPECT_EQ(10, key.via.u64);
EXPECT_EQ(MSGPACK_OBJECT_NEGATIVE_INTEGER, val.type);
EXPECT_EQ(-10, val.via.i64);
break;
}
}
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}
TEST(MSGPACKC, simple_buffer_raw)
{
unsigned int raw_size = 7;
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_raw(&pk, raw_size);
msgpack_pack_raw_body(&pk, "fr", 2);
msgpack_pack_raw_body(&pk, "syuki", 5);
// invalid data
msgpack_pack_raw_body(&pk, "", 0);
msgpack_pack_raw_body(&pk, "kzk", 0);
msgpack_zone z;
msgpack_zone_init(&z, 2048);
msgpack_object obj;
msgpack_unpack_return ret;
ret = msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
EXPECT_EQ(MSGPACK_UNPACK_SUCCESS, ret);
EXPECT_EQ(MSGPACK_OBJECT_RAW, obj.type);
EXPECT_EQ(raw_size, obj.via.raw.size);
EXPECT_EQ(0, memcmp("frsyuki", obj.via.raw.ptr, raw_size));
msgpack_zone_destroy(&z);
msgpack_sbuffer_destroy(&sbuf);
}

View File

@@ -101,7 +101,7 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
{
o->type = MSGPACK_OBJECT_ARRAY;
o->via.array.size = 0;
o->via.array.ptr = msgpack_zone_malloc(u->z, n*sizeof(msgpack_object));
o->via.array.ptr = (msgpack_object*)msgpack_zone_malloc(u->z, n*sizeof(msgpack_object));
if(o->via.array.ptr == NULL) { return -1; }
return 0;
}
@@ -141,31 +141,31 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
#define CTX_CAST(m) ((template_context*)(m))
#define CTX_REFERENCED(mpac) CTX_CAST((mpac)->ctx)->user.referenced
#define COUNTER_SIZE (sizeof(_msgpack_atomic_counter_t))
static const size_t COUNTER_SIZE = sizeof(unsigned int);
static inline void init_count(void* buffer)
{
*(volatile unsigned int*)buffer = 1;
*(volatile _msgpack_atomic_counter_t*)buffer = 1;
}
static inline void decl_count(void* buffer)
{
//if(--*(unsigned int*)buffer == 0) {
if(__sync_sub_and_fetch((unsigned int*)buffer, 1) == 0) {
// atomic if(--*(_msgpack_atomic_counter_t*)buffer == 0) { free(buffer); }
if(_msgpack_sync_decr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer) == 0) {
free(buffer);
}
}
static inline void incr_count(void* buffer)
{
//++*(unsigned int*)buffer;
__sync_add_and_fetch((unsigned int*)buffer, 1);
// atomic ++*(_msgpack_atomic_counter_t*)buffer;
_msgpack_sync_incr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer);
}
static inline unsigned int get_count(void* buffer)
static inline _msgpack_atomic_counter_t get_count(void* buffer)
{
return *(volatile unsigned int*)buffer;
return *(volatile _msgpack_atomic_counter_t*)buffer;
}

View File

@@ -19,19 +19,18 @@
#include <stdlib.h>
#include <string.h>
struct msgpack_vrefbuffer_chunk {
struct msgpack_vrefbuffer_chunk* next;
/* data ... */
};
bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
size_t ref_size, size_t chunk_size)
{
if(chunk_size < sizeof(msgpack_vrefbuffer_chunk)+72) {
chunk_size = 72;
} else {
chunk_size -= sizeof(msgpack_vrefbuffer_chunk);
}
vbuf->chunk_size = chunk_size;
vbuf->ref_size = ref_size;
// glibcは72バイト以下のmallocが高速
// glibcは72バイト以下のmallocが高速
size_t nfirst = (sizeof(struct iovec) < 72/2) ?
72 / sizeof(struct iovec) : 8;
@@ -45,26 +44,30 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
vbuf->end = array + nfirst;
vbuf->array = array;
vbuf->chunk = (msgpack_vrefbuffer_chunk*)malloc(
chunk_size + sizeof(msgpack_vrefbuffer_chunk));
if(vbuf->chunk == NULL) {
msgpack_vrefbuffer_chunk* chunk = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
if(chunk == NULL) {
free(array);
return false;
}
vbuf->chunk->next = NULL;
vbuf->chunk->free = chunk_size;
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
ib->free = chunk_size;
ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
ib->head = chunk;
chunk->next = NULL;
return true;
}
void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
{
msgpack_vrefbuffer_chunk* c = vbuf->chunk;
msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head;
while(true) {
msgpack_vrefbuffer_chunk* n = c->next;
free(c);
if(n) {
if(n != NULL) {
c = n;
} else {
break;
@@ -77,7 +80,7 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
const char* buf, unsigned int len)
{
if(vbuf->tail == vbuf->end) {
const size_t nused = vbuf->end - vbuf->array;
const size_t nused = vbuf->tail - vbuf->array;
const size_t nnext = nused * 2;
struct iovec* nvec = (struct iovec*)realloc(
@@ -101,28 +104,30 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
const char* buf, unsigned int len)
{
msgpack_vrefbuffer_chunk* chunk = vbuf->chunk;
size_t cur_size = vbuf->chunk_size;
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
if(chunk->free < len) {
cur_size = (cur_size > len) ? cur_size : len;
if(ib->free < len) {
size_t sz = vbuf->chunk_size;
if(sz < len) {
sz = len;
}
chunk = (msgpack_vrefbuffer_chunk*)malloc(
cur_size + sizeof(msgpack_vrefbuffer_chunk));
msgpack_vrefbuffer_chunk* chunk = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + sz);
if(chunk == NULL) {
return -1;
}
chunk->free = cur_size;
chunk->next = vbuf->chunk;
vbuf->chunk = chunk;
chunk->next = ib->head;
ib->head = chunk;
ib->free = sz;
ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
}
char* m = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk)
+ (cur_size - chunk->free);
char* m = ib->ptr;
memcpy(m, buf, len);
chunk->free -= len;
ib->free -= len;
ib->ptr += len;
if(vbuf->tail != vbuf->array && m ==
(const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
@@ -133,3 +138,65 @@ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
}
}
int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{
size_t sz = vbuf->chunk_size;
msgpack_vrefbuffer_chunk* empty = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + sz);
if(empty == NULL) {
return -1;
}
empty->next = NULL;
const size_t nused = vbuf->tail - vbuf->array;
if(to->tail + nused < vbuf->end) {
const size_t tosize = to->tail - to->array;
const size_t reqsize = nused + tosize;
size_t nnext = (to->end - to->array) * 2;
while(nnext < reqsize) {
nnext *= 2;
}
struct iovec* nvec = (struct iovec*)realloc(
to->array, sizeof(struct iovec)*nnext);
if(nvec == NULL) {
free(empty);
return -1;
}
to->array = nvec;
to->end = nvec + nnext;
to->tail = nvec + tosize;
}
memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
to->tail += nused;
vbuf->tail = vbuf->array;
msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
msgpack_vrefbuffer_inner_buffer* const toib = &to->inner_buffer;
msgpack_vrefbuffer_chunk* last = ib->head;
while(last->next != NULL) {
last = last->next;
}
last->next = toib->head;
toib->head = ib->head;
if(toib->free < ib->free) {
toib->free = ib->free;
toib->ptr = ib->ptr;
}
ib->head = empty;
ib->free = sz;
ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk);
return 0;
}

157
c/zone.c
View File

@@ -19,83 +19,61 @@
#include <stdlib.h>
#include <string.h>
static inline bool init_chunk_array(msgpack_zone_chunk_array* ca, size_t chunk_size)
{
// glibcは72バイト以下のmallocが高速
const size_t nfirst = (sizeof(msgpack_zone_chunk) < 72/2) ?
72 / sizeof(msgpack_zone_chunk) : 8;
struct msgpack_zone_chunk {
struct msgpack_zone_chunk* next;
/* data ... */
};
msgpack_zone_chunk* array = (msgpack_zone_chunk*)malloc(
sizeof(msgpack_zone_chunk) * nfirst);
if(array == NULL) {
static inline bool init_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size)
{
msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
sizeof(msgpack_zone_chunk) + chunk_size);
if(chunk == NULL) {
return false;
}
const size_t sz = chunk_size;
char* ptr = (char*)malloc(sz);
if(ptr == NULL) {
free(array);
return NULL;
}
ca->tail = array;
ca->end = array + nfirst;
ca->array = array;
array[0].free = sz;
array[0].ptr = ptr;
array[0].alloc = ptr;
cl->head = chunk;
cl->free = chunk_size;
cl->ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
chunk->next = NULL;
return true;
}
static inline void destroy_chunk_array(msgpack_zone_chunk_array* ca)
static inline void destroy_chunk_list(msgpack_zone_chunk_list* cl)
{
msgpack_zone_chunk* chunk = ca->array;
for(; chunk != ca->tail+1; ++chunk) {
free(chunk->alloc);
msgpack_zone_chunk* c = cl->head;
while(true) {
msgpack_zone_chunk* n = c->next;
free(c);
if(n != NULL) {
c = n;
} else {
break;
}
}
free(ca->array);
}
static inline void clear_chunk_array(msgpack_zone_chunk_array* ca)
static inline void clear_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size)
{
msgpack_zone_chunk* chunk = ca->array + 1;
for(; chunk != ca->tail+1; ++chunk) {
free(chunk->alloc);
msgpack_zone_chunk* c = cl->head;
while(true) {
msgpack_zone_chunk* n = c->next;
if(n != NULL) {
free(c);
c = n;
} else {
break;
}
}
ca->tail = ca->array;
ca->array[0].free += ca->array[0].ptr - (char*)ca->array[0].alloc;
ca->array[0].ptr = (char*)ca->array[0].alloc;
cl->head->next = NULL;
cl->free = chunk_size;
cl->ptr = ((char*)cl->head) + sizeof(msgpack_zone_chunk);
}
void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
{
msgpack_zone_chunk_array* const ca = &zone->chunk_array;
msgpack_zone_chunk* chunk = ++ca->tail;
if(chunk == ca->end) {
// ca->arrayに空きがない
// ca->arrayを拡張する
const size_t nused = ca->end - ca->array;
const size_t nnext = (ca->end - ca->array) * 2;
chunk = (msgpack_zone_chunk*)realloc(ca->array,
sizeof(msgpack_zone_chunk) * nnext);
if(chunk == NULL) {
return NULL;
}
ca->array = chunk;
ca->end = chunk + nnext;
chunk = ca->tail = chunk + nused;
}
msgpack_zone_chunk_list* const cl = &zone->chunk_list;
size_t sz = zone->chunk_size;
@@ -103,14 +81,15 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
sz *= 2;
}
char* ptr = (char*)malloc(sz);
if(ptr == NULL) {
return NULL;
}
msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
sizeof(msgpack_zone_chunk) + sz);
chunk->free = sz - size;
chunk->ptr = ptr + size;
chunk->alloc = ptr;
char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
chunk->next = cl->head;
cl->head = chunk;
cl->free = sz - size;
cl->ptr = ptr + size;
return ptr;
}
@@ -125,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)
{
// 逆順に呼び出し
msgpack_zone_finalizer* fin = fa->tail;
for(; fin != fa->array; --fin) {
(*(fin-1)->func)((fin-1)->data);
@@ -153,9 +131,6 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
size_t nnext;
if(nused == 0) {
// 初回の呼び出しfa->tail == fa->end == fa->array == NULL
// glibcは72バイト以下のmallocが高速
nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
72 / sizeof(msgpack_zone_finalizer) : 8;
@@ -185,19 +160,30 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
bool msgpack_zone_is_empty(msgpack_zone* zone)
{
msgpack_zone_chunk_array* const ca = &zone->chunk_array;
msgpack_zone_chunk_list* const cl = &zone->chunk_list;
msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
return ca->array[0].ptr == ca->array[0].alloc &&
ca->tail == ca->array &&
return cl->free == zone->chunk_size && cl->head->next == NULL &&
fa->tail == fa->array;
}
void msgpack_zone_destroy(msgpack_zone* zone)
{
destroy_finalizer_array(&zone->finalizer_array);
destroy_chunk_list(&zone->chunk_list);
}
void msgpack_zone_clear(msgpack_zone* zone)
{
clear_finalizer_array(&zone->finalizer_array);
clear_chunk_list(&zone->chunk_list, zone->chunk_size);
}
bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size)
{
zone->chunk_size = chunk_size;
if(!init_chunk_array(&zone->chunk_array, chunk_size)) {
if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
return false;
}
@@ -206,30 +192,23 @@ bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size)
return true;
}
void msgpack_zone_destroy(msgpack_zone* zone)
{
destroy_finalizer_array(&zone->finalizer_array);
destroy_chunk_array(&zone->chunk_array);
}
void msgpack_zone_clear(msgpack_zone* zone)
{
clear_finalizer_array(&zone->finalizer_array);
clear_chunk_array(&zone->chunk_array);
}
msgpack_zone* msgpack_zone_new(size_t chunk_size)
{
msgpack_zone* zone = (msgpack_zone*)malloc(sizeof(msgpack_zone));
msgpack_zone* zone = (msgpack_zone*)malloc(
sizeof(msgpack_zone) + chunk_size);
if(zone == NULL) {
return NULL;
}
if(!msgpack_zone_init(zone, chunk_size)) {
zone->chunk_size = chunk_size;
if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
free(zone);
return NULL;
return false;
}
init_finalizer_array(&zone->finalizer_array);
return zone;
}

View File

@@ -1,6 +1,6 @@
AC_INIT(msgpack/unpack_template.h)
AC_CONFIG_AUX_DIR(ac)
AM_INIT_AUTOMAKE(msgpack, 0.3.2)
AM_INIT_AUTOMAKE(msgpack, 0.4.1)
AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)
@@ -12,7 +12,6 @@ AC_PROG_CC
CFLAGS="-O4 -Wall $CFLAGS -I.."
AC_MSG_CHECKING([if c++ api is enabled])
AC_ARG_ENABLE(cxx,
AS_HELP_STRING([--disable-cxx],
@@ -23,18 +22,36 @@ if test "$enable_cxx" != "no"; then
if test "" = "$CXXFLAGS"; then
CXXFLAGS="-g -O4"
fi
AC_CHECK_PROG(ERB, erb, erb)
if test "x$ERB" = x; then
AC_MSG_ERROR([cannot find erb. Ruby is needed to build.])
fi
fi
# FIXME
# FIXME enable_cxx
AC_PROG_CXX
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")

View File

@@ -12,36 +12,33 @@ nobase_include_HEADERS = \
msgpack/object.hpp \
msgpack/zone.hpp \
msgpack/type.hpp \
msgpack/type/array.hpp \
msgpack/type/boolean.hpp \
msgpack/type/bool.hpp \
msgpack/type/float.hpp \
msgpack/type/integer.hpp \
msgpack/type/int.hpp \
msgpack/type/list.hpp \
msgpack/type/deque.hpp \
msgpack/type/map.hpp \
msgpack/type/nil.hpp \
msgpack/type/pair.hpp \
msgpack/type/raw.hpp \
msgpack/type/tuple.hpp
# FIXME
object.lo: msgpack/type/tuple.hpp msgpack/zone.hpp
msgpack/type/tuple.hpp: msgpack/type/tuple.hpp.erb
$(ERB) $< > $@.tmp
mv $@.tmp $@
msgpack/zone.hpp: msgpack/zone.hpp.erb
$(ERB) $< > $@.tmp
mv $@.tmp $@
MOSTLYCLEANFILES = \
msgpack/type/set.hpp \
msgpack/type/string.hpp \
msgpack/type/vector.hpp \
msgpack/type/tuple.hpp \
msgpack/zone.hpp
EXTRA_DIST = \
msgpack/type/tuple.hpp.erb \
msgpack/zone.hpp.erb
msgpack/type/define.hpp \
msgpack/type/tr1/unordered_map.hpp \
msgpack/type/tr1/unordered_set.hpp
libmsgpack_la_LIBADD = -L../c -lmsgpackc
# -version-info CURRENT:REVISION:AGE
libmsgpack_la_LDFLAGS = -version-info 1:0:0
libmsgpack_la_LDFLAGS = -version-info 2:0:0
check_PROGRAMS = \
msgpack_test
msgpack_test_SOURCES = test.cpp
msgpack_test_CXXFLAGS = -I$(top_srcdir) -I$(top_srcdir)/c -I$(top_srcdir)/cpp
msgpack_test_LDADD = libmsgpack.la -lgtest_main
TESTS = $(check_PROGRAMS)

View File

@@ -1 +0,0 @@
.

View File

@@ -20,7 +20,6 @@
#include "msgpack/object.h"
#include "msgpack/pack.hpp"
#include <stdint.h>
#include <string.h>
#include <stdexcept>
#include <typeinfo>
@@ -129,6 +128,7 @@ private:
};
// obsolete
template <typename Type>
class define : public Type {
public:

View File

@@ -18,10 +18,9 @@
#ifndef MSGPACK_PACK_HPP__
#define MSGPACK_PACK_HPP__
#include <arpa/inet.h> // __BYTE_ORDER
#include "msgpack/pack_define.h"
#include <stdexcept>
#include <limits.h>
#include "msgpack/pack_define.h"
namespace msgpack {

15
cpp/msgpack/type.hpp Normal file
View File

@@ -0,0 +1,15 @@
#include "msgpack/type/bool.hpp"
#include "msgpack/type/float.hpp"
#include "msgpack/type/int.hpp"
#include "msgpack/type/list.hpp"
#include "msgpack/type/deque.hpp"
#include "msgpack/type/map.hpp"
#include "msgpack/type/nil.hpp"
#include "msgpack/type/pair.hpp"
#include "msgpack/type/raw.hpp"
#include "msgpack/type/set.hpp"
#include "msgpack/type/string.hpp"
#include "msgpack/type/vector.hpp"
#include "msgpack/type/tuple.hpp"
#include "msgpack/type/define.hpp"

View File

@@ -15,8 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_BOOLEAN_HPP__
#define MSGPACK_TYPE_BOOLEAN_HPP__
#ifndef MSGPACK_TYPE_BOOL_HPP__
#define MSGPACK_TYPE_BOOL_HPP__
#include "msgpack/object.hpp"
#include <vector>
@@ -31,7 +31,6 @@ inline bool& operator>> (object o, bool& v)
return v;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v)
{

View File

@@ -0,0 +1,98 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_DEFINE_HPP__
#define MSGPACK_TYPE_DEFINE_HPP__
#define MSGPACK_DEFINE(...) \
template <typename Packer> \
void msgpack_pack(Packer& pk) const \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
} \
void msgpack_unpack(msgpack::object o) \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
}
namespace msgpack {
namespace type {
<% GENERATION_LIMIT = 31 %>
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
struct define;
template <>
struct define<> {
typedef define<> value_type;
typedef tuple<> tuple_type;
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(1);
}
void msgpack_unpack(msgpack::object o)
{
if(o.type != type::ARRAY) { throw type_error(); }
}
};
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
typedef define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> tuple_type;
define(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) :
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(<%=i+1%>);
<%0.upto(i) {|j|%>
pk.pack(a<%=j%>);<%}%>
}
void msgpack_unpack(msgpack::object o)
{
if(o.type != type::ARRAY) { throw type_error(); }
const size_t size = o.via.array.size;
<%0.upto(i) {|j|%>
if(size <= <%=j%>) { return; } o.via.array.ptr[<%=j%>].convert(&a<%=j%>);<%}%>
}
<%0.upto(i) {|j|%>
A<%=j%>& a<%=j%>;<%}%>
};
<%}%>
inline define<> make_define()
{
return define<>();
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>)
{
return define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
} // namespace type
} // namespace msgpack
#endif /* msgpack/type/define.hpp */

View File

@@ -0,0 +1,56 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_DEQUE_HPP__
#define MSGPACK_TYPE_DEQUE_HPP__
#include "msgpack/object.hpp"
#include <deque>
namespace msgpack {
template <typename T>
inline std::deque<T>& operator>> (object o, std::deque<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.array.size);
object* p = o.via.array.ptr;
object* const pend = o.via.array.ptr + o.via.array.size;
typename std::deque<T>::iterator it = v.begin();
for(; p < pend; ++p, ++it) {
p->convert(&*it);
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v)
{
o.pack_array(v.size());
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
} // namespace msgpack
#endif /* msgpack/type/deque.hpp */

View File

@@ -34,7 +34,6 @@ inline float& operator>> (object o, float& v)
return v;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
{
@@ -50,7 +49,6 @@ inline double& operator>> (object o, double& v)
return v;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
{

View File

@@ -15,8 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_INTEGER_HPP__
#define MSGPACK_TYPE_INTEGER_HPP__
#ifndef MSGPACK_TYPE_INT_HPP__
#define MSGPACK_TYPE_INT_HPP__
#include "msgpack/object.hpp"
#include <limits>
@@ -37,7 +37,7 @@ namespace detail {
{ throw type_error(); }
return o.via.u64;
} else if(o.type == type::NEGATIVE_INTEGER) {
if(o.via.i64 < (int64_t)-std::numeric_limits<T>::max())
if(o.via.i64 < (int64_t)std::numeric_limits<T>::min())
{ throw type_error(); }
return o.via.i64;
}
@@ -143,5 +143,5 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long long&
} // namespace msgpack
#endif /* msgpack/type/integer.hpp */
#endif /* msgpack/type/int.hpp */

View File

@@ -15,35 +15,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_ARRAY_HPP__
#define MSGPACK_TYPE_ARRAY_HPP__
#ifndef MSGPACK_TYPE_LIST_HPP__
#define MSGPACK_TYPE_LIST_HPP__
#include "msgpack/object.hpp"
#include <vector>
#include <list>
namespace msgpack {
template <typename T>
inline std::vector<T> operator>> (object o, std::vector<T>& v)
inline std::list<T>& operator>> (object o, std::list<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.array.size);
object* p = o.via.array.ptr;
object* const pend = o.via.array.ptr + o.via.array.size;
T* it = &v.front();
typename std::list<T>::iterator it = v.begin();
for(; p < pend; ++p, ++it) {
p->convert(it);
p->convert(&*it);
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v)
{
o.pack_array(v.size());
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
@@ -53,5 +52,5 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
} // namespace msgpack
#endif /* msgpack/type/array.hpp */
#endif /* msgpack/type/list.hpp */

50
cpp/msgpack/type/pair.hpp Normal file
View File

@@ -0,0 +1,50 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_PAIR_HPP__
#define MSGPACK_TYPE_PAIR_HPP__
#include "msgpack/object.hpp"
#include <utility>
namespace msgpack {
template <typename T1, typename T2>
inline std::pair<T1, T2>& operator>> (object o, std::pair<T1, T2>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
if(o.via.array.size != 2) { throw type_error(); }
o.via.array.ptr[0].convert(&v.first);
o.via.array.ptr[1].convert(&v.second);
return v;
}
template <typename Stream, typename T1, typename T2>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::pair<T1, T2>& v)
{
o.pack_array(2);
o.pack(v.first);
o.pack(v.second);
return o;
}
} // namespace msgpack
#endif /* msgpack/type/pair.hpp */

View File

@@ -69,16 +69,6 @@ inline type::raw_ref& operator>> (object o, type::raw_ref& v)
return v;
}
inline std::string& operator>> (object o, std::string& v)
{
type::raw_ref r;
o >> r;
v.assign(r.ptr, r.size);
return v;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v)
{
@@ -88,15 +78,6 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v)
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
{
o.pack_raw(v.size());
o.pack_raw_body(v.data(), v.size());
return o;
}
} // namespace msgpack
#endif /* msgpack/type/raw.hpp */

80
cpp/msgpack/type/set.hpp Normal file
View File

@@ -0,0 +1,80 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_SET_HPP__
#define MSGPACK_TYPE_SET_HPP__
#include "msgpack/object.hpp"
#include <set>
namespace msgpack {
template <typename T>
inline std::set<T>& operator>> (object o, std::set<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
object* p = o.via.array.ptr + o.via.array.size;
object* const pbegin = o.via.array.ptr;
while(p > pbegin) {
--p;
v.insert(p->as<T>());
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::set<T>& v)
{
o.pack_array(v.size());
for(typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
template <typename T>
inline std::multiset<T>& operator>> (object o, std::multiset<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
object* p = o.via.array.ptr + o.via.array.size;
object* const pbegin = o.via.array.ptr;
while(p > pbegin) {
--p;
v.insert(p->as<T>());
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::multiset<T>& v)
{
o.pack_array(v.size());
for(typename std::multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
} // namespace msgpack
#endif /* msgpack/type/set.hpp */

View File

@@ -0,0 +1,46 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_STRING_HPP__
#define MSGPACK_TYPE_STRING_HPP__
#include "msgpack/object.hpp"
#include <string>
namespace msgpack {
inline std::string& operator>> (object o, std::string& v)
{
if(o.type != type::RAW) { throw type_error(); }
v.assign(o.via.raw.ptr, o.via.raw.size);
return v;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
{
o.pack_raw(v.size());
o.pack_raw_body(v.data(), v.size());
return o;
}
} // namespace msgpack
#endif /* msgpack/type/string.hpp */

View File

@@ -0,0 +1,85 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP__
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP__
#include "msgpack/object.hpp"
#include <tr1/unordered_map>
namespace msgpack {
template <typename K, typename V>
inline std::tr1::unordered_map<K, V> operator>> (object o, std::tr1::unordered_map<K, V>& v)
{
if(o.type != type::MAP) { throw type_error(); }
object_kv* p(o.via.map.ptr);
object_kv* const pend(o.via.map.ptr + o.via.map.size);
for(; p != pend; ++p) {
K key;
p->key.convert(&key);
p->val.convert(&v[key]);
}
return v;
}
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_map<K,V>& v)
{
o.pack_map(v.size());
for(typename std::tr1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
return o;
}
template <typename K, typename V>
inline std::tr1::unordered_multimap<K, V> operator>> (object o, std::tr1::unordered_multimap<K, V>& v)
{
if(o.type != type::MAP) { throw type_error(); }
object_kv* p(o.via.map.ptr);
object_kv* const pend(o.via.map.ptr + o.via.map.size);
for(; p != pend; ++p) {
std::pair<K, V> value;
p->key.convert(&value.first);
p->val.convert(&value.second);
v.insert(value);
}
return v;
}
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_multimap<K,V>& v)
{
o.pack_map(v.size());
for(typename std::tr1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
return o;
}
} // namespace msgpack
#endif /* msgpack/type/map.hpp */

View File

@@ -0,0 +1,80 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_TR1_UNORDERED_SET_HPP__
#define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP__
#include "msgpack/object.hpp"
#include <tr1/unordered_set>
namespace msgpack {
template <typename T>
inline std::tr1::unordered_set<T>& operator>> (object o, std::tr1::unordered_set<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
object* p = o.via.array.ptr + o.via.array.size;
object* const pbegin = o.via.array.ptr;
while(p > pbegin) {
--p;
v.insert(p->as<T>());
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_set<T>& v)
{
o.pack_array(v.size());
for(typename std::tr1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
template <typename T>
inline std::tr1::unordered_multiset<T>& operator>> (object o, std::tr1::unordered_multiset<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
object* p = o.via.array.ptr + o.via.array.size;
object* const pbegin = o.via.array.ptr;
while(p > pbegin) {
--p;
v.insert(p->as<T>());
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_multiset<T>& v)
{
o.pack_array(v.size());
for(typename std::tr1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
} // namespace msgpack
#endif /* msgpack/type/set.hpp */

View File

@@ -26,7 +26,7 @@ namespace type {
// FIXME operator==
// FIXME operator!=
<% GENERATION_LIMIT = 15 %>
<% GENERATION_LIMIT = 31 %>
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
struct tuple;
@@ -64,7 +64,6 @@ struct tuple_type<const T&> {
typedef const T& transparent_reference;
};
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
@@ -78,7 +77,6 @@ private:
<%}%>
<%}%>
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
@@ -91,18 +89,11 @@ private:
<%}%>
<%}%>
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>)
{
return tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
template <>
struct tuple<> {
tuple() {}
tuple(object o) { o.convert(this); }
typedef tuple<> value_type;
};
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
@@ -121,6 +112,18 @@ struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
};
<%}%>
inline tuple<> make_tuple()
{
return tuple<>();
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>)
{
return tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
} // namespace type
@@ -143,7 +146,6 @@ type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& operator>> (
}
<%}%>
template <typename Stream>
const packer<Stream>& operator<< (
packer<Stream>& o,
@@ -163,7 +165,6 @@ const packer<Stream>& operator<< (
}
<%}%>
} // namespace msgpack
#endif /* msgpack/type/tuple.hpp */

View File

@@ -0,0 +1,60 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_VECTOR_HPP__
#define MSGPACK_TYPE_VECTOR_HPP__
#include "msgpack/object.hpp"
#include <vector>
namespace msgpack {
template <typename T>
inline std::vector<T>& operator>> (object o, std::vector<T>& v)
{
if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.array.size);
if(o.via.array.size > 0) {
object* p = o.via.array.ptr;
object* const pend = o.via.array.ptr + o.via.array.size;
T* it = &v[0];
do {
p->convert(it);
++p;
++it;
} while(p < pend);
}
return v;
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
{
o.pack_array(v.size());
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
return o;
}
} // namespace msgpack
#endif /* msgpack/type/vector.hpp */

View File

@@ -71,6 +71,13 @@ public:
return msgpack_vrefbuffer_veclen(this);
}
void migrate(vrefbuffer* to)
{
if(msgpack_vrefbuffer_migrate(this, to) < 0) {
throw std::bad_alloc();
}
}
private:
typedef msgpack_vrefbuffer base;

View File

@@ -21,6 +21,7 @@
#include "msgpack/object.hpp"
#include "msgpack/zone.h"
#include <cstdlib>
#include <memory>
#include <vector>
<% GENERATION_LIMIT = 15 %>
@@ -38,6 +39,9 @@ public:
void push_finalizer(void (*func)(void*), void* data);
template <typename T>
void push_finalizer(std::auto_ptr<T> obj);
void clear();
<%0.upto(GENERATION_LIMIT) {|i|%>
@@ -94,6 +98,15 @@ inline void zone::push_finalizer(void (*func)(void*), void* data)
}
}
template <typename T>
inline void zone::push_finalizer(std::auto_ptr<T> obj)
{
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, obj.get())) {
throw std::bad_alloc();
}
obj.release();
}
inline void zone::clear()
{
msgpack_zone_clear(this);
@@ -107,9 +120,8 @@ void zone::object_destructor(void* obj)
inline void zone::undo_malloc(size_t size)
{
msgpack_zone_chunk* chunk = base::chunk_array.tail;
chunk->ptr -= size;
chunk->free += size;
base::chunk_list.ptr -= size;
base::chunk_list.free += size;
}
<%0.upto(GENERATION_LIMIT) {|i|%>

View File

@@ -16,7 +16,6 @@
// limitations under the License.
//
#include "msgpack/object.hpp"
#include <string.h>
namespace msgpack {

17
cpp/preprocess.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
preprocess() {
ruby -r erb -e 'puts ERB.new(ARGF.read).result' $1.erb > $1.tmp
if [ "$?" != 0 ]; then
echo ""
echo "** preprocess failed **"
echo ""
else
mv $1.tmp $1
fi
}
preprocess msgpack/type/tuple.hpp
preprocess msgpack/type/define.hpp
preprocess msgpack/zone.hpp

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +0,0 @@
#include "msgpack/type/array.hpp"
#include "msgpack/type/boolean.hpp"
#include "msgpack/type/float.hpp"
#include "msgpack/type/integer.hpp"
#include "msgpack/type/map.hpp"
#include "msgpack/type/nil.hpp"
#include "msgpack/type/raw.hpp"
#include "msgpack/type/tuple.hpp"

58
example/custom.cc Normal file
View File

@@ -0,0 +1,58 @@
#include <msgpack.hpp>
#include <string>
#include <iostream>
class old_class {
public:
old_class() : value("default") { }
std::string value;
MSGPACK_DEFINE(value);
};
class new_class {
public:
new_class() : value("default"), flag(-1) { }
std::string value;
int flag;
MSGPACK_DEFINE(value, flag);
};
int main(void)
{
{
old_class oc;
new_class nc;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, oc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
obj.convert(&nc);
std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
}
{
new_class nc;
old_class oc;
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, nc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
obj.convert(&oc);
std::cout << obj << " value=" << oc.value << std::endl;
}
}

View File

@@ -22,14 +22,14 @@ public:
ssize_t count =
read(m_sock, m_pac.buffer(), m_pac.buffer_capacity());
if(count < 0) {
if(count <= 0) {
if(count == 0) {
throw std::runtime_error("connection closed");
}
if(errno == EAGAIN || errno == EINTR) {
return;
} else {
throw std::runtime_error(strerror(errno));
}
} else if(count == 0) {
throw std::runtime_error("connection closed");
throw std::runtime_error(strerror(errno));
}
m_pac.buffer_consumed(count);

18
java/build.xml Normal file
View File

@@ -0,0 +1,18 @@
<project name="MessagePack for Java">
<target name="prepare">
<mkdir dir="build" />
<mkdir dir="dist" />
</target>
<target name="clean">
<delete dir="build"/>
<delete dir="dist"/>
</target>
<target name="compile" depends="prepare">
<javac srcdir="src" destdir="build" source="1.5" target="1.5">
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>
<target name="jar" depends="compile">
<jar jarfile="dist/msgpack-0.0.0.jar" basedir="build" />
</target>
</project>

View File

@@ -0,0 +1,23 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
public interface MessageMergeable {
public void messageMerge(Object obj) throws MessageTypeException;
}

View File

@@ -0,0 +1,25 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.IOException;
public interface MessagePackable {
public void messagePack(Packer pk) throws IOException;
}

View File

@@ -0,0 +1,39 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.IOException;
public class MessageTypeException extends IOException {
public MessageTypeException() { }
public MessageTypeException(String s) {
super(s);
}
public static MessageTypeException invalidConvert(Object from, Schema to) {
return new MessageTypeException(from.getClass().getName()+" cannot be convert to "+to.getExpression());
}
/* FIXME
public static MessageTypeException schemaMismatch(Schema to) {
return new MessageTypeException("schema mismatch "+to.getExpression());
}
*/
}

View File

@@ -0,0 +1,409 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
public class Packer {
protected byte[] castBytes = new byte[9];
protected ByteBuffer castBuffer = ByteBuffer.wrap(castBytes);
protected OutputStream out;
public Packer(OutputStream out) {
this.out = out;
}
public Packer packByte(byte d) throws IOException {
if(d < -(1<<5)) {
castBytes[0] = (byte)0xd1;
castBytes[1] = d;
out.write(castBytes, 0, 2);
} else {
out.write(d);
}
return this;
}
public Packer packShort(short d) throws IOException {
if(d < -(1<<5)) {
if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, d);
out.write(castBytes, 0, 3);
} else {
// signed 8
castBytes[0] = (byte)0xd0;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
}
} else if(d < (1<<7)) {
// fixnum
out.write((byte)d);
} else {
if(d < (1<<8)) {
// unsigned 8
castBytes[0] = (byte)0xcc;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
} else {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, d);
out.write(castBytes, 0, 3);
}
}
return this;
}
public Packer packInt(int d) throws IOException {
if(d < -(1<<5)) {
if(d < -(1<<15)) {
// signed 32
castBytes[0] = (byte)0xd2;
castBuffer.putInt(1, d);
out.write(castBytes, 0, 5);
} else if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, (short)d);
out.write(castBytes, 0, 3);
} else {
// signed 8
castBytes[0] = (byte)0xd0;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
}
} else if(d < (1<<7)) {
// fixnum
out.write((byte)d);
} else {
if(d < (1<<8)) {
// unsigned 8
castBytes[0] = (byte)0xcc;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
} else if(d < (1<<16)) {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, (short)d);
out.write(castBytes, 0, 3);
} else {
// unsigned 32
castBytes[0] = (byte)0xce;
castBuffer.putInt(1, d);
out.write(castBytes, 0, 5);
}
}
return this;
}
public Packer packLong(long d) throws IOException {
if(d < -(1L<<5)) {
if(d < -(1L<<15)) {
if(d < -(1L<<31)) {
// signed 64
castBytes[0] = (byte)0xd3;
castBuffer.putLong(1, d);
out.write(castBytes, 0, 9);
} else {
// signed 32
castBytes[0] = (byte)0xd2;
castBuffer.putInt(1, (int)d);
out.write(castBytes, 0, 5);
}
} else {
if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, (short)d);
out.write(castBytes, 0, 3);
} else {
// signed 8
castBytes[0] = (byte)0xd0;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
}
}
} else if(d < (1<<7)) {
// fixnum
out.write((byte)d);
} else {
if(d < (1L<<16)) {
if(d < (1<<8)) {
// unsigned 8
castBytes[0] = (byte)0xcc;
castBytes[1] = (byte)d;
out.write(castBytes, 0, 2);
} else {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, (short)d);
out.write(castBytes, 0, 3);
//System.out.println("pack uint 16 "+(short)d);
}
} else {
if(d < (1L<<32)) {
// unsigned 32
castBytes[0] = (byte)0xce;
castBuffer.putInt(1, (int)d);
out.write(castBytes, 0, 5);
} else {
// unsigned 64
castBytes[0] = (byte)0xcf;
castBuffer.putLong(1, d);
out.write(castBytes, 0, 9);
}
}
}
return this;
}
public Packer packFloat(float d) throws IOException {
castBytes[0] = (byte)0xca;
castBuffer.putFloat(1, d);
out.write(castBytes, 0, 5);
return this;
}
public Packer packDouble(double d) throws IOException {
castBytes[0] = (byte)0xcb;
castBuffer.putDouble(1, d);
out.write(castBytes, 0, 9);
return this;
}
public Packer packNil() throws IOException {
out.write((byte)0xc0);
return this;
}
public Packer packTrue() throws IOException {
out.write((byte)0xc3);
return this;
}
public Packer packFalse() throws IOException {
out.write((byte)0xc2);
return this;
}
public Packer packArray(int n) throws IOException {
if(n < 16) {
final int d = 0x90 | n;
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xdc;
castBuffer.putShort(1, (short)n);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdd;
castBuffer.putInt(1, n);
out.write(castBytes, 0, 5);
}
return this;
}
public Packer packMap(int n) throws IOException {
if(n < 16) {
final int d = 0x80 | n;
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xde;
castBuffer.putShort(1, (short)n);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdf;
castBuffer.putInt(1, n);
out.write(castBytes, 0, 5);
}
return this;
}
public Packer packRaw(int n) throws IOException {
if(n < 32) {
final int d = 0xa0 | n;
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xda;
castBuffer.putShort(1, (short)n);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdb;
castBuffer.putInt(1, n);
out.write(castBytes, 0, 5);
}
return this;
}
public Packer packRawBody(byte[] b) throws IOException {
out.write(b);
return this;
}
public Packer packRawBody(byte[] b, int off, int length) throws IOException {
out.write(b, off, length);
return this;
}
public Packer packWithSchema(Object o, Schema s) throws IOException {
s.pack(this, o);
return this;
}
public Packer packString(String s) throws IOException {
byte[] b = ((String)s).getBytes("UTF-8");
packRaw(b.length);
return packRawBody(b);
}
public Packer pack(String o) throws IOException {
if(o == null) { return packNil(); }
return packString(o);
}
public Packer pack(MessagePackable o) throws IOException {
if(o == null) { return packNil(); }
o.messagePack(this);
return this;
}
public Packer pack(byte[] o) throws IOException {
if(o == null) { return packNil(); }
packRaw(o.length);
return packRawBody(o);
}
public Packer pack(List o) throws IOException {
if(o == null) { return packNil(); }
packArray(o.size());
for(Object i : o) { pack(i); }
return this;
}
@SuppressWarnings("unchecked")
public Packer pack(Map o) throws IOException {
if(o == null) { return packNil(); }
packMap(o.size());
for(Map.Entry e : ((Map<Object,Object>)o).entrySet()) {
pack(e.getKey());
pack(e.getValue());
}
return this;
}
public Packer pack(Boolean o) throws IOException {
if(o == null) { return packNil(); }
if(o) {
return packTrue();
} else {
return packFalse();
}
}
public Packer pack(Byte o) throws IOException {
if(o == null) { return packNil(); }
return packByte(o);
}
public Packer pack(Short o) throws IOException {
if(o == null) { return packNil(); }
return packShort(o);
}
public Packer pack(Integer o) throws IOException {
if(o == null) { return packNil(); }
return packInt(o);
}
public Packer pack(Long o) throws IOException {
if(o == null) { return packNil(); }
return packLong(o);
}
public Packer pack(Float o) throws IOException {
if(o == null) { return packNil(); }
return packFloat(o);
}
public Packer pack(Double o) throws IOException {
if(o == null) { return packNil(); }
return packDouble(o);
}
@SuppressWarnings("unchecked")
public Packer pack(Object o) throws IOException {
if(o == null) {
return packNil();
} else if(o instanceof String) {
byte[] b = ((String)o).getBytes("UTF-8");
packRaw(b.length);
return packRawBody(b);
} else if(o instanceof MessagePackable) {
((MessagePackable)o).messagePack(this);
return this;
} else if(o instanceof byte[]) {
byte[] b = (byte[])o;
packRaw(b.length);
return packRawBody(b);
} else if(o instanceof List) {
List<Object> l = (List<Object>)o;
packArray(l.size());
for(Object i : l) { pack(i); }
return this;
} else if(o instanceof Map) {
Map<Object,Object> m = (Map<Object,Object>)o;
packMap(m.size());
for(Map.Entry e : m.entrySet()) {
pack(e.getKey());
pack(e.getValue());
}
return this;
} else if(o instanceof Boolean) {
if((Boolean)o) {
return packTrue();
} else {
return packFalse();
}
} else if(o instanceof Integer) {
return packInt((Integer)o);
} else if(o instanceof Long) {
return packLong((Long)o);
} else if(o instanceof Short) {
return packShort((Short)o);
} else if(o instanceof Byte) {
return packByte((Byte)o);
} else if(o instanceof Float) {
return packFloat((Float)o);
} else if(o instanceof Double) {
return packDouble((Double)o);
} else {
throw new IOException("unknown object "+o+" ("+o.getClass()+")");
}
}
}

View File

@@ -0,0 +1,133 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.Writer;
import java.io.IOException;
import org.msgpack.schema.SSchemaParser;
import org.msgpack.schema.ClassGenerator;
public abstract class Schema {
private String expression;
private String name;
public Schema(String name) {
this.expression = expression;
this.name = name;
}
public String getName() {
return name;
}
public String getFullName() {
return name;
}
public String getExpression() {
return name;
}
public static Schema parse(String source) {
return SSchemaParser.parse(source);
}
public static Schema load(String source) {
return SSchemaParser.load(source);
}
public void write(Writer output) throws IOException {
ClassGenerator.write(this, output);
}
public abstract void pack(Packer pk, Object obj) throws IOException;
public abstract Object convert(Object obj) throws MessageTypeException;
public Object createFromNil() {
return null;
}
public Object createFromBoolean(boolean v) {
throw new RuntimeException("type error");
}
public Object createFromByte(byte v) {
throw new RuntimeException("type error");
}
public Object createFromShort(short v) {
throw new RuntimeException("type error");
}
public Object createFromInt(int v) {
throw new RuntimeException("type error");
}
public Object createFromLong(long v) {
throw new RuntimeException("type error");
}
public Object createFromFloat(float v) {
throw new RuntimeException("type error");
}
public Object createFromDouble(double v) {
throw new RuntimeException("type error");
}
public Object createFromRaw(byte[] b, int offset, int length) {
throw new RuntimeException("type error");
}
/* FIXME
public Object createFromBoolean(boolean v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromByte(byte v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromShort(short v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromInt(int v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromLong(long v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromFloat(float v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromDouble(double v) {
throw MessageTypeException.schemaMismatch(this);
}
public Object createFromRaw(byte[] b, int offset, int length) {
throw MessageTypeException.schemaMismatch(this);
}
*/
}

View File

@@ -0,0 +1,82 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.lang.Iterable;
import java.io.InputStream;
import java.io.IOException;
import java.util.Iterator;
import org.msgpack.impl.UnpackerImpl;
public class UnbufferedUnpacker extends UnpackerImpl {
private int offset;
private boolean finished;
private Object data;
public UnbufferedUnpacker() {
super();
this.offset = 0;
this.finished = false;
}
public UnbufferedUnpacker useSchema(Schema s) {
super.setSchema(s);
return this;
}
public Object getData() {
return data;
}
public boolean isFinished() {
return finished;
}
public void reset() {
super.reset();
this.offset = 0;
}
int getOffset() {
return offset;
}
void setOffset(int offset) {
this.offset = offset;
}
public int execute(byte[] buffer) throws UnpackException {
return execute(buffer, 0, buffer.length);
}
// FIXME
public int execute(byte[] buffer, int offset, int length) throws UnpackException
{
int noffset = super.execute(buffer, offset + this.offset, length);
this.offset = noffset - offset;
if(super.isFinished()) {
this.data = super.getData();
this.finished = true;
super.reset();
} else {
this.finished = false;
}
return noffset;
}
}

View File

@@ -0,0 +1,29 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.IOException;
public class UnpackException extends IOException {
public UnpackException() { }
public UnpackException(String s) {
super(s);
}
}

View File

@@ -0,0 +1,66 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class UnpackIterator implements Iterator<Object> {
private Unpacker pac;
private boolean have;
private Object data;
UnpackIterator(Unpacker pac) {
this.pac = pac;
this.have = false;
}
public boolean hasNext() {
if(have) { return true; }
try {
while(true) {
if(pac.execute()) {
data = pac.getData();
pac.reset();
have = true;
return true;
}
if(!pac.fill()) {
return false;
}
}
} catch (IOException e) {
return false;
}
}
public Object next() {
if(!have && !hasNext()) {
throw new NoSuchElementException();
}
have = false;
return data;
}
public void remove() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,245 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.lang.Iterable;
import java.io.InputStream;
import java.io.IOException;
import java.util.Iterator;
import org.msgpack.impl.UnpackerImpl;
public class Unpacker extends UnpackerImpl implements Iterable<Object> {
public static final int DEFAULT_BUFFER_SIZE = 32*1024;
private int used;
private int offset;
private int parsed;
private byte[] buffer;
private int bufferReserveSize;
private InputStream stream;
public Unpacker() {
this(DEFAULT_BUFFER_SIZE);
}
public Unpacker(int bufferReserveSize) {
this(null, bufferReserveSize);
}
public Unpacker(InputStream stream) {
this(stream, DEFAULT_BUFFER_SIZE);
}
public Unpacker(InputStream stream, int bufferReserveSize) {
super();
this.used = 0;
this.offset = 0;
this.parsed = 0;
this.buffer = new byte[bufferReserveSize];
this.bufferReserveSize = bufferReserveSize/2;
this.stream = stream;
}
public Unpacker useSchema(Schema s) {
super.setSchema(s);
return this;
}
public void reserveBuffer(int size) {
if(buffer.length - used >= size) {
return;
}
/*
if(used == parsed && buffer.length >= size) {
// rewind buffer
used = 0;
offset = 0;
return;
}
*/
int nextSize = buffer.length * 2;
while(nextSize < size + used) {
nextSize *= 2;
}
byte[] tmp = new byte[nextSize];
System.arraycopy(buffer, offset, tmp, 0, used - offset);
buffer = tmp;
used -= offset;
offset = 0;
}
public byte[] getBuffer() {
return buffer;
}
public int getBufferOffset() {
return used;
}
public int getBufferCapacity() {
return buffer.length - used;
}
public void bufferConsumed(int size) {
used += size;
}
public void feed(byte[] buffer) {
feed(buffer, 0, buffer.length);
}
public void feed(byte[] buffer, int offset, int length) {
reserveBuffer(length);
System.arraycopy(buffer, offset, this.buffer, this.offset, length);
bufferConsumed(length);
}
public boolean fill() throws IOException {
if(stream == null) {
return false;
}
reserveBuffer(bufferReserveSize);
int rl = stream.read(getBuffer(), getBufferOffset(), getBufferCapacity());
if(rl <= 0) {
return false;
}
bufferConsumed(rl);
return true;
}
public Iterator<Object> iterator() {
return new UnpackIterator(this);
}
public boolean execute() throws UnpackException {
int noffset = super.execute(buffer, offset, used);
if(noffset <= offset) {
return false;
}
parsed += noffset - offset;
offset = noffset;
return super.isFinished();
}
public Object getData() {
return super.getData();
}
public void reset() {
super.reset();
parsed = 0;
}
public int getMessageSize() {
return parsed - offset + used;
}
public int getParsedSize() {
return parsed;
}
public int getNonParsedSize() {
return used - offset;
}
public void skipNonparsedBuffer(int size) {
offset += size;
}
public void removeNonparsedBuffer() {
used = offset;
}
/*
public static class Context {
private boolean finished;
private Object data;
private int offset;
private UnpackerImpl impl;
public Context()
{
this.finished = false;
this.impl = new UnpackerImpl();
}
public boolean isFinished()
{
return finished;
}
public Object getData()
{
return data;
}
int getOffset()
{
return offset;
}
void setFinished(boolean finished)
{
this.finished = finished;
}
void setData(Object data)
{
this.data = data;
}
void setOffset(int offset)
{
this.offset = offset;
}
UnpackerImpl getImpl()
{
return impl;
}
}
public static int unpack(Context ctx, byte[] buffer) throws UnpackException
{
return unpack(ctx, buffer, 0, buffer.length);
}
public static int unpack(Context ctx, byte[] buffer, int offset, int length) throws UnpackException
{
UnpackerImpl impl = ctx.getImpl();
int noffset = impl.execute(buffer, offset + ctx.getOffset(), length);
ctx.setOffset(noffset - offset);
if(impl.isFinished()) {
ctx.setData(impl.getData());
ctx.setFinished(false);
impl.reset();
} else {
ctx.setData(null);
ctx.setFinished(true);
}
int parsed = noffset - offset;
ctx.setOffset(parsed);
return noffset;
}
*/
}

View File

@@ -0,0 +1,500 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.impl;
import java.nio.ByteBuffer;
//import java.math.BigInteger;
import org.msgpack.*;
import org.msgpack.schema.GenericSchema;
import org.msgpack.schema.IMapSchema;
import org.msgpack.schema.IArraySchema;
public class UnpackerImpl {
static final int CS_HEADER = 0x00;
static final int CS_FLOAT = 0x0a;
static final int CS_DOUBLE = 0x0b;
static final int CS_UINT_8 = 0x0c;
static final int CS_UINT_16 = 0x0d;
static final int CS_UINT_32 = 0x0e;
static final int CS_UINT_64 = 0x0f;
static final int CS_INT_8 = 0x10;
static final int CS_INT_16 = 0x11;
static final int CS_INT_32 = 0x12;
static final int CS_INT_64 = 0x13;
static final int CS_RAW_16 = 0x1a;
static final int CS_RAW_32 = 0x1b;
static final int CS_ARRAY_16 = 0x1c;
static final int CS_ARRAY_32 = 0x1d;
static final int CS_MAP_16 = 0x1e;
static final int CS_MAP_32 = 0x1f;
static final int ACS_RAW_VALUE = 0x20;
static final int CT_ARRAY_ITEM = 0x00;
static final int CT_MAP_KEY = 0x01;
static final int CT_MAP_VALUE = 0x02;
static final int MAX_STACK_SIZE = 16;
private int cs;
private int trail;
private int top;
private int[] stack_ct = new int[MAX_STACK_SIZE];
private int[] stack_count = new int[MAX_STACK_SIZE];
private Object[] stack_obj = new Object[MAX_STACK_SIZE];
private Schema[] stack_schema = new Schema[MAX_STACK_SIZE];
private int top_ct;
private int top_count;
private Object top_obj;
private Schema top_schema;
private ByteBuffer castBuffer = ByteBuffer.allocate(8);
private boolean finished = false;
private Object data = null;
private static final Schema GENERIC_SCHEMA = new GenericSchema();
private Schema rootSchema;
protected UnpackerImpl()
{
setSchema(GENERIC_SCHEMA);
}
protected void setSchema(Schema schema)
{
this.rootSchema = schema;
reset();
}
protected Object getData()
{
return data;
}
protected boolean isFinished()
{
return finished;
}
protected void reset()
{
cs = CS_HEADER;
top = -1;
finished = false;
data = null;
top_ct = 0;
top_count = 0;
top_obj = null;
top_schema = rootSchema;
}
@SuppressWarnings("unchecked")
protected int execute(byte[] src, int off, int length) throws UnpackException
{
if(off >= length) { return off; }
int limit = length;
int i = off;
int count;
Object obj = null;
_out: do {
_header_again: {
//System.out.println("while i:"+i+" limit:"+limit);
int b = src[i];
_push: {
_fixed_trail_again:
if(cs == CS_HEADER) {
if((b & 0x80) == 0) { // Positive Fixnum
//System.out.println("positive fixnum "+b);
obj = top_schema.createFromByte((byte)b);
break _push;
}
if((b & 0xe0) == 0xe0) { // Negative Fixnum
//System.out.println("negative fixnum "+b);
obj = top_schema.createFromByte((byte)b);
break _push;
}
if((b & 0xe0) == 0xa0) { // FixRaw
trail = b & 0x1f;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
break _push;
}
cs = ACS_RAW_VALUE;
break _fixed_trail_again;
}
if((b & 0xf0) == 0x90) { // FixArray
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
count = b & 0x0f;
//System.out.println("fixarray count:"+count);
obj = new Object[count];
if(count == 0) { break _push; } // FIXME check IArraySchema
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
}
if((b & 0xf0) == 0x80) { // FixMap
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
count = b & 0x0f;
obj = new Object[count*2];
if(count == 0) { break _push; } // FIXME check IMapSchema
//System.out.println("fixmap count:"+count);
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
}
switch(b & 0xff) { // FIXME
case 0xc0: // nil
obj = top_schema.createFromNil();
break _push;
case 0xc2: // false
obj = top_schema.createFromBoolean(false);
break _push;
case 0xc3: // true
obj = top_schema.createFromBoolean(true);
break _push;
case 0xca: // float
case 0xcb: // double
case 0xcc: // unsigned int 8
case 0xcd: // unsigned int 16
case 0xce: // unsigned int 32
case 0xcf: // unsigned int 64
case 0xd0: // signed int 8
case 0xd1: // signed int 16
case 0xd2: // signed int 32
case 0xd3: // signed int 64
trail = 1 << (b & 0x03);
cs = b & 0x1f;
//System.out.println("a trail "+trail+" cs:"+cs);
break _fixed_trail_again;
case 0xda: // raw 16
case 0xdb: // raw 32
case 0xdc: // array 16
case 0xdd: // array 32
case 0xde: // map 16
case 0xdf: // map 32
trail = 2 << (b & 0x01);
cs = b & 0x1f;
//System.out.println("b trail "+trail+" cs:"+cs);
break _fixed_trail_again;
default:
//System.out.println("unknown b "+(b&0xff));
throw new UnpackException("parse error");
}
} // _fixed_trail_again
do {
_fixed_trail_again: {
if(limit - i <= trail) { break _out; }
int n = i + 1;
i += trail;
switch(cs) {
case CS_FLOAT:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromFloat( castBuffer.getFloat(0) );
//System.out.println("float "+obj);
break _push;
case CS_DOUBLE:
castBuffer.rewind();
castBuffer.put(src, n, 8);
obj = top_schema.createFromDouble( castBuffer.getDouble(0) );
//System.out.println("double "+obj);
break _push;
case CS_UINT_8:
//System.out.println(n);
//System.out.println(src[n]);
//System.out.println(src[n+1]);
//System.out.println(src[n-1]);
obj = top_schema.createFromShort( (short)((src[n]) & 0xff) );
//System.out.println("uint8 "+obj);
break _push;
case CS_UINT_16:
//System.out.println(src[n]);
//System.out.println(src[n+1]);
castBuffer.rewind();
castBuffer.put(src, n, 2);
obj = top_schema.createFromInt( ((int)castBuffer.getShort(0)) & 0xffff );
//System.out.println("uint 16 "+obj);
break _push;
case CS_UINT_32:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromLong( ((long)castBuffer.getInt(0)) & 0xffffffffL );
//System.out.println("uint 32 "+obj);
break _push;
case CS_UINT_64:
castBuffer.rewind();
castBuffer.put(src, n, 8);
{
long o = castBuffer.getLong(0);
if(o < 0) {
// FIXME
//obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31);
throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported");
} else {
obj = top_schema.createFromLong( o );
}
}
break _push;
case CS_INT_8:
obj = top_schema.createFromByte( src[n] );
break _push;
case CS_INT_16:
castBuffer.rewind();
castBuffer.put(src, n, 2);
obj = top_schema.createFromShort( castBuffer.getShort(0) );
break _push;
case CS_INT_32:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromInt( castBuffer.getInt(0) );
break _push;
case CS_INT_64:
castBuffer.rewind();
castBuffer.put(src, n, 8);
obj = top_schema.createFromLong( castBuffer.getLong(0) );
break _push;
case CS_RAW_16:
castBuffer.rewind();
castBuffer.put(src, n, 2);
trail = ((int)castBuffer.getShort(0)) & 0xffff;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
break _push;
}
cs = ACS_RAW_VALUE;
break _fixed_trail_again;
case CS_RAW_32:
castBuffer.rewind();
castBuffer.put(src, n, 4);
// FIXME overflow check
trail = castBuffer.getInt(0) & 0x7fffffff;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
break _push;
}
cs = ACS_RAW_VALUE;
case ACS_RAW_VALUE:
obj = top_schema.createFromRaw(src, n, trail);
break _push;
case CS_ARRAY_16:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 2);
count = ((int)castBuffer.getShort(0)) & 0xffff;
obj = new Object[count];
if(count == 0) { break _push; } // FIXME check IArraySchema
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
case CS_ARRAY_32:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 4);
// FIXME overflow check
count = castBuffer.getInt(0) & 0x7fffffff;
obj = new Object[count];
if(count == 0) { break _push; } // FIXME check IArraySchema
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
case CS_MAP_16:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 2);
count = ((int)castBuffer.getShort(0)) & 0xffff;
obj = new Object[count*2];
if(count == 0) { break _push; } // FIXME check IMapSchema
//System.out.println("fixmap count:"+count);
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
++top;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
case CS_MAP_32:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 4);
// FIXME overflow check
count = castBuffer.getInt(0) & 0x7fffffff;
obj = new Object[count*2];
if(count == 0) { break _push; } // FIXME check IMapSchema
//System.out.println("fixmap count:"+count);
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
default:
throw new UnpackException("parse error");
}
} // _fixed_trail_again
} while(true);
} // _push
do {
_push: {
//System.out.println("push top:"+top);
if(top == -1) {
++i;
data = obj;
finished = true;
break _out;
}
switch(top_ct) {
case CT_ARRAY_ITEM: {
//System.out.println("array item "+obj);
Object[] ar = (Object[])top_obj;
ar[ar.length - top_count] = obj;
if(--top_count == 0) {
top_obj = stack_obj[top];
top_ct = stack_ct[top];
top_count = stack_count[top];
top_schema = stack_schema[top];
obj = ((IArraySchema)top_schema).createFromArray(ar);
stack_obj[top] = null;
stack_schema[top] = null;
--top;
break _push;
} else {
top_schema = ((IArraySchema)stack_schema[top]).getElementSchema(ar.length - top_count);
}
break _header_again;
}
case CT_MAP_KEY: {
//System.out.println("map key:"+top+" "+obj);
Object[] mp = (Object[])top_obj;
mp[mp.length - top_count*2] = obj;
top_ct = CT_MAP_VALUE;
top_schema = ((IMapSchema)stack_schema[top]).getValueSchema();
break _header_again;
}
case CT_MAP_VALUE: {
//System.out.println("map value:"+top+" "+obj);
Object[] mp = (Object[])top_obj;
mp[mp.length - top_count*2 + 1] = obj;
if(--top_count == 0) {
top_obj = stack_obj[top];
top_ct = stack_ct[top];
top_count = stack_count[top];
top_schema = stack_schema[top];
obj = ((IMapSchema)top_schema).createFromMap(mp);
stack_obj[top] = null;
stack_schema[top] = null;
--top;
break _push;
}
top_ct = CT_MAP_KEY;
break _header_again;
}
default:
throw new UnpackException("parse error");
}
} // _push
} while(true);
} // _header_again
cs = CS_HEADER;
++i;
} while(i < limit); // _out
return i;
}
}

View File

@@ -0,0 +1,125 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;
import java.util.RandomAccess;
import java.io.IOException;
import org.msgpack.*;
public class ArraySchema extends Schema implements IArraySchema {
private Schema elementSchema;
public ArraySchema(Schema elementSchema)
{
super("array");
this.elementSchema = elementSchema;
}
@Override
public String getFullName()
{
return "List<"+elementSchema.getFullName()+">";
}
@Override
public String getExpression()
{
return "(array "+elementSchema.getExpression()+")";
}
@Override
@SuppressWarnings("unchecked")
public void pack(Packer pk, Object obj) throws IOException
{
if(obj instanceof List) {
ArrayList<Object> d = (ArrayList<Object>)obj;
pk.packArray(d.size());
if(obj instanceof RandomAccess) {
for(int i=0; i < d.size(); ++i) {
elementSchema.pack(pk, d.get(i));
}
} else {
for(Object e : d) {
elementSchema.pack(pk, e);
}
}
} else if(obj instanceof Set) {
Set<Object> d = (Set<Object>)obj;
pk.packArray(d.size());
for(Object e : d) {
elementSchema.pack(pk, e);
}
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
@SuppressWarnings("unchecked")
public Object convert(Object obj) throws MessageTypeException
{
if(obj instanceof List) {
List d = (List)obj;
ArrayList ar = new ArrayList(d.size());
if(obj instanceof RandomAccess) {
for(int i=0; i < d.size(); ++i) {
ar.add( elementSchema.convert(d.get(i)) );
}
} else {
for(Object e : d) {
ar.add( elementSchema.convert(e) );
}
}
return ar;
} else if(obj instanceof Collection) {
Collection d = (Collection)obj;
ArrayList ar = new ArrayList(d.size());
for(Object e : (Collection)obj) {
ar.add( elementSchema.convert(e) );
}
return ar;
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Schema getElementSchema(int index)
{
return elementSchema;
}
@Override
public Object createFromArray(Object[] obj)
{
return Arrays.asList(obj);
}
}

View File

@@ -0,0 +1,89 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class ByteSchema extends Schema {
public ByteSchema() {
super("Byte");
}
@Override
public String getExpression() {
return "byte";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packByte( ((Number)obj).byteValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Byte) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).byteValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (byte)v;
}
@Override
public Object createFromShort(short v) {
return (byte)v;
}
@Override
public Object createFromInt(int v) {
return (byte)v;
}
@Override
public Object createFromLong(long v) {
return (byte)v;
}
@Override
public Object createFromFloat(float v) {
return (byte)v;
}
@Override
public Object createFromDouble(double v) {
return (byte)v;
}
}

View File

@@ -0,0 +1,241 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.io.File;
import java.io.Writer;
import org.msgpack.*;
public class ClassGenerator {
private ClassSchema schema;
private Writer writer;
private int indent;
private ClassGenerator(Writer writer) {
this.writer = writer;
this.indent = 0;
}
public static void write(Schema schema, Writer dest) throws IOException {
if(!(schema instanceof ClassSchema)) {
throw new RuntimeException("schema is not class schema");
}
ClassSchema cs = (ClassSchema)schema;
new ClassGenerator(dest).run(cs);
}
private void run(ClassSchema cs) throws IOException {
List<ClassSchema> subclasses = new ArrayList<ClassSchema>();
for(FieldSchema f : cs.getFields()) {
findSubclassSchema(subclasses, f.getSchema());
}
for(ClassSchema sub : subclasses) {
sub.setNamespace(cs.getNamespace());
sub.setImports(cs.getImports());
}
this.schema = cs;
writeHeader();
writeClass();
for(ClassSchema sub : subclasses) {
this.schema = sub;
writeSubclass();
}
writeFooter();
this.schema = null;
writer.flush();
}
private void findSubclassSchema(List<ClassSchema> dst, Schema s) {
if(s instanceof ClassSchema) {
ClassSchema cs = (ClassSchema)s;
if(!dst.contains(cs)) { dst.add(cs); }
for(FieldSchema f : cs.getFields()) {
findSubclassSchema(dst, f.getSchema());
}
} else if(s instanceof ArraySchema) {
ArraySchema as = (ArraySchema)s;
findSubclassSchema(dst, as.getElementSchema(0));
} else if(s instanceof MapSchema) {
MapSchema as = (MapSchema)s;
findSubclassSchema(dst, as.getKeySchema());
findSubclassSchema(dst, as.getValueSchema());
}
}
private void writeHeader() throws IOException {
if(schema.getNamespace() != null) {
line("package "+schema.getNamespace()+";");
line();
}
line("import java.util.*;");
line("import java.io.*;");
line("import org.msgpack.*;");
line("import org.msgpack.schema.ClassSchema;");
line("import org.msgpack.schema.FieldSchema;");
}
private void writeFooter() throws IOException {
line();
}
private void writeClass() throws IOException {
line();
line("public final class "+schema.getName()+" implements MessagePackable, MessageMergeable");
line("{");
pushIndent();
writeSchema();
writeMemberVariables();
writeMemberFunctions();
popIndent();
line("}");
}
private void writeSubclass() throws IOException {
line();
line("final class "+schema.getName()+" implements MessagePackable, MessageMergeable");
line("{");
pushIndent();
writeSchema();
writeMemberVariables();
writeMemberFunctions();
popIndent();
line("}");
}
private void writeSchema() throws IOException {
line("private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load(\""+schema.getExpression()+"\");");
line("public static ClassSchema getSchema() { return _SCHEMA; }");
}
private void writeMemberVariables() throws IOException {
line();
for(FieldSchema f : schema.getFields()) {
line("public "+f.getSchema().getFullName()+" "+f.getName()+";");
}
}
private void writeMemberFunctions() throws IOException {
// void messagePack(Packer pk)
// boolean equals(Object obj)
// int hashCode()
// void set(int _index, Object _value)
// Object get(int _index);
// getXxx()
// setXxx(Xxx xxx)
writeConstructors();
writeAccessors();
writePackFunction();
writeMergeFunction();
writeFactoryFunction();
}
private void writeConstructors() throws IOException {
line();
line("public "+schema.getName()+"() { }");
}
private void writeAccessors() throws IOException {
// FIXME
//line();
//for(FieldSchema f : schema.getFields()) {
// line("");
//}
}
private void writePackFunction() throws IOException {
line();
line("@Override");
line("public void messagePack(Packer _pk) throws IOException");
line("{");
pushIndent();
line("_pk.packArray("+schema.getFields().length+");");
line("FieldSchema[] _fields = _SCHEMA.getFields();");
int i = 0;
for(FieldSchema f : schema.getFields()) {
line("_fields["+i+"].getSchema().pack(_pk, "+f.getName()+");");
++i;
}
popIndent();
line("}");
}
private void writeMergeFunction() throws IOException {
line();
line("@Override");
line("@SuppressWarnings(\"unchecked\")");
line("public void messageMerge(Object obj) throws MessageTypeException");
line("{");
pushIndent();
line("Object[] _source = ((List)obj).toArray();");
line("FieldSchema[] _fields = _SCHEMA.getFields();");
int i = 0;
for(FieldSchema f : schema.getFields()) {
line("if(_source.length <= "+i+") { return; } this."+f.getName()+" = ("+f.getSchema().getFullName()+")_fields["+i+"].getSchema().convert(_source["+i+"]);");
++i;
}
popIndent();
line("}");
}
private void writeFactoryFunction() throws IOException {
line();
line("@SuppressWarnings(\"unchecked\")");
line("public static "+schema.getName()+" createFromMessage(Object[] _message)");
line("{");
pushIndent();
line(schema.getName()+" _self = new "+schema.getName()+"();");
int i = 0;
for(FieldSchema f : schema.getFields()) {
line("if(_message.length <= "+i+") { return _self; } _self."+f.getName()+" = ("+f.getSchema().getFullName()+")_message["+i+"];");
++i;
}
line("return _self;");
popIndent();
line("}");
}
private void line(String str) throws IOException {
for(int i=0; i < indent; ++i) {
writer.write("\t");
}
writer.write(str+"\n");
}
private void line() throws IOException {
writer.write("\n");
}
private void pushIndent() {
indent += 1;
}
private void popIndent() {
indent -= 1;
}
}

View File

@@ -0,0 +1,95 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Arrays;
import java.util.List;
import org.msgpack.*;
public abstract class ClassSchema extends Schema implements IArraySchema {
protected FieldSchema[] fields;
protected List<String> imports;
protected String namespace;
protected String fqdn;
public ClassSchema(
String name, String namespace,
List<String> imports, List<FieldSchema> fields) {
super(name);
this.namespace = namespace;
this.imports = imports; // FIXME clone?
this.fields = new FieldSchema[fields.size()];
System.arraycopy(fields.toArray(), 0, this.fields, 0, fields.size());
if(namespace == null) {
this.fqdn = name;
} else {
this.fqdn = namespace+"."+name;
}
}
public final FieldSchema[] getFields() {
return fields;
}
String getNamespace() {
return namespace;
}
List<String> getImports() {
return imports;
}
void setNamespace(String namespace) {
this.namespace = namespace;
}
void setImports(List<String> imports) {
this.imports = imports; // FIXME clone?
}
//@Override
//public String getFullName()
//{
// if(namespace == null) {
// return getName();
// } else {
// return namespace+"."+getName();
// }
//}
@Override
public String getExpression() {
StringBuffer b = new StringBuffer();
b.append("(class ");
b.append(getName());
if(namespace != null) {
b.append(" (package "+namespace+")");
}
for(FieldSchema f : fields) {
b.append(" "+f.getExpression());
}
b.append(")");
return b.toString();
}
public boolean equals(SpecificClassSchema o) {
return (namespace != null ? namespace.equals(o.getNamespace()) : o.getNamespace() == null) &&
getName().equals(o.getName());
}
}

View File

@@ -0,0 +1,84 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class DoubleSchema extends Schema {
public DoubleSchema() {
super("Double");
}
@Override
public String getExpression() {
return "double";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packDouble( ((Number)obj).doubleValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Double) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).doubleValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (double)v;
}
@Override
public Object createFromShort(short v) {
return (double)v;
}
@Override
public Object createFromInt(int v) {
return (double)v;
}
@Override
public Object createFromFloat(float v) {
return (double)v;
}
@Override
public Object createFromDouble(double v) {
return (double)v;
}
}

View File

@@ -0,0 +1,43 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import org.msgpack.Schema;
public class FieldSchema {
private String name;
private Schema schema;
public FieldSchema(String name, Schema schema) {
this.name = name;
this.schema = schema;
}
public final String getName() {
return name;
}
public final Schema getSchema() {
return schema;
}
public String getExpression() {
return "(field "+name+" "+schema.getExpression()+")";
}
}

View File

@@ -0,0 +1,84 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class FloatSchema extends Schema {
public FloatSchema() {
super("Float");
}
@Override
public String getExpression() {
return "float";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packFloat( ((Number)obj).floatValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Float) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).floatValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (float)v;
}
@Override
public Object createFromShort(short v) {
return (float)v;
}
@Override
public Object createFromInt(int v) {
return (float)v;
}
@Override
public Object createFromFloat(float v) {
return (float)v;
}
@Override
public Object createFromDouble(double v) {
return (float)v;
}
}

View File

@@ -0,0 +1,91 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import org.msgpack.*;
public class GenericClassSchema extends ClassSchema {
public GenericClassSchema(
String name, String namespace,
List<String> imports, List<FieldSchema> fields) {
super(name, namespace, imports, fields);
}
@Override
@SuppressWarnings("unchecked")
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Map) {
Map d = (Map)obj;
pk.packArray(fields.length);
for(int i=0; i < fields.length; ++i) {
FieldSchema f = fields[i];
f.getSchema().pack(pk, d.get(f.getName()));
}
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Collection) {
// FIXME optimize
return createFromArray( ((Collection)obj).toArray() );
} else if(obj instanceof Map) {
HashMap<String,Object> m = new HashMap<String,Object>(fields.length);
Map d = (Map)obj;
for(int i=0; i < fields.length; ++i) {
FieldSchema f = fields[i];
String fieldName = f.getName();
m.put(fieldName, f.getSchema().convert(d.get(fieldName)));
}
return m;
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
public Schema getElementSchema(int index) {
// FIXME check index < fields.length
return fields[index].getSchema();
}
public Object createFromArray(Object[] obj) {
HashMap<String,Object> m = new HashMap<String,Object>(fields.length);
int i=0;
for(; i < obj.length; ++i) {
m.put(fields[i].getName(), obj[i]);
}
for(; i < fields.length; ++i) {
m.put(fields[i].getName(), null);
}
return m;
}
}

View File

@@ -0,0 +1,192 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.io.IOException;
import org.msgpack.*;
//import org.msgpack.generic.*;
public class GenericSchema extends Schema implements IArraySchema, IMapSchema {
public GenericSchema() {
super("Object");
}
@Override
public String getExpression() {
return "object";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
pk.pack(obj);
}
@Override
public Object convert(Object obj) throws MessageTypeException {
return obj;
}
@Override
public Schema getElementSchema(int index) {
return this;
}
@Override
public Schema getKeySchema() {
return this;
}
@Override
public Schema getValueSchema() {
return this;
}
@Override
public Object createFromNil() {
return null;
}
@Override
public Object createFromBoolean(boolean v) {
return v;
}
@Override
public Object createFromByte(byte v) {
return v;
}
@Override
public Object createFromShort(short v) {
return v;
}
@Override
public Object createFromInt(int v) {
return v;
}
@Override
public Object createFromLong(long v) {
return v;
}
@Override
public Object createFromFloat(float v) {
return v;
}
@Override
public Object createFromDouble(double v) {
return v;
}
@Override
public Object createFromRaw(byte[] b, int offset, int length) {
byte[] bytes = new byte[length];
System.arraycopy(b, offset, bytes, 0, length);
return bytes;
}
@Override
public Object createFromArray(Object[] obj) {
return Arrays.asList(obj);
}
@Override
@SuppressWarnings("unchecked")
public Object createFromMap(Object[] obj) {
HashMap m = new HashMap(obj.length / 2);
int i = 0;
while(i < obj.length) {
Object k = obj[i++];
Object v = obj[i++];
m.put(k, v);
}
return m;
}
/*
@Override
public Object createFromNil() {
return null;
}
@Override
public Object createFromBoolean(boolean v) {
return new GenericBoolean(v);
}
@Override
public Object createFromFromByte(byte v) {
return new GenericByte(v);
}
@Override
public Object createFromShort(short v) {
return new GenericShort(v);
}
@Override
public Object createFromInt(int v) {
return new GenericInt(v);
}
@Override
public Object createFromLong(long v) {
return new GenericLong(v);
}
@Override
public Object createFromFloat(float v) {
return new GenericFloat(v);
}
@Override
public Object createFromDouble(double v) {
return new GenericDouble(v);
}
@Override
public Object createFromRaw(byte[] b, int offset, int length) {
return new GenericRaw(b, offset, length);
}
@Override
public Object createFromArray(Object[] obj) {
// FIXME GenericArray
return Arrays.asList(obj);
}
@Override
public Object createFromMap(Object[] obj) {
GenericMap m = new GenericMap(obj.length / 2);
int i = 0;
while(i < obj.length) {
Object k = obj[i++];
Object v = obj[i++];
m.put(k, v);
}
return m;
}
*/
}

View File

@@ -0,0 +1,26 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import org.msgpack.Schema;
public interface IArraySchema {
public Schema getElementSchema(int index);
public Object createFromArray(Object[] obj);
}

View File

@@ -0,0 +1,27 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import org.msgpack.Schema;
public interface IMapSchema {
public Schema getKeySchema();
public Schema getValueSchema();
public Object createFromMap(Object[] obj);
}

View File

@@ -0,0 +1,89 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class IntSchema extends Schema {
public IntSchema() {
super("Integer");
}
@Override
public String getExpression() {
return "int";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packInt( ((Number)obj).intValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Integer) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).intValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (int)v;
}
@Override
public Object createFromShort(short v) {
return (int)v;
}
@Override
public Object createFromInt(int v) {
return (int)v;
}
@Override
public Object createFromLong(long v) {
return (int)v;
}
@Override
public Object createFromFloat(float v) {
return (int)v;
}
@Override
public Object createFromDouble(double v) {
return (int)v;
}
}

View File

@@ -0,0 +1,89 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class LongSchema extends Schema {
public LongSchema() {
super("Long");
}
@Override
public String getExpression() {
return "long";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packLong( ((Number)obj).longValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Long) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).longValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (long)v;
}
@Override
public Object createFromShort(short v) {
return (long)v;
}
@Override
public Object createFromInt(int v) {
return (long)v;
}
@Override
public Object createFromLong(long v) {
return (long)v;
}
@Override
public Object createFromFloat(float v) {
return (long)v;
}
@Override
public Object createFromDouble(double v) {
return (long)v;
}
}

View File

@@ -0,0 +1,103 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import org.msgpack.*;
public class MapSchema extends Schema implements IMapSchema {
private Schema keySchema;
private Schema valueSchema;
public MapSchema(Schema keySchema, Schema valueSchema) {
super("map");
this.keySchema = keySchema;
this.valueSchema = valueSchema;
}
@Override
public String getFullName() {
return "HashList<"+keySchema.getFullName()+", "+valueSchema.getFullName()+">";
}
@Override
public String getExpression() {
return "(map "+keySchema.getExpression()+" "+valueSchema.getExpression()+")";
}
@Override
@SuppressWarnings("unchecked")
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Map) {
Map<Object,Object> d = (Map<Object,Object>)obj;
pk.packMap(d.size());
for(Map.Entry<Object,Object> e : d.entrySet()) {
keySchema.pack(pk, e.getKey());
valueSchema.pack(pk, e.getValue());
}
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
@SuppressWarnings("unchecked")
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Map) {
Map<Object,Object> d = (Map<Object,Object>)obj;
Map<Object,Object> m = new HashMap<Object,Object>();
for(Map.Entry<Object,Object> e : d.entrySet()) {
m.put(keySchema.convert(e.getKey()), valueSchema.convert(e.getValue()));
}
return m;
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Schema getKeySchema() {
return keySchema;
}
@Override
public Schema getValueSchema() {
return valueSchema;
}
@Override
@SuppressWarnings("unchecked")
public Object createFromMap(Object[] obj) {
HashMap m = new HashMap(obj.length / 2);
int i = 0;
while(i < obj.length) {
Object k = obj[i++];
Object v = obj[i++];
m.put(k, v);
}
return m;
}
}

View File

@@ -0,0 +1,105 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.nio.ByteBuffer;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.msgpack.*;
public class RawSchema extends Schema {
public RawSchema() {
super("raw");
}
public String getFullName() {
return "byte[]";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
// FIXME instanceof GenericObject
if(obj instanceof byte[]) {
byte[] d = (byte[])obj;
pk.packRaw(d.length);
pk.packRawBody(d);
} else if(obj instanceof ByteBuffer) {
ByteBuffer d = (ByteBuffer)obj;
if(!d.hasArray()) {
throw MessageTypeException.invalidConvert(obj, this);
}
pk.packRaw(d.capacity());
pk.packRawBody(d.array(), d.position(), d.capacity());
} else if(obj instanceof String) {
try {
byte[] d = ((String)obj).getBytes("UTF-8");
pk.packRaw(d.length);
pk.packRawBody(d);
} catch (UnsupportedEncodingException e) {
throw MessageTypeException.invalidConvert(obj, this);
}
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
// FIXME instanceof GenericObject
if(obj instanceof byte[]) {
// FIXME copy?
//byte[] d = (byte[])obj;
//byte[] v = new byte[d.length];
//System.arraycopy(d, 0, v, 0, d.length);
//return v;
return obj;
} else if(obj instanceof ByteBuffer) {
ByteBuffer d = (ByteBuffer)obj;
byte[] v = new byte[d.capacity()];
int pos = d.position();
d.get(v);
d.position(pos);
return v;
} else if(obj instanceof String) {
try {
return ((String)obj).getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw MessageTypeException.invalidConvert(obj, this);
}
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromRaw(byte[] b, int offset, int length) {
byte[] d = new byte[length];
System.arraycopy(b, offset, d, 0, length);
return d;
}
}

View File

@@ -0,0 +1,64 @@
package org.msgpack.schema;
import java.util.Arrays;
import java.util.List;
import java.lang.reflect.*;
import org.msgpack.*;
// FIXME
public abstract class ReflectionClassSchema extends ClassSchema {
private Constructor constructorCache;
public ReflectionClassSchema(String name, List<FieldSchema> fields, String namespace, List<String> imports) {
super(name, namespace, imports, fields);
}
/*
Schema getElementSchema(int index)
{
// FIXME check index < fields.length
fields[index].getSchema();
}
Object createFromArray(Object[] obj)
{
Object o = newInstance();
((MessageConvertable)o).messageConvert(obj);
return o;
}
Object newInstance()
{
if(constructorCache == null) {
cacheConstructor();
}
try {
return constructorCache.newInstance((Object[])null);
} catch (InvocationTargetException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
} catch (InstantiationException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
}
}
private void cacheConstructor()
{
try {
Class c = Class.forName(fqdn);
int index = 0;
for(SpecificFieldSchema f : fields) {
f.cacheField(c, index++);
}
constructorCache = c.getDeclaredConstructor((Class[])null);
constructorCache.setAccessible(true);
} catch(ClassNotFoundException e) {
throw new RuntimeException("class not found: "+fqdn);
} catch (NoSuchMethodException e) {
throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
}
}
*/
}

View File

@@ -0,0 +1,254 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.msgpack.*;
// FIXME exception class
public class SSchemaParser {
public static Schema parse(String source) {
return new SSchemaParser(false).run(source);
}
public static Schema load(String source) {
return new SSchemaParser(true).run(source);
}
private static abstract class SExp {
boolean isAtom() { return false; }
public String getAtom() { return null; }
boolean isTuple() { return false; }
public SExp getTuple(int i) { return null; }
public int size() { return 0; }
public boolean empty() { return size() == 0; }
Iterator<SExp> iterator(int offset) { return null; }
}
private static class SAtom extends SExp {
private String atom;
SAtom(String atom) { this.atom = atom; }
boolean isAtom() { return true; }
public String getAtom() { return atom; }
public String toString() { return atom; }
}
private static class STuple extends SExp {
private List<SExp> tuple;
STuple() { this.tuple = new ArrayList<SExp>(); }
public void add(SExp e) { tuple.add(e); }
boolean isTuple() { return true; }
public SExp getTuple(int i) { return tuple.get(i); }
public int size() { return tuple.size(); }
Iterator<SExp> iterator(int skip) {
Iterator<SExp> i = tuple.iterator();
for(int s=0; s < skip; ++s) { i.next(); }
return i;
}
public String toString() {
if(tuple.isEmpty()) { return "()"; }
Iterator<SExp> i = tuple.iterator();
StringBuffer o = new StringBuffer();
o.append("(").append(i.next());
while(i.hasNext()) { o.append(" ").append(i.next()); }
o.append(")");
return o.toString();
}
}
boolean specificClass;
private SSchemaParser(boolean specificClass) {
this.specificClass = specificClass;
}
private static Pattern pattern = Pattern.compile(
"(?:\\s+)|([\\(\\)]|[\\d\\w\\.]+)");
private Schema run(String source) {
Matcher m = pattern.matcher(source);
Stack<STuple> stack = new Stack<STuple>();
String token;
while(true) {
while(true) {
if(!m.find()) { throw new RuntimeException("unexpected end of file"); }
token = m.group(1);
if(token != null) { break; }
}
if(token.equals("(")) {
stack.push(new STuple());
} else if(token.equals(")")) {
STuple top = stack.pop();
if(stack.empty()) {
stack.push(top);
break;
}
stack.peek().add(top);
} else {
if(stack.empty()) {
throw new RuntimeException("unexpected token '"+token+"'");
}
stack.peek().add(new SAtom(token));
}
}
while(true) {
if(!m.find()) { break; }
token = m.group(1);
if(token != null) { throw new RuntimeException("unexpected token '"+token+"'"); }
}
return readType( stack.pop() );
}
private Schema readType(SExp exp) {
if(exp.isAtom()) {
String type = exp.getAtom();
if(type.equals("string")) {
return new StringSchema();
} else if(type.equals("raw")) {
return new RawSchema();
} else if(type.equals("byte")) {
return new ByteSchema();
} else if(type.equals("short")) {
return new ShortSchema();
} else if(type.equals("int")) {
return new IntSchema();
} else if(type.equals("long")) {
return new LongSchema();
} else if(type.equals("float")) {
return new FloatSchema();
} else if(type.equals("double")) {
return new DoubleSchema();
} else if(type.equals("object")) {
return new GenericSchema();
} else {
throw new RuntimeException("byte, short, int, long, float, double, raw, string or object is expected but got '"+type+"': "+exp);
}
} else {
String type = exp.getTuple(0).getAtom();
if(type.equals("class")) {
return parseClass(exp);
} else if(type.equals("array")) {
return parseArray(exp);
} else if(type.equals("map")) {
return parseMap(exp);
} else {
throw new RuntimeException("class, array or map is expected but got '"+type+"': "+exp);
}
}
}
private ClassSchema parseClass(SExp exp) {
if(exp.size() < 3 || !exp.getTuple(1).isAtom()) {
throw new RuntimeException("class is (class NAME CLASS_BODY): "+exp);
}
String namespace = null;
List<String> imports = new ArrayList<String>();
String name = exp.getTuple(1).getAtom();
List<FieldSchema> fields = new ArrayList<FieldSchema>();
for(Iterator<SExp> i=exp.iterator(2); i.hasNext();) {
SExp subexp = i.next();
if(!subexp.isTuple() || subexp.empty() || !subexp.getTuple(0).isAtom()) {
throw new RuntimeException("field, package or import is expected: "+subexp);
}
String type = subexp.getTuple(0).getAtom();
if(type.equals("field")) {
fields.add( parseField(subexp) );
} else if(type.equals("package")) {
if(namespace != null) {
throw new RuntimeException("duplicated package definition: "+subexp);
}
namespace = parseNamespace(subexp);
} else if(type.equals("import")) {
imports.add( parseImport(subexp) );
} else {
throw new RuntimeException("field, package or import is expected but got '"+type+"': "+subexp);
}
}
if(specificClass) {
return new SpecificClassSchema(name, namespace, imports, fields);
} else {
return new GenericClassSchema(name, namespace, imports, fields);
}
}
private ArraySchema parseArray(SExp exp) {
if(exp.size() != 2) {
throw new RuntimeException("array is (array ELEMENT_TYPE): "+exp);
}
Schema elementType = readType(exp.getTuple(1));
return new ArraySchema(elementType);
}
private MapSchema parseMap(SExp exp) {
if(exp.size() != 3 || !exp.getTuple(1).isAtom()) {
throw new RuntimeException("map is (map KEY_TYPE VALUE_TYPE): "+exp);
}
Schema keyType = readType(exp.getTuple(1));
Schema valueType = readType(exp.getTuple(2));
return new MapSchema(keyType, valueType);
}
private String parseNamespace(SExp exp) {
if(exp.size() != 2 || !exp.getTuple(1).isAtom()) {
throw new RuntimeException("package is (package NAME): "+exp);
}
String name = exp.getTuple(1).getAtom();
return name;
}
private String parseImport(SExp exp) {
if(exp.size() != 2 || !exp.getTuple(1).isAtom()) {
throw new RuntimeException("import is (import NAME): "+exp);
}
String name = exp.getTuple(1).getAtom();
return name;
}
private FieldSchema parseField(SExp exp) {
if(exp.size() != 3 || !exp.getTuple(1).isAtom()) {
throw new RuntimeException("field is (field NAME TYPE): "+exp);
}
String name = exp.getTuple(1).getAtom();
Schema type = readType(exp.getTuple(2));
return new FieldSchema(name, type);
}
}

View File

@@ -0,0 +1,89 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.io.IOException;
import org.msgpack.*;
public class ShortSchema extends Schema {
public ShortSchema() {
super("Short");
}
@Override
public String getExpression() {
return "short";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Number) {
pk.packShort( ((Number)obj).shortValue() );
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Short) {
return obj;
} else if(obj instanceof Number) {
return ((Number)obj).shortValue();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromByte(byte v) {
return (short)v;
}
@Override
public Object createFromShort(short v) {
return (short)v;
}
@Override
public Object createFromInt(int v) {
return (short)v;
}
@Override
public Object createFromLong(long v) {
return (short)v;
}
@Override
public Object createFromFloat(float v) {
return (short)v;
}
@Override
public Object createFromDouble(double v) {
return (short)v;
}
}

View File

@@ -0,0 +1,122 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.util.Collection;
import java.util.List;
import java.lang.reflect.*;
import java.io.IOException;
import org.msgpack.*;
public class SpecificClassSchema extends ClassSchema {
private Class classCache;
private Method factoryCache;
private Constructor constructorCache;
public SpecificClassSchema(
String name, String namespace,
List<String> imports, List<FieldSchema> fields) {
super(name, namespace, imports, fields);
}
@Override
@SuppressWarnings("unchecked")
public void pack(Packer pk, Object obj) throws IOException {
if(obj == null) {
pk.packNil();
return;
}
if(classCache == null) {
cacheFactory();
}
if(classCache.isInstance(obj)) {
((MessagePackable)obj).messagePack(pk);
} else {
// FIXME Map<String,Object>
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
if(obj instanceof Collection) {
if(constructorCache == null) {
cacheConstructor();
}
try {
MessageMergeable o = (MessageMergeable)constructorCache.newInstance((Object[])null);
o.messageMerge(obj);
return o;
} catch (InvocationTargetException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
} catch (InstantiationException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
}
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
public Schema getElementSchema(int index) {
// FIXME check index < fields.length
return fields[index].getSchema();
}
public Object createFromArray(Object[] obj) {
if(factoryCache == null) {
cacheFactory();
}
try {
return factoryCache.invoke(null, new Object[]{obj});
} catch (InvocationTargetException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getCause());
} catch (IllegalAccessException e) {
throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
}
}
@SuppressWarnings("unchecked")
private void cacheFactory() {
try {
classCache = Class.forName(fqdn);
factoryCache = classCache.getDeclaredMethod("createFromMessage", new Class[]{Object[].class});
factoryCache.setAccessible(true);
} catch(ClassNotFoundException e) {
throw new RuntimeException("class not found: "+fqdn);
} catch (NoSuchMethodException e) {
throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
}
}
@SuppressWarnings("unchecked")
private void cacheConstructor() {
try {
classCache = Class.forName(fqdn);
constructorCache = classCache.getDeclaredConstructor((Class[])null);
constructorCache.setAccessible(true);
} catch(ClassNotFoundException e) {
throw new RuntimeException("class not found: "+fqdn);
} catch (NoSuchMethodException e) {
throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
}
}
}

View File

@@ -0,0 +1,111 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
import java.nio.ByteBuffer;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.msgpack.*;
public class StringSchema extends Schema {
public StringSchema() {
super("string");
}
@Override
public String getFullName() {
return "String";
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
// FIXME instanceof GenericObject
if(obj instanceof String) {
try {
byte[] d = ((String)obj).getBytes("UTF-8");
pk.packRaw(d.length);
pk.packRawBody(d);
} catch (UnsupportedEncodingException e) {
throw MessageTypeException.invalidConvert(obj, this);
}
} else if(obj instanceof byte[]) {
byte[] d = (byte[])obj;
pk.packRaw(d.length);
pk.packRawBody(d);
} else if(obj instanceof ByteBuffer) {
ByteBuffer d = (ByteBuffer)obj;
if(!d.hasArray()) {
throw MessageTypeException.invalidConvert(obj, this);
}
pk.packRaw(d.capacity());
pk.packRawBody(d.array(), d.position(), d.capacity());
} else if(obj == null) {
pk.packNil();
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object convert(Object obj) throws MessageTypeException {
// FIXME instanceof GenericObject
if(obj instanceof String) {
return obj;
} else if(obj instanceof byte[]) {
try {
return new String((byte[])obj, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw MessageTypeException.invalidConvert(obj, this);
}
} else if(obj instanceof ByteBuffer) {
ByteBuffer d = (ByteBuffer)obj;
try {
if(d.hasArray()) {
return new String(d.array(), d.position(), d.capacity(), "UTF-8");
} else {
byte[] v = new byte[d.capacity()];
int pos = d.position();
d.get(v);
d.position(pos);
return new String(v, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
throw MessageTypeException.invalidConvert(obj, this);
}
} else {
throw MessageTypeException.invalidConvert(obj, this);
}
}
@Override
public Object createFromRaw(byte[] b, int offset, int length) {
try {
return new String(b, offset, length, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}

38
java/test/Generate.java Normal file
View File

@@ -0,0 +1,38 @@
import java.io.*;
import java.util.*;
import org.msgpack.*;
import org.msgpack.schema.*;
public class Generate {
public static void main(String[] args) throws IOException
{
String source =
"(class MediaContent"+
" (package serializers.msgpack)"+
" (field image (array (class Image"+
" (field uri string)"+
" (field title string)"+
" (field width int)"+
" (field height int)"+
" (field size int))))"+
" (field media (class Media"+
" (field uri string)"+
" (field title string)"+
" (field width int)"+
" (field height int)"+
" (field format string)"+
" (field duration long)"+
" (field size long)"+
" (field bitrate int)"+
" (field person (array string))"+
" (field player int)"+
" (field copyright string)))"+
" )";
Schema schema = Schema.parse(source);
Writer output = new OutputStreamWriter(System.out);
ClassGenerator.write(schema, output);
}
}

7
java/test/README Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
svn checkout -r114 http://thrift-protobuf-compare.googlecode.com/svn/trunk/ thrift-protobuf-compare-base
cp -rf thrift-protobuf-compare/tpc thrift-protobuf-compare-base
cp ../dist/msgpack.jar thrift-protobuf-compare-base/tpc/lib/
cd thrift-protobuf-compare-base/tpc/
ant compile
./run-benchmark.sh

View File

@@ -0,0 +1,434 @@
package serializers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import serializers.msgpack.MessagePackSpecificSerializer;
import serializers.msgpack.MessagePackIndirectSerializer;
import serializers.msgpack.MessagePackDynamicSerializer;
import serializers.msgpack.MessagePackGenericSerializer;
import serializers.avro.AvroGenericSerializer;
import serializers.avro.specific.AvroSpecificSerializer;
import serializers.kryo.KryoOptimizedSerializer;
import serializers.kryo.KryoSerializer;
public class BenchmarkRunner
{
public final static int ITERATIONS = 2000;
public final static int TRIALS = 20;
/**
* Number of milliseconds to warm up for each operation type for each serializer. Let's
* start with 3 seconds.
*/
final static long WARMUP_MSECS = 3000;
@SuppressWarnings("unchecked")
private Set<ObjectSerializer> _serializers = new LinkedHashSet<ObjectSerializer>();
public static void main(String... args) throws Exception
{
BenchmarkRunner runner = new BenchmarkRunner();
// binary codecs first
runner.addObjectSerializer(new MessagePackSpecificSerializer());
runner.addObjectSerializer(new MessagePackIndirectSerializer());
runner.addObjectSerializer(new MessagePackDynamicSerializer());
runner.addObjectSerializer(new MessagePackGenericSerializer());
runner.addObjectSerializer(new AvroGenericSerializer());
runner.addObjectSerializer(new AvroSpecificSerializer());
runner.addObjectSerializer(new ActiveMQProtobufSerializer());
runner.addObjectSerializer(new ProtobufSerializer());
runner.addObjectSerializer(new ThriftSerializer());
runner.addObjectSerializer(new HessianSerializer());
runner.addObjectSerializer(new KryoSerializer());
runner.addObjectSerializer(new KryoOptimizedSerializer());
// None of the other serializers use compression, so we'll leave this out.
// runner.addObjectSerializer(new KryoCompressedSerializer());
// then language default serializers
runner.addObjectSerializer(new JavaSerializer());
runner.addObjectSerializer(new JavaExtSerializer());
runner.addObjectSerializer(new ScalaSerializer());
// then Json
runner.addObjectSerializer(new JsonSerializer());
runner.addObjectSerializer(new JsonDataBindingSerializer());
runner.addObjectSerializer(new JsonMarshallerSerializer());
runner.addObjectSerializer(new ProtostuffJsonSerializer());
runner.addObjectSerializer(new ProtostuffNumericJsonSerializer());
// this is pretty slow; so slow that it's almost not worth keeping but:
runner.addObjectSerializer(new GsonSerializer());
// then xml via stax, textual and binary
runner.addObjectSerializer(new StaxSerializer("stax/woodstox",
new com.ctc.wstx.stax.WstxInputFactory(),
new com.ctc.wstx.stax.WstxOutputFactory()));
runner.addObjectSerializer(new StaxSerializer("stax/aalto",
new com.fasterxml.aalto.stax.InputFactoryImpl(),
new com.fasterxml.aalto.stax.OutputFactoryImpl()));
runner.addObjectSerializer(new StaxSerializer("binaryxml/FI",
new com.sun.xml.fastinfoset.stax.factory.StAXInputFactory(),
new com.sun.xml.fastinfoset.stax.factory.StAXOutputFactory()));
// No point in running all 4 variants: let's just use fastest one:
//runner.addObjectSerializer(new XStreamSerializer("xstream (xpp)", false, null, null));
//runner.addObjectSerializer(new XStreamSerializer("xstream (xpp with conv)", true, null, null));
//runner.addObjectSerializer(new XStreamSerializer("xstream (stax)", false, new com.ctc.wstx.stax.WstxInputFactory(), new com.ctc.wstx.stax.WstxOutputFactory()));
runner.addObjectSerializer(new XStreamSerializer("xstream (stax with conv)",
true,
new com.ctc.wstx.stax.WstxInputFactory(),
new com.ctc.wstx.stax.WstxOutputFactory()));
runner.addObjectSerializer(new JavolutionXMLFormatSerializer());
runner.addObjectSerializer(new SbinarySerializer());
// broken? Does not correctly round-trip:
// runner.addObjectSerializer(new YamlSerializer());
System.out.println("Starting");
runner.start();
}
@SuppressWarnings("unchecked")
private void addObjectSerializer(ObjectSerializer serializer)
{
_serializers.add(serializer);
}
private <T> double createObjects(ObjectSerializer<T> serializer, int iterations) throws Exception
{
long start = System.nanoTime();
for (int i = 0; i < iterations; i++)
{
serializer.create();
}
return iterationTime(System.nanoTime() - start, iterations);
}
private double iterationTime(long delta, int iterations)
{
return (double) delta / (double) (iterations);
}
private <T> double serializeDifferentObjects(ObjectSerializer<T> serializer, int iterations) throws Exception
{
long start = System.nanoTime();
for (int i = 0; i < iterations; i++)
{
T obj = serializer.create();
serializer.serialize(obj);
}
return iterationTime(System.nanoTime()-start, iterations);
}
private <T> double serializeSameObject(ObjectSerializer<T> serializer, int iterations) throws Exception
{
// let's reuse same instance to reduce overhead
T obj = serializer.create();
long delta = 0;
for (int i = 0; i < iterations; i++)
{
long start = System.nanoTime();
serializer.serialize(obj);
delta += System.nanoTime() - start;
if (i % 1000 == 0)
doGc();
}
return iterationTime(delta, iterations);
}
private <T> double deserializeNoFieldAccess(ObjectSerializer<T> serializer, int iterations) throws Exception
{
byte[] array = serializer.serialize(serializer.create());
long start = System.nanoTime();
T result = null;
for (int i = 0; i < iterations; i++)
{
result = serializer.deserialize(array);
}
return iterationTime(System.nanoTime()-start, iterations);
}
private <T> double deserializeAndCheckAllFields(CheckingObjectSerializer<T> serializer, int iterations) throws Exception
{
byte[] array = serializer.serialize(serializer.create());
long delta = 0;
for (int i = 0; i < iterations; i++)
{
long start = System.nanoTime();
T obj = serializer.deserialize(array);
serializer.checkAllFields(obj);
delta += System.nanoTime() - start;
}
return iterationTime(delta, iterations);
}
private <T> double deserializeAndCheckMediaField(CheckingObjectSerializer<T> serializer, int iterations) throws Exception
{
byte[] array = serializer.serialize(serializer.create());
long delta = 0;
for (int i = 0; i < iterations; i++)
{
long start = System.nanoTime();
T obj = serializer.deserialize(array);
serializer.checkMediaField(obj);
delta += System.nanoTime() - start;
}
return iterationTime(delta, iterations);
}
/**
* JVM is not required to honor GC requests, but adding bit of sleep around request is
* most likely to give it a chance to do it.
*/
private void doGc()
{
try {
Thread.sleep(50L);
} catch (InterruptedException ie) { }
System.gc();
try { // longer sleep afterwards (not needed by GC, but may help with scheduling)
Thread.sleep(200L);
} catch (InterruptedException ie) { }
}
enum measurements
{
timeCreate, timeSerializeDifferentObjects, timeSerializeSameObject, timeDeserializeNoFieldAccess, timeDeserializeAndCheckMediaField, timeDeserializeAndCheckAllFields, totalTime, length
}
@SuppressWarnings("unchecked")
private void start() throws Exception
{
System.out.printf("%-24s, %15s, %15s, %15s, %15s, %15s, %15s, %15s, %10s\n",
" ",
"Object create",
"Serialize",
"/w Same Object",
"Deserialize",
"and Check Media",
"and Check All",
"Total Time",
"Serialized Size");
EnumMap<measurements, Map<String, Double>> values = new EnumMap<measurements, Map<String, Double>>(measurements.class);
for (measurements m : measurements.values())
values.put(m, new HashMap<String, Double>());
for (ObjectSerializer serializer : _serializers)
{
/*
* Should only warm things for the serializer that we test next: HotSpot JIT will
* otherwise spent most of its time optimizing slower ones... Use
* -XX:CompileThreshold=1 to hint the JIT to start immediately
*
* Actually: 1 is often not a good value -- threshold is the number
* of samples needed to trigger inlining, and there's no point in
* inlining everything. Default value is in thousands, so lowering
* it to, say, 1000 is usually better.
*/
warmCreation(serializer);
doGc();
double timeCreate = Double.MAX_VALUE;
// do more iteration for object creation because of its short time
for (int i = 0; i < TRIALS; i++)
timeCreate = Math.min(timeCreate, createObjects(serializer, ITERATIONS * 100));
warmSerialization(serializer);
// actually: let's verify serializer actually works now:
checkCorrectness(serializer);
doGc();
double timeSerializeDifferentObjects = Double.MAX_VALUE;
for (int i = 0; i < TRIALS; i++)
timeSerializeDifferentObjects = Math.min(timeSerializeDifferentObjects, serializeDifferentObjects(serializer, ITERATIONS));
doGc();
double timeSerializeSameObject = Double.MAX_VALUE;
for (int i = 0; i < TRIALS; i++)
timeSerializeSameObject = Math.min(timeSerializeSameObject, serializeSameObject(serializer, ITERATIONS));
warmDeserialization(serializer);
doGc();
double timeDeserializeNoFieldAccess = Double.MAX_VALUE;
for (int i = 0; i < TRIALS; i++)
timeDeserializeNoFieldAccess = Math.min(timeDeserializeNoFieldAccess, deserializeNoFieldAccess(serializer, ITERATIONS));
double timeDeserializeAndCheckAllFields = Double.NaN;
double timeDeserializeAndCheckMediaField = Double.NaN;
double totalTime = timeSerializeDifferentObjects + timeDeserializeNoFieldAccess;
if( serializer instanceof CheckingObjectSerializer) {
CheckingObjectSerializer checkingSerializer = (CheckingObjectSerializer)serializer;
timeDeserializeAndCheckMediaField = Double.MAX_VALUE;
doGc();
for (int i = 0; i < TRIALS; i++)
timeDeserializeAndCheckMediaField = Math.min(timeDeserializeAndCheckMediaField, deserializeAndCheckMediaField(checkingSerializer, ITERATIONS));
timeDeserializeAndCheckAllFields = Double.MAX_VALUE;
doGc();
for (int i = 0; i < TRIALS; i++)
timeDeserializeAndCheckAllFields = Math.min(timeDeserializeAndCheckAllFields, deserializeAndCheckAllFields(checkingSerializer, ITERATIONS));
totalTime = timeSerializeDifferentObjects + timeDeserializeAndCheckAllFields;
}
byte[] array = serializer.serialize(serializer.create());
System.out.printf("%-24s, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %10d\n",
serializer.getName(),
timeCreate,
timeSerializeDifferentObjects,
timeSerializeSameObject,
timeDeserializeNoFieldAccess,
timeDeserializeAndCheckMediaField,
timeDeserializeAndCheckAllFields,
totalTime,
array.length);
addValue(values, serializer.getName(), timeCreate, timeSerializeDifferentObjects, timeSerializeSameObject,
timeDeserializeNoFieldAccess, timeDeserializeAndCheckMediaField, timeDeserializeAndCheckAllFields, totalTime, array.length);
}
printImages(values);
}
/**
* Method that tries to validate correctness of serializer, using
* round-trip (construct, serializer, deserialize; compare objects
* after steps 1 and 3).
* Currently only done for StdMediaDeserializer...
*/
private void checkCorrectness(ObjectSerializer serializer)
throws Exception
{
Object input = serializer.create();
byte[] array = serializer.serialize(input);
Object output = serializer.deserialize(array);
if (!input.equals(output)) {
/* Should throw an exception; but for now (that we have a few
* failures) let's just whine...
*/
String msg = "serializer '"+serializer.getName()+"' failed round-trip test (ser+deser produces Object different from input), input="+input+", output="+output;
//throw new Exception("Error: "+msg);
System.err.println("WARN: "+msg);
}
}
private void printImages(EnumMap<measurements, Map<String, Double>> values)
{
for (measurements m : values.keySet()) {
Map<String, Double> map = values.get(m);
ArrayList<Entry> list = new ArrayList(map.entrySet());
Collections.sort(list, new Comparator<Entry>() {
public int compare (Entry o1, Entry o2) {
double diff = (Double)o1.getValue() - (Double)o2.getValue();
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
}
});
LinkedHashMap<String, Double> sortedMap = new LinkedHashMap<String, Double>();
for (Entry<String, Double> entry : list) {
if( !entry.getValue().isNaN() ) {
sortedMap.put(entry.getKey(), entry.getValue());
}
}
printImage(sortedMap, m);
}
}
private void printImage(Map<String, Double> map, measurements m)
{
StringBuilder valSb = new StringBuilder();
String names = "";
double max = Double.MIN_NORMAL;
for (Entry<String, Double> entry : map.entrySet())
{
valSb.append(entry.getValue()).append(',');
max = Math.max(max, entry.getValue());
names = entry.getKey() + '|' + names;
}
int height = Math.min(30+map.size()*20, 430);
double scale = max * 1.1;
System.out.println("<img src='http://chart.apis.google.com/chart?chtt="
+ m.name()
+ "&chf=c||lg||0||FFFFFF||1||76A4FB||0|bg||s||EFEFEF&chs=689x"+height+"&chd=t:"
+ valSb.toString().substring(0, valSb.length() - 1)
+ "&chds=0,"+ scale
+ "&chxt=y"
+ "&chxl=0:|" + names.substring(0, names.length() - 1)
+ "&chm=N *f*,000000,0,-1,10&lklk&chdlp=t&chco=660000|660033|660066|660099|6600CC|6600FF|663300|663333|663366|663399|6633CC|6633FF|666600|666633|666666&cht=bhg&chbh=10&nonsense=aaa.png'/>");
}
private void addValue(EnumMap<measurements, Map<String, Double>> values,
String name,
double timeCreate,
double timeSerializeDifferentObjects,
double timeSerializeSameObject,
double timeDeserializeNoFieldAccess,
double timeDeserializeAndCheckMediaField,
double timeDeserializeAndCheckAllFields,
double totalTime,
double length)
{
values.get(measurements.timeCreate).put(name, timeCreate);
values.get(measurements.timeSerializeDifferentObjects).put(name, timeSerializeDifferentObjects);
values.get(measurements.timeSerializeSameObject).put(name, timeSerializeSameObject);
values.get(measurements.timeDeserializeNoFieldAccess).put(name, timeDeserializeNoFieldAccess);
values.get(measurements.timeDeserializeAndCheckMediaField).put(name, timeDeserializeAndCheckMediaField);
values.get(measurements.timeDeserializeAndCheckAllFields).put(name, timeDeserializeAndCheckAllFields);
values.get(measurements.totalTime).put(name, totalTime);
values.get(measurements.length).put(name, length);
}
private <T> void warmCreation(ObjectSerializer<T> serializer) throws Exception
{
// Instead of fixed counts, let's try to prime by running for N seconds
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
do
{
createObjects(serializer, 1);
}
while (System.currentTimeMillis() < endTime);
}
private <T> void warmSerialization(ObjectSerializer<T> serializer) throws Exception
{
// Instead of fixed counts, let's try to prime by running for N seconds
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
do
{
serializeDifferentObjects(serializer, 1);
}
while (System.currentTimeMillis() < endTime);
}
private <T> void warmDeserialization(ObjectSerializer<T> serializer) throws Exception
{
// Instead of fixed counts, let's try to prime by running for N seconds
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
do
{
deserializeNoFieldAccess(serializer, 1);
}
while (System.currentTimeMillis() < endTime);
}
}

View File

@@ -0,0 +1,173 @@
package serializers.msgpack;
import java.util.*;
import java.io.*;
import org.msgpack.*;
import org.msgpack.schema.ClassSchema;
import org.msgpack.schema.FieldSchema;
public final class MediaContent implements MessagePackable, MessageMergeable
{
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class MediaContent (package serializers.msgpack) (field image (array (class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int)))) (field media (class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))))");
public static ClassSchema getSchema() { return _SCHEMA; }
public List<Image> image;
public Media media;
public MediaContent() { }
@Override
public void messagePack(Packer _pk) throws IOException
{
_pk.packArray(2);
FieldSchema[] _fields = _SCHEMA.getFields();
_fields[0].getSchema().pack(_pk, image);
_fields[1].getSchema().pack(_pk, media);
}
@Override
@SuppressWarnings("unchecked")
public void messageMerge(Object obj) throws MessageTypeException
{
Object[] _source = ((List)obj).toArray();
FieldSchema[] _fields = _SCHEMA.getFields();
if(_source.length <= 0) { return; } this.image = (List<Image>)_fields[0].getSchema().convert(_source[0]);
if(_source.length <= 1) { return; } this.media = (Media)_fields[1].getSchema().convert(_source[1]);
}
@SuppressWarnings("unchecked")
public static MediaContent createFromMessage(Object[] _message)
{
MediaContent _self = new MediaContent();
if(_message.length <= 0) { return _self; } _self.image = (List<Image>)_message[0];
if(_message.length <= 1) { return _self; } _self.media = (Media)_message[1];
return _self;
}
}
final class Image implements MessagePackable, MessageMergeable
{
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int))");
public static ClassSchema getSchema() { return _SCHEMA; }
public String uri;
public String title;
public Integer width;
public Integer height;
public Integer size;
public Image() { }
@Override
public void messagePack(Packer _pk) throws IOException
{
_pk.packArray(5);
FieldSchema[] _fields = _SCHEMA.getFields();
_fields[0].getSchema().pack(_pk, uri);
_fields[1].getSchema().pack(_pk, title);
_fields[2].getSchema().pack(_pk, width);
_fields[3].getSchema().pack(_pk, height);
_fields[4].getSchema().pack(_pk, size);
}
@Override
@SuppressWarnings("unchecked")
public void messageMerge(Object obj) throws MessageTypeException
{
Object[] _source = ((List)obj).toArray();
FieldSchema[] _fields = _SCHEMA.getFields();
if(_source.length <= 0) { return; } this.uri = (String)_fields[0].getSchema().convert(_source[0]);
if(_source.length <= 1) { return; } this.title = (String)_fields[1].getSchema().convert(_source[1]);
if(_source.length <= 2) { return; } this.width = (Integer)_fields[2].getSchema().convert(_source[2]);
if(_source.length <= 3) { return; } this.height = (Integer)_fields[3].getSchema().convert(_source[3]);
if(_source.length <= 4) { return; } this.size = (Integer)_fields[4].getSchema().convert(_source[4]);
}
@SuppressWarnings("unchecked")
public static Image createFromMessage(Object[] _message)
{
Image _self = new Image();
if(_message.length <= 0) { return _self; } _self.uri = (String)_message[0];
if(_message.length <= 1) { return _self; } _self.title = (String)_message[1];
if(_message.length <= 2) { return _self; } _self.width = (Integer)_message[2];
if(_message.length <= 3) { return _self; } _self.height = (Integer)_message[3];
if(_message.length <= 4) { return _self; } _self.size = (Integer)_message[4];
return _self;
}
}
final class Media implements MessagePackable, MessageMergeable
{
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))");
public static ClassSchema getSchema() { return _SCHEMA; }
public String uri;
public String title;
public Integer width;
public Integer height;
public String format;
public Long duration;
public Long size;
public Integer bitrate;
public List<String> person;
public Integer player;
public String copyright;
public Media() { }
@Override
public void messagePack(Packer _pk) throws IOException
{
_pk.packArray(11);
FieldSchema[] _fields = _SCHEMA.getFields();
_fields[0].getSchema().pack(_pk, uri);
_fields[1].getSchema().pack(_pk, title);
_fields[2].getSchema().pack(_pk, width);
_fields[3].getSchema().pack(_pk, height);
_fields[4].getSchema().pack(_pk, format);
_fields[5].getSchema().pack(_pk, duration);
_fields[6].getSchema().pack(_pk, size);
_fields[7].getSchema().pack(_pk, bitrate);
_fields[8].getSchema().pack(_pk, person);
_fields[9].getSchema().pack(_pk, player);
_fields[10].getSchema().pack(_pk, copyright);
}
@Override
@SuppressWarnings("unchecked")
public void messageMerge(Object obj) throws MessageTypeException
{
Object[] _source = ((List)obj).toArray();
FieldSchema[] _fields = _SCHEMA.getFields();
if(_source.length <= 0) { return; } this.uri = (String)_fields[0].getSchema().convert(_source[0]);
if(_source.length <= 1) { return; } this.title = (String)_fields[1].getSchema().convert(_source[1]);
if(_source.length <= 2) { return; } this.width = (Integer)_fields[2].getSchema().convert(_source[2]);
if(_source.length <= 3) { return; } this.height = (Integer)_fields[3].getSchema().convert(_source[3]);
if(_source.length <= 4) { return; } this.format = (String)_fields[4].getSchema().convert(_source[4]);
if(_source.length <= 5) { return; } this.duration = (Long)_fields[5].getSchema().convert(_source[5]);
if(_source.length <= 6) { return; } this.size = (Long)_fields[6].getSchema().convert(_source[6]);
if(_source.length <= 7) { return; } this.bitrate = (Integer)_fields[7].getSchema().convert(_source[7]);
if(_source.length <= 8) { return; } this.person = (List<String>)_fields[8].getSchema().convert(_source[8]);
if(_source.length <= 9) { return; } this.player = (Integer)_fields[9].getSchema().convert(_source[9]);
if(_source.length <= 10) { return; } this.copyright = (String)_fields[10].getSchema().convert(_source[10]);
}
@SuppressWarnings("unchecked")
public static Media createFromMessage(Object[] _message)
{
Media _self = new Media();
if(_message.length <= 0) { return _self; } _self.uri = (String)_message[0];
if(_message.length <= 1) { return _self; } _self.title = (String)_message[1];
if(_message.length <= 2) { return _self; } _self.width = (Integer)_message[2];
if(_message.length <= 3) { return _self; } _self.height = (Integer)_message[3];
if(_message.length <= 4) { return _self; } _self.format = (String)_message[4];
if(_message.length <= 5) { return _self; } _self.duration = (Long)_message[5];
if(_message.length <= 6) { return _self; } _self.size = (Long)_message[6];
if(_message.length <= 7) { return _self; } _self.bitrate = (Integer)_message[7];
if(_message.length <= 8) { return _self; } _self.person = (List<String>)_message[8];
if(_message.length <= 9) { return _self; } _self.player = (Integer)_message[9];
if(_message.length <= 10) { return _self; } _self.copyright = (String)_message[10];
return _self;
}
}

View File

@@ -0,0 +1,21 @@
(class MediaContent
(package serializers.msgpack)
(field image (array (class Image
(field uri string)
(field title string)
(field width int)
(field height int)
(field size int))))
(field media (class Media
(field uri string)
(field title string)
(field width int)
(field height int)
(field format string)
(field duration long)
(field size long)
(field bitrate int)
(field person (array string))
(field player int)
(field copyright string)))
)

View File

@@ -0,0 +1,68 @@
package serializers.msgpack;
import java.io.*;
import java.util.*;
import org.msgpack.*;
import serializers.ObjectSerializer;
public class MessagePackDynamicSerializer implements ObjectSerializer<Object>
{
public String getName() {
return "msgpack-dynamic";
}
public Object create() throws Exception {
ArrayList media = new ArrayList(11);
media.add("http://javaone.com/keynote.mpg");
media.add("video/mpg4");
media.add("Javaone Keynote");
media.add(1234567L);
media.add(0);
ArrayList<String> person = new ArrayList<String>(2);
person.add("Bill Gates");
person.add("Steve Jobs");
media.add(person);
media.add(0);
media.add(0);
media.add(0);
media.add(123L);
media.add("");
ArrayList image1 = new ArrayList(5);
image1.add("http://javaone.com/keynote_large.jpg");
image1.add(0);
image1.add(0);
image1.add(2);
image1.add("Javaone Keynote");
ArrayList image2 = new ArrayList(5);
image2.add("http://javaone.com/keynote_thumbnail.jpg");
image2.add(0);
image2.add(0);
image2.add(1);
image2.add("Javaone Keynote");
ArrayList content = new ArrayList(2);
content.add(media);
ArrayList<Object> images = new ArrayList<Object>(2);
images.add(image1);
images.add(image2);
content.add(images);
return content;
}
public byte[] serialize(Object content) throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Packer pk = new Packer(os);
pk.pack(content);
return os.toByteArray();
}
public Object deserialize(byte[] array) throws Exception {
UnbufferedUnpacker pac = new UnbufferedUnpacker();
pac.execute(array);
return (Object)pac.getData();
}
}

View File

@@ -0,0 +1,70 @@
package serializers.msgpack;
import java.io.*;
import java.util.*;
import org.msgpack.*;
import serializers.ObjectSerializer;
public class MessagePackGenericSerializer implements ObjectSerializer<Object>
{
private static final Schema MEDIA_CONTENT_SCHEMA = Schema.parse("(class MediaContent (package serializers.msgpack) (field image (array (class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int)))) (field media (class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))))");
public String getName() {
return "msgpack-generic";
}
public Object create() throws Exception {
HashMap<String,Object> media = new HashMap<String, Object>(11);
media.put("uri", "http://javaone.com/keynote.mpg");
media.put("format", "video/mpg4");
media.put("title", "Javaone Keynote");
media.put("duration", 1234567L);
media.put("bitrate", 0);
ArrayList<String> person = new ArrayList<String>(2);
person.add("Bill Gates");
person.add("Steve Jobs");
media.put("person", person);
media.put("player", 0);
media.put("height", 0);
media.put("width", 0);
media.put("size", 123L);
media.put("copyright", "");
HashMap<String,Object> image1 = new HashMap<String,Object>(5);
image1.put("uri", "http://javaone.com/keynote_large.jpg");
image1.put("width", 0);
image1.put("height", 0);
image1.put("size", 2);
image1.put("title", "Javaone Keynote");
HashMap<String,Object> image2 = new HashMap<String,Object>(5);
image2.put("uri", "http://javaone.com/keynote_thumbnail.jpg");
image2.put("width", 0);
image2.put("height", 0);
image2.put("size", 1);
image2.put("title", "Javaone Keynote");
HashMap<String,Object> content = new HashMap<String,Object>(2);
content.put("media", media);
ArrayList<Object> images = new ArrayList<Object>(2);
images.add(image1);
images.add(image2);
content.put("image", images);
return content;
}
public byte[] serialize(Object content) throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Packer pk = new Packer(os);
pk.packWithSchema(content, MEDIA_CONTENT_SCHEMA);
return os.toByteArray();
}
public Object deserialize(byte[] array) throws Exception {
UnbufferedUnpacker pac = new UnbufferedUnpacker().useSchema(MEDIA_CONTENT_SCHEMA);
pac.execute(array);
return (Object)pac.getData();
}
}

View File

@@ -0,0 +1,67 @@
package serializers.msgpack;
import java.io.*;
import java.util.*;
import org.msgpack.*;
import serializers.ObjectSerializer;
public class MessagePackIndirectSerializer implements ObjectSerializer<MediaContent>
{
public String getName() {
return "msgpack-indirect";
}
public MediaContent create() throws Exception {
Media media = new Media();
media.uri = "http://javaone.com/keynote.mpg";
media.format = "video/mpg4";
media.title = "Javaone Keynote";
media.duration = 1234567L;
media.bitrate = 0;
media.person = new ArrayList<String>(2);
media.person.add("Bill Gates");
media.person.add("Steve Jobs");
media.player = 0;
media.height = 0;
media.width = 0;
media.size = 123L;
media.copyright = "";
Image image1 = new Image();
image1.uri = "http://javaone.com/keynote_large.jpg";
image1.width = 0;
image1.height = 0;
image1.size = 2;
image1.title = "Javaone Keynote";
Image image2 = new Image();
image2.uri = "http://javaone.com/keynote_thumbnail.jpg";
image2.width = 0;
image2.height = 0;
image2.size = 1;
image2.title = "Javaone Keynote";
MediaContent content = new MediaContent();
content.media = media;
content.image = new ArrayList<Image>(2);
content.image.add(image1);
content.image.add(image2);
return content;
}
public byte[] serialize(MediaContent content) throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Packer pk = new Packer(os);
pk.pack(content);
return os.toByteArray();
}
public MediaContent deserialize(byte[] array) throws Exception {
UnbufferedUnpacker pac = new UnbufferedUnpacker();
pac.execute(array);
Object obj = pac.getData();
return (MediaContent)MediaContent.getSchema().convert(obj);
}
}

View File

@@ -0,0 +1,66 @@
package serializers.msgpack;
import java.io.*;
import java.util.*;
import org.msgpack.*;
import serializers.ObjectSerializer;
public class MessagePackSpecificSerializer implements ObjectSerializer<MediaContent>
{
public String getName() {
return "msgpack-specific";
}
public MediaContent create() throws Exception {
Media media = new Media();
media.uri = "http://javaone.com/keynote.mpg";
media.format = "video/mpg4";
media.title = "Javaone Keynote";
media.duration = 1234567L;
media.bitrate = 0;
media.person = new ArrayList<String>(2);
media.person.add("Bill Gates");
media.person.add("Steve Jobs");
media.player = 0;
media.height = 0;
media.width = 0;
media.size = 123L;
media.copyright = "";
Image image1 = new Image();
image1.uri = "http://javaone.com/keynote_large.jpg";
image1.width = 0;
image1.height = 0;
image1.size = 2;
image1.title = "Javaone Keynote";
Image image2 = new Image();
image2.uri = "http://javaone.com/keynote_thumbnail.jpg";
image2.width = 0;
image2.height = 0;
image2.size = 1;
image2.title = "Javaone Keynote";
MediaContent content = new MediaContent();
content.media = media;
content.image = new ArrayList<Image>(2);
content.image.add(image1);
content.image.add(image2);
return content;
}
public byte[] serialize(MediaContent content) throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Packer pk = new Packer(os);
pk.pack(content);
return os.toByteArray();
}
public MediaContent deserialize(byte[] array) throws Exception {
UnbufferedUnpacker pac = new UnbufferedUnpacker().useSchema(MediaContent.getSchema());
pac.execute(array);
return (MediaContent)pac.getData();
}
}

View File

@@ -1,7 +1,7 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@
#ifndef MSGPACK_PACK_DEFINE_H__
#define MSGPACK_PACK_DEFINE_H__
#include <stddef.h>
#include <stdint.h>
#include "msgpack/sysdep.h"
#include <limits.h>
#include <string.h>
#endif /* msgpack/pack_define.h */

View File

@@ -1,7 +1,7 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -16,88 +16,16 @@
* limitations under the License.
*/
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define __LITTLE_ENDIAN__
#elif __BYTE_ORDER == __BIG_ENDIAN
#define __BIG_ENDIAN__
#endif
#endif
#ifdef __LITTLE_ENDIAN__
#define STORE8_BE8(d) \
((uint8_t*)&d)[0]
#define STORE16_BE8(d) \
((uint8_t*)&d)[0]
#define STORE16_BE16(d) \
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define STORE32_BE8(d) \
((uint8_t*)&d)[0]
#define STORE32_BE16(d) \
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define STORE32_BE32(d) \
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define STORE64_BE8(d) \
((uint8_t*)&d)[0]
#define STORE64_BE16(d) \
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define STORE64_BE32(d) \
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define STORE64_BE64(d) \
((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[0]
#define TAKE8_32(d) ((uint8_t*)&d)[0]
#define TAKE8_64(d) ((uint8_t*)&d)[0]
#elif __BIG_ENDIAN__
#define STORE8_BE8(d) \
((uint8_t*)&d)[0]
#define STORE16_BE8(d) \
((uint8_t*)&d)[1]
#define STORE16_BE16(d) \
((uint8_t*)&d)[0], ((uint8_t*)&d)[1]
#define STORE32_BE8(d) \
((uint8_t*)&d)[3]
#define STORE32_BE16(d) \
((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
#define STORE32_BE32(d) \
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
#define STORE64_BE8(d) \
((uint8_t*)&d)[7]
#define STORE64_BE16(d) \
((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
#define STORE64_BE32(d) \
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
#define STORE64_BE64(d) \
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3], \
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[1]
#define TAKE8_32(d) ((uint8_t*)&d)[3]
#define TAKE8_64(d) ((uint8_t*)&d)[7]
#endif
#ifndef msgpack_pack_inline_func
@@ -121,10 +49,10 @@
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} else { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} while(0)
@@ -133,14 +61,15 @@ do { \
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else if(d < (1<<8)) { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} while(0)
@@ -150,20 +79,22 @@ do { \
if(d < (1<<8)) { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1<<16)) { \
/* unsigned 16 */ \
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
@@ -174,24 +105,27 @@ do { \
if(d < (1ULL<<8)) { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1ULL<<16)) { \
/* signed 16 */ \
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else if(d < (1ULL<<32)) { \
/* signed 32 */ \
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* signed 64 */ \
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
@@ -201,11 +135,11 @@ do { \
do { \
if(d < -(1<<5)) { \
/* signed 8 */ \
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} \
} while(0)
@@ -214,24 +148,26 @@ do { \
if(d < -(1<<5)) { \
if(d < -(1<<7)) { \
/* signed 16 */ \
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} \
@@ -242,32 +178,36 @@ do { \
if(d < -(1<<5)) { \
if(d < -(1<<15)) { \
/* signed 32 */ \
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else if(d < -(1<<7)) { \
/* signed 16 */ \
const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else if(d < (1<<16)) { \
/* unsigned 16 */ \
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
@@ -279,46 +219,52 @@ do { \
if(d < -(1LL<<15)) { \
if(d < -(1LL<<31)) { \
/* signed 64 */ \
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \
unsigned char buf[9]; \
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} else { \
/* signed 32 */ \
const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} else { \
if(d < -(1<<7)) { \
/* signed 16 */ \
const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
if(d < (1LL<<16)) { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} else { \
if(d < (1LL<<32)) { \
/* unsigned 32 */ \
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* unsigned 64 */ \
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
@@ -330,49 +276,55 @@ do { \
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
{
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)};
unsigned char buf[2] = {0xcc, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
{
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)};
unsigned char buf[3];
buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
{
const unsigned char buf[5] = {0xce, STORE32_BE32(d)};
unsigned char buf[5];
buf[0] = 0xce; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
{
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)};
unsigned char buf[9];
buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
{
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)};
unsigned char buf[2] = {0xd0, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
{
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)};
unsigned char buf[3];
buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
{
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)};
unsigned char buf[5];
buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
{
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)};
unsigned char buf[9];
buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
@@ -602,17 +554,19 @@ if(sizeof(unsigned long long) == 2) {
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
{
union { char buf[4]; uint32_t num; } f;
*((float*)&f.buf) = d; // FIXME
const unsigned char buf[5] = {0xca, STORE32_BE32(f.num)};
union { float f; uint32_t i; } mem;
mem.f = d;
unsigned char buf[5];
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
{
union { char buf[8]; uint64_t num; } f;
*((double*)&f.buf) = d; // FIXME
const unsigned char buf[9] = {0xcb, STORE64_BE64(f.num)};
union { double f; uint64_t i; } mem;
mem.f = d;
unsigned char buf[9];
buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 9);
}
@@ -655,12 +609,12 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
unsigned char d = 0x90 | n;
msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) {
uint16_t d = (uint16_t)n;
unsigned char buf[3] = {0xdc, STORE16_BE16(d)};
unsigned char buf[3];
buf[0] = 0xdc; _msgpack_store16(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
uint32_t d = (uint32_t)n;
unsigned char buf[5] = {0xdd, STORE32_BE32(d)};
unsigned char buf[5];
buf[0] = 0xdd; _msgpack_store32(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
@@ -674,14 +628,14 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
{
if(n < 16) {
unsigned char d = 0x80 | n;
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) {
uint16_t d = (uint16_t)n;
unsigned char buf[3] = {0xde, STORE16_BE16(d)};
unsigned char buf[3];
buf[0] = 0xde; _msgpack_store16(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
uint32_t d = (uint32_t)n;
unsigned char buf[5] = {0xdf, STORE32_BE32(d)};
unsigned char buf[5];
buf[0] = 0xdf; _msgpack_store32(&buf[1], n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
@@ -695,14 +649,14 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
{
if(l < 32) {
unsigned char d = 0xa0 | l;
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 65536) {
uint16_t d = (uint16_t)l;
unsigned char buf[3] = {0xda, STORE16_BE16(d)};
unsigned char buf[3];
buf[0] = 0xda; _msgpack_store16(&buf[1], l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
uint32_t d = (uint32_t)l;
unsigned char buf[5] = {0xdb, STORE32_BE32(d)};
unsigned char buf[5];
buf[0] = 0xdb; _msgpack_store32(&buf[1], l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
@@ -716,19 +670,10 @@ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l
#undef msgpack_pack_user
#undef msgpack_pack_append_buffer
#undef STORE8_BE8
#undef STORE16_BE8
#undef STORE16_BE16
#undef STORE32_BE8
#undef STORE32_BE16
#undef STORE32_BE32
#undef STORE64_BE8
#undef STORE64_BE16
#undef STORE64_BE32
#undef STORE64_BE64
#undef TAKE8_8
#undef TAKE8_16
#undef TAKE8_32
#undef TAKE8_64
#undef msgpack_pack_real_uint8
#undef msgpack_pack_real_uint16

118
msgpack/sysdep.h Normal file
View File

@@ -0,0 +1,118 @@
/*
* MessagePack system dependencies
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_SYSDEP_H__
#define MSGPACK_SYSDEP_H__
#ifdef _MSC_VER
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#endif
#ifdef _WIN32
typedef long _msgpack_atomic_counter_t;
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
#else
typedef unsigned int _msgpack_atomic_counter_t;
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
#endif
#ifdef _WIN32
#include <winsock2.h>
#ifdef __cplusplus
/* numeric_limits<T>::min,max */
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#endif
#else
#include <arpa/inet.h> /* __BYTE_ORDER */
#endif
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define __LITTLE_ENDIAN__
#elif __BYTE_ORDER == __BIG_ENDIAN
#define __BIG_ENDIAN__
#endif
#endif
#ifdef __LITTLE_ENDIAN__
#define _msgpack_be16(x) ntohs(x)
#define _msgpack_be32(x) ntohl(x)
#if defined(_byteswap_uint64)
# define _msgpack_be64(x) (_byteswap_uint64(x))
#elif defined(bswap_64)
# define _msgpack_be64(x) bswap_64(x)
#elif defined(__DARWIN_OSSwapInt64)
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
#else
#define _msgpack_be64(x) \
( ((((uint64_t)x) << 56) & 0xff00000000000000ULL ) | \
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
((((uint64_t)x) >> 56) & 0x00000000000000ffULL ) )
#endif
#else
#define _msgpack_be16(x) (x)
#define _msgpack_be32(x) (x)
#define _msgpack_be64(x) (x)
#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 */

View File

@@ -1,7 +1,7 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -18,14 +18,10 @@
#ifndef MSGPACK_UNPACK_DEFINE_H__
#define MSGPACK_UNPACK_DEFINE_H__
#include <stddef.h>
#include <stdint.h>
#include "msgpack/sysdep.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#ifndef __WIN32__
#include <arpa/inet.h>
#endif
#ifdef __cplusplus
extern "C" {
@@ -37,39 +33,6 @@ extern "C" {
#endif
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define __LITTLE_ENDIAN__
#elif __BYTE_ORDER == __BIG_ENDIAN
#define __BIG_ENDIAN__
#endif
#endif
#define msgpack_betoh16(x) ntohs(x)
#define msgpack_betoh32(x) ntohl(x)
#ifdef __LITTLE_ENDIAN__
#if defined(__bswap_64)
# define msgpack_betoh64(x) __bswap_64(x)
#elif defined(__DARWIN_OSSwapInt64)
# define msgpack_betoh64(x) __DARWIN_OSSwapInt64(x)
#else
static inline uint64_t msgpack_betoh64(uint64_t x) {
return ((x << 56) & 0xff00000000000000ULL ) |
((x << 40) & 0x00ff000000000000ULL ) |
((x << 24) & 0x0000ff0000000000ULL ) |
((x << 8) & 0x000000ff00000000ULL ) |
((x >> 8) & 0x00000000ff000000ULL ) |
((x >> 24) & 0x0000000000ff0000ULL ) |
((x >> 40) & 0x000000000000ff00ULL ) |
((x >> 56) & 0x00000000000000ffULL ) ;
}
#endif
#else
#define msgpack_betoh64(x) (x)
#endif
typedef enum {
CS_HEADER = 0x00, // nil

View File

@@ -1,7 +1,7 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,11 @@
#error msgpack_unpack_user type is not defined
#endif
#ifndef USE_CASE_RANGE
#if !defined(_MSC_VER)
#define USE_CASE_RANGE
#endif
#endif
msgpack_unpack_struct_decl(_stack) {
msgpack_unpack_object obj;
@@ -125,21 +130,28 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
#define NEXT_CS(p) \
((unsigned int)*p & 0x1f)
#define PTR_CAST_8(ptr) (*(uint8_t*)ptr)
#define PTR_CAST_16(ptr) msgpack_betoh16(*(uint16_t*)ptr)
#define PTR_CAST_32(ptr) msgpack_betoh32(*(uint32_t*)ptr)
#define PTR_CAST_64(ptr) msgpack_betoh64(*(uint64_t*)ptr)
#ifdef USE_CASE_RANGE
#define SWITCH_RANGE_BEGIN switch(*p) {
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
#define SWITCH_RANGE_DEFAULT default:
#define SWITCH_RANGE_END }
#else
#define SWITCH_RANGE_BEGIN { if(0) {
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
#define SWITCH_RANGE_DEFAULT } else {
#define SWITCH_RANGE_END } }
#endif
if(p == pe) { goto _out; }
do {
switch(cs) {
case CS_HEADER:
switch(*p) {
case 0x00 ... 0x7f: // Positive Fixnum
SWITCH_RANGE_BEGIN
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
push_fixed_value(_uint8, *(uint8_t*)p);
case 0xe0 ... 0xff: // Negative Fixnum
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
push_fixed_value(_int8, *(int8_t*)p);
case 0xc0 ... 0xdf: // Variable
SWITCH_RANGE(0xc0, 0xdf) // Variable
switch(*p) {
case 0xc0: // nil
push_simple_value(_nil);
@@ -182,16 +194,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
default:
goto _failed;
}
case 0xa0 ... 0xbf: // FixRaw
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
case 0x90 ... 0x9f: // FixArray
SWITCH_RANGE(0x90, 0x9f) // FixArray
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
case 0x80 ... 0x8f: // FixMap
SWITCH_RANGE(0x80, 0x8f) // FixMap
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
default:
SWITCH_RANGE_DEFAULT
goto _failed;
}
SWITCH_RANGE_END
// end CS_HEADER
@@ -205,70 +217,70 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
//case CS_
//case CS_
case CS_FLOAT: {
union { uint32_t num; char buf[4]; } f;
f.num = PTR_CAST_32(n); // FIXME
push_fixed_value(_float, *((float*)f.buf)); }
union { uint32_t i; float f; } mem;
mem.i = _msgpack_load32(uint32_t,n);
push_fixed_value(_float, mem.f); }
case CS_DOUBLE: {
union { uint64_t num; char buf[8]; } f;
f.num = PTR_CAST_64(n); // FIXME
push_fixed_value(_double, *((double*)f.buf)); }
union { uint64_t i; double f; } mem;
mem.i = _msgpack_load64(uint64_t,n);
push_fixed_value(_double, mem.f); }
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:
push_fixed_value(_uint16, (uint16_t)PTR_CAST_16(n));
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
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:
push_fixed_value(_uint64, (uint64_t)PTR_CAST_64(n));
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
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:
push_fixed_value(_int16, (int16_t)PTR_CAST_16(n));
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
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:
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_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:
// 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:
//_big_int_zero:
// // FIXME
// push_variable_value(_big_int, data, n, trail);
//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:
// 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:
//_big_float_zero:
// // FIXME
// push_variable_value(_big_float, data, n, trail);
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:
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:
_raw_zero:
push_variable_value(_raw, data, n, trail);
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:
/* 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:
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:
/* 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:
goto _failed;
@@ -354,8 +366,4 @@ _end:
#undef start_container
#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>

13
perl/.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
META.yml
Makefile
Makefile.old
MessagePack.bs
MessagePack.o
blib/
inc/
msgpack/
pack.o
pm_to_blib
unpack.o
MANIFEST
ppport.h

2
perl/.shipit Normal file
View File

@@ -0,0 +1,2 @@
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
git.tagpattern = perl-%v

42
perl/Changes Normal file
View File

@@ -0,0 +1,42 @@
0.09
- support NVTYPE=="long double" or IVTYPE=="long long" environment
(thanks to Jun Kuriyama++)
0.08
- fixed PVNV issue...
0.07
- do not use switch (SvTYPE(val)).
0.06
- use SvNOK.
0.05
- change type detection for old perl
0.04
- check SvROK first(reported by yappo++)
- PreferInteger: faster string to integer conversion; support negative value
(frsyuki++)
- make PreferInteger variable magical and remove get_sv from _msgpack_pack_sv
(frsyuki++)
0.03
- performance tuning for too long string
- fixed memory leaks in stream unpacker
0.02
- added $Data::MessagePack::PreferInteger
(requested by yappo++)
0.01
- initial release to CPAN

25
perl/MANIFEST.SKIP Normal file
View File

@@ -0,0 +1,25 @@
\bRCS\b
\bCVS\b
^MANIFEST\.
^Makefile$
~$
^#
\.old$
^blib/
^pm_to_blib
^MakeMaker-\d
\.gz$
\.cvsignore
^t/9\d_.*\.t
^t/perlcritic
^tools/
\.svn/
^[^/]+\.yaml$
^[^/]+\.pl$
^\.shipit$
^\.git/
\.sw[pon]$
^\.gitignore$
\.o$
\.bs$
^Data-MessagePack-[0-9.]+/

View File

@@ -1,30 +1,36 @@
use inc::Module::Install;
name 'Data-MessagePack';
all_from 'lib/Data/MessagePack.pm';
readme_from 'lib/Data/MessagePack.pm';
perl_version '5.008005';
license 'perl';
can_cc or die "This module requires a C compiler";
my $ccflags = '-I../ ';
makemaker_args(
OBJECT => '$(O_FILES)',
LIBS => [''],
CCFLAGS => $ccflags,
clean => {
FILES => q{
*.stackdump
*.gcov *.gcda *.gcno
*.out
nytprof
cover_db
},
},
);
tests 't/*.t';
author_tests('xt');
use_ppport 3.19;
clean_files qw{
*.stackdump
*.gcov *.gcda *.gcno
*.out
nytprof
cover_db
};
if ($ENV{DEBUG}) {
cc_append_to_ccflags '-g';
}
# copy modules
if ($Module::Install::AUTHOR && -d File::Spec->catfile('..', 'msgpack')) {
mkdir 'msgpack' unless -d 'msgpack';
require File::Copy;
for my $src (<../msgpack/*.h>) {
File::Copy::copy($src, 'msgpack/') or die "copy failed: $!";
}
}
auto_set_repository;
build_requires 'Test::More';

Some files were not shown because too many files have changed in this diff Show More