mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
Compare commits
1050 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
197ed8c983 | ||
![]() |
990860fe65 | ||
![]() |
dbeb6e61c6 | ||
![]() |
2b3f37f9e0 | ||
![]() |
f50148a9cc | ||
![]() |
9fc8ec5b61 | ||
![]() |
751a6f98fe | ||
![]() |
9d8e6b92fc | ||
![]() |
c868da2879 | ||
![]() |
e0c40c1c59 | ||
![]() |
f185284776 | ||
![]() |
1656ef0111 | ||
![]() |
3cb2e4f7c6 | ||
![]() |
3104f7e451 | ||
![]() |
ab8e7ea822 | ||
![]() |
6daef66ea7 | ||
![]() |
04286eb9dc | ||
![]() |
d15e30bf4a | ||
![]() |
fb1d480faf | ||
![]() |
c8fa0be345 | ||
![]() |
643b0c9523 | ||
![]() |
06930616b2 | ||
![]() |
6e5fc6d396 | ||
![]() |
17b0753023 | ||
![]() |
7491348d40 | ||
![]() |
eef2036c36 | ||
![]() |
fbec8f4470 | ||
![]() |
8e0137e1d2 | ||
![]() |
1dac3f890a | ||
![]() |
9f33266f23 | ||
![]() |
d8c7fd5161 | ||
![]() |
731bc643d0 | ||
![]() |
12e8615ac5 | ||
![]() |
22703d2cdb | ||
![]() |
cb518f472a | ||
![]() |
271f1fa319 | ||
![]() |
9ecc4f0a1e | ||
![]() |
977eab7c4a | ||
![]() |
c9f342f4b2 | ||
![]() |
126e4d8414 | ||
![]() |
14ee1e5827 | ||
![]() |
ecbb9055a2 | ||
![]() |
862f04104d | ||
![]() |
d47f72be0c | ||
![]() |
98c5767372 | ||
![]() |
97a7b7545a | ||
![]() |
caf5616573 | ||
![]() |
b8076fa71f | ||
![]() |
2360466aa9 | ||
![]() |
28370b36aa | ||
![]() |
9d82356ea9 | ||
![]() |
ca24e040c4 | ||
![]() |
0fd629857d | ||
![]() |
8eff14db11 | ||
![]() |
81e26fe9b9 | ||
![]() |
9eb4583dd5 | ||
![]() |
5a23c86dc1 | ||
![]() |
ffd0525607 | ||
![]() |
3dc636bf3e | ||
![]() |
260ce4aa1d | ||
![]() |
8bc827ebf5 | ||
![]() |
a97f764088 | ||
![]() |
143b90af3e | ||
![]() |
4e0a6ae624 | ||
![]() |
0c60cfc5c0 | ||
![]() |
deb6b0e334 | ||
![]() |
27777dcd31 | ||
![]() |
bdb397e043 | ||
![]() |
cb4d851761 | ||
![]() |
17aa517e41 | ||
![]() |
7ac16f4834 | ||
![]() |
bf7fece440 | ||
![]() |
c04ef9efe5 | ||
![]() |
b774c07d19 | ||
![]() |
229467cb29 | ||
![]() |
949b472f7e | ||
![]() |
be67d3e362 | ||
![]() |
2c1a1fd4f8 | ||
![]() |
3e2ae7cc78 | ||
![]() |
505660e1fa | ||
![]() |
09d90e1231 | ||
![]() |
5a9f89ae1f | ||
![]() |
6f56345dd8 | ||
![]() |
edef040688 | ||
![]() |
9fc196e750 | ||
![]() |
dc1698eaf4 | ||
![]() |
53ded063a0 | ||
![]() |
8a2c50c374 | ||
![]() |
f71148f3a6 | ||
![]() |
172105828c | ||
![]() |
6cca6cb20d | ||
![]() |
b7336f817c | ||
![]() |
88356b79be | ||
![]() |
ce9e543882 | ||
![]() |
3ff3ba83f4 | ||
![]() |
edb525a030 | ||
![]() |
ea5314f076 | ||
![]() |
be8e53163b | ||
![]() |
79151f517f | ||
![]() |
e8ffe7ef96 | ||
![]() |
b5a7b5e277 | ||
![]() |
85b5e1088f | ||
![]() |
680ddb1557 | ||
![]() |
44fff522bd | ||
![]() |
90815f0d27 | ||
![]() |
f07950c60a | ||
![]() |
f8c4125892 | ||
![]() |
1f30cc203a | ||
![]() |
764bfdcb9f | ||
![]() |
f290814f64 | ||
![]() |
3a2508545d | ||
![]() |
79a06a338a | ||
![]() |
509f27eee1 | ||
![]() |
e511c32a36 | ||
![]() |
b463d9b687 | ||
![]() |
e96e20ccfd | ||
![]() |
06ebdbfd37 | ||
![]() |
df9fd047b4 | ||
![]() |
85d65c59d2 | ||
![]() |
754126644f | ||
![]() |
220436f4f9 | ||
![]() |
b62a6ae1d0 | ||
![]() |
eae0532b8c | ||
![]() |
d642487f99 | ||
![]() |
320510506b | ||
![]() |
b2839ac78b | ||
![]() |
834d5a0e72 | ||
![]() |
13ce808c47 | ||
![]() |
980a6529c1 | ||
![]() |
c92384fe68 | ||
![]() |
9f563f87b9 | ||
![]() |
44f37b8d1b | ||
![]() |
5f41c1cf3f | ||
![]() |
2a664b9ae6 | ||
![]() |
5456814199 | ||
![]() |
33ceaeb208 | ||
![]() |
b33e60b3ae | ||
![]() |
9dd0a6eb86 | ||
![]() |
ed6faf4e65 | ||
![]() |
df2ee5de49 | ||
![]() |
36fef91a67 | ||
![]() |
3399148d75 | ||
![]() |
0eea92de66 | ||
![]() |
92975bb21d | ||
![]() |
bf18e04134 | ||
![]() |
4a0d7f18fd | ||
![]() |
65c360a2ca | ||
![]() |
71919f7523 | ||
![]() |
31a49db68b | ||
![]() |
0d615442ba | ||
![]() |
8f35dbc306 | ||
![]() |
154bcbc4f7 | ||
![]() |
c96a39d315 | ||
![]() |
06ba74c366 | ||
![]() |
8786a8e6e0 | ||
![]() |
748236fef0 | ||
![]() |
ae1b06f20b | ||
![]() |
b8aa93ce30 | ||
![]() |
49d40a42f1 | ||
![]() |
1845f34b81 | ||
![]() |
43903d446a | ||
![]() |
256da2124b | ||
![]() |
7869e96bac | ||
![]() |
79b51a6e4b | ||
![]() |
cad9f6d46e | ||
![]() |
da2960880a | ||
![]() |
0eacc58e29 | ||
![]() |
3bec736aee | ||
![]() |
3241ffd1b4 | ||
![]() |
d0d7b266bc | ||
![]() |
c24948258b | ||
![]() |
d36666bd98 | ||
![]() |
2794b1d310 | ||
![]() |
f456fa03da | ||
![]() |
356b7b43f8 | ||
![]() |
92718e2140 | ||
![]() |
4021160a64 | ||
![]() |
6f043e3326 | ||
![]() |
74b0b1da21 | ||
![]() |
3a5f676687 | ||
![]() |
4fa7cffc37 | ||
![]() |
79b83e78a5 | ||
![]() |
048a3835e7 | ||
![]() |
4a4891036a | ||
![]() |
ff00c83f15 | ||
![]() |
79d31b7452 | ||
![]() |
20cc6f7463 | ||
![]() |
8acabaa135 | ||
![]() |
ba7183a5b4 | ||
![]() |
28f4338a6c | ||
![]() |
800a93a859 | ||
![]() |
2e969e3a0a | ||
![]() |
3fb31f651d | ||
![]() |
682d25b551 | ||
![]() |
bcad8d4c4c | ||
![]() |
96bab8e02e | ||
![]() |
fa4a615d0f | ||
![]() |
f1265c4fed | ||
![]() |
df01cd9a09 | ||
![]() |
255bac642d | ||
![]() |
6d8c3bd13d | ||
![]() |
75b8272710 | ||
![]() |
2f80e154f2 | ||
![]() |
cc0114c482 | ||
![]() |
e5e2b9095c | ||
![]() |
6977edc032 | ||
![]() |
177cc55ee5 | ||
![]() |
feb7ec03ba | ||
![]() |
6630a643d3 | ||
![]() |
d70e64a434 | ||
![]() |
896ad51102 | ||
![]() |
be6d6560a7 | ||
![]() |
709d0cc33e | ||
![]() |
bd73742552 | ||
![]() |
ed4518e09a | ||
![]() |
6c8301eae8 | ||
![]() |
6e30d504e3 | ||
![]() |
cee09a0261 | ||
![]() |
76a72558b3 | ||
![]() |
22124a33ce | ||
![]() |
3731373de1 | ||
![]() |
bbaf8c2f67 | ||
![]() |
f50694cc96 | ||
![]() |
4930ea7dab | ||
![]() |
96bb4cf49d | ||
![]() |
5e7563ac5b | ||
![]() |
f199b80453 | ||
![]() |
5de8eec206 | ||
![]() |
076bd07f39 | ||
![]() |
00e897503b | ||
![]() |
2f3c47f385 | ||
![]() |
2b28211701 | ||
![]() |
46c794fc2e | ||
![]() |
0408738b48 | ||
![]() |
6cfea98501 | ||
![]() |
33498d3673 | ||
![]() |
ed3ead06fe | ||
![]() |
eb8a338a0e | ||
![]() |
23480bfe8a | ||
![]() |
3384dbc92d | ||
![]() |
8446549ed8 | ||
![]() |
6a9f3ae71d | ||
![]() |
94e5b0d78f | ||
![]() |
0812eb1c04 | ||
![]() |
8cb5ccad99 | ||
![]() |
743d69ec0b | ||
![]() |
f6de4c9479 | ||
![]() |
fb59927d32 | ||
![]() |
c58ce1a975 | ||
![]() |
c6d9bbd7b0 | ||
![]() |
08974f00ed | ||
![]() |
60643f023f | ||
![]() |
65ddd1a455 | ||
![]() |
68a98d3dd0 | ||
![]() |
ca9015452e | ||
![]() |
05ac2603e6 | ||
![]() |
8e923777b8 | ||
![]() |
8949551c2e | ||
![]() |
0b45e9442b | ||
![]() |
1d1a9d7933 | ||
![]() |
58c0fe0f91 | ||
![]() |
b96b62f2ac | ||
![]() |
43fc0a52a6 | ||
![]() |
4f3d9a1ded | ||
![]() |
b50ff920f0 | ||
![]() |
983ae0c5a2 | ||
![]() |
9d4db84987 | ||
![]() |
1f372cf0cc | ||
![]() |
c43d597aa9 | ||
![]() |
dfaa281476 | ||
![]() |
df14629a25 | ||
![]() |
c1c25c455c | ||
![]() |
e65197f386 | ||
![]() |
ecbb8f8711 | ||
![]() |
03aa736199 | ||
![]() |
821b1f0384 | ||
![]() |
233ad3aaff | ||
![]() |
9c4812f4d4 | ||
![]() |
337cc9fa78 | ||
![]() |
dfe29a0329 | ||
![]() |
85e90aa81e | ||
![]() |
86d30fe571 | ||
![]() |
173302267f | ||
![]() |
8e3ea8d26c | ||
![]() |
cb065563c2 | ||
![]() |
27b89b237b | ||
![]() |
21f0d0bfc4 | ||
![]() |
d5e583b09e | ||
![]() |
15fb9bbcb2 | ||
![]() |
a03418ab12 | ||
![]() |
035513844d | ||
![]() |
193906b8ce | ||
![]() |
d354f2e8c2 | ||
![]() |
24a8ee436f | ||
![]() |
6e5f9404b7 | ||
![]() |
64fe90aabb | ||
![]() |
7e31d487e0 | ||
![]() |
ee16e2eb30 | ||
![]() |
003fb3392f | ||
![]() |
0e82278cd5 | ||
![]() |
5b544248bc | ||
![]() |
d4d7495c0a | ||
![]() |
8325cce44c | ||
![]() |
ee0debc5b3 | ||
![]() |
8f1bd12a17 | ||
![]() |
fccf1016e4 | ||
![]() |
1b010a082b | ||
![]() |
324f215316 | ||
![]() |
ace4f1e7f0 | ||
![]() |
5c5f16f148 | ||
![]() |
f50855d5c0 | ||
![]() |
86917b0ba7 | ||
![]() |
7201fcbe0f | ||
![]() |
83f1735fbb | ||
![]() |
80fd8e70f0 | ||
![]() |
698c1c2b7a | ||
![]() |
5d3287f5aa | ||
![]() |
6990fe6f51 | ||
![]() |
0b81068368 | ||
![]() |
5b1851ae22 | ||
![]() |
0d5708a01d | ||
![]() |
67ab510b5d | ||
![]() |
d1264a1289 | ||
![]() |
3b973021a1 | ||
![]() |
182624895f | ||
![]() |
548de3739c | ||
![]() |
718a3efd64 | ||
![]() |
76b8c3250b | ||
![]() |
dafaa8bd8c | ||
![]() |
9c9b2c25ea | ||
![]() |
e89cd81022 | ||
![]() |
5debbd2be8 | ||
![]() |
fe26df5355 | ||
![]() |
85778494e4 | ||
![]() |
a94ce3c715 | ||
![]() |
a440ff1117 | ||
![]() |
8195137bc5 | ||
![]() |
3e2bd25e4e | ||
![]() |
ffd0c2f624 | ||
![]() |
23333c98d7 | ||
![]() |
5a12ab98c4 | ||
![]() |
0b327a63fc | ||
![]() |
15b28a245c | ||
![]() |
6ef5684797 | ||
![]() |
d439b1495b | ||
![]() |
9e096a3f0e | ||
![]() |
0acf6ec150 | ||
![]() |
4b36340474 | ||
![]() |
910e642a8b | ||
![]() |
9f571146fb | ||
![]() |
339725f73d | ||
![]() |
aff964c58b | ||
![]() |
0c07e745f8 | ||
![]() |
419d2e9564 | ||
![]() |
f936a307c6 | ||
![]() |
4e4678edfa | ||
![]() |
cb7a4b3116 | ||
![]() |
5ca4c42a74 | ||
![]() |
1238a7ca07 | ||
![]() |
a9db60a73d | ||
![]() |
bd32ac19d4 | ||
![]() |
eaf9944e43 | ||
![]() |
703fdbc01d | ||
![]() |
2daa08b0e7 | ||
![]() |
05d9d22d9e | ||
![]() |
8b7894f9bd | ||
![]() |
a71439607f | ||
![]() |
aca0d7f969 | ||
![]() |
310a8e4342 | ||
![]() |
24fbe1ef5b | ||
![]() |
33d8faa35d | ||
![]() |
44be714f65 | ||
![]() |
0df3da6b10 | ||
![]() |
79197b6ec7 | ||
![]() |
353b6b51cb | ||
![]() |
bd9a2c0d3a | ||
![]() |
53b0ee6536 | ||
![]() |
78daac0f1b | ||
![]() |
b970b9b9a8 | ||
![]() |
0339db57f1 | ||
![]() |
461b147897 | ||
![]() |
a3cd13b399 | ||
![]() |
eb5d326a1e | ||
![]() |
cce6eb94e2 | ||
![]() |
8311c72c69 | ||
![]() |
9a059285d9 | ||
![]() |
469ac7891d | ||
![]() |
16264a5693 | ||
![]() |
6eedb50f56 | ||
![]() |
5f07215662 | ||
![]() |
d3a02fb2ca | ||
![]() |
2c823f1aaa | ||
![]() |
706293aadc | ||
![]() |
dfdceb4258 | ||
![]() |
0014b7fdb9 | ||
![]() |
3b28f1f8af | ||
![]() |
c689d476ca | ||
![]() |
cc534fd21f | ||
![]() |
124efcf247 | ||
![]() |
dd452b05e3 | ||
![]() |
b5617f7df9 | ||
![]() |
b73ca1ba3a | ||
![]() |
39ad071c4f | ||
![]() |
fa0b576a45 | ||
![]() |
c2c7591987 | ||
![]() |
3e939e3775 | ||
![]() |
f6384e10bc | ||
![]() |
c283842563 | ||
![]() |
1135976225 | ||
![]() |
76679d33df | ||
![]() |
e9d44b90bc | ||
![]() |
8a7a391166 | ||
![]() |
d6c5a9eece | ||
![]() |
56ad6915d0 | ||
![]() |
466c260782 | ||
![]() |
d8e2d1725a | ||
![]() |
33b43d03ac | ||
![]() |
517509db6e | ||
![]() |
95f01a5976 | ||
![]() |
d08d3bf56d | ||
![]() |
587fd669e8 | ||
![]() |
e3553b87fe | ||
![]() |
a078d2360c | ||
![]() |
2d3abf8e6e | ||
![]() |
cacae0fb7d | ||
![]() |
d7fc215c16 | ||
![]() |
bb69aa18f2 | ||
![]() |
e4f515166a | ||
![]() |
f325acb0ea | ||
![]() |
d1b6e65dd8 | ||
![]() |
4688252bd4 | ||
![]() |
b1df5d3ad7 | ||
![]() |
09bad2938e | ||
![]() |
bad69fd397 | ||
![]() |
b4ae6bf82c | ||
![]() |
eac0f83864 | ||
![]() |
3f16f080ac | ||
![]() |
5de2b974fb | ||
![]() |
6a9cb51828 | ||
![]() |
f1c294ca50 | ||
![]() |
c320e44a23 | ||
![]() |
ea36ef3107 | ||
![]() |
fedc37d079 | ||
![]() |
86ccfcc03c | ||
![]() |
bc8d8ab65a | ||
![]() |
a7a23d3bc8 | ||
![]() |
82d33944e6 | ||
![]() |
8a629ad6fb | ||
![]() |
e1711ffcf2 | ||
![]() |
063d51c662 | ||
![]() |
d8e3575a46 | ||
![]() |
6fa609be3f | ||
![]() |
70982e204c | ||
![]() |
2af7df5865 | ||
![]() |
59610e81de | ||
![]() |
cdfac703ef | ||
![]() |
ad5ebd007e | ||
![]() |
1bd347d997 | ||
![]() |
147056073d | ||
![]() |
1b3231e617 | ||
![]() |
7ac4ad3e38 | ||
![]() |
0a345cb12b | ||
![]() |
19ff0dd17f | ||
![]() |
e3bf8a404b | ||
![]() |
dbb28d9a8f | ||
![]() |
19fd4e755c | ||
![]() |
77698cd924 | ||
![]() |
945d279f28 | ||
![]() |
645d296841 | ||
![]() |
57446de875 | ||
![]() |
3473800ab6 | ||
![]() |
7e5c5153a8 | ||
![]() |
1b8979f285 | ||
![]() |
2aac51dd20 | ||
![]() |
69e32d264c | ||
![]() |
71ae75a5bf | ||
![]() |
86043fd87e | ||
![]() |
d8aaef4f04 | ||
![]() |
7fc34b6369 | ||
![]() |
92b346efa7 | ||
![]() |
c790735b9f | ||
![]() |
64711e615e | ||
![]() |
2065affd45 | ||
![]() |
4067c56b5d | ||
![]() |
65515638aa | ||
![]() |
371ba3ffe3 | ||
![]() |
5395b62f2f | ||
![]() |
3e164eab26 | ||
![]() |
ad85533975 | ||
![]() |
d6c2a97931 | ||
![]() |
17def94ba4 | ||
![]() |
cf254ea240 | ||
![]() |
2d05110239 | ||
![]() |
0017f4fce8 | ||
![]() |
02f3dd947a | ||
![]() |
ef0874feba | ||
![]() |
14aa1420f0 | ||
![]() |
c506cd97e0 | ||
![]() |
3761aacb1d | ||
![]() |
233f13aac5 | ||
![]() |
0ced3ec2d2 | ||
![]() |
5b786f65a4 | ||
![]() |
770542c8c7 | ||
![]() |
4f1207a38c | ||
![]() |
2b65f81e23 | ||
![]() |
c10eb2c17b | ||
![]() |
3f5ac54bf5 | ||
![]() |
790f9409b1 | ||
![]() |
a3d831b723 | ||
![]() |
b9483deea3 | ||
![]() |
c211d2ac45 | ||
![]() |
119a03dd5f | ||
![]() |
f3fbb7e1f6 | ||
![]() |
2be98e8467 | ||
![]() |
91b1806e9d | ||
![]() |
8548b3645a | ||
![]() |
4bbfb3f9a3 | ||
![]() |
98eec72522 | ||
![]() |
562d50df4d | ||
![]() |
f3ee5ab372 | ||
![]() |
aa2a3e5b07 | ||
![]() |
8467307239 | ||
![]() |
90da951a6f | ||
![]() |
59f81b331c | ||
![]() |
77a7d3d26a | ||
![]() |
4321b80999 | ||
![]() |
4b93b06323 | ||
![]() |
96fb2e4b7c | ||
![]() |
3dc1048dfb | ||
![]() |
28f4bd5a67 | ||
![]() |
b01c270889 | ||
![]() |
7c92f8a90b | ||
![]() |
a4a04872a3 | ||
![]() |
f2d13cd647 | ||
![]() |
9346908485 | ||
![]() |
b3a7ba14f7 | ||
![]() |
524ef9553c | ||
![]() |
a85f6e72fe | ||
![]() |
1ae6a41336 | ||
![]() |
3ec55791c6 | ||
![]() |
a3accd28ea | ||
![]() |
fc5bc84207 | ||
![]() |
d8b4051d6d | ||
![]() |
804a1cc22d | ||
![]() |
cdd60e5f9c | ||
![]() |
7c76f07384 | ||
![]() |
a3b1ef9527 | ||
![]() |
0bd4150a80 | ||
![]() |
7f7f5253f2 | ||
![]() |
2a0a847634 | ||
![]() |
92ddb37ed3 | ||
![]() |
01f944e6bd | ||
![]() |
732c8d7350 | ||
![]() |
21678aeef5 | ||
![]() |
cda1ca35a4 | ||
![]() |
923580d2cd | ||
![]() |
190af1d32b | ||
![]() |
bffe0443f9 | ||
![]() |
29e99e229b | ||
![]() |
2736b88dd5 | ||
![]() |
e739c60e9f | ||
![]() |
1c0afbc5c5 | ||
![]() |
ee1ba5c0f2 | ||
![]() |
02342ba540 | ||
![]() |
12a130e9bc | ||
![]() |
dfb97e7961 | ||
![]() |
54e03a62bd | ||
![]() |
ec9659ff25 | ||
![]() |
0a41b253f3 | ||
![]() |
002b86198c | ||
![]() |
7161a235f1 | ||
![]() |
391034a785 | ||
![]() |
446a7fbd67 | ||
![]() |
2ccb09434f | ||
![]() |
7974060a40 | ||
![]() |
e8abcc1765 | ||
![]() |
1be1927a1f | ||
![]() |
894ff71664 | ||
![]() |
93bed9c5df | ||
![]() |
34c008adce | ||
![]() |
22ddd91b1f | ||
![]() |
e121f34407 | ||
![]() |
df8a3e870a | ||
![]() |
13b6708a09 | ||
![]() |
6aa196cf55 | ||
![]() |
142493076a | ||
![]() |
3d905a7a4f | ||
![]() |
0a8a6ed168 | ||
![]() |
68b6fa46e6 | ||
![]() |
80f7c54e4d | ||
![]() |
c0e2041006 | ||
![]() |
f6d2cd7704 | ||
![]() |
6d9a629b15 | ||
![]() |
ead8edc7cd | ||
![]() |
664eefdddb | ||
![]() |
220d76c974 | ||
![]() |
d973192b5e | ||
![]() |
978bb5059f | ||
![]() |
f59178bc33 | ||
![]() |
53899cc492 | ||
![]() |
6379d0fe0f | ||
![]() |
a1c4d8696a | ||
![]() |
7f42ed86f2 | ||
![]() |
6bb8b4c994 | ||
![]() |
afefbe4e56 | ||
![]() |
5cd37e5505 | ||
![]() |
d6a825981d | ||
![]() |
a1c01c6722 | ||
![]() |
8d182f1d79 | ||
![]() |
29707bd2ea | ||
![]() |
c2bf2a8174 | ||
![]() |
b402849557 | ||
![]() |
cb85dcfcb8 | ||
![]() |
49379140c7 | ||
![]() |
63f6c86b46 | ||
![]() |
1865898cd4 | ||
![]() |
8935ecfdb8 | ||
![]() |
4902bed409 | ||
![]() |
e6f6aba207 | ||
![]() |
bab622de25 | ||
![]() |
a86c1624a7 | ||
![]() |
c707392a5a | ||
![]() |
1f07721ec4 | ||
![]() |
4767e45035 | ||
![]() |
f2a64ed685 | ||
![]() |
2c9966a0a3 | ||
![]() |
953aa95c64 | ||
![]() |
446266776e | ||
![]() |
845af014dc | ||
![]() |
7c8f8703a1 | ||
![]() |
a0c18e4380 | ||
![]() |
e8d8099563 | ||
![]() |
2c9d90d463 | ||
![]() |
130d2064d5 | ||
![]() |
a10eb2a0d7 | ||
![]() |
b71cc5d7ee | ||
![]() |
8512f9eda1 | ||
![]() |
80058083b8 | ||
![]() |
d5a17a3c25 | ||
![]() |
eab7c87781 | ||
![]() |
d2962d8676 | ||
![]() |
5e602fb575 | ||
![]() |
599964ea5f | ||
![]() |
562de7926b | ||
![]() |
8eaed95e02 | ||
![]() |
3cffd46008 | ||
![]() |
e239bfda8a | ||
![]() |
bd887b660d | ||
![]() |
7c1e0ea95d | ||
![]() |
afbddbfcda | ||
![]() |
9eeb702ca5 | ||
![]() |
4cb6d6995f | ||
![]() |
fe7e7a8d07 | ||
![]() |
f8ee79ab72 | ||
![]() |
a11165830b | ||
![]() |
11cde61eab | ||
![]() |
cd862409cc | ||
![]() |
7644555d6b | ||
![]() |
07e68aa694 | ||
![]() |
0ae206b1bb | ||
![]() |
5bdac96375 | ||
![]() |
f0e044ecd8 | ||
![]() |
f32234291e | ||
![]() |
83acd6529f | ||
![]() |
6a60cb4dc0 | ||
![]() |
1de03fbe18 | ||
![]() |
0e0a2aa981 | ||
![]() |
af73b9d11b | ||
![]() |
859969241a | ||
![]() |
6852a8ca9d | ||
![]() |
c694f1a4a9 | ||
![]() |
d36543b204 | ||
![]() |
6981234736 | ||
![]() |
10bf3ee9de | ||
![]() |
9953218de1 | ||
![]() |
50c74103aa | ||
![]() |
c5e15123fd | ||
![]() |
4adcdb5ba8 | ||
![]() |
60b36ffaa3 | ||
![]() |
d86104ed5d | ||
![]() |
0f02ef20a9 | ||
![]() |
0768cf17b6 | ||
![]() |
197205853f | ||
![]() |
bebcc24ab8 | ||
![]() |
987248ccbb | ||
![]() |
56ece4db0f | ||
![]() |
c7f8b94ccd | ||
![]() |
95b820305a | ||
![]() |
599b200ca5 | ||
![]() |
a9566b31be | ||
![]() |
f30837d726 | ||
![]() |
1242ffa4c6 | ||
![]() |
37c0347c47 | ||
![]() |
65befb84a0 | ||
![]() |
a41f7ce3bd | ||
![]() |
81ced6bf2a | ||
![]() |
fa8033f998 | ||
![]() |
19e3178d0c | ||
![]() |
1e6262f24f | ||
![]() |
beb2284440 | ||
![]() |
0c4f0de13d | ||
![]() |
0cd31a4b96 | ||
![]() |
ef0a86e7cc | ||
![]() |
b79c1345b9 | ||
![]() |
5bb8b6f16c | ||
![]() |
f6f675d1e1 | ||
![]() |
9f684e7670 | ||
![]() |
a998706452 | ||
![]() |
5e19bc6f84 | ||
![]() |
169f287970 | ||
![]() |
c56926428c | ||
![]() |
43eab5c4e5 | ||
![]() |
c6424c2ce7 | ||
![]() |
dfe19d308c | ||
![]() |
b75db110dc | ||
![]() |
9e50ba6ec6 | ||
![]() |
aca2ba13c2 | ||
![]() |
c5afe7a573 | ||
![]() |
8b90968cb1 | ||
![]() |
9281dba896 | ||
![]() |
c7555f1c3c | ||
![]() |
e781831032 | ||
![]() |
8025895168 | ||
![]() |
799935e44c | ||
![]() |
209d8d058c | ||
![]() |
0368a70dd7 | ||
![]() |
c3603426de | ||
![]() |
80db9971b5 | ||
![]() |
e3e771708e | ||
![]() |
b9bca2a19f | ||
![]() |
ffae70a99a | ||
![]() |
10ec1e48b0 | ||
![]() |
84123f5445 | ||
![]() |
25531d8393 | ||
![]() |
adfadc542a | ||
![]() |
7682e1cb57 | ||
![]() |
1fe4109a42 | ||
![]() |
b97baf4d47 | ||
![]() |
f91728561f | ||
![]() |
2b75d54ce1 | ||
![]() |
cdc09a7d30 | ||
![]() |
4cc6c3e535 | ||
![]() |
8f43e033a4 | ||
![]() |
918dbd1926 | ||
![]() |
8fc86ce7fa | ||
![]() |
bf0cb40586 | ||
![]() |
a62aefe74b | ||
![]() |
138d232149 | ||
![]() |
8fa64e3ab2 | ||
![]() |
8d0d2bd3fc | ||
![]() |
2146f5f623 | ||
![]() |
623df23570 | ||
![]() |
4a15d8b6d2 | ||
![]() |
af83a62474 | ||
![]() |
a0705a6c67 | ||
![]() |
712b8eec3d | ||
![]() |
558e9c21ed | ||
![]() |
23a7137e6a | ||
![]() |
71a1cb0184 | ||
![]() |
09b47cc536 | ||
![]() |
b5c78de2dd | ||
![]() |
a1bd14e516 | ||
![]() |
9684c8664f | ||
![]() |
3c75361e5a | ||
![]() |
c44c9ab74d | ||
![]() |
8cc9c871b7 | ||
![]() |
31d211cded | ||
![]() |
c42cba1d54 | ||
![]() |
c87f7cb9ac | ||
![]() |
421bee3871 | ||
![]() |
2c7573a032 | ||
![]() |
fe2a0f5089 | ||
![]() |
59ba8dec4e | ||
![]() |
ff0e1bbbc0 | ||
![]() |
18c712cd99 | ||
![]() |
8de1f764fd | ||
![]() |
a91c1ec6d9 | ||
![]() |
c8e351b31e | ||
![]() |
b4c98584db | ||
![]() |
1d17836b7d | ||
![]() |
193a739749 | ||
![]() |
48da2b8353 | ||
![]() |
40dc9de6c9 | ||
![]() |
d7469e4694 | ||
![]() |
fdfabc9f88 | ||
![]() |
5658ca5b90 | ||
![]() |
8b79e6d3c7 | ||
![]() |
8c67087a15 | ||
![]() |
057f73a73e | ||
![]() |
d3bb37d113 | ||
![]() |
6c91b862c9 | ||
![]() |
cba47b635a | ||
![]() |
cd83388f8b | ||
![]() |
02ae247536 | ||
![]() |
1621a68191 | ||
![]() |
2aef495d62 | ||
![]() |
227c168b65 | ||
![]() |
dcbcf5842f | ||
![]() |
8a3ac6d9bd | ||
![]() |
6cabad19d5 | ||
![]() |
dad7a03d19 | ||
![]() |
7b152640d9 | ||
![]() |
78fddff34e | ||
![]() |
78f542f6c0 | ||
![]() |
f8a016edb5 | ||
![]() |
f5453d38ec | ||
![]() |
331bf0af21 | ||
![]() |
9ac69337e8 | ||
![]() |
ca0c844f32 | ||
![]() |
e629e8784f | ||
![]() |
e944c1ee93 | ||
![]() |
02c882bda3 | ||
![]() |
2c29377abf | ||
![]() |
21992f1b9e | ||
![]() |
8a3f090684 | ||
![]() |
a4258505a9 | ||
![]() |
ba4a971bfa | ||
![]() |
6abc120279 | ||
![]() |
64c36b7a8f | ||
![]() |
64b9f0762c | ||
![]() |
e799082e5c | ||
![]() |
eab66a022e | ||
![]() |
485915c27a | ||
![]() |
45fb482ab4 | ||
![]() |
167e2475d8 | ||
![]() |
fe77251242 | ||
![]() |
0c331d2887 | ||
![]() |
39facd5dc6 | ||
![]() |
a2bd5ae638 | ||
![]() |
c57f616141 | ||
![]() |
3af10a1d00 | ||
![]() |
b3987e2402 | ||
![]() |
71dd44f430 | ||
![]() |
584462f9b9 | ||
![]() |
ff5d5d7cbc | ||
![]() |
370e92b1a6 | ||
![]() |
2469768a85 | ||
![]() |
acb8fa613e | ||
![]() |
83b4b7d83d | ||
![]() |
33a7d56042 | ||
![]() |
20de730541 | ||
![]() |
134c27c900 | ||
![]() |
123ae024c6 | ||
![]() |
34a29cd0a5 | ||
![]() |
9fffa9800a | ||
![]() |
8f7f23a0e5 | ||
![]() |
358457f49d | ||
![]() |
90e305d789 | ||
![]() |
b471e52e28 | ||
![]() |
9b5fc37399 | ||
![]() |
537322e3b5 | ||
![]() |
279121f87f | ||
![]() |
a1b2b41cdc | ||
![]() |
0cca90c21d | ||
![]() |
ad052cb510 | ||
![]() |
57f0598373 | ||
![]() |
92d192277e | ||
![]() |
2cdfbd8970 | ||
![]() |
bc0c5f0cdc | ||
![]() |
230ee3a03b | ||
![]() |
ab0bf37d30 | ||
![]() |
b1e66256ce | ||
![]() |
fd80693420 | ||
![]() |
f222f5ed9b | ||
![]() |
59603b902a | ||
![]() |
82a5dd6cf9 | ||
![]() |
a97f9081a3 | ||
![]() |
b3e0ad1303 | ||
![]() |
251090406a | ||
![]() |
9c3ed173b1 | ||
![]() |
7cd41aeb72 | ||
![]() |
8ecaf7ad4c | ||
![]() |
d4049fe593 | ||
![]() |
989b14b519 | ||
![]() |
fb3e11408c | ||
![]() |
3d3af3284e | ||
![]() |
eabcf15790 | ||
![]() |
684bca203a | ||
![]() |
d42ecccf6f | ||
![]() |
5a92c861e3 | ||
![]() |
103b14ea3c | ||
![]() |
e49f091b4e | ||
![]() |
6056f93910 | ||
![]() |
18fa2d1af4 | ||
![]() |
062ed8a4c4 | ||
![]() |
49f3872d04 | ||
![]() |
d9b467098a | ||
![]() |
7d1e51437e | ||
![]() |
f5a7d444e2 | ||
![]() |
a0071c2f9f | ||
![]() |
98a5e43883 | ||
![]() |
f40ebe5b43 | ||
![]() |
d7d78d9a2b | ||
![]() |
5a12d36a0a | ||
![]() |
e61dc76ae1 | ||
![]() |
0da22193bd | ||
![]() |
d43921823e | ||
![]() |
6b5b76b0c9 | ||
![]() |
602971408b | ||
![]() |
2f5d83f07d | ||
![]() |
81b0c316cd | ||
![]() |
6df86384ca | ||
![]() |
3fbcde4bd7 | ||
![]() |
293293c23c | ||
![]() |
47185d757e | ||
![]() |
94c3998507 | ||
![]() |
5fa589691c | ||
![]() |
26bc835c7e | ||
![]() |
fc7da17fa2 | ||
![]() |
dbebe9771b | ||
![]() |
d0af8aa9f1 | ||
![]() |
f8173e93f5 | ||
![]() |
fa6ea6848f | ||
![]() |
5982970e21 | ||
![]() |
c43e5e0c95 | ||
![]() |
b4fc79c38e | ||
![]() |
b9cb270b8f | ||
![]() |
1fe35d7efe | ||
![]() |
ec8c19b1f0 | ||
![]() |
c2525bcc05 | ||
![]() |
985c31b378 | ||
![]() |
135a9f5586 | ||
![]() |
979ff80982 | ||
![]() |
6cde9f3a9d | ||
![]() |
5cad81bf4c | ||
![]() |
18967162cf | ||
![]() |
6ea75f3a9f | ||
![]() |
f51123d009 | ||
![]() |
be6376ee2d | ||
![]() |
120a85a3e5 | ||
![]() |
262fe96c29 | ||
![]() |
1864df5ed0 | ||
![]() |
09bae0a9e8 | ||
![]() |
ebe41a24f1 | ||
![]() |
f0f574a15b | ||
![]() |
9420436c09 | ||
![]() |
2b8f853b96 | ||
![]() |
2c2bf60d0c | ||
![]() |
62b82448d5 | ||
![]() |
2f12e6c3d0 | ||
![]() |
8ce23f8e3e | ||
![]() |
dbe760d6e2 | ||
![]() |
674c26d9c7 | ||
![]() |
7b68b04efd | ||
![]() |
e0b65bf196 | ||
![]() |
77f5cb1f1f | ||
![]() |
2a222737f8 | ||
![]() |
77d48f9cee | ||
![]() |
c77eac325e | ||
![]() |
517ced2a54 | ||
![]() |
70d2c47367 | ||
![]() |
e57084f6df | ||
![]() |
8783cf8ec3 | ||
![]() |
2af7a7c6ac | ||
![]() |
91a1f8d9e1 | ||
![]() |
fc5e8ddca1 | ||
![]() |
6352472c5f | ||
![]() |
833ee6484c | ||
![]() |
dda3d24bca | ||
![]() |
f77d76a320 | ||
![]() |
c51fabf6ed | ||
![]() |
b10cb658ca | ||
![]() |
68f60568ac | ||
![]() |
9fbca83ac0 | ||
![]() |
d19bfaa2cb | ||
![]() |
53d5ddb345 | ||
![]() |
0a5c2e7ab9 | ||
![]() |
35802ba949 | ||
![]() |
72160aac9a | ||
![]() |
9df6916029 | ||
![]() |
9bfa2354ff | ||
![]() |
7d945d3c8e | ||
![]() |
05e28752f1 | ||
![]() |
01b6673528 | ||
![]() |
4e85ebbf98 | ||
![]() |
120e8bffd7 | ||
![]() |
8335823748 | ||
![]() |
c9fcf4020f | ||
![]() |
b10a736744 | ||
![]() |
60fbaf7612 | ||
![]() |
d24193630e | ||
![]() |
354af69f62 | ||
![]() |
bccac610a4 | ||
![]() |
5aa6209664 | ||
![]() |
d693d92702 | ||
![]() |
f2622e54e3 | ||
![]() |
20fe9b6dde | ||
![]() |
11f7aa4212 | ||
![]() |
f53c351fd2 | ||
![]() |
fb96617377 | ||
![]() |
05b8c00ee7 | ||
![]() |
58854fdae9 | ||
![]() |
fd31ff772f | ||
![]() |
ab8e0c9e31 | ||
![]() |
abeed3be84 | ||
![]() |
a65438c6fe | ||
![]() |
c3f43fb0cf | ||
![]() |
2807504a81 | ||
![]() |
08b716c96d | ||
![]() |
b4b1f0a2c9 | ||
![]() |
228f742b2f | ||
![]() |
a55affe4d5 | ||
![]() |
a6ec726ed7 | ||
![]() |
87835a4e60 | ||
![]() |
1f18af4395 | ||
![]() |
e79747a600 | ||
![]() |
bd36ac2c0c | ||
![]() |
c6186f2c01 | ||
![]() |
d639f57470 | ||
![]() |
99a2d28592 | ||
![]() |
254ee80c16 | ||
![]() |
e43f57fe1a | ||
![]() |
f88c029a4c | ||
![]() |
93c3cbeaef | ||
![]() |
88c77b793f | ||
![]() |
11286524a5 | ||
![]() |
7c863c341e | ||
![]() |
3416cf984e | ||
![]() |
1784746e7e | ||
![]() |
6c6df1adaf | ||
![]() |
f91e1c17c0 | ||
![]() |
58201b95f2 | ||
![]() |
fcce8f6d51 | ||
![]() |
f7bdda8828 | ||
![]() |
df5a60fd5b | ||
![]() |
5782ab7ccc | ||
![]() |
72e3f98213 | ||
![]() |
1b1433a664 | ||
![]() |
568704ed22 | ||
![]() |
05a7e4eb64 | ||
![]() |
7a0acf2838 | ||
![]() |
27787505e0 | ||
![]() |
2c8048115d | ||
![]() |
7df1780853 | ||
![]() |
d5609f3207 | ||
![]() |
cd10fbc1fe | ||
![]() |
ca0b085d15 | ||
![]() |
9a034234d8 | ||
![]() |
66ef6c9e4c | ||
![]() |
7df60b259b | ||
![]() |
34b3bbc883 | ||
![]() |
e02d20dd74 | ||
![]() |
1a11608f1f | ||
![]() |
9e2c9d7812 | ||
![]() |
404a393315 | ||
![]() |
c69092e110 | ||
![]() |
ebc0eeac79 | ||
![]() |
2b72f35c32 | ||
![]() |
d8212ad620 | ||
![]() |
1066bb38a8 |
48
.gitignore
vendored
Normal file
48
.gitignore
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# Files generated by the bootstrap script.
|
||||
/INSTALL
|
||||
/NEWS
|
||||
/README
|
||||
/ac/
|
||||
/aclocal.m4
|
||||
/autom4te.cache/
|
||||
/config.h.in
|
||||
/configure
|
||||
/msgpack_vc2008.sln
|
||||
/msgpack_vc2008.vcproj
|
||||
Makefile.in
|
||||
|
||||
# Files generated by the configure script.
|
||||
|
||||
/config.h
|
||||
/config.log
|
||||
/config.status
|
||||
/libtool
|
||||
/msgpack.pc
|
||||
/src/msgpack/version.h
|
||||
/stamp-h1
|
||||
Makefile
|
||||
.deps
|
||||
.libs
|
||||
|
||||
# Files generated by make.
|
||||
*.o
|
||||
*.so
|
||||
*.lo
|
||||
*.la
|
||||
|
||||
# Files generated by make check.
|
||||
# TODO: Replace these with something like /test/*_test
|
||||
/test/buffer
|
||||
/test/cases
|
||||
/test/convert
|
||||
/test/fixint
|
||||
/test/fixint_c
|
||||
/test/msgpack_test
|
||||
/test/msgpackc_test
|
||||
/test/object
|
||||
/test/pack_unpack
|
||||
/test/pack_unpack_c
|
||||
/test/streaming
|
||||
/test/streaming_c
|
||||
/test/version
|
||||
/test/zone
|
188
CMakeLists.txt
Normal file
188
CMakeLists.txt
Normal file
@@ -0,0 +1,188 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
|
||||
PROJECT (msgpack)
|
||||
|
||||
SET (VERSION 0.5.9)
|
||||
SET (VERSION_MAJOR 0)
|
||||
SET (VERSION_MINOR 5)
|
||||
|
||||
SET (prefix ${CMAKE_INSTALL_PREFIX})
|
||||
SET (exec_prefix "\${prefix}")
|
||||
SET (libdir "\${exec_prefix}/lib")
|
||||
SET (includedir "\${prefix}/include")
|
||||
|
||||
FIND_PACKAGE (GTest)
|
||||
FIND_PACKAGE (ZLIB)
|
||||
FIND_PACKAGE (Threads)
|
||||
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
|
||||
ENDIF ()
|
||||
|
||||
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
|
||||
|
||||
INCLUDE (CheckCXXSourceCompiles)
|
||||
CHECK_CXX_SOURCE_COMPILES ("
|
||||
#include <bits/atomicity.h>
|
||||
int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1) - 1; }
|
||||
int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1) + 1; }
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
atomic_sub(1);
|
||||
atomic_add(1);
|
||||
}
|
||||
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/object.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/gcc_atomic.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/unpack.c
|
||||
src/objectc.c
|
||||
src/version.c
|
||||
src/vrefbuffer.c
|
||||
src/zone.c
|
||||
)
|
||||
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
src/msgpack/pack_define.h
|
||||
src/msgpack/pack_template.h
|
||||
src/msgpack/unpack_define.h
|
||||
src/msgpack/unpack_template.h
|
||||
src/msgpack/sysdep.h
|
||||
src/msgpack/sbuffer.h
|
||||
src/msgpack/version.h
|
||||
src/msgpack/vrefbuffer.h
|
||||
src/msgpack/zbuffer.h
|
||||
src/msgpack/fbuffer.h
|
||||
src/msgpack/pack.h
|
||||
src/msgpack/unpack.h
|
||||
src/msgpack/object.h
|
||||
src/msgpack/zone.h
|
||||
)
|
||||
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
src/msgpack.hpp
|
||||
src/msgpack/sbuffer.hpp
|
||||
src/msgpack/vrefbuffer.hpp
|
||||
src/msgpack/zbuffer.hpp
|
||||
src/msgpack/fbuffer.hpp
|
||||
src/msgpack/pack.hpp
|
||||
src/msgpack/unpack.hpp
|
||||
src/msgpack/object.hpp
|
||||
src/msgpack/zone.hpp
|
||||
src/msgpack/type.hpp
|
||||
src/msgpack/type/bool.hpp
|
||||
src/msgpack/type/deque.hpp
|
||||
src/msgpack/type/float.hpp
|
||||
src/msgpack/type/fixint.hpp
|
||||
src/msgpack/type/int.hpp
|
||||
src/msgpack/type/list.hpp
|
||||
src/msgpack/type/map.hpp
|
||||
src/msgpack/type/nil.hpp
|
||||
src/msgpack/type/pair.hpp
|
||||
src/msgpack/type/raw.hpp
|
||||
src/msgpack/type/set.hpp
|
||||
src/msgpack/type/string.hpp
|
||||
src/msgpack/type/vector.hpp
|
||||
src/msgpack/type/tuple.hpp
|
||||
src/msgpack/type/define.hpp
|
||||
src/msgpack/type/tr1/unordered_map.hpp
|
||||
src/msgpack/type/tr1/unordered_set.hpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
EXECUTE_PROCESS (
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack
|
||||
)
|
||||
|
||||
CONFIGURE_FILE (
|
||||
src/msgpack/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/version.h
|
||||
)
|
||||
|
||||
CONFIGURE_FILE (
|
||||
msgpack.pc.in
|
||||
msgpack.pc
|
||||
@ONLY
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES (
|
||||
./
|
||||
src/
|
||||
src/msgpack/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/
|
||||
)
|
||||
|
||||
ADD_LIBRARY (msgpack SHARED
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
)
|
||||
|
||||
ADD_LIBRARY (msgpack-static STATIC
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
)
|
||||
|
||||
SET_TARGET_PROPERTIES (msgpack-static PROPERTIES OUTPUT_NAME "msgpack")
|
||||
SET_TARGET_PROPERTIES (msgpack PROPERTIES IMPORT_SUFFIX "_import.lib")
|
||||
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 3.0.0)
|
||||
|
||||
IF (MSGPACK_BUILD_TESTS)
|
||||
ENABLE_TESTING ()
|
||||
ADD_SUBDIRECTORY (test)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET msgpack APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3 -DPIC")
|
||||
SET_PROPERTY (TARGET msgpack-static APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3" )
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
INSTALL (TARGETS msgpack msgpack-static DESTINATION lib)
|
||||
INSTALL (DIRECTORY src/msgpack DESTINATION include)
|
||||
INSTALL (FILES src/msgpack.h src/msgpack.hpp DESTINATION include)
|
||||
INSTALL (FILES msgpack.pc DESTINATION lib/pkgconfig)
|
||||
|
||||
# Doxygen
|
||||
FIND_PACKAGE (Doxygen)
|
||||
IF (DOXYGEN_FOUND)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_c
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.h" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_c" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
VERBATIM
|
||||
)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_cpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C++\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
VERBATIM
|
||||
)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen
|
||||
DEPENDS doxygen_c doxygen_cpp
|
||||
)
|
||||
ENDIF ()
|
2
COPYING
2
COPYING
@@ -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.
|
||||
|
72
ChangeLog
72
ChangeLog
@@ -0,0 +1,72 @@
|
||||
2014-07-02 version 0.5.9:
|
||||
|
||||
* Support std::tr1 unordered containers by default (#51, #63, #68, #69)
|
||||
* Remove some warnings (#56)
|
||||
* Fix segmentation fault after malloc failures (#58, #59)
|
||||
* Fix alloc/dealloc mismatch (#52, #61)
|
||||
* Fix sample codes (#60, #64)
|
||||
* Support implicit conversion from integer to float/double (#54)
|
||||
* Improve documents (#45, #75, #82, #83)
|
||||
* Support CMake (#20, #87)
|
||||
* Remove Ruby dependencies in bootstrap (#86, #87)
|
||||
* Add FILE* buffer (#40)
|
||||
* Other bug fixes and refactoring: #39, #73, #77, #79, #80, #81, #84, #90
|
||||
|
||||
2013-12-23 version 0.5.8:
|
||||
|
||||
* Move to the new github repository msgpack/msgpack-c
|
||||
* Support the new deserialization specification
|
||||
* fixes the problem of unpack helpers for array and map with 32bit compilers (#37, #38)
|
||||
* Other bug fixes and refactoring: #46, #41, #36, #35, #33, #32, #30, #29, #28, #27, #26, #25, #8, #3
|
||||
* Update of documents: #23, #18, #17
|
||||
|
||||
2011-08-08 version 0.5.7:
|
||||
|
||||
* fixes compile error problem with llvm-gcc and Mac OS X Lion
|
||||
|
||||
2011-04-24 version 0.5.6:
|
||||
|
||||
* #42 fixes double-free problem on msgpack_unpacker_release_zone
|
||||
|
||||
2011-02-24 version 0.5.5:
|
||||
|
||||
* eliminates dependency of winsock2.h header
|
||||
* fixes msgpack_vc.postbuild.bat file
|
||||
* fixes some implicit cast warnings
|
||||
|
||||
2010-08-29 version 0.5.4:
|
||||
|
||||
* includes msgpack_vc2008.vcproj file in source package
|
||||
* fixes type::fix_int types
|
||||
|
||||
2010-08-27 version 0.5.3:
|
||||
|
||||
* adds type::fix_{u,}int{8,16,32,64} types
|
||||
* adds msgpack_pack_fix_{u,}int{8,16,32,64} functions
|
||||
* adds packer<Stream>::pack_fix_{u,}int{8,16,32,64} functions
|
||||
* fixes include paths
|
||||
|
||||
2010-07-14 version 0.5.2:
|
||||
|
||||
* type::raw::str(), operator==, operator!=, operator< and operator> are now const
|
||||
* generates version.h using AC_OUTPUT macro in ./configure
|
||||
|
||||
2010-07-06 version 0.5.1:
|
||||
|
||||
* Add msgpack_vrefbuffer_new and msgpack_vrefbuffer_free
|
||||
* Add msgpack_sbuffer_new and msgpack_sbuffer_free
|
||||
* Add msgpack_unpacker_next and msgpack_unpack_next
|
||||
* msgpack::unpack returns void
|
||||
* Add MSGPACK_VERSION{,_MAJOR,_MINOR} macros to check header version
|
||||
* Add msgpack_version{,_major,_minor} functions to check library version
|
||||
* ./configure supports --disable-cxx option not to build C++ API
|
||||
|
||||
2010-04-29 version 0.5.0:
|
||||
|
||||
* msgpack_object_type is changed. MSGPACK_OBJECT_NIL is now 0x00.
|
||||
* New safe streaming deserializer API.
|
||||
* Add object::object(const T&) and object::operator=(const T&)
|
||||
* Add operator==(object, const T&)
|
||||
* MSGPACK_DEFINE macro defines msgpack_object(object* obj, zone* z)
|
||||
* C++ programs doesn't need to link "msgpackc" library.
|
||||
|
||||
|
30
Makefile.am
30
Makefile.am
@@ -1,13 +1,21 @@
|
||||
if ENABLE_CXX
|
||||
SUBDIRS = c cpp
|
||||
else
|
||||
SUBDIRS = c
|
||||
endif
|
||||
SUBDIRS = src test
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
msgpack/pack_define.h \
|
||||
msgpack/pack_template.h \
|
||||
msgpack/unpack_define.h \
|
||||
msgpack/unpack_template.h \
|
||||
msgpack/sysdep.h
|
||||
DOC_FILES = \
|
||||
README.md \
|
||||
LICENSE \
|
||||
NOTICE \
|
||||
msgpack_vc8.vcproj \
|
||||
msgpack_vc8.sln \
|
||||
msgpack_vc.postbuild.bat
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(DOC_FILES) CMakeLists.txt test/CMakeLists.txt
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = msgpack.pc
|
||||
|
||||
doxygen:
|
||||
./preprocess clean
|
||||
cd src && $(MAKE) doxygen
|
||||
./preprocess
|
||||
|
||||
|
194
QUICKSTART-C.md
Normal file
194
QUICKSTART-C.md
Normal file
@@ -0,0 +1,194 @@
|
||||
# Implementation Status
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, no RPC implementation is not available.
|
||||
|
||||
# Install
|
||||
|
||||
|
||||
## Mac OS X with MacPorts
|
||||
|
||||
On Mac OS X, you can install MessagePack for C using MacPorts.
|
||||
|
||||
```
|
||||
$ sudo port install msgpack
|
||||
```
|
||||
|
||||
You might need to run `sudo port selfupdate` before installing to update the package repository.
|
||||
|
||||
You can also install via Homebrew.
|
||||
|
||||
```
|
||||
$ sudo brew install msgpack
|
||||
```
|
||||
|
||||
## FreeBSD with Ports Collection
|
||||
|
||||
On FreeBSD, you can use Ports Collection. Install [net/msgpack|http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/] package.
|
||||
|
||||
## Gentoo Linux with Portage
|
||||
|
||||
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack|http://gentoo-portage.com/dev-libs/msgpack] package.
|
||||
|
||||
## Other UNIX-like platform with ./configure
|
||||
|
||||
On the other UNIX-like platforms, download source package from [Releases|http://msgpack.org/releases/cpp/] and run `./configure && make && make install`.
|
||||
|
||||
```
|
||||
$ wget http://msgpack.org/releases/cpp/msgpack-0.5.5.tar.gz
|
||||
$ tar zxvf msgpack-0.5.5.tar.gz
|
||||
$ cd msgpack-0.5.5
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
On Windows, download source package from [here|https://sourceforge.net/projects/msgpack/files/] and extract it.
|
||||
Then open `msgpack_vc8.vcproj` file and build it using batch build. It builds libraries on `lib/` folder and header files on `include/` folder.
|
||||
|
||||
You can build using command line as follows:
|
||||
|
||||
```
|
||||
> vcbuild msgpack_vc2008.vcproj
|
||||
> dir lib % DLL files are here
|
||||
> dir include % header files are here
|
||||
```
|
||||
|
||||
## Install from git repository
|
||||
|
||||
You need to install gcc (4.1.0 or higher), autotools.
|
||||
|
||||
```
|
||||
$ git clone git@github.com:msgpack/msgpack.git
|
||||
$ cd msgpack/cpp
|
||||
$ ./bootstrap
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
# Serialization QuickStart for C
|
||||
|
||||
## First program
|
||||
|
||||
Include `msgpack.h` header and link `msgpack` library to use MessagePack on your program.
|
||||
|
||||
```c
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
/* creates buffer and serializer instance. */
|
||||
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
|
||||
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
|
||||
|
||||
/* serializes ["Hello", "MessagePack"]. */
|
||||
msgpack_pack_array(pk, 2);
|
||||
msgpack_pack_raw(pk, 5);
|
||||
msgpack_pack_raw_body(pk, "Hello", 5);
|
||||
msgpack_pack_raw(pk, 11);
|
||||
msgpack_pack_raw_body(pk, "MessagePack", 11);
|
||||
|
||||
/* deserializes it. */
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
bool success = msgpack_unpack_next(&msg, buffer->data, buffer->size, NULL);
|
||||
|
||||
/* prints the deserialized object. */
|
||||
msgpack_object obj = msg.data;
|
||||
msgpack_object_print(stdout, obj); /*=> ["Hello", "MessagePack"] */
|
||||
|
||||
/* cleaning */
|
||||
msgpack_sbuffer_free(buffer);
|
||||
msgpack_packer_free(pk);
|
||||
}
|
||||
```
|
||||
|
||||
## Simple program with a loop
|
||||
|
||||
```c
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
/* creates buffer and serializer instance. */
|
||||
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
|
||||
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
|
||||
|
||||
int j;
|
||||
|
||||
for(j = 0; j<23; j++) {
|
||||
/* NB: the buffer needs to be cleared on each iteration */
|
||||
msgpack_sbuffer_clear(buffer);
|
||||
|
||||
/* serializes ["Hello", "MessagePack"]. */
|
||||
msgpack_pack_array(pk, 3);
|
||||
msgpack_pack_raw(pk, 5);
|
||||
msgpack_pack_raw_body(pk, "Hello", 5);
|
||||
msgpack_pack_raw(pk, 11);
|
||||
msgpack_pack_raw_body(pk, "MessagePack", 11);
|
||||
msgpack_pack_int(pk, j);
|
||||
|
||||
/* deserializes it. */
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
bool success = msgpack_unpack_next(&msg, buffer->data, buffer->size, NULL);
|
||||
|
||||
/* prints the deserialized object. */
|
||||
msgpack_object obj = msg.data;
|
||||
msgpack_object_print(stdout, obj); /*=> ["Hello", "MessagePack"] */
|
||||
puts("");
|
||||
}
|
||||
|
||||
/* cleaning */
|
||||
msgpack_sbuffer_free(buffer);
|
||||
msgpack_packer_free(pk);
|
||||
}
|
||||
```
|
||||
|
||||
## Streaming feature
|
||||
|
||||
```c
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
/* serializes multiple objects using msgpack_packer. */
|
||||
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
|
||||
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
|
||||
msgpack_pack_int(pk, 1);
|
||||
msgpack_pack_int(pk, 2);
|
||||
msgpack_pack_int(pk, 3);
|
||||
|
||||
/* deserializes these objects using msgpack_unpacker. */
|
||||
msgpack_unpacker pac;
|
||||
msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
|
||||
|
||||
/* feeds the buffer. */
|
||||
msgpack_unpacker_reserve_buffer(&pac, buffer->size);
|
||||
memcpy(msgpack_unpacker_buffer(&pac), buffer->data, buffer->size);
|
||||
msgpack_unpacker_buffer_consumed(&pac, buffer->size);
|
||||
|
||||
/* now starts streaming deserialization. */
|
||||
msgpack_unpacked result;
|
||||
msgpack_unpacked_init(&result);
|
||||
|
||||
while(msgpack_unpacker_next(&pac, &result)) {
|
||||
msgpack_object_print(stdout, result.data);
|
||||
puts("");
|
||||
}
|
||||
|
||||
/* results:
|
||||
* $ gcc stream.cc -lmsgpack -o stream
|
||||
* $ ./stream
|
||||
* 1
|
||||
* 2
|
||||
* 3
|
||||
*/
|
||||
}
|
||||
```
|
159
QUICKSTART-CPP.md
Normal file
159
QUICKSTART-CPP.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# Implementation Status
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, RPC implementation is testing phase. Requires newer kernel, not running on RHEL5/CentOS5.
|
||||
|
||||
# Install
|
||||
|
||||
Same as QuickStart for C Language.
|
||||
|
||||
# Serialization QuickStart for C+\+
|
||||
|
||||
## First program
|
||||
|
||||
Include `msgpack.hpp` header and link `msgpack` library to use MessagePack on your program.
|
||||
|
||||
```cpp
|
||||
#include <msgpack.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main(void) {
|
||||
// serializes this object.
|
||||
std::vector<std::string> vec;
|
||||
vec.push_back("Hello");
|
||||
vec.push_back("MessagePack");
|
||||
|
||||
// serialize it into simple buffer.
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, vec);
|
||||
|
||||
// deserialize it.
|
||||
msgpack::unpacked msg;
|
||||
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
|
||||
|
||||
// print the deserialized object.
|
||||
msgpack::object obj = msg.get();
|
||||
std::cout << obj << std::endl; //=> ["Hello", "MessagePack"]
|
||||
|
||||
// convert it into statically typed object.
|
||||
std::vector<std::string> rvec;
|
||||
obj.convert(&rvec);
|
||||
}
|
||||
```
|
||||
|
||||
Compile it as follows:
|
||||
|
||||
```
|
||||
$ g++ hello.cc -lmsgpack -o hello
|
||||
$ ./hello
|
||||
["Hello", "MessagePack"]
|
||||
```
|
||||
|
||||
## Streaming feature
|
||||
|
||||
```cpp
|
||||
#include <msgpack.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main(void) {
|
||||
// serializes multiple objects using msgpack::packer.
|
||||
msgpack::sbuffer buffer;
|
||||
|
||||
msgpack::packer<msgpack::sbuffer> pk(&buffer);
|
||||
pk.pack(std::string("Log message ... 1"));
|
||||
pk.pack(std::string("Log message ... 2"));
|
||||
pk.pack(std::string("Log message ... 3"));
|
||||
|
||||
// deserializes these objects using msgpack::unpacker.
|
||||
msgpack::unpacker pac;
|
||||
|
||||
// feeds the buffer.
|
||||
pac.reserve_buffer(buffer.size());
|
||||
memcpy(pac.buffer(), buffer.data(), buffer.size());
|
||||
pac.buffer_consumed(buffer.size());
|
||||
|
||||
// now starts streaming deserialization.
|
||||
msgpack::unpacked result;
|
||||
while(pac.next(&result)) {
|
||||
std::cout << result.get() << std::endl;
|
||||
}
|
||||
|
||||
// results:
|
||||
// $ g++ stream.cc -lmsgpack -o stream
|
||||
// $ ./stream
|
||||
// "Log message ... 1"
|
||||
// "Log message ... 2"
|
||||
// "Log message ... 3"
|
||||
}
|
||||
```
|
||||
|
||||
### Streaming into an array or map
|
||||
|
||||
```cpp
|
||||
#include <msgpack.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main(void) {
|
||||
// serializes multiple objects into one message containing an array using msgpack::packer.
|
||||
msgpack::sbuffer buffer;
|
||||
|
||||
msgpack::packer<msgpack::sbuffer> pk(&buffer);
|
||||
pk.pack_array(3);
|
||||
pk.pack(std::string("Log message ... 1"));
|
||||
pk.pack(std::string("Log message ... 2"));
|
||||
pk.pack(std::string("Log message ... 3"));
|
||||
|
||||
// serializes multiple objects into one message containing a map using msgpack::packer.
|
||||
msgpack::sbuffer buffer2;
|
||||
|
||||
msgpack::packer<msgpack::sbuffer> pk2(&buffer2);
|
||||
pk2.pack_map(2);
|
||||
pk2.pack(std::string("x"));
|
||||
pk2.pack(3);
|
||||
pk2.pack(std::string("y"));
|
||||
pk2.pack(3.4321);
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## User-defined classes
|
||||
|
||||
You can use serialize/deserializes user-defined classes using `MSGPACK_DEFINE` macro.
|
||||
|
||||
```cpp
|
||||
#include <msgpack.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class myclass {
|
||||
private:
|
||||
std::string m_str;
|
||||
std::vector<int> m_vec;
|
||||
public:
|
||||
MSGPACK_DEFINE(m_str, m_vec);
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
std::vector<myclass> vec;
|
||||
// add some elements into vec...
|
||||
|
||||
// you can serialize myclass directly
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, vec);
|
||||
|
||||
msgpack::unpacked msg;
|
||||
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
|
||||
|
||||
msgpack::object obj = msg.get();
|
||||
|
||||
// you can convert object to myclass directly
|
||||
std::vector<myclass> rvec;
|
||||
obj.convert(&rvec);
|
||||
}
|
||||
```
|
70
README
70
README
@@ -1,70 +0,0 @@
|
||||
MessagePack
|
||||
-----------
|
||||
Binary-based efficient data interchange format.
|
||||
|
||||
|
||||
*Requirements
|
||||
|
||||
MessagePack is only tested on Linux and Mac OS X, but it may run on other
|
||||
UNIX-like platforms.
|
||||
|
||||
gcc >= 4.1 is required to build.
|
||||
|
||||
|
||||
*Installation
|
||||
|
||||
Simply run ./configure && make && make install to install C and C++ binding.
|
||||
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
To install Ruby binding, run ./gengem.sh script on ruby/ directory and install
|
||||
generated gem package.
|
||||
|
||||
$ cd ruby
|
||||
$ ./gengem.sh
|
||||
$ gem install gem/pkg/msgpack-*.gem
|
||||
|
||||
|
||||
*Usage
|
||||
|
||||
C++:
|
||||
include msgpack.hpp header and link libmsgpack library.
|
||||
see example/simple.cc for example.
|
||||
|
||||
g++ simple.cc -lmsgpack
|
||||
g++ stream.cc -lmsgpack -lpthread
|
||||
|
||||
|
||||
C:
|
||||
include msgpack.h header and link libmsgpackc library.
|
||||
see example/simple.c for example.
|
||||
|
||||
gcc simple.c -lmsgpackc
|
||||
|
||||
|
||||
Ruby:
|
||||
require msgpack library.
|
||||
see example/simple.rb for example.
|
||||
|
||||
ruby -rubygems simple.rb
|
||||
|
||||
|
||||
API Document is available at http://msgpack.sourceforge.jp/.
|
||||
|
||||
|
||||
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.
|
||||
|
159
README.md
Normal file
159
README.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# Msgpack for C/C++
|
||||
|
||||
It's like JSON but small and fast.
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Msgpack is Copyright (C) 2008-2010 FURUHASHI Sadayuki and licensed under the Apache License, Version 2.0 (the "License"). For details see the `COPYING` file in this directory.
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
The source for msgpack-c is held at [msgpack-c](https://github.com/msgpack/msgpack-c) github.com site.
|
||||
|
||||
To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack/msgpack-c/issues) at github.com.
|
||||
|
||||
|
||||
## Using Msgpack
|
||||
|
||||
### Building and Installing
|
||||
|
||||
#### Install from git repository
|
||||
|
||||
##### Using autotools
|
||||
You will need gcc (4.1.0 or higher), autotools.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ ./bootstrap
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
##### Using cmake
|
||||
You will need gcc (4.1.0 or higher), cmake.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ cmake .
|
||||
$ make
|
||||
```
|
||||
|
||||
#### Install from package
|
||||
|
||||
##### UNIX-like platform with ./configure
|
||||
|
||||
On typical UNIX-like platforms, download source package from [Releases](https://github.com/msgpack/msgpack-c/releases) and run `./configure && make && make install`. Example:
|
||||
|
||||
```
|
||||
$ wget https://github.com/msgpack/msgpack-c/releases/download/cpp-0.5.9/msgpack-0.5.9.tar.gz
|
||||
$ tar zxvf msgpack-0.5.9.tar.gz
|
||||
$ cd msgpack-0.5.9
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
##### FreeBSD with Ports Collection
|
||||
|
||||
On FreeBSD, you can use Ports Collection. Install [net/msgpack](http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/) package.
|
||||
|
||||
##### Gentoo Linux with Portage
|
||||
|
||||
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack](http://gentoo-portage.com/dev-libs/msgpack) package.
|
||||
|
||||
##### Mac OS X with MacPorts
|
||||
|
||||
On Mac OS X, you can install MessagePack for C using MacPorts.
|
||||
|
||||
```
|
||||
$ sudo port install msgpack
|
||||
```
|
||||
|
||||
You might need to run `sudo port selfupdate` before installing to update the package repository.
|
||||
|
||||
You can also install via Homebrew.
|
||||
|
||||
```
|
||||
$ sudo brew install msgpack
|
||||
```
|
||||
|
||||
|
||||
##### Windows
|
||||
|
||||
Clone msgpack-c git repository.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
```
|
||||
|
||||
or using GUI git client.
|
||||
|
||||
e.g.) tortoise git https://code.google.com/p/tortoisegit/
|
||||
|
||||
Launch cmake GUI client. http://www.cmake.org/cmake/resources/software.html
|
||||
|
||||
Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.
|
||||
|
||||
Click 'Configure' button.
|
||||
|
||||
Choose your Visual Studio version.
|
||||
|
||||
Click 'Generate' button.
|
||||
|
||||
Open the created msgpack.sln on Visual Studio.
|
||||
|
||||
Build all.
|
||||
|
||||
### Linking with an Application
|
||||
|
||||
Include `msgpack.hpp` (or `msgpack.h` for C) in your application and link with libmsgpack. Here is a typical gcc link command:
|
||||
|
||||
g++ myapp.cpp -lmsgpack -o myapp
|
||||
|
||||
|
||||
### Code Example
|
||||
```CPP
|
||||
#include <msgpack.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
// This is target object.
|
||||
std::vector<std::string> target;
|
||||
target.push_back("Hello,");
|
||||
target.push_back("World!");
|
||||
|
||||
// Serialize it.
|
||||
msgpack::sbuffer sbuf; // simple buffer
|
||||
msgpack::pack(&sbuf, target);
|
||||
|
||||
// Deserialize the serialized data.
|
||||
msgpack::unpacked msg; // includes memory pool and deserialized object
|
||||
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
|
||||
msgpack::object obj = msg.get();
|
||||
|
||||
// Print the deserialized object to stdout.
|
||||
std::cout << obj << std::endl; // ["Hello," "World!"]
|
||||
|
||||
// Convert the deserialized object to staticaly typed object.
|
||||
std::vector<std::string> result;
|
||||
obj.convert(&result);
|
||||
|
||||
// If the type is mismatched, it throws msgpack::type_error.
|
||||
obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
|
||||
}
|
||||
```
|
||||
### Quickstart Guides
|
||||
|
||||
For more detailed examples see [QuickStart for C](QUICKSTART-C.md) and [QuickStart for C++](QUICKSTART-CPP.md).
|
38
README_crosslang.md
Normal file
38
README_crosslang.md
Normal file
@@ -0,0 +1,38 @@
|
||||
MessagePack cross-language test cases
|
||||
=====================================
|
||||
|
||||
## cases
|
||||
|
||||
Valid serialized data are stored in "cases.mpac" and "cases_compact.mpac".
|
||||
These files describe same objects. And "cases.json" describes an array of the described objects.
|
||||
|
||||
Thus you can verify your implementations as comparing the objects.
|
||||
|
||||
|
||||
## crosslang
|
||||
|
||||
The *crosslang* tool reads serialized data from stdin and writes re-serialize data to stdout.
|
||||
|
||||
There are C++ and Ruby implementation of crosslang tool. You can verify your implementation
|
||||
as comparing that implementations.
|
||||
|
||||
### C++ version
|
||||
|
||||
$ cd ../cpp && ./configure && make && make install
|
||||
or
|
||||
$ port install msgpack # MacPorts
|
||||
|
||||
$ g++ -Wall crosslang.cc -lmsgpack -o crosslang
|
||||
|
||||
$ ./crosslang
|
||||
Usage: ./crosslang [in-file] [out-file]
|
||||
|
||||
### Ruby version
|
||||
|
||||
$ gem install msgpack
|
||||
or
|
||||
$ port install rb_msgpack # MacPorts
|
||||
|
||||
$ ruby crosslang.rb
|
||||
Usage: crosslang.rb [in-file] [out-file]
|
||||
|
@@ -32,8 +32,11 @@ fi
|
||||
|
||||
|
||||
mkdir -p ac
|
||||
(cd cpp && ./preprocess.sh $@; cd ..)
|
||||
|
||||
test -f AUTHORS || touch AUTHORS
|
||||
test -f COPYING || touch COPYING
|
||||
test -f ChangeLog || touch ChangeLog
|
||||
test -f NEWS || touch NEWS
|
||||
test -f README || cp -f README.md README
|
||||
|
||||
ACLOCAL="aclocal"
|
||||
ACLOCAL_FILES="aclocal.m4"
|
||||
|
@@ -1,28 +0,0 @@
|
||||
lib_LTLIBRARIES = libmsgpackc.la
|
||||
|
||||
libmsgpackc_la_SOURCES = \
|
||||
unpack.c \
|
||||
object.c \
|
||||
vrefbuffer.c \
|
||||
zone.c
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
msgpack.h \
|
||||
msgpack/sbuffer.h \
|
||||
msgpack/vrefbuffer.h \
|
||||
msgpack/pack.h \
|
||||
msgpack/unpack.h \
|
||||
msgpack/object.h \
|
||||
msgpack/zone.h
|
||||
|
||||
# -version-info CURRENT:REVISION:AGE
|
||||
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_LDFLAGS = libmsgpackc.la -lgtest_main
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
323
c/bench.c
323
c/bench.c
@@ -1,323 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <msgpack/pack.h>
|
||||
#include <msgpack/unpack.h>
|
||||
#include <yajl/yajl_parse.h>
|
||||
#include <yajl/yajl_gen.h>
|
||||
|
||||
|
||||
static struct timeval g_timer;
|
||||
|
||||
void reset_timer()
|
||||
{
|
||||
gettimeofday(&g_timer, NULL);
|
||||
}
|
||||
|
||||
void show_timer(size_t bufsz)
|
||||
{
|
||||
struct timeval endtime;
|
||||
gettimeofday(&endtime, NULL);
|
||||
double sec = (endtime.tv_sec - g_timer.tv_sec)
|
||||
+ (double)(endtime.tv_usec - g_timer.tv_usec) / 1000 / 1000;
|
||||
printf("%f sec\n", sec);
|
||||
printf("%f MB\n", ((double)bufsz)/1024/1024);
|
||||
printf("%f Mbps\n", ((double)bufsz)*8/sec/1000/1000);
|
||||
}
|
||||
|
||||
|
||||
static int reformat_null(void * ctx) { return 1; }
|
||||
static int reformat_boolean(void * ctx, int boolean) { return 1; }
|
||||
static int reformat_number(void * ctx, const char * s, unsigned int l) { return 1; }
|
||||
static int reformat_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { return 1; }
|
||||
static int reformat_map_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { return 1; }
|
||||
static int reformat_start_map(void * ctx) { return 1; }
|
||||
static int reformat_end_map(void * ctx) { return 1; }
|
||||
static int reformat_start_array(void * ctx) { return 1; }
|
||||
static int reformat_end_array(void * ctx) { return 1; }
|
||||
|
||||
|
||||
static void* unpack_uint8(void* data, uint8_t d) { return NULL; }
|
||||
static void* unpack_uint16(void* data, uint16_t d) { return NULL; }
|
||||
static void* unpack_uint32(void* data, uint32_t d) { return NULL; }
|
||||
static void* unpack_uint64(void* data, uint64_t d) { return NULL; }
|
||||
static void* unpack_int8(void* data, int8_t d) { return NULL; }
|
||||
static void* unpack_int16(void* data, int16_t d) { return NULL; }
|
||||
static void* unpack_int32(void* data, int32_t d) { return NULL; }
|
||||
static void* unpack_int64(void* data, int64_t d) { return NULL; }
|
||||
static void* unpack_float(void* data, float d) { return NULL; }
|
||||
static void* unpack_double(void* data, double d) { return NULL; }
|
||||
static void* unpack_nil(void* data) { return NULL; }
|
||||
static void* unpack_true(void* data) { return NULL; }
|
||||
static void* unpack_false(void* data) { return NULL; }
|
||||
static void* unpack_array(void* data, unsigned int n) { return NULL; }
|
||||
static void unpack_array_item(void* data, void* c, void* o) { }
|
||||
static void* unpack_map(void* data, unsigned int n) { return NULL; }
|
||||
static void unpack_map_item(void* data, void* c, void* k, void* v) { }
|
||||
static void* unpack_raw(void* data, const char* b, const char* p, unsigned int l) { /*printf("unpack raw %p %lu\n",p,l);*/ return NULL; }
|
||||
|
||||
|
||||
typedef struct {
|
||||
size_t allocated;
|
||||
size_t length;
|
||||
char* buffer;
|
||||
} pack_buffer;
|
||||
|
||||
static const size_t PACK_INITIAL_BUFFER_SIZE = 32*1024;
|
||||
|
||||
static void pack_buffer_init(pack_buffer* data)
|
||||
{
|
||||
data->buffer = malloc(PACK_INITIAL_BUFFER_SIZE);
|
||||
data->length = 0;
|
||||
data->allocated = PACK_INITIAL_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
static void pack_buffer_reset(pack_buffer* data)
|
||||
{
|
||||
data->buffer = realloc(data->buffer, PACK_INITIAL_BUFFER_SIZE);
|
||||
data->allocated = PACK_INITIAL_BUFFER_SIZE;
|
||||
data->length = 0;
|
||||
}
|
||||
|
||||
static void pack_buffer_free(pack_buffer* data)
|
||||
{
|
||||
free(data->buffer);
|
||||
}
|
||||
|
||||
static void pack_append_buffer(void* user, const char* b, unsigned int l)
|
||||
{
|
||||
pack_buffer* data = (pack_buffer*)user;
|
||||
if(data->allocated - data->length < l) {
|
||||
data->buffer = realloc(data->buffer, data->allocated*2);
|
||||
data->allocated *= 2;
|
||||
}
|
||||
memcpy(data->buffer + data->length, b, l);
|
||||
data->length += l;
|
||||
}
|
||||
|
||||
|
||||
static const unsigned int TASK_INT_NUM = 1<<24;
|
||||
static const unsigned int TASK_STR_LEN = 1<<15;
|
||||
//static const unsigned int TASK_INT_NUM = 1<<20;
|
||||
//static const unsigned int TASK_STR_LEN = 1<<12;
|
||||
static const char* TASK_STR_PTR;
|
||||
|
||||
|
||||
void bench_json(void)
|
||||
{
|
||||
puts("== JSON ==");
|
||||
|
||||
|
||||
yajl_gen_config gcfg = {0, NULL};
|
||||
yajl_gen g = yajl_gen_alloc(&gcfg);
|
||||
|
||||
yajl_parser_config hcfg = { 0, 0 };
|
||||
yajl_callbacks callbacks = {
|
||||
reformat_null,
|
||||
reformat_boolean,
|
||||
NULL,
|
||||
NULL,
|
||||
reformat_number,
|
||||
reformat_string,
|
||||
reformat_start_map,
|
||||
reformat_map_key,
|
||||
reformat_end_map,
|
||||
reformat_start_array,
|
||||
reformat_end_array
|
||||
};
|
||||
yajl_handle h = yajl_alloc(&callbacks, &hcfg, NULL);
|
||||
|
||||
|
||||
const unsigned char * buf;
|
||||
unsigned int len;
|
||||
|
||||
|
||||
puts("generate integer");
|
||||
reset_timer();
|
||||
{
|
||||
unsigned int i;
|
||||
yajl_gen_array_open(g);
|
||||
for(i=0; i < TASK_INT_NUM; ++i) {
|
||||
yajl_gen_integer(g, i);
|
||||
}
|
||||
yajl_gen_array_close(g);
|
||||
}
|
||||
show_timer(len);
|
||||
|
||||
yajl_gen_get_buf(g, &buf, &len);
|
||||
|
||||
puts("----");
|
||||
puts("parse integer");
|
||||
reset_timer();
|
||||
{
|
||||
yajl_status stat = yajl_parse(h, buf, len);
|
||||
if (stat != yajl_status_ok && stat != yajl_status_insufficient_data) {
|
||||
unsigned char * str = yajl_get_error(h, 1, buf, len);
|
||||
fprintf(stderr, (const char *) str);
|
||||
}
|
||||
}
|
||||
show_timer(len);
|
||||
|
||||
|
||||
//yajl_gen_clear(g);
|
||||
yajl_gen_free(g);
|
||||
g = yajl_gen_alloc(&gcfg);
|
||||
yajl_free(h);
|
||||
h = yajl_alloc(&callbacks, &hcfg, NULL);
|
||||
|
||||
|
||||
puts("----");
|
||||
puts("generate string");
|
||||
reset_timer();
|
||||
{
|
||||
unsigned int i;
|
||||
yajl_gen_array_open(g);
|
||||
for(i=0; i < TASK_STR_LEN; ++i) {
|
||||
yajl_gen_string(g, (const unsigned char*)TASK_STR_PTR, i);
|
||||
}
|
||||
yajl_gen_array_close(g);
|
||||
}
|
||||
show_timer(len);
|
||||
|
||||
yajl_gen_get_buf(g, &buf, &len);
|
||||
|
||||
puts("----");
|
||||
puts("parse string");
|
||||
reset_timer();
|
||||
{
|
||||
yajl_status stat = yajl_parse(h, buf, len);
|
||||
if (stat != yajl_status_ok && stat != yajl_status_insufficient_data) {
|
||||
unsigned char * str = yajl_get_error(h, 1, buf, len);
|
||||
fprintf(stderr, (const char *) str);
|
||||
}
|
||||
}
|
||||
show_timer(len);
|
||||
|
||||
|
||||
yajl_gen_free(g);
|
||||
yajl_free(h);
|
||||
}
|
||||
|
||||
|
||||
void bench_msgpack(void)
|
||||
{
|
||||
puts("== MessagePack ==");
|
||||
|
||||
|
||||
pack_buffer mpkbuf;
|
||||
pack_buffer_init(&mpkbuf);
|
||||
|
||||
msgpack_pack_t* mpk = msgpack_pack_new(
|
||||
&mpkbuf, pack_append_buffer);
|
||||
|
||||
msgpack_unpack_callback cb = {
|
||||
unpack_uint8,
|
||||
unpack_uint16,
|
||||
unpack_uint32,
|
||||
unpack_uint64,
|
||||
unpack_int8,
|
||||
unpack_int16,
|
||||
unpack_int32,
|
||||
unpack_int64,
|
||||
unpack_float,
|
||||
unpack_double,
|
||||
unpack_nil,
|
||||
unpack_true,
|
||||
unpack_false,
|
||||
unpack_array,
|
||||
unpack_array_item,
|
||||
unpack_map,
|
||||
unpack_map_item,
|
||||
unpack_raw,
|
||||
};
|
||||
msgpack_unpack_t* mupk = msgpack_unpack_new(NULL, &cb);
|
||||
|
||||
|
||||
size_t len;
|
||||
const char* buf;
|
||||
|
||||
|
||||
puts("pack integer");
|
||||
reset_timer();
|
||||
{
|
||||
unsigned int i;
|
||||
msgpack_pack_array(mpk, TASK_INT_NUM);
|
||||
for(i=0; i < TASK_INT_NUM; ++i) {
|
||||
msgpack_pack_unsigned_int(mpk, i);
|
||||
}
|
||||
}
|
||||
show_timer(mpkbuf.length);
|
||||
|
||||
len = mpkbuf.length;
|
||||
buf = mpkbuf.buffer;
|
||||
|
||||
puts("----");
|
||||
puts("unpack integer");
|
||||
reset_timer();
|
||||
{
|
||||
size_t off = 0;
|
||||
int ret = msgpack_unpack_execute(mupk, buf, len, &off);
|
||||
if(ret < 0) {
|
||||
fprintf(stderr, "Parse error.\n");
|
||||
} else if(ret == 0) {
|
||||
fprintf(stderr, "Not finished.\n");
|
||||
}
|
||||
}
|
||||
show_timer(mpkbuf.length);
|
||||
|
||||
|
||||
pack_buffer_reset(&mpkbuf);
|
||||
msgpack_unpack_reset(mupk);
|
||||
|
||||
|
||||
puts("----");
|
||||
puts("pack string");
|
||||
reset_timer();
|
||||
{
|
||||
unsigned int i;
|
||||
msgpack_pack_array(mpk, TASK_STR_LEN);
|
||||
for(i=0; i < TASK_STR_LEN; ++i) {
|
||||
msgpack_pack_raw(mpk, i);
|
||||
msgpack_pack_raw_body(mpk, TASK_STR_PTR, i);
|
||||
}
|
||||
}
|
||||
show_timer(mpkbuf.length);
|
||||
|
||||
len = mpkbuf.length;
|
||||
buf = mpkbuf.buffer;
|
||||
|
||||
puts("----");
|
||||
puts("unpack string");
|
||||
reset_timer();
|
||||
{
|
||||
size_t off = 0;
|
||||
int ret = msgpack_unpack_execute(mupk, buf, len, &off);
|
||||
if(ret < 0) {
|
||||
fprintf(stderr, "Parse error.\n");
|
||||
} else if(ret == 0) {
|
||||
fprintf(stderr, "Not finished.\n");
|
||||
}
|
||||
}
|
||||
show_timer(mpkbuf.length);
|
||||
|
||||
|
||||
msgpack_unpack_free(mupk);
|
||||
msgpack_pack_free(mpk);
|
||||
pack_buffer_free(&mpkbuf);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char* str = malloc(TASK_STR_LEN);
|
||||
memset(str, 'a', TASK_STR_LEN);
|
||||
TASK_STR_PTR = str;
|
||||
|
||||
bench_msgpack();
|
||||
bench_json();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -1,9 +0,0 @@
|
||||
|
||||
CFLAGS += -Wall -g -I. -I.. -O4
|
||||
LDFLAGS += -lyajl
|
||||
|
||||
all: bench
|
||||
|
||||
bench: bench.o pack.o unpack.o pack.h unpack.h
|
||||
$(CC) bench.o pack.o unpack.o $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
123
c/unpack.h
123
c/unpack.h
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* MessagePack for C unpacking 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_UNPACKER_H__
|
||||
#define MSGPACK_UNPACKER_H__
|
||||
|
||||
#include "msgpack/zone.h"
|
||||
#include "msgpack/object.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct msgpack_unpacker {
|
||||
char* buffer;
|
||||
size_t used;
|
||||
size_t free;
|
||||
size_t off;
|
||||
size_t parsed;
|
||||
msgpack_zone* z;
|
||||
size_t initial_buffer_size;
|
||||
void* ctx;
|
||||
} msgpack_unpacker;
|
||||
|
||||
|
||||
bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size);
|
||||
void msgpack_unpacker_destroy(msgpack_unpacker* mpac);
|
||||
|
||||
msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size);
|
||||
void msgpack_unpacker_free(msgpack_unpacker* mpac);
|
||||
|
||||
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size);
|
||||
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac);
|
||||
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac);
|
||||
static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size);
|
||||
|
||||
|
||||
int msgpack_unpacker_execute(msgpack_unpacker* mpac);
|
||||
|
||||
msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac);
|
||||
|
||||
msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac);
|
||||
|
||||
void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac);
|
||||
|
||||
void msgpack_unpacker_reset(msgpack_unpacker* mpac);
|
||||
|
||||
static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac);
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
MSGPACK_UNPACK_SUCCESS = 2,
|
||||
MSGPACK_UNPACK_EXTRA_BYTES = 1,
|
||||
MSGPACK_UNPACK_CONTINUE = 0,
|
||||
MSGPACK_UNPACK_PARSE_ERROR = -1,
|
||||
} msgpack_unpack_return;
|
||||
|
||||
msgpack_unpack_return
|
||||
msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
msgpack_zone* z, msgpack_object* result);
|
||||
|
||||
|
||||
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac);
|
||||
|
||||
bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac);
|
||||
|
||||
bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size);
|
||||
|
||||
bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size)
|
||||
{
|
||||
if(mpac->free >= size) { return true; }
|
||||
return msgpack_unpacker_expand_buffer(mpac, size);
|
||||
}
|
||||
|
||||
char* msgpack_unpacker_buffer(msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->buffer + mpac->used;
|
||||
}
|
||||
|
||||
size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->free;
|
||||
}
|
||||
|
||||
void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size)
|
||||
{
|
||||
mpac->used += size;
|
||||
mpac->free -= size;
|
||||
}
|
||||
|
||||
size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->parsed - mpac->off + mpac->used;
|
||||
}
|
||||
|
||||
size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac)
|
||||
{
|
||||
return mpac->parsed;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/unpack.h */
|
||||
|
1
cases.json
Normal file
1
cases.json
Normal file
@@ -0,0 +1 @@
|
||||
[false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,127,127,255,65535,4294967295,-32,-32,-128,-32768,-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",[0],[0],[0],[],[],[],{},{},{},{"a":97},{"a":97},{"a":97},[[]],[["a"]]]
|
99
cases_gen.rb
Normal file
99
cases_gen.rb
Normal file
@@ -0,0 +1,99 @@
|
||||
#
|
||||
# MessagePack format test case
|
||||
#
|
||||
begin
|
||||
require 'rubygems'
|
||||
rescue LoadError
|
||||
end
|
||||
require 'msgpack'
|
||||
require 'json'
|
||||
|
||||
source = <<EOF
|
||||
c2 # false
|
||||
c3 # true
|
||||
c0 # nil
|
||||
00 # 0 Positive FixNum
|
||||
cc 00 # 0 uint8
|
||||
cd 00 00 # 0 uint16
|
||||
ce 00 00 00 00 # 0 uint32
|
||||
cf 00 00 00 00 00 00 00 00 # 0 uint64
|
||||
d0 00 # 0 int8
|
||||
d1 00 00 # 0 int16
|
||||
d2 00 00 00 00 # 0 int32
|
||||
d3 00 00 00 00 00 00 00 00 # 0 int64
|
||||
ff # -1 Negative FixNum
|
||||
d0 ff # -1 int8
|
||||
d1 ff ff # -1 int16
|
||||
d2 ff ff ff ff # -1 int32
|
||||
d3 ff ff ff ff ff ff ff ff # -1 int64
|
||||
7f # 127 Positive FixNum
|
||||
cc 7f # 127 uint8
|
||||
cd 00 ff # 255 uint16
|
||||
ce 00 00 ff ff # 65535 uint32
|
||||
cf 00 00 00 00 ff ff ff ff # 4294967295 uint64
|
||||
e0 # -32 Negative FixNum
|
||||
d0 e0 # -32 int8
|
||||
d1 ff 80 # -128 int16
|
||||
d2 ff ff 80 00 # -32768 int32
|
||||
d3 ff ff ff ff 80 00 00 00 # -2147483648 int64
|
||||
#ca 00 00 00 00 # 0.0 float
|
||||
cb 00 00 00 00 00 00 00 00 # 0.0 double
|
||||
#ca 80 00 00 00 # -0.0 float
|
||||
cb 80 00 00 00 00 00 00 00 # -0.0 double
|
||||
cb 3f f0 00 00 00 00 00 00 # 1.0 double
|
||||
cb bf f0 00 00 00 00 00 00 # -1.0 double
|
||||
a1 61 # "a" FixRaw
|
||||
da 00 01 61 # "a" raw 16
|
||||
db 00 00 00 01 61 # "a" raw 32
|
||||
a0 # "" FixRaw
|
||||
da 00 00 # "" raw 16
|
||||
db 00 00 00 00 # "" raw 32
|
||||
91 00 # [0] FixArray
|
||||
dc 00 01 00 # [0] array 16
|
||||
dd 00 00 00 01 00 # [0] array 32
|
||||
90 # [] FixArray
|
||||
dc 00 00 # [] array 16
|
||||
dd 00 00 00 00 # [] array 32
|
||||
80 # {} FixMap
|
||||
de 00 00 # {} map 16
|
||||
df 00 00 00 00 # {} map 32
|
||||
81 a1 61 61 # {"a"=>97} FixMap
|
||||
de 00 01 a1 61 61 # {"a"=>97} map 16
|
||||
df 00 00 00 01 a1 61 61 # {"a"=>97} map 32
|
||||
91 90 # [[]]
|
||||
91 91 a1 61 # [["a"]]
|
||||
EOF
|
||||
|
||||
source.gsub!(/\#.+$/,'')
|
||||
bytes = source.strip.split(/\s+/).map {|x| x.to_i(16) }.pack('C*')
|
||||
|
||||
objs = []
|
||||
compact_bytes = ""
|
||||
|
||||
pac = MessagePack::Unpacker.new
|
||||
pac.feed(bytes)
|
||||
pac.each {|obj|
|
||||
p obj
|
||||
objs << obj
|
||||
compact_bytes << obj.to_msgpack
|
||||
}
|
||||
|
||||
json = objs.to_json
|
||||
|
||||
# self check
|
||||
cpac = MessagePack::Unpacker.new
|
||||
cpac.feed(compact_bytes)
|
||||
cpac.each {|cobj|
|
||||
obj = objs.shift
|
||||
if obj != cobj
|
||||
puts "** SELF CHECK FAILED **"
|
||||
puts "expected: #{obj.inspect}"
|
||||
puts "actual: #{cobj.inspect}"
|
||||
exit 1
|
||||
end
|
||||
}
|
||||
|
||||
File.open("cases.mpac","w") {|f| f.write(bytes) }
|
||||
File.open("cases_compact.mpac","w") {|f| f.write(compact_bytes) }
|
||||
File.open("cases.json","w") {|f| f.write(json) }
|
||||
|
101
configure.in
101
configure.in
@@ -1,39 +1,100 @@
|
||||
AC_INIT(msgpack/unpack_template.h)
|
||||
AC_INIT(src/object.cpp)
|
||||
AC_CONFIG_AUX_DIR(ac)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.4.0)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.5.9)
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_SUBST(CFLAGS)
|
||||
if test "" = "$CFLAGS"; then
|
||||
CFLAGS="-g -O4"
|
||||
fi
|
||||
CFLAGS="-O3 -Wall $CFLAGS"
|
||||
|
||||
AC_SUBST(CXXFLAGS)
|
||||
CXXFLAGS="-O3 -Wall $CXXFLAGS"
|
||||
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
CFLAGS="-O4 -Wall $CFLAGS -I.."
|
||||
|
||||
|
||||
AC_MSG_CHECKING([if c++ api is enabled])
|
||||
AC_MSG_CHECKING([if C++ API is enabled])
|
||||
AC_ARG_ENABLE(cxx,
|
||||
AS_HELP_STRING([--disable-cxx],
|
||||
[don't build c++ api.]) )
|
||||
AC_MSG_RESULT($enable_cxx)
|
||||
[don't build C++ API]) ) #'
|
||||
AC_MSG_RESULT([$enable_cxx])
|
||||
if test "$enable_cxx" != "no"; then
|
||||
AC_SUBST(CXXFLAGS)
|
||||
if test "" = "$CXXFLAGS"; then
|
||||
CXXFLAGS="-g -O4"
|
||||
AC_PROG_CXX
|
||||
AM_PROG_CC_C_O
|
||||
fi
|
||||
AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no")
|
||||
|
||||
|
||||
AC_PROG_LIBTOOL
|
||||
AM_PROG_AS
|
||||
|
||||
|
||||
AC_MSG_CHECKING([if debug option is enabled])
|
||||
AC_ARG_ENABLE(debug,
|
||||
AS_HELP_STRING([--disable-debug],
|
||||
[disable assert macros and omit -g option]) )
|
||||
AC_MSG_RESULT([$enable_debug])
|
||||
if test "$enable_debug" != "no"; then
|
||||
CXXFLAGS="$CXXFLAGS -g"
|
||||
CFLAGS="$CFLAGS -g"
|
||||
else
|
||||
CXXFLAGS="$CXXFLAGS -DNDEBUG"
|
||||
CFLAGS="$CFLAGS -DNDEBUG"
|
||||
fi
|
||||
|
||||
|
||||
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); }
|
||||
], [atomic_sub(1); atomic_add(1);], msgpack_cv_atomic_ops="yes")
|
||||
])
|
||||
if test "$msgpack_cv_atomic_ops" != "yes"; then
|
||||
if test "$enable_cxx" = "no"; then
|
||||
AC_MSG_ERROR([__sync_* atomic operations are not found. Try to enable C++ support.
|
||||
If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to
|
||||
add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows:
|
||||
|
||||
$ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686"
|
||||
])
|
||||
fi
|
||||
|
||||
AC_LANG_PUSH([C++])
|
||||
AC_CACHE_CHECK([for __gnu_cxx::__exchange_and_add], msgpack_cv_gcc_cxx_atomic_ops, [
|
||||
AC_TRY_LINK([
|
||||
#include <bits/atomicity.h>
|
||||
int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1) - 1; }
|
||||
int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1) + 1; }
|
||||
], [atomic_sub(1); atomic_add(1);], msgpack_cv_gcc_cxx_atomic_ops="yes")
|
||||
])
|
||||
AC_LANG_POP([C++])
|
||||
|
||||
if test "$msgpack_cv_gcc_cxx_atomic_ops" != "yes"; then
|
||||
AC_MSG_ERROR([__sync_* atomic operations nor __gnu_cxx::__exchange_and_add are not found.
|
||||
|
||||
If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to
|
||||
add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows:
|
||||
|
||||
$ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686"
|
||||
])
|
||||
|
||||
else
|
||||
enable_gcc_cxx_atomic=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
# FIXME
|
||||
AC_PROG_CXX
|
||||
|
||||
CXXFLAGS="-O4 -Wall $CXXFLAGS -I.. -I../c"
|
||||
AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes")
|
||||
|
||||
|
||||
AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no")
|
||||
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
|
||||
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
|
||||
AC_SUBST(VERSION_MAJOR, $major)
|
||||
AC_SUBST(VERSION_MINOR, $minor)
|
||||
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
AC_OUTPUT([Makefile c/Makefile cpp/Makefile])
|
||||
AC_OUTPUT([Makefile
|
||||
msgpack.pc
|
||||
src/Makefile
|
||||
src/msgpack/version.h
|
||||
test/Makefile])
|
||||
|
||||
|
@@ -1,44 +0,0 @@
|
||||
lib_LTLIBRARIES = libmsgpack.la
|
||||
|
||||
libmsgpack_la_SOURCES = \
|
||||
object.cpp
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
msgpack.hpp \
|
||||
msgpack/sbuffer.hpp \
|
||||
msgpack/vrefbuffer.hpp \
|
||||
msgpack/pack.hpp \
|
||||
msgpack/unpack.hpp \
|
||||
msgpack/object.hpp \
|
||||
msgpack/zone.hpp \
|
||||
msgpack/type.hpp \
|
||||
msgpack/type/bool.hpp \
|
||||
msgpack/type/float.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/set.hpp \
|
||||
msgpack/type/string.hpp \
|
||||
msgpack/type/vector.hpp \
|
||||
msgpack/type/tuple.hpp \
|
||||
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 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_LDFLAGS = libmsgpack.la -lgtest_main
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
188
cpp/bench.cpp
188
cpp/bench.cpp
@@ -1,188 +0,0 @@
|
||||
#include <msgpack/unpack.hpp>
|
||||
#include <msgpack/pack.hpp>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
static const unsigned int TASK_INT_NUM = 1<<24;
|
||||
static const unsigned int TASK_STR_LEN = 1<<15;
|
||||
//static const unsigned int TASK_INT_NUM = 1<<22;
|
||||
//static const unsigned int TASK_STR_LEN = 1<<13;
|
||||
static const char* TASK_STR_PTR;
|
||||
|
||||
|
||||
class simple_timer {
|
||||
public:
|
||||
void reset() { gettimeofday(&m_timeval, NULL); }
|
||||
void show_stat(size_t bufsz)
|
||||
{
|
||||
struct timeval endtime;
|
||||
gettimeofday(&endtime, NULL);
|
||||
double sec = (endtime.tv_sec - m_timeval.tv_sec)
|
||||
+ (double)(endtime.tv_usec - m_timeval.tv_usec) / 1000 / 1000;
|
||||
std::cout << sec << " sec" << std::endl;
|
||||
std::cout << (double(bufsz)/1024/1024) << " MB" << std::endl;
|
||||
std::cout << (bufsz/sec/1000/1000*8) << " Mbps" << std::endl;
|
||||
}
|
||||
private:
|
||||
timeval m_timeval;
|
||||
};
|
||||
|
||||
|
||||
class simple_buffer {
|
||||
public:
|
||||
static const size_t DEFAULT_INITIAL_SIZE = 32*1024;//512*1024*1024*2;
|
||||
|
||||
simple_buffer(size_t initial_size = DEFAULT_INITIAL_SIZE) :
|
||||
m_storage((char*)malloc(initial_size)),
|
||||
m_allocated(initial_size),
|
||||
m_used(0)
|
||||
{
|
||||
if(!m_storage) { throw std::bad_alloc(); }
|
||||
}
|
||||
|
||||
~simple_buffer()
|
||||
{
|
||||
free(m_storage);
|
||||
}
|
||||
|
||||
public:
|
||||
inline void write(const char* buf, size_t len)
|
||||
{
|
||||
if(m_allocated - m_used < len) {
|
||||
expand_buffer(len);
|
||||
}
|
||||
memcpy(m_storage + m_used, buf, len);
|
||||
m_used += len;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_used = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void expand_buffer(size_t req)
|
||||
{
|
||||
size_t nsize = m_allocated * 2;
|
||||
size_t at_least = m_used + req;
|
||||
while(nsize < at_least) { nsize *= 2; }
|
||||
char* tmp = (char*)realloc(m_storage, nsize);
|
||||
if(!tmp) { throw std::bad_alloc(); }
|
||||
m_storage = tmp;
|
||||
m_allocated = nsize;
|
||||
}
|
||||
|
||||
public:
|
||||
size_t size() const { return m_used; }
|
||||
const char* data() const { return m_storage; }
|
||||
|
||||
private:
|
||||
char* m_storage;
|
||||
size_t m_allocated;
|
||||
size_t m_used;
|
||||
};
|
||||
|
||||
|
||||
void bench_msgpack_int()
|
||||
{
|
||||
simple_buffer buf;
|
||||
simple_timer timer;
|
||||
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "pack integer" << std::endl;
|
||||
|
||||
timer.reset();
|
||||
{
|
||||
msgpack::packer<simple_buffer> pk(buf);
|
||||
pk.pack_array(TASK_INT_NUM);
|
||||
for(unsigned int i=0; i < TASK_INT_NUM; ++i) {
|
||||
pk.pack_unsigned_int(i);
|
||||
}
|
||||
}
|
||||
timer.show_stat(buf.size());
|
||||
|
||||
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "unpack integer" << std::endl;
|
||||
|
||||
msgpack::zone z;
|
||||
msgpack::object obj;
|
||||
|
||||
timer.reset();
|
||||
{
|
||||
obj = msgpack::unpack(buf.data(), buf.size(), z);
|
||||
}
|
||||
timer.show_stat(buf.size());
|
||||
|
||||
/*
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "dynamic pack integer" << std::endl;
|
||||
|
||||
buf.clear();
|
||||
|
||||
timer.reset();
|
||||
msgpack::pack(buf, obj);
|
||||
timer.show_stat(buf.size());
|
||||
*/
|
||||
}
|
||||
|
||||
void bench_msgpack_str()
|
||||
{
|
||||
simple_buffer buf;
|
||||
simple_timer timer;
|
||||
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "pack string" << std::endl;
|
||||
|
||||
timer.reset();
|
||||
{
|
||||
msgpack::packer<simple_buffer> pk(buf);
|
||||
pk.pack_array(TASK_STR_LEN);
|
||||
for(unsigned int i=0; i < TASK_STR_LEN; ++i) {
|
||||
pk.pack_raw(i);
|
||||
pk.pack_raw_body(TASK_STR_PTR, i);
|
||||
}
|
||||
}
|
||||
timer.show_stat(buf.size());
|
||||
|
||||
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "unpack string" << std::endl;
|
||||
|
||||
msgpack::zone z;
|
||||
msgpack::object obj;
|
||||
|
||||
timer.reset();
|
||||
{
|
||||
obj = msgpack::unpack(buf.data(), buf.size(), z);
|
||||
}
|
||||
timer.show_stat(buf.size());
|
||||
|
||||
|
||||
/*
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "dynamic pack string" << std::endl;
|
||||
|
||||
buf.clear();
|
||||
|
||||
timer.reset();
|
||||
msgpack::pack(buf, obj);
|
||||
timer.show_stat(buf.size());
|
||||
*/
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char* str = (char*)malloc(TASK_STR_LEN);
|
||||
memset(str, 'a', TASK_STR_LEN);
|
||||
TASK_STR_PTR = str;
|
||||
|
||||
bench_msgpack_int();
|
||||
bench_msgpack_str();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
|
||||
CXXFLAGS += -Wall -g -I. -I.. -O4
|
||||
LDFLAGS +=
|
||||
|
||||
all: bench
|
||||
|
||||
bench: bench.o unpack.o zone.o object.o pack.hpp unpack.hpp zone.hpp object.hpp
|
||||
$(CXX) bench.o unpack.o zone.o object.o $(CXXFLAGS) $(LDFLAGS) -o $@
|
||||
|
@@ -1 +0,0 @@
|
||||
.
|
@@ -1,9 +0,0 @@
|
||||
|
||||
CXXFLAGS += -Wall -g -I. -I.. -O4
|
||||
LDFLAGS +=
|
||||
|
||||
all: test
|
||||
|
||||
test: test.o unpack.o zone.o object.o pack.hpp unpack.hpp zone.hpp object.hpp
|
||||
$(CXX) test.o unpack.o zone.o object.o $(CXXFLAGS) $(LDFLAGS) -o $@
|
||||
|
15
cpp/type.hpp
15
cpp/type.hpp
@@ -1,15 +0,0 @@
|
||||
#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"
|
||||
|
147
cpp/type/int.hpp
147
cpp/type/int.hpp
@@ -1,147 +0,0 @@
|
||||
//
|
||||
// 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_INT_HPP__
|
||||
#define MSGPACK_TYPE_INT_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
namespace type {
|
||||
namespace detail {
|
||||
template <typename T, bool Signed>
|
||||
struct convert_integer_sign;
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, true> {
|
||||
static inline T convert(object o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
|
||||
{ throw type_error(); }
|
||||
return o.via.u64;
|
||||
} else if(o.type == type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < (int64_t)std::numeric_limits<T>::min())
|
||||
{ throw type_error(); }
|
||||
return o.via.i64;
|
||||
}
|
||||
throw type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, false> {
|
||||
static inline T convert(object o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
|
||||
{ throw type_error(); }
|
||||
return o.via.u64;
|
||||
}
|
||||
throw type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline T convert_integer(object o)
|
||||
{
|
||||
return detail::convert_integer_sign<T, std::numeric_limits<T>::is_signed>::convert(o);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline signed char& operator>> (object o, signed char& v)
|
||||
{ v = type::detail::convert_integer<signed char>(o); return v; }
|
||||
|
||||
inline signed short& operator>> (object o, signed short& v)
|
||||
{ v = type::detail::convert_integer<signed short>(o); return v; }
|
||||
|
||||
inline signed int& operator>> (object o, signed int& v)
|
||||
{ v = type::detail::convert_integer<signed int>(o); return v; }
|
||||
|
||||
inline signed long& operator>> (object o, signed long& v)
|
||||
{ v = type::detail::convert_integer<signed long>(o); return v; }
|
||||
|
||||
inline signed long long& operator>> (object o, signed long long& v)
|
||||
{ v = type::detail::convert_integer<signed long long>(o); return v; }
|
||||
|
||||
|
||||
inline unsigned char& operator>> (object o, unsigned char& v)
|
||||
{ v = type::detail::convert_integer<unsigned char>(o); return v; }
|
||||
|
||||
inline unsigned short& operator>> (object o, unsigned short& v)
|
||||
{ v = type::detail::convert_integer<unsigned short>(o); return v; }
|
||||
|
||||
inline unsigned int& operator>> (object o, unsigned int& v)
|
||||
{ v = type::detail::convert_integer<unsigned int>(o); return v; }
|
||||
|
||||
inline unsigned long& operator>> (object o, unsigned long& v)
|
||||
{ v = type::detail::convert_integer<unsigned long>(o); return v; }
|
||||
|
||||
inline unsigned long long& operator>> (object o, unsigned long long& v)
|
||||
{ v = type::detail::convert_integer<unsigned long long>(o); return v; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed char& v)
|
||||
{ o.pack_int8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed short& v)
|
||||
{ o.pack_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed int& v)
|
||||
{ o.pack_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed long& v)
|
||||
{ o.pack_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed long long& v)
|
||||
{ o.pack_long_long(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned char& v)
|
||||
{ o.pack_uint8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned short& v)
|
||||
{ o.pack_unsigned_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned int& v)
|
||||
{ o.pack_unsigned_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long& v)
|
||||
{ o.pack_unsigned_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long long& v)
|
||||
{ o.pack_unsigned_long_long(v); return o; }
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/int.hpp */
|
||||
|
@@ -1,85 +0,0 @@
|
||||
//
|
||||
// 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 */
|
||||
|
@@ -1,80 +0,0 @@
|
||||
//
|
||||
// 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 */
|
||||
|
133
crosslang.cc
Normal file
133
crosslang.cc
Normal file
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// MessagePack cross-language test tool
|
||||
//
|
||||
// $ cd ../cpp && ./configure && make && make install
|
||||
// or
|
||||
// $ port install msgpack # MacPorts
|
||||
//
|
||||
// $ g++ -Wall crosslang.cc -lmsgpack
|
||||
//
|
||||
#include <msgpack.hpp>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int run(int infd, int outfd)
|
||||
try {
|
||||
msgpack::unpacker pac;
|
||||
|
||||
while(true) {
|
||||
pac.reserve_buffer(32*1024);
|
||||
|
||||
ssize_t count =
|
||||
read(infd, pac.buffer(), pac.buffer_capacity());
|
||||
|
||||
if(count <= 0) {
|
||||
if(count == 0) {
|
||||
return 0;
|
||||
}
|
||||
if(errno == EAGAIN || errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
pac.buffer_consumed(count);
|
||||
|
||||
msgpack::unpacked result;
|
||||
while(pac.next(&result)) {
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, result.get());
|
||||
|
||||
const char* p = sbuf.data();
|
||||
const char* const pend = p + sbuf.size();
|
||||
while(p < pend) {
|
||||
ssize_t bytes = write(outfd, p, pend-p);
|
||||
|
||||
if(bytes <= 0) {
|
||||
if(count == 0) {
|
||||
return 0;
|
||||
}
|
||||
if(errno == EAGAIN || errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
p += bytes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void usage(const char* prog)
|
||||
{
|
||||
printf(
|
||||
"Usage: %s [in-file] [out-file]\n"
|
||||
"\n"
|
||||
"This tool is for testing of MessagePack implementation.\n"
|
||||
"This does following behavior:\n"
|
||||
"\n"
|
||||
" 1. Reads objects serialized by MessagePack from <in-file> (default: stdin)\n"
|
||||
" 2. Re-serializes the objects using C++ implementation of MessagePack (Note that C++ implementation is considered valid)\n"
|
||||
" 3. Writes the re-serialized objects into <out-file> (default: stdout)\n"
|
||||
"\n"
|
||||
, prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int infd = 0;
|
||||
int outfd = 1;
|
||||
|
||||
if(argc < 1 || argc > 3) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
for(int i=1; i < argc; ++i) {
|
||||
if(strlen(argv[i]) > 1 && argv[i][0] == '-') {
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if(argc >= 2) {
|
||||
const char* fname = argv[1];
|
||||
if(strcmp(fname, "-") != 0) {
|
||||
infd = open(fname, O_RDONLY);
|
||||
if(infd < 0) {
|
||||
perror("can't open input file");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(argc >= 3) {
|
||||
const char* fname = argv[2];
|
||||
if(strcmp(fname, "-") != 0) {
|
||||
outfd = open(fname, O_WRONLY | O_CREAT| O_TRUNC, 0666);
|
||||
if(outfd < 0) {
|
||||
perror("can't open output file");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int code = run(infd, outfd);
|
||||
|
||||
close(infd);
|
||||
close(outfd);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
88
crosslang.rb
Normal file
88
crosslang.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
#
|
||||
# MessagePack cross-language test tool
|
||||
#
|
||||
# $ gem install msgpack
|
||||
# or
|
||||
# $ port install rb_msgpack # MacPorts
|
||||
#
|
||||
begin
|
||||
require 'rubygems'
|
||||
rescue LoadError
|
||||
end
|
||||
require 'msgpack'
|
||||
|
||||
def run(inio, outio)
|
||||
pac = MessagePack::Unpacker.new(inio)
|
||||
|
||||
begin
|
||||
pac.each {|obj|
|
||||
outio.write MessagePack.pack(obj)
|
||||
outio.flush
|
||||
}
|
||||
rescue EOFError
|
||||
return 0
|
||||
rescue
|
||||
$stderr.puts $!
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def usage
|
||||
puts <<EOF
|
||||
Usage: #{$0} [in-file] [out-file]
|
||||
|
||||
This tool is for testing of MessagePack implementation.
|
||||
This does following behavior:
|
||||
|
||||
1. Reads objects serialized by MessagePack from <in-file> (default: stdin)
|
||||
2. Re-serializes the objects using Ruby implementation of MessagePack (Note that Ruby implementation is considered valid)
|
||||
3. Writes the re-serialized objects into <out-file> (default: stdout)
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
end
|
||||
|
||||
inio = $stdin
|
||||
outio = $stdout
|
||||
|
||||
if ARGV.length > 2
|
||||
usage
|
||||
end
|
||||
|
||||
ARGV.each {|str|
|
||||
if str.size > 1 && str[0] == ?-
|
||||
usage
|
||||
end
|
||||
}
|
||||
|
||||
if fname = ARGV[0]
|
||||
unless fname == "-"
|
||||
begin
|
||||
inio = File.open(fname)
|
||||
rescue
|
||||
puts "can't open output file: #{$!}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fname = ARGV[1]
|
||||
unless fname == "-"
|
||||
begin
|
||||
outio = File.open(fname, "w")
|
||||
rescue
|
||||
puts "can't open output file: #{$!}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
code = run(inio, outio)
|
||||
|
||||
inio.close
|
||||
outio.close
|
||||
|
||||
exit code
|
||||
|
@@ -17,7 +17,7 @@ namespace myprotocol {
|
||||
|
||||
struct Put : define< tuple<uint32_t, std::string, raw_ref> > {
|
||||
Put() { }
|
||||
Put(uint32_t f, const std::string& k, const char* valref, size_t vallen) :
|
||||
Put(uint32_t f, const std::string& k, const char* valref, uint32_t vallen) :
|
||||
define_type(msgpack_type( f, k, raw_ref(valref,vallen) )) { }
|
||||
uint32_t& flags() { return get<0>(); }
|
||||
std::string& key() { return get<1>(); }
|
||||
|
@@ -1,5 +0,0 @@
|
||||
require 'msgpack'
|
||||
|
||||
serialized = [1, -1, true, false, nil, {"key" => "value"}].to_msgpack
|
||||
p MessagePack.unpack(serialized)
|
||||
|
36
example/speed_test_uint32_array.c
Normal file
36
example/speed_test_uint32_array.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint32(pk, 1);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
37
example/speed_test_uint64_array.c
Normal file
37
example/speed_test_uint64_array.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
uint64_t test_u64 = 0xFFF0000000000001LL;
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint64(pk, test_u64);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
@@ -34,13 +34,10 @@ public:
|
||||
|
||||
m_pac.buffer_consumed(count);
|
||||
|
||||
while(m_pac.execute()) {
|
||||
msgpack::object msg = m_pac.data();
|
||||
|
||||
auto_zone life( m_pac.release_zone() );
|
||||
|
||||
m_pac.reset();
|
||||
|
||||
msgpack::unpacked result;
|
||||
while (m_pac.next(&result)) {
|
||||
msgpack::object msg = result.get();
|
||||
auto_zone& life = result.zone();
|
||||
process_message(msg, life);
|
||||
}
|
||||
|
||||
|
@@ -1,72 +0,0 @@
|
||||
require 'msgpack'
|
||||
|
||||
class Server
|
||||
def initialize(sock)
|
||||
@sock = sock
|
||||
@pk = MessagePack::Unpacker.new
|
||||
@buffer = ''
|
||||
@nread = 0
|
||||
end
|
||||
|
||||
def run
|
||||
while true
|
||||
begin
|
||||
data = @sock.sysread(1024)
|
||||
rescue
|
||||
puts "connection closed (#{$!})"
|
||||
return
|
||||
end
|
||||
receive_data(data)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def receive_data(data)
|
||||
@buffer << data
|
||||
|
||||
while true
|
||||
@nread = @pk.execute(@buffer, @nread)
|
||||
|
||||
if @pk.finished?
|
||||
msg = @pk.data
|
||||
process_message(msg)
|
||||
|
||||
@pk.reset
|
||||
@buffer.slice!(0, @nread)
|
||||
@nread = 0
|
||||
|
||||
next unless @buffer.empty?
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
if @buffer.length > 10*1024*1024
|
||||
raise "message is too large"
|
||||
end
|
||||
|
||||
rescue
|
||||
puts "error while processing client packet: #{$!}"
|
||||
end
|
||||
|
||||
def process_message(msg)
|
||||
puts "message reached: #{msg.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
rpipe, wpipe = IO.pipe
|
||||
|
||||
# run server thread
|
||||
thread = Thread.new(Server.new(rpipe)) {|srv|
|
||||
srv.run
|
||||
}
|
||||
|
||||
# client thread:
|
||||
wpipe.write ["put", "apple", "red"].to_msgpack
|
||||
wpipe.write ["put", "lemon", "yellow"].to_msgpack
|
||||
wpipe.write ["get", "apple"].to_msgpack
|
||||
wpipe.close
|
||||
|
||||
thread.join
|
||||
|
@@ -1,18 +0,0 @@
|
||||
<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>
|
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,409 +0,0 @@
|
||||
//
|
||||
// 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()+")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,133 +0,0 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,82 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
@@ -1,245 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,500 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,125 +0,0 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,241 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,95 +0,0 @@
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// 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()+")";
|
||||
}
|
||||
}
|
||||
|
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,192 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,103 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,64 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,254 +0,0 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,122 +0,0 @@
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,111 +0,0 @@
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,38 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +0,0 @@
|
||||
#!/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
|
@@ -1,434 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,173 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
(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)))
|
||||
)
|
@@ -1,68 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,66 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
10
msgpack.pc.in
Normal file
10
msgpack.pc.in
Normal file
@@ -0,0 +1,10 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: MessagePack
|
||||
Description: Binary-based efficient object serialization library
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lmsgpack
|
||||
Cflags: -I${includedir}
|
@@ -1,686 +0,0 @@
|
||||
/*
|
||||
* MessagePack packing routine template
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
#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 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
|
||||
#error msgpack_pack_inline_func template is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_pack_user
|
||||
#error msgpack_pack_user type is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_pack_append_buffer
|
||||
#error msgpack_pack_append_buffer callback is not defined
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Integer
|
||||
*/
|
||||
|
||||
#define msgpack_pack_real_uint8(x, d) \
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_uint16(x, d) \
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
||||
} else if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_uint32(x, d) \
|
||||
do { \
|
||||
if(d < (1<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_uint64(x, d) \
|
||||
do { \
|
||||
if(d < (1ULL<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1ULL<<16)) { \
|
||||
/* signed 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else if(d < (1ULL<<32)) { \
|
||||
/* signed 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* signed 64 */ \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_int8(x, d) \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
/* signed 8 */ \
|
||||
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_int16(x, d) \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
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, &TAKE8_16(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_int32(x, d) \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<15)) { \
|
||||
/* signed 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
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, &TAKE8_32(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_int64(x, d) \
|
||||
do { \
|
||||
if(d < -(1LL<<5)) { \
|
||||
if(d < -(1LL<<15)) { \
|
||||
if(d < -(1LL<<31)) { \
|
||||
/* signed 64 */ \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} else { \
|
||||
/* signed 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
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, &TAKE8_64(d), 1); \
|
||||
} else { \
|
||||
if(d < (1LL<<16)) { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1LL<<32)) { \
|
||||
/* unsigned 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* unsigned 64 */ \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifdef msgpack_pack_inline_func_fastint
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t 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)
|
||||
{
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
{
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
{
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t 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)
|
||||
{
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
||||
{
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
||||
{
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
#undef msgpack_pack_inline_func_fastint
|
||||
#endif
|
||||
|
||||
|
||||
msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||
{
|
||||
msgpack_pack_real_uint8(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||
{
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
{
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
{
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d)
|
||||
{
|
||||
msgpack_pack_real_int8(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d)
|
||||
{
|
||||
msgpack_pack_real_int16(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d)
|
||||
{
|
||||
msgpack_pack_real_int32(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
|
||||
{
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
|
||||
|
||||
#ifdef msgpack_pack_inline_func_cint
|
||||
|
||||
msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d)
|
||||
{
|
||||
#if defined(SIZEOF_SHORT) || defined(SHRT_MAX)
|
||||
#if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_SHORT == 4 || SHRT_MAX == 0x7fffffff
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(short) == 2) {
|
||||
msgpack_pack_real_int16(x, d);
|
||||
} else if(sizeof(short) == 4) {
|
||||
msgpack_pack_real_int32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d)
|
||||
{
|
||||
#if defined(SIZEOF_INT) || defined(INT_MAX)
|
||||
#if SIZEOF_INT == 2 || INT_MAX == 0x7fff
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_INT == 4 || INT_MAX == 0x7fffffff
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(int) == 2) {
|
||||
msgpack_pack_real_int16(x, d);
|
||||
} else if(sizeof(int) == 4) {
|
||||
msgpack_pack_real_int32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d)
|
||||
{
|
||||
#if defined(SIZEOF_LONG) || defined(LONG_MAX)
|
||||
#if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_LONG == 4 || LONG_MAX == 0x7fffffffL
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(long) == 2) {
|
||||
msgpack_pack_real_int16(x, d);
|
||||
} else if(sizeof(long) == 4) {
|
||||
msgpack_pack_real_int32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
|
||||
{
|
||||
#if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX)
|
||||
#if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_LONG_LONG == 4 || LLONG_MAX == 0x7fffffffL
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(long long) == 2) {
|
||||
msgpack_pack_real_int16(x, d);
|
||||
} else if(sizeof(long long) == 4) {
|
||||
msgpack_pack_real_int32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
|
||||
{
|
||||
#if defined(SIZEOF_SHORT) || defined(USHRT_MAX)
|
||||
#if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_SHORT == 4 || USHRT_MAX == 0xffffffffU
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(unsigned short) == 2) {
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned short) == 4) {
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
|
||||
{
|
||||
#if defined(SIZEOF_INT) || defined(UINT_MAX)
|
||||
#if SIZEOF_INT == 2 || UINT_MAX == 0xffffU
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_INT == 4 || UINT_MAX == 0xffffffffU
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(unsigned int) == 2) {
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned int) == 4) {
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
|
||||
{
|
||||
#if defined(SIZEOF_LONG) || defined(ULONG_MAX)
|
||||
#if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_LONG == 4 || ULONG_MAX == 0xffffffffUL
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(unsigned int) == 2) {
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned int) == 4) {
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
|
||||
{
|
||||
#if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX)
|
||||
#if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_LONG_LONG == 4 || ULLONG_MAX == 0xffffffffUL
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(unsigned long long) == 2) {
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned long long) == 4) {
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef msgpack_pack_inline_func_cint
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Float
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
||||
{
|
||||
union { char buf[4]; uint32_t num; } f;
|
||||
*((float*)&f.buf) = d; // FIXME
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(f.num);
|
||||
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
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(f.num);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Nil
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_nil)(msgpack_pack_user x)
|
||||
{
|
||||
static const unsigned char d = 0xc0;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Boolean
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_true)(msgpack_pack_user x)
|
||||
{
|
||||
static const unsigned char d = 0xc3;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_false)(msgpack_pack_user x)
|
||||
{
|
||||
static const unsigned char d = 0xc2;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Array
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
||||
{
|
||||
if(n < 16) {
|
||||
unsigned char d = 0x90 | n;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
} else if(n < 65536) {
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xdc; *(uint16_t*)&buf[1] = _msgpack_be16(n);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdd; *(uint32_t*)&buf[1] = _msgpack_be32(n);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Map
|
||||
*/
|
||||
|
||||
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, &TAKE8_8(d), 1);
|
||||
} else if(n < 65536) {
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xde; *(uint16_t*)&buf[1] = _msgpack_be16(n);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdf; *(uint32_t*)&buf[1] = _msgpack_be32(n);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Raw
|
||||
*/
|
||||
|
||||
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, &TAKE8_8(d), 1);
|
||||
} else if(l < 65536) {
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xda; *(uint16_t*)&buf[1] = _msgpack_be16(l);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdb; *(uint32_t*)&buf[1] = _msgpack_be32(l);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l)
|
||||
{
|
||||
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
|
||||
}
|
||||
|
||||
#undef msgpack_pack_inline_func
|
||||
#undef msgpack_pack_user
|
||||
#undef msgpack_pack_append_buffer
|
||||
|
||||
#undef TAKE8_8
|
||||
#undef TAKE8_16
|
||||
#undef TAKE8_32
|
||||
#undef TAKE8_64
|
||||
|
||||
#undef msgpack_pack_real_uint8
|
||||
#undef msgpack_pack_real_uint16
|
||||
#undef msgpack_pack_real_uint32
|
||||
#undef msgpack_pack_real_uint64
|
||||
#undef msgpack_pack_real_int8
|
||||
#undef msgpack_pack_real_int16
|
||||
#undef msgpack_pack_real_int32
|
||||
#undef msgpack_pack_real_int64
|
||||
|
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* MessagePack system dependencies
|
||||
*
|
||||
* 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_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>
|
||||
#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
|
||||
|
||||
|
||||
#endif /* msgpack/sysdep.h */
|
||||
|
47
msgpack_vc.postbuild.bat
Normal file
47
msgpack_vc.postbuild.bat
Normal file
@@ -0,0 +1,47 @@
|
||||
IF NOT EXIST include MKDIR include
|
||||
IF NOT EXIST include\msgpack MKDIR include\msgpack
|
||||
IF NOT EXIST include\msgpack\type MKDIR include\msgpack\type
|
||||
IF NOT EXIST include\msgpack\type\tr1 MKDIR include\msgpack\type\tr1
|
||||
copy src\msgpack\pack_define.h include\msgpack\
|
||||
copy src\msgpack\pack_template.h include\msgpack\
|
||||
copy src\msgpack\unpack_define.h include\msgpack\
|
||||
copy src\msgpack\unpack_template.h include\msgpack\
|
||||
copy src\msgpack\sysdep.h include\msgpack\
|
||||
copy src\msgpack.h include\
|
||||
copy src\msgpack\sbuffer.h include\msgpack\
|
||||
copy src\msgpack\version.h include\msgpack\
|
||||
copy src\msgpack\vrefbuffer.h include\msgpack\
|
||||
copy src\msgpack\zbuffer.h include\msgpack\
|
||||
copy src\msgpack\fbuffer.h include\msgpack\
|
||||
copy src\msgpack\pack.h include\msgpack\
|
||||
copy src\msgpack\unpack.h include\msgpack\
|
||||
copy src\msgpack\object.h include\msgpack\
|
||||
copy src\msgpack\zone.h include\msgpack\
|
||||
copy src\msgpack.hpp include\
|
||||
copy src\msgpack\sbuffer.hpp include\msgpack\
|
||||
copy src\msgpack\vrefbuffer.hpp include\msgpack\
|
||||
copy src\msgpack\zbuffer.hpp include\msgpack\
|
||||
copy src\msgpack\fbuffer.hpp include\msgpack\
|
||||
copy src\msgpack\pack.hpp include\msgpack\
|
||||
copy src\msgpack\unpack.hpp include\msgpack\
|
||||
copy src\msgpack\object.hpp include\msgpack\
|
||||
copy src\msgpack\zone.hpp include\msgpack\
|
||||
copy src\msgpack\type.hpp include\msgpack\
|
||||
copy src\msgpack\type\bool.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\deque.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\fixint.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\float.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\int.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\list.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\map.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\nil.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\pair.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\raw.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\set.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\string.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\vector.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\tuple.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\define.hpp include\msgpack\type\
|
||||
copy src\msgpack\type\tr1\unordered_map.hpp include\msgpack\type\tr1\
|
||||
copy src\msgpack\type\tr1\unordered_set.hpp include\msgpack\type\tr1\
|
||||
|
20
msgpack_vc8.sln
Normal file
20
msgpack_vc8.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MessagePack", "msgpack_vc8.vcproj", "{122A2EA4-B283-4241-9655-786DE78283B2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{122A2EA4-B283-4241-9655-786DE78283B2}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{122A2EA4-B283-4241-9655-786DE78283B2}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{122A2EA4-B283-4241-9655-786DE78283B2}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{122A2EA4-B283-4241-9655-786DE78283B2}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
219
msgpack_vc8.vcproj
Normal file
219
msgpack_vc8.vcproj
Normal file
@@ -0,0 +1,219 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<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"
|
||||
Description="Gathering header files"
|
||||
CommandLine="msgpack_vc.postbuild.bat"
|
||||
Outputs="include"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="."
|
||||
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"
|
||||
OutputFile="lib\msgpackd.lib"
|
||||
/>
|
||||
<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"
|
||||
Description="Gathering header files"
|
||||
CommandLine="msgpack_vc.postbuild.bat"
|
||||
Outputs="include"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="."
|
||||
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"
|
||||
OutputFile="lib\msgpack.lib"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\objectc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\unpack.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\version.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\vrefbuffer.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\zone.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\object.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\msgpack\pack_define.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\msgpack\pack_template.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\msgpack\sysdep.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\msgpack\unpack_define.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\msgpack\unpack_template.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
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
13
perl/.gitignore
vendored
@@ -1,13 +0,0 @@
|
||||
META.yml
|
||||
Makefile
|
||||
Makefile.old
|
||||
MessagePack.bs
|
||||
MessagePack.o
|
||||
blib/
|
||||
inc/
|
||||
msgpack/
|
||||
pack.o
|
||||
pm_to_blib
|
||||
unpack.o
|
||||
MANIFEST
|
||||
ppport.h
|
@@ -1,2 +0,0 @@
|
||||
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
|
||||
git.tagpattern = perl-%v
|
42
perl/Changes
42
perl/Changes
@@ -1,42 +0,0 @@
|
||||
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
|
@@ -1,25 +0,0 @@
|
||||
\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.]+/
|
@@ -1,40 +0,0 @@
|
||||
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";
|
||||
|
||||
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';
|
||||
use_test_base;
|
||||
auto_include;
|
||||
WriteAll;
|
||||
|
@@ -1,43 +0,0 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#define NEED_newCONSTSUB
|
||||
#include "ppport.h"
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
XS(xs_pack);
|
||||
XS(xs_unpack);
|
||||
XS(xs_unpacker_new);
|
||||
XS(xs_unpacker_execute);
|
||||
XS(xs_unpacker_execute_limit);
|
||||
XS(xs_unpacker_is_finished);
|
||||
XS(xs_unpacker_data);
|
||||
XS(xs_unpacker_reset);
|
||||
XS(xs_unpacker_destroy);
|
||||
|
||||
void boot_Data__MessagePack_pack(void);
|
||||
|
||||
XS(boot_Data__MessagePack) {
|
||||
dXSARGS;
|
||||
HV * stash;
|
||||
|
||||
boot_Data__MessagePack_pack();
|
||||
|
||||
newXS("Data::MessagePack::pack", xs_pack, __FILE__);
|
||||
newXS("Data::MessagePack::unpack", xs_unpack, __FILE__);
|
||||
stash = gv_stashpvn("Data::MessagePack", strlen("Data::MessagePack"), TRUE);
|
||||
|
||||
newXS("Data::MessagePack::Unpacker::new", xs_unpacker_new, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::execute", xs_unpacker_execute, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::execute_limit", xs_unpacker_execute_limit, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::is_finished", xs_unpacker_is_finished, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::data", xs_unpacker_data, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::reset", xs_unpacker_reset, __FILE__);
|
||||
newXS("Data::MessagePack::Unpacker::DESTROY", xs_unpacker_destroy, __FILE__);
|
||||
}
|
||||
|
@@ -1,20 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
use JSON::XS;
|
||||
use Benchmark ':all';
|
||||
|
||||
my $a = [0..2**24];
|
||||
my $j = JSON::XS::encode_json($a);
|
||||
my $m = Data::MessagePack->pack($a);
|
||||
|
||||
print "-- deserialize\n";
|
||||
print "JSON::XS: $JSON::XS::VERSION\n";
|
||||
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
|
||||
cmpthese(
|
||||
-1 => {
|
||||
json => sub { JSON::XS::decode_json($j) },
|
||||
mp => sub { Data::MessagePack->unpack($m) },
|
||||
}
|
||||
);
|
||||
|
@@ -1,18 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
use JSON::XS;
|
||||
use Benchmark ':all';
|
||||
|
||||
my $a = [0..2**24];
|
||||
|
||||
print "-- serialize\n";
|
||||
print "JSON::XS: $JSON::XS::VERSION\n";
|
||||
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
|
||||
cmpthese(
|
||||
-1 => {
|
||||
json => sub { JSON::XS::encode_json($a) },
|
||||
mp => sub { Data::MessagePack->pack($a) },
|
||||
}
|
||||
);
|
||||
|
@@ -1,37 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
use Storable;
|
||||
use Text::SimpleTable;
|
||||
|
||||
my @entries = (
|
||||
'1',
|
||||
'3.14',
|
||||
'{}',
|
||||
'[]',
|
||||
"[('a')x10]",
|
||||
"{('a')x10}",
|
||||
"+{1,+{1,+{}}}",
|
||||
"+[+[+[]]]",
|
||||
);
|
||||
|
||||
my $table = Text::SimpleTable->new([15, 'src'], [9, 'storable'], [7, 'msgpack']);
|
||||
|
||||
for my $src (@entries) {
|
||||
my $e = eval $src;
|
||||
die $@ if $@;
|
||||
|
||||
$table->row(
|
||||
$src,
|
||||
length(Storable::nfreeze(ref $e ? $e : \$e)),
|
||||
length(Data::MessagePack->pack($e)),
|
||||
);
|
||||
}
|
||||
|
||||
print "perl: $]\n";
|
||||
print "Storable: $Storable::VERSION\n";
|
||||
print "Data::MessagePack: $Data::MessagePack::VERSION\n";
|
||||
print "\n";
|
||||
print $table->draw;
|
||||
|
@@ -1,60 +0,0 @@
|
||||
package Data::MessagePack;
|
||||
use strict;
|
||||
use warnings;
|
||||
use XSLoader;
|
||||
use 5.008001;
|
||||
|
||||
our $VERSION = '0.09';
|
||||
our $PreferInteger = 0;
|
||||
|
||||
our $true = do { bless \(my $dummy = 1), "Data::MessagePack::Boolean" };
|
||||
our $false = do { bless \(my $dummy = 0), "Data::MessagePack::Boolean" };
|
||||
sub true () { $true }
|
||||
sub false () { $false }
|
||||
|
||||
XSLoader::load(__PACKAGE__, $VERSION);
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Data::MessagePack - messagepack
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
my $packed = Data::MessagePack->pack($dat);
|
||||
my $unpacked = Data::MessagePack->unpack($dat);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Data::MessagePack is a binary packer for perl.
|
||||
|
||||
=head1 Configuration Variables
|
||||
|
||||
=over 4
|
||||
|
||||
=item $Data::MessagePack::PreferInteger
|
||||
|
||||
Pack the string as int when the value looks like int(EXPERIMENTAL).
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Tokuhiro Matsuno
|
||||
|
||||
=head1 THANKS TO
|
||||
|
||||
Jun Kuriyama
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the same terms as Perl itself.
|
||||
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<http://msgpack.sourceforge.jp/>
|
||||
|
@@ -1,52 +0,0 @@
|
||||
=head1 NAME
|
||||
|
||||
Data::MessagePack::Unpacker - messagepack streaming deserializer
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Data::Dumper;
|
||||
my $up = Data::MessagePack::Unpacker->new;
|
||||
my $ret = $up->execute($v, 0);
|
||||
if ($ret != length($v)) {
|
||||
fail "extra bytes";
|
||||
}
|
||||
return Dumper($up->data);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is an streaming deserializer for messagepack.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item my $up = Data::MessagePack::Unpacker->new()
|
||||
|
||||
create new stream deserializer
|
||||
|
||||
=item $up->execute()
|
||||
|
||||
=item $up->execute_limit()
|
||||
|
||||
=item $up->is_finished()
|
||||
|
||||
is this deserializer finished?
|
||||
|
||||
=item $up->data()
|
||||
|
||||
returns deserialized object.
|
||||
|
||||
=item $up->reset()
|
||||
|
||||
reset the stream deserializer, without memory zone.
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Tokuhiro Matsuno
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<Data::MessagePack>
|
||||
|
266
perl/pack.c
266
perl/pack.c
@@ -1,266 +0,0 @@
|
||||
/*
|
||||
* code is written by tokuhirom.
|
||||
* buffer alocation technique is taken from JSON::XS. thanks to mlehmann.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "ppport.h"
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#include "msgpack/pack_define.h"
|
||||
|
||||
#define msgpack_pack_inline_func(name) \
|
||||
static inline void msgpack_pack ## name
|
||||
|
||||
#define msgpack_pack_inline_func_cint(name) \
|
||||
static inline void msgpack_pack ## name
|
||||
|
||||
typedef struct {
|
||||
char *cur; /* SvPVX (sv) + current output position */
|
||||
char *end; /* SvEND (sv) */
|
||||
SV *sv; /* result scalar */
|
||||
} enc_t;
|
||||
static void need(enc_t *enc, STRLEN len);
|
||||
|
||||
#define msgpack_pack_user enc_t*
|
||||
|
||||
#define msgpack_pack_append_buffer(enc, buf, len) \
|
||||
need(enc, len); \
|
||||
memcpy(enc->cur, buf, len); \
|
||||
enc->cur += len;
|
||||
|
||||
#include "msgpack/pack_template.h"
|
||||
|
||||
#define INIT_SIZE 32 /* initial scalar size to be allocated */
|
||||
|
||||
#if IVSIZE == 8
|
||||
# define PACK_IV msgpack_pack_int64
|
||||
#elif IVSIZE == 4
|
||||
# define PACK_IV msgpack_pack_int32
|
||||
#elif IVSIZE == 2
|
||||
# define PACK_IV msgpack_pack_int16
|
||||
#else
|
||||
# error "msgpack only supports IVSIZE = 8,4,2 environment."
|
||||
#endif
|
||||
|
||||
|
||||
static void need(enc_t *enc, STRLEN len)
|
||||
{
|
||||
if (enc->cur + len >= enc->end) {
|
||||
STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
|
||||
SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
|
||||
enc->cur = SvPVX (enc->sv) + cur;
|
||||
enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int s_pref_int = 0;
|
||||
|
||||
static int pref_int_set(pTHX_ SV* sv, MAGIC* mg) {
|
||||
if (SvTRUE(sv)) {
|
||||
s_pref_int = 1;
|
||||
} else {
|
||||
s_pref_int = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MGVTBL pref_int_vtbl = {
|
||||
NULL,
|
||||
pref_int_set,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
#ifdef MGf_LOCAL
|
||||
NULL,
|
||||
#endif
|
||||
};
|
||||
|
||||
void boot_Data__MessagePack_pack(void) {
|
||||
SV* var = get_sv("Data::MessagePack::PreferInteger", 0);
|
||||
sv_magicext(var, NULL, PERL_MAGIC_ext, &pref_int_vtbl, NULL, 0);
|
||||
SvSETMAGIC(var);
|
||||
}
|
||||
|
||||
|
||||
static int try_int(enc_t* enc, const char *p, size_t len) {
|
||||
int negative = 0;
|
||||
const char* pe = p + len;
|
||||
uint64_t num = 0;
|
||||
|
||||
if (len == 0) { return 0; }
|
||||
|
||||
if (*p == '-') {
|
||||
/* length(-0x80000000) == 11 */
|
||||
if (len <= 1 || len > 11) { return 0; }
|
||||
negative = 1;
|
||||
++p;
|
||||
} else {
|
||||
/* length(0xFFFFFFFF) == 10 */
|
||||
if (len > 10) { return 0; }
|
||||
}
|
||||
|
||||
#if '9'=='8'+1 && '8'=='7'+1 && '7'=='6'+1 && '6'=='5'+1 && '5'=='4'+1 \
|
||||
&& '4'=='3'+1 && '3'=='2'+1 && '2'=='1'+1 && '1'=='0'+1
|
||||
do {
|
||||
unsigned int c = ((int)*(p++)) - '0';
|
||||
if (c > 9) { return 0; }
|
||||
num = num * 10 + c;
|
||||
} while(p < pe);
|
||||
#else
|
||||
do {
|
||||
switch (*(p++)) {
|
||||
case '0': num = num * 10 + 0; break;
|
||||
case '1': num = num * 10 + 1; break;
|
||||
case '2': num = num * 10 + 2; break;
|
||||
case '3': num = num * 10 + 3; break;
|
||||
case '4': num = num * 10 + 4; break;
|
||||
case '5': num = num * 10 + 5; break;
|
||||
case '6': num = num * 10 + 6; break;
|
||||
case '7': num = num * 10 + 7; break;
|
||||
case '8': num = num * 10 + 8; break;
|
||||
case '9': num = num * 10 + 9; break;
|
||||
default: return 0;
|
||||
}
|
||||
} while(p < pe);
|
||||
#endif
|
||||
|
||||
if (negative) {
|
||||
if (num > 0x80000000) { return 0; }
|
||||
msgpack_pack_int32(enc, ((int32_t)num) * -1);
|
||||
} else {
|
||||
if (num > 0xFFFFFFFF) { return 0; }
|
||||
msgpack_pack_uint32(enc, (uint32_t)num);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void _msgpack_pack_rv(enc_t *enc, SV* sv);
|
||||
|
||||
static void _msgpack_pack_sv(enc_t *enc, SV* sv) {
|
||||
SvGETMAGIC(sv);
|
||||
|
||||
if (sv==NULL) {
|
||||
msgpack_pack_nil(enc);
|
||||
} else if (SvPOKp(sv)) {
|
||||
STRLEN len;
|
||||
char * csv = SvPV(sv, len);
|
||||
|
||||
if (s_pref_int && try_int(enc, csv, len)) {
|
||||
return;
|
||||
} else {
|
||||
msgpack_pack_raw(enc, len);
|
||||
msgpack_pack_raw_body(enc, csv, len);
|
||||
}
|
||||
} else if (SvNOKp(sv)) {
|
||||
/* XXX long double is not supported yet. */
|
||||
msgpack_pack_double(enc, (double)SvNVX(sv));
|
||||
} else if (SvIOK_UV(sv)) {
|
||||
msgpack_pack_uint32(enc, SvUV(sv));
|
||||
} else if (SvIOKp(sv)) {
|
||||
PACK_IV(enc, SvIV(sv));
|
||||
} else if (SvROK(sv)) {
|
||||
_msgpack_pack_rv(enc, SvRV(sv));
|
||||
} else if (!SvOK(sv)) {
|
||||
msgpack_pack_nil(enc);
|
||||
} else if (isGV(sv)) {
|
||||
Perl_croak(aTHX_ "msgpack cannot pack the GV\n");
|
||||
} else {
|
||||
sv_dump(sv);
|
||||
Perl_croak(aTHX_ "msgpack for perl doesn't supported this type: %d\n", SvTYPE(sv));
|
||||
}
|
||||
}
|
||||
|
||||
static void _msgpack_pack_rv(enc_t *enc, SV* sv) {
|
||||
svtype svt;
|
||||
SvGETMAGIC(sv);
|
||||
svt = SvTYPE(sv);
|
||||
|
||||
if (SvOBJECT (sv)) {
|
||||
HV *stash = gv_stashpv ("Data::MessagePack::Boolean", 1); // TODO: cache?
|
||||
if (SvSTASH (sv) == stash) {
|
||||
if (SvIV(sv)) {
|
||||
msgpack_pack_true(enc);
|
||||
} else {
|
||||
msgpack_pack_false(enc);
|
||||
}
|
||||
} else {
|
||||
croak ("encountered object '%s', Data::MessagePack doesn't allow the object",
|
||||
SvPV_nolen(sv_2mortal(newRV_inc(sv))));
|
||||
}
|
||||
} else if (svt == SVt_PVHV) {
|
||||
HV* hval = (HV*)sv;
|
||||
int count = hv_iterinit(hval);
|
||||
HE* he;
|
||||
|
||||
msgpack_pack_map(enc, count);
|
||||
|
||||
while (he = hv_iternext(hval)) {
|
||||
_msgpack_pack_sv(enc, hv_iterkeysv(he));
|
||||
_msgpack_pack_sv(enc, HeVAL(he));
|
||||
}
|
||||
} else if (svt == SVt_PVAV) {
|
||||
AV* ary = (AV*)sv;
|
||||
int len = av_len(ary) + 1;
|
||||
int i;
|
||||
msgpack_pack_array(enc, len);
|
||||
for (i=0; i<len; i++) {
|
||||
SV** svp = av_fetch(ary, i, 0);
|
||||
if (svp) {
|
||||
_msgpack_pack_sv(enc, *svp);
|
||||
} else {
|
||||
msgpack_pack_nil(enc);
|
||||
}
|
||||
}
|
||||
} else if (svt < SVt_PVAV) {
|
||||
STRLEN len = 0;
|
||||
char *pv = svt ? SvPV (sv, len) : 0;
|
||||
|
||||
if (len == 1 && *pv == '1')
|
||||
msgpack_pack_true(enc);
|
||||
else if (len == 1 && *pv == '0')
|
||||
msgpack_pack_false(enc);
|
||||
else {
|
||||
sv_dump(sv);
|
||||
croak("cannot encode reference to scalar '%s' unless the scalar is 0 or 1",
|
||||
SvPV_nolen (sv_2mortal (newRV_inc (sv))));
|
||||
}
|
||||
} else {
|
||||
croak ("encountered %s, but msgpack can only represent references to arrays or hashes",
|
||||
SvPV_nolen (sv_2mortal (newRV_inc (sv))));
|
||||
}
|
||||
}
|
||||
|
||||
XS(xs_pack) {
|
||||
dXSARGS;
|
||||
if (items != 2) {
|
||||
Perl_croak(aTHX_ "Usage: Data::MessagePack->pack($dat)");
|
||||
}
|
||||
|
||||
SV* val = ST(1);
|
||||
|
||||
enc_t enc;
|
||||
enc.sv = sv_2mortal(NEWSV(0, INIT_SIZE));
|
||||
enc.cur = SvPVX(enc.sv);
|
||||
enc.end = SvEND(enc.sv);
|
||||
SvPOK_only(enc.sv);
|
||||
|
||||
_msgpack_pack_sv(&enc, val);
|
||||
|
||||
SvCUR_set(enc.sv, enc.cur - SvPVX (enc.sv));
|
||||
*SvEND (enc.sv) = 0; /* many xs functions expect a trailing 0 for text strings */
|
||||
|
||||
ST(0) = enc.sv;
|
||||
XSRETURN(1);
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 1;
|
||||
|
||||
use_ok 'Data::MessagePack';
|
||||
|
@@ -1,64 +0,0 @@
|
||||
use t::Util;
|
||||
use Test::More;
|
||||
use Data::MessagePack;
|
||||
|
||||
sub packit {
|
||||
local $_ = unpack("H*", Data::MessagePack->pack($_[0]));
|
||||
s/(..)/$1 /g;
|
||||
s/ $//;
|
||||
$_;
|
||||
}
|
||||
|
||||
sub pis ($$) {
|
||||
is packit($_[0]), $_[1], 'dump ' . $_[1];
|
||||
}
|
||||
|
||||
my @dat = (
|
||||
0, '00',
|
||||
(my $foo="0")+0, '00',
|
||||
{2 => undef}, '81 a1 32 c0',
|
||||
do {no warnings; my $foo = 10; "$foo"; $foo = undef; $foo} => 'c0', # PVIV but !POK && !IOK
|
||||
1, '01',
|
||||
127, '7f',
|
||||
128, 'cc 80',
|
||||
255, 'cc ff',
|
||||
256, 'cd 01 00',
|
||||
65535, 'cd ff ff',
|
||||
65536, 'ce 00 01 00 00',
|
||||
-1, 'ff',
|
||||
-32, 'e0',
|
||||
-33, 'd0 df',
|
||||
-128, 'd0 80',
|
||||
-129, 'd1 ff 7f',
|
||||
-32768, 'd1 80 00',
|
||||
-32769, 'd2 ff ff 7f ff',
|
||||
1.0, 'cb 3f f0 00 00 00 00 00 00',
|
||||
do { my $x=3.0;my $y = "$x";$x }, 'a1 33', # PVNV
|
||||
"", 'a0',
|
||||
"a", 'a1 61',
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 'bf 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61',
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 'da 00 20 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61',
|
||||
undef, 'c0',
|
||||
Data::MessagePack::true(), 'c3',
|
||||
Data::MessagePack::false(), 'c2',
|
||||
[], '90',
|
||||
[+[]], '91 90',
|
||||
[[], undef], '92 90 c0',
|
||||
{'a', 0}, '81 a1 61 00',
|
||||
8388608, 'ce 00 80 00 00',
|
||||
|
||||
[undef, false, true], '93 c0 c2 c3',
|
||||
["", "a", "bc", "def"], '94 a0 a1 61 a2 62 63 a3 64 65 66',
|
||||
[[], [[undef]]], '92 90 91 91 c0',
|
||||
[undef, false, true], '93 c0 c2 c3',
|
||||
[[0, 64, 127], [-32, -16, -1]], '92 93 00 40 7f 93 e0 f0 ff',
|
||||
[0, -128, -1, 0, -32768, -1, 0, -2147483648, -1], '99 00 d0 80 ff 00 d1 80 00 ff 00 d2 80 00 00 00 ff',
|
||||
2147483648, 'ce 80 00 00 00',
|
||||
-2147483648, 'd2 80 00 00 00',
|
||||
);
|
||||
plan tests => 1*(scalar(@dat)/2);
|
||||
|
||||
for (my $i=0; $i<scalar(@dat); ) {
|
||||
pis $dat[$i++], $dat[$i++];
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
use Test::More;
|
||||
use Data::MessagePack;
|
||||
use t::Util;
|
||||
no warnings 'uninitialized'; # i need this. i need this.
|
||||
|
||||
sub unpackit {
|
||||
my $v = $_[0];
|
||||
$v =~ s/ //g;
|
||||
$v = pack 'H*', $v;
|
||||
return Data::MessagePack->unpack($v);
|
||||
}
|
||||
|
||||
sub pis ($$) {
|
||||
is_deeply unpackit($_[0]), $_[1], 'dump ' . $_[0];
|
||||
}
|
||||
|
||||
my @dat = do 't/data.pl';
|
||||
|
||||
plan tests => 1*(scalar(@dat)/2);
|
||||
|
||||
for (my $i=0; $i<scalar(@dat); ) {
|
||||
pis $dat[$i++], $dat[$i++];
|
||||
}
|
||||
|
@@ -1,32 +0,0 @@
|
||||
use t::Util;
|
||||
use Test::More;
|
||||
use Data::MessagePack;
|
||||
|
||||
no warnings 'uninitialized'; # i need this. i need this.
|
||||
|
||||
my $up = Data::MessagePack::Unpacker->new;
|
||||
sub unpackit {
|
||||
my $v = $_[0];
|
||||
$v =~ s/ //g;
|
||||
$v = pack 'H*', $v;
|
||||
$up->reset;
|
||||
my $ret = $up->execute($v, 0);
|
||||
if ($ret != length($v)) {
|
||||
fail "extra bytes";
|
||||
}
|
||||
return $up->data;
|
||||
}
|
||||
|
||||
sub pis ($$) {
|
||||
is_deeply unpackit($_[0]), $_[1], 'dump ' . $_[0];
|
||||
}
|
||||
|
||||
my @dat = do 't/data.pl';
|
||||
|
||||
plan tests => 1*(scalar(@dat)/2) + 1;
|
||||
|
||||
isa_ok $up, 'Data::MessagePack::Unpacker';
|
||||
for (my $i=0; $i<scalar(@dat); ) {
|
||||
pis $dat[$i++], $dat[$i++];
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
use Test::More;
|
||||
use Data::MessagePack;
|
||||
use t::Util;
|
||||
no warnings 'uninitialized'; # i need this. i need this.
|
||||
|
||||
sub invert {
|
||||
return Data::MessagePack->unpack(
|
||||
Data::MessagePack->pack($_[0]),
|
||||
);
|
||||
}
|
||||
|
||||
sub pis ($) {
|
||||
is_deeply invert($_[0]), $_[0], 'dump ' . $_[0];
|
||||
}
|
||||
|
||||
my @dat = do 't/data.pl';
|
||||
|
||||
plan tests => 1*(scalar(@dat)/2);
|
||||
|
||||
for (my $i=0; $i<scalar(@dat); ) {
|
||||
$i++;
|
||||
pis $dat[$i++];
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user