mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-21 07:45:02 +02:00
Compare commits
1109 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 | ||
![]() |
2bf3f1856f | ||
![]() |
f145129f6e | ||
![]() |
8d365458d5 | ||
![]() |
55cfbf378e | ||
![]() |
d76093b148 | ||
![]() |
7873e41e00 | ||
![]() |
9817e9b18d | ||
![]() |
519716bbe4 | ||
![]() |
c2dd22ec10 | ||
![]() |
232aced926 | ||
![]() |
63b9a876b0 | ||
![]() |
5cf85a82d3 | ||
![]() |
b9f78821d4 | ||
![]() |
f4c5b15cc6 | ||
![]() |
4d33bd456c | ||
![]() |
3a5f7f53ff | ||
![]() |
1ed4236bcf | ||
![]() |
5ff2c6be74 | ||
![]() |
dd18402737 | ||
![]() |
686e8ca0f0 | ||
![]() |
5aa47d6677 | ||
![]() |
0d44348c7d | ||
![]() |
35929b46ae | ||
![]() |
ba3ba0367c | ||
![]() |
7ce866ad7c | ||
![]() |
0ae1965f6b | ||
![]() |
eb9e892491 | ||
![]() |
e39e1d4f60 | ||
![]() |
93a95725fc | ||
![]() |
4758d9f04b | ||
![]() |
d39c016e1d | ||
![]() |
5393a0df16 | ||
![]() |
68176e10f5 | ||
![]() |
c6a2569af8 | ||
![]() |
3424dc916c | ||
![]() |
c8ad32a39e | ||
![]() |
d0b76814b0 | ||
![]() |
bf3cb63d46 | ||
![]() |
8da7b692f6 | ||
![]() |
320c79db49 | ||
![]() |
ebf64d9892 | ||
![]() |
c12d5b8461 | ||
![]() |
7186edc45e | ||
![]() |
c94772104d | ||
![]() |
9374571056 | ||
![]() |
c232e91f83 | ||
![]() |
5b8777026a | ||
![]() |
51e435d46c | ||
![]() |
d3f9ab7dec | ||
![]() |
1ba330c473 | ||
![]() |
dba7f480ed | ||
![]() |
3a39accb0b | ||
![]() |
387eca6fbf | ||
![]() |
b2381d0513 | ||
![]() |
92952f6566 | ||
![]() |
a62a5d6c69 | ||
![]() |
0627324da6 | ||
![]() |
394331cd4e | ||
![]() |
0491768fb2 |
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
|
||||
export ERB
|
||||
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
|
||||
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);
|
||||
}
|
||||
```
|
72
README
72
README
@@ -1,72 +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.
|
||||
|
||||
Following programs are required to build:
|
||||
- gcc >= 4.1 with C++ support
|
||||
- ruby >= 1.8 (ruby is used as a preprocessor)
|
||||
|
||||
|
||||
*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]
|
||||
|
10
bootstrap
10
bootstrap
@@ -31,12 +31,12 @@ if test x"$1" = x"--help"; then
|
||||
fi
|
||||
|
||||
|
||||
#if [ -z "$NO_NEST" ];then
|
||||
# cd c && ./bootstrap $@; cd ..
|
||||
# cd cpp && ./bootstrap $@; cd ..
|
||||
#fi
|
||||
mkdir -p ac
|
||||
|
||||
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,20 +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 1:0:0
|
||||
|
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 $@
|
||||
|
125
c/unpack.h
125
c/unpack.h
@@ -1,125 +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"
|
||||
#include <stdint.h>
|
||||
#include <stddef.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 */
|
||||
|
135
c/vrefbuffer.c
135
c/vrefbuffer.c
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* MessagePack for C zero-copy buffer implementation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "msgpack/vrefbuffer.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
|
||||
size_t ref_size, size_t chunk_size)
|
||||
{
|
||||
if(chunk_size < sizeof(msgpack_vrefbuffer_chunk)+72) {
|
||||
chunk_size = 72;
|
||||
} else {
|
||||
chunk_size -= sizeof(msgpack_vrefbuffer_chunk);
|
||||
}
|
||||
|
||||
vbuf->chunk_size = chunk_size;
|
||||
vbuf->ref_size = ref_size;
|
||||
|
||||
// glibcは72バイト以下のmallocが高速
|
||||
size_t nfirst = (sizeof(struct iovec) < 72/2) ?
|
||||
72 / sizeof(struct iovec) : 8;
|
||||
|
||||
struct iovec* array = (struct iovec*)malloc(
|
||||
sizeof(struct iovec) * nfirst);
|
||||
if(array == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
vbuf->tail = array;
|
||||
vbuf->end = array + nfirst;
|
||||
vbuf->array = array;
|
||||
|
||||
vbuf->chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
chunk_size + sizeof(msgpack_vrefbuffer_chunk));
|
||||
if(vbuf->chunk == NULL) {
|
||||
free(array);
|
||||
return false;
|
||||
}
|
||||
|
||||
vbuf->chunk->next = NULL;
|
||||
vbuf->chunk->free = chunk_size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
|
||||
{
|
||||
msgpack_vrefbuffer_chunk* c = vbuf->chunk;
|
||||
while(true) {
|
||||
msgpack_vrefbuffer_chunk* n = c->next;
|
||||
free(c);
|
||||
if(n) {
|
||||
c = n;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(vbuf->array);
|
||||
}
|
||||
|
||||
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
|
||||
const char* buf, unsigned int len)
|
||||
{
|
||||
if(vbuf->tail == vbuf->end) {
|
||||
const size_t nused = vbuf->end - vbuf->array;
|
||||
const size_t nnext = nused * 2;
|
||||
|
||||
struct iovec* nvec = (struct iovec*)realloc(
|
||||
vbuf->array, sizeof(struct iovec)*nnext);
|
||||
if(nvec == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
vbuf->array = nvec;
|
||||
vbuf->end = nvec + nnext;
|
||||
vbuf->tail = nvec + nused;
|
||||
}
|
||||
|
||||
vbuf->tail->iov_base = (char*)buf;
|
||||
vbuf->tail->iov_len = len;
|
||||
++vbuf->tail;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
|
||||
const char* buf, unsigned int len)
|
||||
{
|
||||
msgpack_vrefbuffer_chunk* chunk = vbuf->chunk;
|
||||
size_t cur_size = vbuf->chunk_size;
|
||||
|
||||
if(chunk->free < len) {
|
||||
cur_size = (cur_size > len) ? cur_size : len;
|
||||
|
||||
chunk = (msgpack_vrefbuffer_chunk*)malloc(
|
||||
cur_size + sizeof(msgpack_vrefbuffer_chunk));
|
||||
if(chunk == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
chunk->free = cur_size;
|
||||
chunk->next = vbuf->chunk;
|
||||
vbuf->chunk = chunk;
|
||||
}
|
||||
|
||||
char* m = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk)
|
||||
+ (cur_size - chunk->free);
|
||||
|
||||
memcpy(m, buf, len);
|
||||
chunk->free -= len;
|
||||
|
||||
if(vbuf->tail != vbuf->array && m ==
|
||||
(const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
|
||||
(vbuf->tail-1)->iov_len += len;
|
||||
return 0;
|
||||
} else {
|
||||
return msgpack_vrefbuffer_append_ref(vbuf, m, len);
|
||||
}
|
||||
}
|
||||
|
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) }
|
||||
|
104
configure.in
104
configure.in
@@ -1,44 +1,100 @@
|
||||
AC_INIT(msgpack/unpack_template.h)
|
||||
AC_INIT(src/object.cpp)
|
||||
AC_CONFIG_AUX_DIR(ac)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.3.5)
|
||||
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_CHECK_PROG(ERB, erb, erb)
|
||||
if test "x$ERB" = x; then
|
||||
AC_MSG_ERROR([cannot find erb. Ruby is needed to build.])
|
||||
|
||||
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,54 +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/array.hpp \
|
||||
msgpack/type/boolean.hpp \
|
||||
msgpack/type/float.hpp \
|
||||
msgpack/type/integer.hpp \
|
||||
msgpack/type/map.hpp \
|
||||
msgpack/type/nil.hpp \
|
||||
msgpack/type/raw.hpp \
|
||||
msgpack/type/tuple.hpp \
|
||||
msgpack/type/define.hpp
|
||||
|
||||
# FIXME
|
||||
object.lo: msgpack/type/tuple.hpp msgpack/zone.hpp
|
||||
|
||||
msgpack/type/tuple.hpp: msgpack/type/tuple.hpp.erb
|
||||
$(ERB) $< > $@.tmp
|
||||
mv $@.tmp $@
|
||||
|
||||
msgpack/type/define.hpp: msgpack/type/define.hpp.erb
|
||||
$(ERB) $< > $@.tmp
|
||||
mv $@.tmp $@
|
||||
|
||||
msgpack/zone.hpp: msgpack/zone.hpp.erb
|
||||
$(ERB) $< > $@.tmp
|
||||
mv $@.tmp $@
|
||||
|
||||
MOSTLYCLEANFILES = \
|
||||
msgpack/type/tuple.hpp \
|
||||
msgpack/type/define.hpp \
|
||||
msgpack/zone.hpp
|
||||
|
||||
EXTRA_DIST = \
|
||||
msgpack/type/tuple.hpp.erb \
|
||||
msgpack/type/define.hpp.erb \
|
||||
msgpack/zone.hpp.erb
|
||||
|
||||
libmsgpack_la_LIBADD = -L../c -lmsgpackc
|
||||
|
||||
# -version-info CURRENT:REVISION:AGE
|
||||
libmsgpack_la_LDFLAGS = -version-info 1:0:0
|
||||
|
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 @@
|
||||
.
|
201
cpp/test.cpp
201
cpp/test.cpp
@@ -1,201 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <msgpack.hpp>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
using namespace msgpack;
|
||||
|
||||
class checker {
|
||||
public:
|
||||
template <typename T>
|
||||
void check(const char* d, size_t len, T should) {
|
||||
try {
|
||||
std::cout << "----" << std::endl;
|
||||
|
||||
object o;
|
||||
try {
|
||||
o = unpack(d, len, m_zone);
|
||||
} catch (std::runtime_error& e) {
|
||||
std::cout << o << std::endl;
|
||||
std::cout << "**" << e.what() << "**" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << o << std::endl;
|
||||
|
||||
try {
|
||||
std::stringstream s;
|
||||
pack(s, should);
|
||||
std::string str(s.str());
|
||||
object ro = unpack(str.data(), str.size(), m_zone);
|
||||
std::cout << ro << std::endl;
|
||||
if(ro != o) { throw std::runtime_error("NOT MATCH"); }
|
||||
} catch (std::runtime_error& e) {
|
||||
std::cout << "** REUNPACK FAILED **" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "** REUNPACK FAILED **" << std::endl;
|
||||
std::cout << "unknown error" << std::endl;
|
||||
}
|
||||
|
||||
} catch (...) { m_zone.clear(); throw; }
|
||||
m_zone.clear();
|
||||
}
|
||||
private:
|
||||
zone m_zone;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
checker c;
|
||||
|
||||
#if 0
|
||||
{ // SimpleValue
|
||||
const char d[] = {
|
||||
0x93, 0xc0, 0xc2, 0xc3,
|
||||
};
|
||||
c.check(d, sizeof(d),
|
||||
type::make_tuple(
|
||||
type::nil(), false, true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
{ // Fixnum
|
||||
const char d[] = {
|
||||
0x92,
|
||||
0x93, 0x00, 0x40, 0x7f,
|
||||
0x93, 0xe0, 0xf0, 0xff,
|
||||
};
|
||||
c.check(d, sizeof(d),
|
||||
type::make_tuple(
|
||||
type::make_tuple(
|
||||
0, 64, 127
|
||||
),
|
||||
type::make_tuple(
|
||||
-32, -16, -1
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
{ // FixArray
|
||||
const char d[] = {
|
||||
0x92,
|
||||
0x90,
|
||||
0x91,
|
||||
0x91, 0xc0,
|
||||
};
|
||||
std::vector<int> empty;
|
||||
c.check(d, sizeof(d),
|
||||
type::make_tuple(
|
||||
empty,
|
||||
type::make_tuple(
|
||||
type::make_tuple(
|
||||
type::nil()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
{ // FixRaw
|
||||
const char d[] = {
|
||||
0x94,
|
||||
0xa0,
|
||||
0xa1, 'a',
|
||||
0xa2, 'b', 'c',
|
||||
0xa3, 'd', 'e', 'f',
|
||||
};
|
||||
c.check(d, sizeof(d),
|
||||
type::make_tuple(
|
||||
std::string(""),
|
||||
std::string("a"),
|
||||
std::string("bc"),
|
||||
type::raw_ref("def", 3)
|
||||
)
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static const unsigned TASK_ARRAY = 1000;
|
||||
static const unsigned TASK_REPEAT = 10;
|
||||
std::vector<std::string> task;
|
||||
|
||||
// create task
|
||||
{
|
||||
static char traw[64];
|
||||
memset(traw, 'a', sizeof(traw));
|
||||
|
||||
task.resize(TASK_ARRAY);
|
||||
for(unsigned i=0; i < TASK_ARRAY; ++i) {
|
||||
task[i] = std::string(traw, sizeof(traw));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::stringstream stream;
|
||||
|
||||
// send message
|
||||
{
|
||||
for(unsigned i=0; i < TASK_REPEAT; ++i) {
|
||||
pack(stream, task);
|
||||
}
|
||||
std::cout << "send " << stream.str().size() << " bytes" << std::endl;
|
||||
}
|
||||
|
||||
ssize_t total_bytes = stream.str().size();
|
||||
stream.seekg(0);
|
||||
|
||||
// reserive message
|
||||
{
|
||||
unsigned num_msg = 0;
|
||||
static const size_t RESERVE_SIZE = 32;//*1024;
|
||||
|
||||
unpacker pac;
|
||||
|
||||
while(stream.good() && total_bytes > 0) {
|
||||
|
||||
// 1. reserve buffer
|
||||
pac.reserve_buffer(RESERVE_SIZE);
|
||||
|
||||
// 2. read data to buffer() up to buffer_capacity() bytes
|
||||
size_t sz = stream.readsome(
|
||||
pac.buffer(),
|
||||
pac.buffer_capacity());
|
||||
|
||||
total_bytes -= sz;
|
||||
std::cout << "read " << sz << " bytes to capacity "
|
||||
<< pac.buffer_capacity() << " bytes"
|
||||
<< std::endl;
|
||||
|
||||
// 3. specify the number of bytes actually copied
|
||||
pac.buffer_consumed(sz);
|
||||
|
||||
// 4. repeat execute() until it returns false
|
||||
while( pac.execute() ) {
|
||||
// 5.1. take out the parsed object
|
||||
object o = pac.data();
|
||||
|
||||
// 5.2 release the zone
|
||||
std::auto_ptr<zone> olife( pac.release_zone() );
|
||||
|
||||
// 5.3 re-initialize the unpacker */
|
||||
pac.reset();
|
||||
|
||||
// do some with the o and olife
|
||||
std::cout << "message parsed: " << o << std::endl;
|
||||
++num_msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::cout << "stream finished" << std::endl;
|
||||
std::cout << num_msg << " messages reached" << std::endl;
|
||||
}
|
||||
|
||||
return 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 $@
|
||||
|
10
cpp/type.hpp
10
cpp/type.hpp
@@ -1,10 +0,0 @@
|
||||
#include "msgpack/type/array.hpp"
|
||||
#include "msgpack/type/boolean.hpp"
|
||||
#include "msgpack/type/float.hpp"
|
||||
#include "msgpack/type/integer.hpp"
|
||||
#include "msgpack/type/map.hpp"
|
||||
#include "msgpack/type/nil.hpp"
|
||||
#include "msgpack/type/raw.hpp"
|
||||
#include "msgpack/type/tuple.hpp"
|
||||
#include "msgpack/type/define.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_INTEGER_HPP__
|
||||
#define MSGPACK_TYPE_INTEGER_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>::max())
|
||||
{ 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/integer.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
|
||||
|
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}
|
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
|
37
perl/Changes
37
perl/Changes
@@ -1,37 +0,0 @@
|
||||
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,23 +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$
|
||||
ppport.h
|
@@ -1,39 +0,0 @@
|
||||
use inc::Module::Install;
|
||||
name 'Data-MessagePack';
|
||||
all_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,50 +0,0 @@
|
||||
package Data::MessagePack;
|
||||
use strict;
|
||||
use warnings;
|
||||
use XSLoader;
|
||||
use 5.008001;
|
||||
|
||||
our $VERSION = '0.08';
|
||||
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 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>
|
||||
|
256
perl/pack.c
256
perl/pack.c
@@ -1,256 +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 _PACK_WRAPPER(t) msgpack_pack_##t
|
||||
#define PACK_WRAPPER(t) _PACK_WRAPPER(t)
|
||||
#define INIT_SIZE 32 /* initial scalar size to be allocated */
|
||||
|
||||
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)) {
|
||||
PACK_WRAPPER(NVTYPE)(enc, SvNVX(sv));
|
||||
} else if (SvIOK_UV(sv)) {
|
||||
msgpack_pack_uint32(enc, SvUV(sv));
|
||||
} else if (SvIOKp(sv)) {
|
||||
PACK_WRAPPER(IVTYPE)(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++];
|
||||
}
|
||||
|
@@ -1,57 +0,0 @@
|
||||
use t::Util;
|
||||
use Test::More;
|
||||
use Data::MessagePack;
|
||||
use Data::Dumper;
|
||||
no warnings; # shut up "Integer overflow in hexadecimal number"
|
||||
|
||||
sub packit {
|
||||
local $_ = unpack("H*", Data::MessagePack->pack($_[0]));
|
||||
s/(..)/$1 /g;
|
||||
s/ $//;
|
||||
$_;
|
||||
}
|
||||
|
||||
sub pis ($$) {
|
||||
is packit($_[0]), $_[1], 'dump ' . $_[1];
|
||||
# is(Dumper(Data::MessagePack->unpack(Data::MessagePack->pack($_[0]))), Dumper($_[0]));
|
||||
}
|
||||
|
||||
my @dat = (
|
||||
'', 'a0',
|
||||
'0', '00',
|
||||
'1', '01',
|
||||
'10', '0a',
|
||||
'-1', 'ff',
|
||||
'-10', 'f6',
|
||||
'-', 'a1 2d',
|
||||
''.0xEFFF => 'cd ef ff',
|
||||
''.0xFFFF => 'cd ff ff',
|
||||
''.0xFFFFFF => 'ce 00 ff ff ff',
|
||||
''.0xFFFFFFFF => 'ce ff ff ff ff',
|
||||
''.0xFFFFFFFFF => 'ab 36 38 37 31 39 34 37 36 37 33 35',
|
||||
''.0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => 'b4 38 2e 33 30 37 36 37 34 39 37 33 36 35 35 37 32 65 2b 33 34',
|
||||
'-'.0x8000000 => 'd2 f8 00 00 00',
|
||||
'-'.0x80000000 => 'd2 80 00 00 00',
|
||||
'-'.0x800000000 => 'ac 2d 33 34 33 35 39 37 33 38 33 36 38',
|
||||
'-'.0x8000000000 => 'ad 2d 35 34 39 37 35 35 38 31 33 38 38 38',
|
||||
'-'.0x800000000000000000000000000000 => 'b5 2d 36 2e 36 34 36 31 33 39 39 37 38 39 32 34 35 38 65 2b 33 35',
|
||||
{'0' => '1'}, '81 00 01',
|
||||
{'abc' => '1'}, '81 a3 61 62 63 01',
|
||||
);
|
||||
plan tests => 1*(scalar(@dat)/2) + 2;
|
||||
|
||||
for (my $i=0; $i<scalar(@dat); ) {
|
||||
local $Data::MessagePack::PreferInteger = 1;
|
||||
my($x, $y) = ($i++, $i++);
|
||||
pis $dat[$x], $dat[$y];
|
||||
}
|
||||
|
||||
# flags working?
|
||||
{
|
||||
local $Data::MessagePack::PreferInteger;
|
||||
$Data::MessagePack::PreferInteger = 1;
|
||||
pis '0', '00';
|
||||
$Data::MessagePack::PreferInteger = 0;
|
||||
pis '0', 'a1 30';
|
||||
}
|
||||
|
@@ -1,20 +0,0 @@
|
||||
package t::Util;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub import {
|
||||
my $pkg = caller(0);
|
||||
|
||||
strict->import;
|
||||
warnings->import;
|
||||
|
||||
no strict 'refs';
|
||||
*{"$pkg\::true"} = sub () {
|
||||
Data::MessagePack::true()
|
||||
};
|
||||
*{"$pkg\::false"} = sub () {
|
||||
Data::MessagePack::false()
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
@@ -1,18 +0,0 @@
|
||||
no warnings; # i need this, i need this.
|
||||
(
|
||||
'93 c0 c2 c3' => [undef, false, true],
|
||||
'94 a0 a1 61 a2 62 63 a3 64 65 66', ["", "a", "bc", "def"],
|
||||
'92 90 91 91 c0', [[], [[undef]]],
|
||||
'93 c0 c2 c3', [undef, false, true],
|
||||
'ce 80 00 00 00', 2147483648,
|
||||
'99 cc 00 cc 80 cc ff cd 00 00 cd 80 00 cd ff ff ce 00 00 00 00 ce 80 00 00 00 ce ff ff ff ff', [0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295],
|
||||
'92 93 00 40 7f 93 e0 f0 ff', [[0, 64, 127], [-32, -16, -1]],
|
||||
'96 dc 00 00 dc 00 01 c0 dc 00 02 c2 c3 dd 00 00 00 00 dd 00 00 00 01 c0 dd 00 00 00 02 c2 c3', [[], [undef], [false, true], [], [undef], [false, true]],
|
||||
'96 da 00 00 da 00 01 61 da 00 02 61 62 db 00 00 00 00 db 00 00 00 01 61 db 00 00 00 02 61 62', ["", "a", "ab", "", "a", "ab"],
|
||||
'99 d0 00 d0 80 d0 ff d1 00 00 d1 80 00 d1 ff ff d2 00 00 00 00 d2 80 00 00 00 d2 ff ff ff ff', [0, -128, -1, 0, -32768, -1, 0, -2147483648, -1],
|
||||
'82 c2 81 c0 c0 c3 81 c0 80', {false,{undef,undef}, true,{undef,{}}},
|
||||
'96 de 00 00 de 00 01 c0 c2 de 00 02 c0 c2 c3 c2 df 00 00 00 00 df 00 00 00 01 c0 c2 df 00 00 00 02 c0 c2 c3 c2', [{}, {undef,false}, {true,false, undef,false}, {}, {undef,false}, {true,false, undef,false}],
|
||||
'ce 00 ff ff ff' => ''.0xFFFFFF,
|
||||
'aa 34 32 39 34 39 36 37 32 39 35' => ''.0xFFFFFFFF,
|
||||
'ab 36 38 37 31 39 34 37 36 37 33 35' => ''.0xFFFFFFFFF,
|
||||
)
|
317
perl/unpack.c
317
perl/unpack.c
@@ -1,317 +0,0 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "util.h"
|
||||
#define NEED_newRV_noinc
|
||||
#define NEED_sv_2pv_flags
|
||||
#include "ppport.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int finished;
|
||||
SV* source;
|
||||
} unpack_user;
|
||||
|
||||
#include "msgpack/unpack_define.h"
|
||||
|
||||
#define msgpack_unpack_struct(name) \
|
||||
struct template ## name
|
||||
|
||||
#define msgpack_unpack_func(ret, name) \
|
||||
ret template ## name
|
||||
|
||||
#define msgpack_unpack_callback(name) \
|
||||
template_callback ## name
|
||||
|
||||
#define msgpack_unpack_object SV*
|
||||
|
||||
#define msgpack_unpack_user unpack_user
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* utility functions */
|
||||
|
||||
static INLINE SV *
|
||||
get_bool (const char *name) {
|
||||
SV * sv = get_sv( name, 1 );
|
||||
|
||||
SvREADONLY_on(sv);
|
||||
SvREADONLY_on( SvRV(sv) );
|
||||
|
||||
return sv;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
struct template_context;
|
||||
typedef struct template_context msgpack_unpack_t;
|
||||
|
||||
static void template_init(msgpack_unpack_t* u);
|
||||
|
||||
static SV* template_data(msgpack_unpack_t* u);
|
||||
|
||||
static int template_execute(msgpack_unpack_t* u,
|
||||
const char* data, size_t len, size_t* off);
|
||||
|
||||
static INLINE SV* template_callback_root(unpack_user* u)
|
||||
{ return &PL_sv_undef; }
|
||||
|
||||
static INLINE int template_callback_uint8(unpack_user* u, uint8_t d, SV** o)
|
||||
{ *o = newSVuv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_uint16(unpack_user* u, uint16_t d, SV** o)
|
||||
{ *o = newSVuv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_uint32(unpack_user* u, uint32_t d, SV** o)
|
||||
{ *o = newSVuv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_uint64(unpack_user* u, uint64_t d, SV** o)
|
||||
{ *o = newSVuv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_int8(unpack_user* u, int8_t d, SV** o)
|
||||
{ *o = newSViv((long)d); return 0; }
|
||||
|
||||
static INLINE int template_callback_int16(unpack_user* u, int16_t d, SV** o)
|
||||
{ *o = newSViv((long)d); return 0; }
|
||||
|
||||
static INLINE int template_callback_int32(unpack_user* u, int32_t d, SV** o)
|
||||
{ *o = newSViv((long)d); return 0; }
|
||||
|
||||
static INLINE int template_callback_int64(unpack_user* u, int64_t d, SV** o)
|
||||
{ *o = newSViv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_float(unpack_user* u, float d, SV** o)
|
||||
{ *o = newSVnv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_double(unpack_user* u, double d, SV** o)
|
||||
{ *o = newSVnv(d); return 0; }
|
||||
|
||||
static INLINE int template_callback_nil(unpack_user* u, SV** o)
|
||||
{ *o = &PL_sv_undef; return 0; }
|
||||
|
||||
static INLINE int template_callback_true(unpack_user* u, SV** o)
|
||||
{ *o = get_bool("Data::MessagePack::true") ; return 0; }
|
||||
|
||||
static INLINE int template_callback_false(unpack_user* u, SV** o)
|
||||
{ *o = get_bool("Data::MessagePack::false") ; return 0; }
|
||||
|
||||
static INLINE int template_callback_array(unpack_user* u, unsigned int n, SV** o)
|
||||
{ AV* a = newAV(); *o = (SV*)newRV_noinc((SV*)a); av_extend(a, n); return 0; }
|
||||
|
||||
static INLINE int template_callback_array_item(unpack_user* u, SV** c, SV* o)
|
||||
{ av_push((AV*)SvRV(*c), o); SvREFCNT_inc(o); return 0; } /* FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++] */
|
||||
|
||||
static INLINE int template_callback_map(unpack_user* u, unsigned int n, SV** o)
|
||||
{ HV * h = newHV(); *o = newRV_noinc((SV*)h); return 0; }
|
||||
|
||||
static INLINE int template_callback_map_item(unpack_user* u, SV** c, SV* k, SV* v)
|
||||
{ hv_store_ent((HV*)SvRV(*c), k, v, 0); SvREFCNT_inc(v); return 0; }
|
||||
|
||||
static INLINE int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, SV** o)
|
||||
{ *o = (l == 0) ? newSVpv("", 0) : newSVpv(p, l); return 0; }
|
||||
|
||||
#define UNPACKER(from, name) \
|
||||
msgpack_unpack_t *name; \
|
||||
name = INT2PTR(msgpack_unpack_t*, SvROK((from)) ? SvIV(SvRV((from))) : SvIV((from))); \
|
||||
if(name == NULL) { \
|
||||
Perl_croak(aTHX_ "NULL found for " # name " when shouldn't be."); \
|
||||
}
|
||||
|
||||
#include "msgpack/unpack_template.h"
|
||||
|
||||
SV* _msgpack_unpack(SV* data, int limit) {
|
||||
msgpack_unpack_t mp;
|
||||
unpack_user u = {0, &PL_sv_undef};
|
||||
int ret;
|
||||
size_t from = 0;
|
||||
STRLEN dlen;
|
||||
const char * dptr = SvPV_const(data, dlen);
|
||||
|
||||
template_init(&mp);
|
||||
mp.user = u;
|
||||
|
||||
mp.user.source = data;
|
||||
ret = template_execute(&mp, dptr, (size_t)dlen, &from);
|
||||
mp.user.source = &PL_sv_undef;
|
||||
|
||||
if(ret < 0) {
|
||||
Perl_croak(aTHX_ "parse error.");
|
||||
} else if(ret == 0) {
|
||||
Perl_croak(aTHX_ "insufficient bytes.");
|
||||
} else {
|
||||
if(from < dlen) {
|
||||
Perl_croak(aTHX_ "extra bytes.");
|
||||
}
|
||||
return template_data(&mp);
|
||||
}
|
||||
}
|
||||
|
||||
XS(xs_unpack_limit) {
|
||||
dXSARGS;
|
||||
|
||||
if (items != 3) {
|
||||
Perl_croak(aTHX_ "Usage: Data::MessagePack->unpack('datadata', $limit)");
|
||||
}
|
||||
|
||||
{
|
||||
int limit = SvIV(ST(2));
|
||||
ST(0) = _msgpack_unpack(ST(1), limit);
|
||||
}
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
|
||||
XS(xs_unpack) {
|
||||
dXSARGS;
|
||||
msgpack_unpack_t mp;
|
||||
|
||||
if (items != 2) {
|
||||
Perl_croak(aTHX_ "Usage: Data::MessagePack->unpack('datadata')");
|
||||
}
|
||||
|
||||
{
|
||||
ST(0) = _msgpack_unpack(ST(1), sv_len(ST(1)));
|
||||
}
|
||||
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
/* ------------------------------ stream -- */
|
||||
|
||||
static void _reset(SV* self) {
|
||||
UNPACKER(self, mp);
|
||||
template_init(mp);
|
||||
unpack_user u = {0, &PL_sv_undef};
|
||||
mp->user = u;
|
||||
}
|
||||
|
||||
XS(xs_unpacker_new) {
|
||||
dXSARGS;
|
||||
if (items != 1) {
|
||||
Perl_croak(aTHX_ "Usage: Data::MessagePack::Unpacker->new()");
|
||||
}
|
||||
|
||||
SV* self = sv_newmortal();
|
||||
msgpack_unpack_t *mp;
|
||||
|
||||
Newx(mp, 1, msgpack_unpack_t);
|
||||
|
||||
sv_setref_pv(self, "Data::MessagePack::Unpacker", mp);
|
||||
_reset(self);
|
||||
|
||||
ST(0) = self;
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
static SV* _execute_impl(SV* self, SV* data, UV off, I32 limit) {
|
||||
UNPACKER(self, mp);
|
||||
|
||||
size_t from = off;
|
||||
const char* dptr = SvPV_nolen_const(data);
|
||||
long dlen = limit;
|
||||
int ret;
|
||||
|
||||
if(from >= dlen) {
|
||||
Perl_croak(aTHX_ "offset is bigger than data buffer size.");
|
||||
}
|
||||
|
||||
mp->user.source = data;
|
||||
ret = template_execute(mp, dptr, (size_t)dlen, &from);
|
||||
mp->user.source = &PL_sv_undef;
|
||||
|
||||
if(ret < 0) {
|
||||
Perl_croak(aTHX_ "parse error.");
|
||||
} else if(ret > 0) {
|
||||
mp->user.finished = 1;
|
||||
return newSVuv(from);
|
||||
} else {
|
||||
mp->user.finished = 0;
|
||||
return newSVuv(from);
|
||||
}
|
||||
}
|
||||
|
||||
XS(xs_unpacker_execute) {
|
||||
dXSARGS;
|
||||
if (items != 3) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->execute_limit(data, off)");
|
||||
}
|
||||
|
||||
{
|
||||
SV* self = ST(0);
|
||||
SV* data = ST(1);
|
||||
IV off = SvIV(ST(2));
|
||||
|
||||
ST(0) = _execute_impl(self, data, off, sv_len(data));
|
||||
}
|
||||
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(xs_unpacker_execute_limit) {
|
||||
dXSARGS;
|
||||
if (items != 4) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->execute_limit(data, off, limit)");
|
||||
}
|
||||
|
||||
SV* self = ST(0);
|
||||
SV* data = ST(1);
|
||||
IV off = SvIV(ST(2));
|
||||
IV limit = SvIV(ST(3));
|
||||
|
||||
ST(0) = _execute_impl(self, data, off, limit);
|
||||
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(xs_unpacker_is_finished) {
|
||||
dXSARGS;
|
||||
if (items != 1) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->is_finished()");
|
||||
}
|
||||
|
||||
UNPACKER(ST(0), mp);
|
||||
ST(0) = (mp->user.finished) ? &PL_sv_yes : &PL_sv_no;
|
||||
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(xs_unpacker_data) {
|
||||
dXSARGS;
|
||||
if (items != 1) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->data()");
|
||||
}
|
||||
|
||||
UNPACKER(ST(0), mp);
|
||||
ST(0) = template_data(mp);
|
||||
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(xs_unpacker_reset) {
|
||||
dXSARGS;
|
||||
if (items != 1) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->reset()");
|
||||
}
|
||||
|
||||
_reset(ST(0));
|
||||
|
||||
XSRETURN(0);
|
||||
}
|
||||
|
||||
XS(xs_unpacker_destroy) {
|
||||
dXSARGS;
|
||||
if (items != 1) {
|
||||
Perl_croak(aTHX_ "Usage: $unpacker->DESTROY()");
|
||||
}
|
||||
|
||||
UNPACKER(ST(0), mp);
|
||||
Safefree(mp);
|
||||
|
||||
XSRETURN(0);
|
||||
}
|
11
perl/util.h
11
perl/util.h
@@ -1,11 +0,0 @@
|
||||
#ifndef __PERL_MSGPACK_UTIL_H__
|
||||
#define __PERL_MSGPACK_UTIL_H__
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
# define INLINE inline
|
||||
#else
|
||||
# define INLINE
|
||||
#endif
|
||||
|
||||
#endif // __PERL_MSGPACK_UTIL_H__
|
||||
|
@@ -1,4 +0,0 @@
|
||||
use Test::More;
|
||||
eval "use Test::Pod 1.00";
|
||||
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
|
||||
all_pod_files_ok();
|
17
preprocess
Executable file
17
preprocess
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
preprocess() {
|
||||
ruby -r erb -e 'puts ERB.new(ARGF.read).result' $1.erb > $1.tmp
|
||||
if [ "$?" != 0 ]; then
|
||||
echo ""
|
||||
echo "** preprocess failed **"
|
||||
echo ""
|
||||
exit 1
|
||||
else
|
||||
mv $1.tmp $1
|
||||
fi
|
||||
}
|
||||
|
||||
preprocess src/msgpack/type/tuple.hpp
|
||||
preprocess src/msgpack/type/define.hpp
|
||||
preprocess src/msgpack/zone.hpp
|
@@ -1,9 +0,0 @@
|
||||
setup.py
|
||||
msgpack/pack.h
|
||||
msgpack/unpack.h
|
||||
msgpack/_msgpack.pyx
|
||||
msgpack/__init__.py
|
||||
msgpack/pack_define.h
|
||||
msgpack/pack_template.h
|
||||
msgpack/unpack_define.h
|
||||
msgpack/unpack_template.h
|
@@ -1,8 +0,0 @@
|
||||
all:
|
||||
python setup.py build_ext -i -f
|
||||
python setup.py build
|
||||
python setup.py sdist
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
nosetests test
|
@@ -1,38 +0,0 @@
|
||||
===========================
|
||||
MessagePack Python Binding
|
||||
===========================
|
||||
|
||||
:author: Naoki INADA
|
||||
:version: 0.1.0
|
||||
:date: 2009-07-12
|
||||
|
||||
HOW TO USE
|
||||
-----------
|
||||
You can read document in docstring after `import msgpack`
|
||||
|
||||
|
||||
INSTALL
|
||||
---------
|
||||
Cython_ is required to build msgpack.
|
||||
|
||||
.. _Cython: http://www.cython.org/
|
||||
|
||||
posix
|
||||
''''''
|
||||
You can install msgpack in common way.
|
||||
|
||||
$ python setup.py install
|
||||
|
||||
Windows
|
||||
''''''''
|
||||
MessagePack requires gcc currently. So you need to prepare
|
||||
MinGW GCC.
|
||||
|
||||
$ python setup.py install -c mingw32
|
||||
|
||||
TEST
|
||||
----
|
||||
MessagePack uses nosetest for testing.
|
||||
Run test with following command:
|
||||
|
||||
$ nosetests test
|
@@ -1,3 +0,0 @@
|
||||
# coding: utf-8
|
||||
from _msgpack import *
|
||||
|
@@ -1,321 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
import cStringIO
|
||||
|
||||
cdef extern from "Python.h":
|
||||
ctypedef char* const_char_ptr "const char*"
|
||||
ctypedef struct PyObject
|
||||
|
||||
cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len)
|
||||
cdef PyObject* Py_True
|
||||
cdef PyObject* Py_False
|
||||
|
||||
cdef char* PyString_AsString(object o)
|
||||
cdef long long PyLong_AsLongLong(object o)
|
||||
cdef unsigned long long PyLong_AsUnsignedLongLong(object o)
|
||||
|
||||
cdef int PyMapping_Check(object o)
|
||||
cdef int PySequence_Check(object o)
|
||||
cdef int PyLong_Check(object o)
|
||||
cdef int PyInt_Check(object o)
|
||||
cdef int PyFloat_Check(object o)
|
||||
cdef int PyString_Check(object o)
|
||||
cdef int PyUnicode_Check(object o)
|
||||
|
||||
cdef extern from "stdlib.h":
|
||||
void* malloc(size_t)
|
||||
void* realloc(void*, size_t)
|
||||
void free(void*)
|
||||
|
||||
cdef extern from "string.h":
|
||||
void* memcpy(char* dst, char* src, size_t size)
|
||||
void* memmove(char* dst, char* src, size_t size)
|
||||
|
||||
cdef extern from "pack.h":
|
||||
struct msgpack_packer:
|
||||
char* buf
|
||||
size_t length
|
||||
size_t buf_size
|
||||
|
||||
int msgpack_pack_int(msgpack_packer* pk, int d)
|
||||
int msgpack_pack_nil(msgpack_packer* pk)
|
||||
int msgpack_pack_true(msgpack_packer* pk)
|
||||
int msgpack_pack_false(msgpack_packer* pk)
|
||||
int msgpack_pack_long(msgpack_packer* pk, long d)
|
||||
int msgpack_pack_long_long(msgpack_packer* pk, long long d)
|
||||
int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d)
|
||||
int msgpack_pack_double(msgpack_packer* pk, double d)
|
||||
int msgpack_pack_array(msgpack_packer* pk, size_t l)
|
||||
int msgpack_pack_map(msgpack_packer* pk, size_t l)
|
||||
int msgpack_pack_raw(msgpack_packer* pk, size_t l)
|
||||
int msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l)
|
||||
|
||||
|
||||
cdef class Packer(object):
|
||||
"""MessagePack Packer
|
||||
|
||||
usage:
|
||||
|
||||
packer = Packer()
|
||||
astream.write(packer.pack(a))
|
||||
astream.write(packer.pack(b))
|
||||
"""
|
||||
cdef msgpack_packer pk
|
||||
|
||||
def __cinit__(self):
|
||||
cdef int buf_size = 1024*1024
|
||||
self.pk.buf = <char*> malloc(buf_size);
|
||||
self.pk.buf_size = buf_size
|
||||
self.pk.length = 0
|
||||
|
||||
def __dealloc__(self):
|
||||
free(self.pk.buf);
|
||||
|
||||
cdef int __pack(self, object o):
|
||||
cdef long long llval
|
||||
cdef unsigned long long ullval
|
||||
cdef long longval
|
||||
cdef double fval
|
||||
cdef char* rawval
|
||||
cdef int ret
|
||||
|
||||
if o is None:
|
||||
ret = msgpack_pack_nil(&self.pk)
|
||||
elif <PyObject*>o == Py_True:
|
||||
ret = msgpack_pack_true(&self.pk)
|
||||
elif <PyObject*>o == Py_False:
|
||||
ret = msgpack_pack_false(&self.pk)
|
||||
elif PyLong_Check(o):
|
||||
if o > 0:
|
||||
ullval = PyLong_AsUnsignedLongLong(o)
|
||||
ret = msgpack_pack_unsigned_long_long(&self.pk, ullval)
|
||||
else:
|
||||
llval = PyLong_AsLongLong(o)
|
||||
ret = msgpack_pack_long_long(&self.pk, llval)
|
||||
elif PyInt_Check(o):
|
||||
longval = o
|
||||
ret = msgpack_pack_long(&self.pk, longval)
|
||||
elif PyFloat_Check(o):
|
||||
fval = o
|
||||
ret = msgpack_pack_double(&self.pk, fval)
|
||||
elif PyString_Check(o):
|
||||
rawval = o
|
||||
ret = msgpack_pack_raw(&self.pk, len(o))
|
||||
if ret == 0:
|
||||
ret = msgpack_pack_raw_body(&self.pk, rawval, len(o))
|
||||
elif PyUnicode_Check(o):
|
||||
o = o.encode('utf-8')
|
||||
rawval = o
|
||||
ret = msgpack_pack_raw(&self.pk, len(o))
|
||||
if ret == 0:
|
||||
ret = msgpack_pack_raw_body(&self.pk, rawval, len(o))
|
||||
elif PyMapping_Check(o):
|
||||
ret = msgpack_pack_map(&self.pk, len(o))
|
||||
if ret == 0:
|
||||
for k,v in o.iteritems():
|
||||
ret = self.__pack(k)
|
||||
if ret != 0: break
|
||||
ret = self.__pack(v)
|
||||
if ret != 0: break
|
||||
elif PySequence_Check(o):
|
||||
ret = msgpack_pack_array(&self.pk, len(o))
|
||||
if ret == 0:
|
||||
for v in o:
|
||||
ret = self.__pack(v)
|
||||
if ret != 0: break
|
||||
else:
|
||||
# TODO: Serialize with defalt() like simplejson.
|
||||
raise TypeError, "can't serialize %r" % (o,)
|
||||
return ret
|
||||
|
||||
def pack(self, object obj):
|
||||
cdef int ret
|
||||
ret = self.__pack(obj)
|
||||
if ret:
|
||||
raise TypeError
|
||||
buf = PyString_FromStringAndSize(self.pk.buf, self.pk.length)
|
||||
self.pk.length = 0
|
||||
return buf
|
||||
|
||||
|
||||
def pack(object o, object stream):
|
||||
"""pack an object `o` and write it to stream)."""
|
||||
packer = Packer()
|
||||
stream.write(packer.pack(o))
|
||||
|
||||
def packb(object o):
|
||||
"""pack o and return packed bytes."""
|
||||
packer = Packer()
|
||||
return packer.pack(o)
|
||||
|
||||
packs = packb
|
||||
|
||||
cdef extern from "unpack.h":
|
||||
ctypedef struct template_context:
|
||||
PyObject* obj
|
||||
size_t count
|
||||
unsigned int ct
|
||||
PyObject* key
|
||||
|
||||
int template_execute(template_context* ctx, const_char_ptr data,
|
||||
size_t len, size_t* off)
|
||||
void template_init(template_context* ctx)
|
||||
object template_data(template_context* ctx)
|
||||
|
||||
|
||||
def unpackb(object packed_bytes):
|
||||
"""Unpack packed_bytes to object. Returns an unpacked object."""
|
||||
cdef const_char_ptr p = packed_bytes
|
||||
cdef template_context ctx
|
||||
cdef size_t off = 0
|
||||
cdef int ret
|
||||
template_init(&ctx)
|
||||
ret = template_execute(&ctx, p, len(packed_bytes), &off)
|
||||
if ret == 1:
|
||||
return template_data(&ctx)
|
||||
else:
|
||||
return None
|
||||
|
||||
unpacks = unpackb
|
||||
|
||||
def unpack(object stream):
|
||||
"""unpack an object from stream."""
|
||||
packed = stream.read()
|
||||
return unpackb(packed)
|
||||
|
||||
cdef class UnpackIterator(object):
|
||||
cdef object unpacker
|
||||
|
||||
def __init__(self, unpacker):
|
||||
self.unpacker = unpacker
|
||||
|
||||
def __next__(self):
|
||||
return self.unpacker.unpack()
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
cdef class Unpacker(object):
|
||||
"""Unpacker(file_like=None, read_size=1024*1024)
|
||||
|
||||
Streaming unpacker.
|
||||
file_like must have read(n) method.
|
||||
read_size is used like file_like.read(read_size)
|
||||
|
||||
If file_like is None, you can ``feed()`` bytes. ``feed()`` is
|
||||
useful for unpacking from non-blocking stream.
|
||||
|
||||
exsample 1:
|
||||
unpacker = Unpacker(afile)
|
||||
for o in unpacker:
|
||||
do_something(o)
|
||||
|
||||
example 2:
|
||||
unpacker = Unpacker()
|
||||
while 1:
|
||||
buf = astream.read()
|
||||
unpacker.feed(buf)
|
||||
for o in unpacker:
|
||||
do_something(o)
|
||||
"""
|
||||
|
||||
cdef template_context ctx
|
||||
cdef char* buf
|
||||
cdef size_t buf_size, buf_head, buf_tail
|
||||
cdef object file_like
|
||||
cdef int read_size
|
||||
cdef object waiting_bytes
|
||||
|
||||
def __cinit__(self):
|
||||
self.buf = NULL
|
||||
|
||||
def __dealloc__(self):
|
||||
if self.buf:
|
||||
free(self.buf);
|
||||
|
||||
def __init__(self, file_like=None, int read_size=1024*1024):
|
||||
self.file_like = file_like
|
||||
self.read_size = read_size
|
||||
self.waiting_bytes = []
|
||||
self.buf = <char*>malloc(read_size)
|
||||
self.buf_size = read_size
|
||||
self.buf_head = 0
|
||||
self.buf_tail = 0
|
||||
template_init(&self.ctx)
|
||||
|
||||
def feed(self, next_bytes):
|
||||
if not isinstance(next_bytes, str):
|
||||
raise ValueError, "Argument must be bytes object"
|
||||
self.waiting_bytes.append(next_bytes)
|
||||
|
||||
cdef append_buffer(self):
|
||||
cdef char* buf = self.buf
|
||||
cdef Py_ssize_t tail = self.buf_tail
|
||||
cdef Py_ssize_t l
|
||||
|
||||
for b in self.waiting_bytes:
|
||||
l = len(b)
|
||||
memcpy(buf + tail, PyString_AsString(b), l)
|
||||
tail += l
|
||||
self.buf_tail = tail
|
||||
del self.waiting_bytes[:]
|
||||
|
||||
# prepare self.buf
|
||||
cdef fill_buffer(self):
|
||||
cdef Py_ssize_t add_size
|
||||
|
||||
if self.file_like is not None:
|
||||
next_bytes = self.file_like.read(self.read_size)
|
||||
if next_bytes:
|
||||
self.waiting_bytes.append(next_bytes)
|
||||
else:
|
||||
self.file_like = None
|
||||
|
||||
if not self.waiting_bytes:
|
||||
return
|
||||
|
||||
add_size = 0
|
||||
for b in self.waiting_bytes:
|
||||
add_size += len(b)
|
||||
|
||||
cdef char* buf = self.buf
|
||||
cdef size_t head = self.buf_head
|
||||
cdef size_t tail = self.buf_tail
|
||||
cdef size_t size = self.buf_size
|
||||
|
||||
if self.buf_tail + add_size <= self.buf_size:
|
||||
# do nothing.
|
||||
pass
|
||||
if self.buf_tail - self.buf_head + add_size < self.buf_size:
|
||||
# move to front.
|
||||
memmove(buf, buf + head, tail - head)
|
||||
tail -= head
|
||||
head = 0
|
||||
else:
|
||||
# expand buffer
|
||||
size = tail + add_size
|
||||
buf = <char*>realloc(<void*>buf, size)
|
||||
|
||||
self.buf = buf
|
||||
self.buf_head = head
|
||||
self.buf_tail = tail
|
||||
self.buf_size = size
|
||||
|
||||
self.append_buffer()
|
||||
|
||||
cpdef unpack(self):
|
||||
"""unpack one object"""
|
||||
cdef int ret
|
||||
self.fill_buffer()
|
||||
ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
|
||||
if ret == 1:
|
||||
return template_data(&self.ctx)
|
||||
elif ret == 0:
|
||||
if self.file_like is not None:
|
||||
return self.unpack()
|
||||
raise StopIteration, "No more unpack data."
|
||||
else:
|
||||
raise ValueError, "Unpack failed."
|
||||
|
||||
def __iter__(self):
|
||||
return UnpackIterator(self)
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* MessagePack for Python packing routine
|
||||
*
|
||||
* Copyright (C) 2009 Naoki INADA
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "pack_define.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct msgpack_packer {
|
||||
char *buf;
|
||||
size_t length;
|
||||
size_t buf_size;
|
||||
} msgpack_packer;
|
||||
|
||||
typedef struct Packer Packer;
|
||||
|
||||
static inline int msgpack_pack_short(msgpack_packer* pk, short d);
|
||||
static inline int msgpack_pack_int(msgpack_packer* pk, int d);
|
||||
static inline int msgpack_pack_long(msgpack_packer* pk, long d);
|
||||
static inline int msgpack_pack_long_long(msgpack_packer* pk, long long d);
|
||||
static inline int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
|
||||
static inline int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
|
||||
static inline int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
|
||||
static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d);
|
||||
|
||||
static inline int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d);
|
||||
static inline int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d);
|
||||
static inline int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d);
|
||||
static inline int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d);
|
||||
static inline int msgpack_pack_int8(msgpack_packer* pk, int8_t d);
|
||||
static inline int msgpack_pack_int16(msgpack_packer* pk, int16_t d);
|
||||
static inline int msgpack_pack_int32(msgpack_packer* pk, int32_t d);
|
||||
static inline int msgpack_pack_int64(msgpack_packer* pk, int64_t d);
|
||||
|
||||
static inline int msgpack_pack_float(msgpack_packer* pk, float d);
|
||||
static inline int msgpack_pack_double(msgpack_packer* pk, double d);
|
||||
|
||||
static inline int msgpack_pack_nil(msgpack_packer* pk);
|
||||
static inline int msgpack_pack_true(msgpack_packer* pk);
|
||||
static inline int msgpack_pack_false(msgpack_packer* pk);
|
||||
|
||||
static inline int msgpack_pack_array(msgpack_packer* pk, unsigned int n);
|
||||
|
||||
static inline int msgpack_pack_map(msgpack_packer* pk, unsigned int n);
|
||||
|
||||
static inline int msgpack_pack_raw(msgpack_packer* pk, size_t l);
|
||||
static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l);
|
||||
|
||||
static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_t l)
|
||||
{
|
||||
char* buf = pk->buf;
|
||||
size_t bs = pk->buf_size;
|
||||
size_t len = pk->length;
|
||||
|
||||
if (len + l > bs) {
|
||||
bs = (len + l) * 2;
|
||||
buf = realloc(buf, bs);
|
||||
if (!buf) return -1;
|
||||
}
|
||||
memcpy(buf + len, data, l);
|
||||
len += l;
|
||||
|
||||
pk->buf = buf;
|
||||
pk->buf_size = bs;
|
||||
pk->length = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define msgpack_pack_inline_func(name) \
|
||||
static inline int msgpack_pack ## name
|
||||
|
||||
#define msgpack_pack_inline_func_cint(name) \
|
||||
static inline int msgpack_pack ## name
|
||||
|
||||
#define msgpack_pack_user msgpack_packer*
|
||||
|
||||
#define msgpack_pack_append_buffer(user, buf, len) \
|
||||
return msgpack_pack_write(user, (const char*)buf, len)
|
||||
|
||||
#include "pack_template.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* MessagePack unpacking 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.
|
||||
*/
|
||||
#ifndef MSGPACK_PACK_DEFINE_H__
|
||||
#define MSGPACK_PACK_DEFINE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
#endif /* msgpack/pack_define.h */
|
||||
|
@@ -1,741 +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.
|
||||
*/
|
||||
|
||||
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN__
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#define STORE8_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE16_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE16_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE32_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE64_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE64(d) \
|
||||
((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#elif __BIG_ENDIAN__
|
||||
|
||||
#define STORE8_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE16_BE8(d) \
|
||||
((uint8_t*)&d)[1]
|
||||
|
||||
#define STORE16_BE16(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1]
|
||||
|
||||
|
||||
#define STORE32_BE8(d) \
|
||||
((uint8_t*)&d)[3]
|
||||
|
||||
#define STORE32_BE16(d) \
|
||||
((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
||||
|
||||
#define STORE32_BE32(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
||||
|
||||
|
||||
#define STORE64_BE8(d) \
|
||||
((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE16(d) \
|
||||
((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE32(d) \
|
||||
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#define STORE64_BE64(d) \
|
||||
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3], \
|
||||
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
||||
|
||||
#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, &STORE8_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(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, &STORE16_BE8(d), 1); \
|
||||
} else if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_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, &STORE32_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE32_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, &STORE64_BE8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1ULL<<16)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else if(d < (1ULL<<32)) { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* signed 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_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 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define msgpack_pack_real_int16(x, d) \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_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 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE32_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 */ \
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} else { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
||||
} else { \
|
||||
if(d < (1LL<<16)) { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1LL<<32)) { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* unsigned 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_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)
|
||||
{
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
||||
{
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)};
|
||||
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
|
||||
const unsigned char buf[5] = {0xca, STORE32_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
|
||||
const unsigned char buf[9] = {0xcb, STORE64_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) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xdc, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdd, STORE32_BE32(d)};
|
||||
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, &STORE8_BE8(d), 1);
|
||||
} else if(n < 65536) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xde, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdf, STORE32_BE32(d)};
|
||||
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, &STORE8_BE8(d), 1);
|
||||
} else if(l < 65536) {
|
||||
uint16_t d = (uint16_t)l;
|
||||
unsigned char buf[3] = {0xda, STORE16_BE16(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)l;
|
||||
unsigned char buf[5] = {0xdb, STORE32_BE32(d)};
|
||||
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 STORE8_BE8
|
||||
|
||||
#undef STORE16_BE8
|
||||
#undef STORE16_BE16
|
||||
|
||||
#undef STORE32_BE8
|
||||
#undef STORE32_BE16
|
||||
#undef STORE32_BE32
|
||||
|
||||
#undef STORE64_BE8
|
||||
#undef STORE64_BE16
|
||||
#undef STORE64_BE32
|
||||
#undef STORE64_BE64
|
||||
|
||||
#undef 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,177 +0,0 @@
|
||||
/*
|
||||
* MessagePack for Python unpacking routine
|
||||
*
|
||||
* Copyright (C) 2009 Naoki INADA
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define MSGPACK_MAX_STACK_SIZE (1024)
|
||||
#include "unpack_define.h"
|
||||
|
||||
typedef struct unpack_user {
|
||||
} unpack_user;
|
||||
|
||||
|
||||
#define msgpack_unpack_struct(name) \
|
||||
struct template ## name
|
||||
|
||||
#define msgpack_unpack_func(ret, name) \
|
||||
static inline ret template ## name
|
||||
|
||||
#define msgpack_unpack_callback(name) \
|
||||
template_callback ## name
|
||||
|
||||
#define msgpack_unpack_object PyObject*
|
||||
|
||||
#define msgpack_unpack_user unpack_user
|
||||
|
||||
|
||||
struct template_context;
|
||||
typedef struct template_context template_context;
|
||||
|
||||
static inline msgpack_unpack_object template_callback_root(unpack_user* u)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyInt_FromLong((long)d);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
return template_callback_uint16(u, d, o);
|
||||
}
|
||||
|
||||
|
||||
static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p;
|
||||
if (d > LONG_MAX) {
|
||||
p = PyLong_FromUnsignedLong((unsigned long)d);
|
||||
} else {
|
||||
p = PyInt_FromLong((long)d);
|
||||
}
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyLong_FromUnsignedLongLong(d);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyInt_FromLong(d);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
return template_callback_int32(u, d, o);
|
||||
}
|
||||
|
||||
static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
return template_callback_int32(u, d, o);
|
||||
}
|
||||
|
||||
static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyLong_FromLongLong(d);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyFloat_FromDouble(d);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o)
|
||||
{
|
||||
return template_callback_double(u, d, o);
|
||||
}
|
||||
|
||||
static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o)
|
||||
{ Py_INCREF(Py_None); *o = Py_None; return 0; }
|
||||
|
||||
static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o)
|
||||
{ Py_INCREF(Py_True); *o = Py_True; return 0; }
|
||||
|
||||
static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o)
|
||||
{ Py_INCREF(Py_False); *o = Py_False; return 0; }
|
||||
|
||||
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyList_New(n);
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o)
|
||||
{ PyList_SET_ITEM(*c, current, o); return 0; }
|
||||
|
||||
static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyDict_New();
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v)
|
||||
{
|
||||
if (PyDict_SetItem(*c, k, v) == 0) {
|
||||
Py_DECREF(k);
|
||||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *py;
|
||||
py = PyString_FromStringAndSize(p, l);
|
||||
if (!py)
|
||||
return -1;
|
||||
*o = py;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "unpack_template.h"
|
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* MessagePack unpacking 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.
|
||||
*/
|
||||
#ifndef MSGPACK_UNPACK_DEFINE_H__
|
||||
#define MSGPACK_UNPACK_DEFINE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#ifndef __WIN32__
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MSGPACK_MAX_STACK_SIZE
|
||||
#define MSGPACK_MAX_STACK_SIZE 16
|
||||
#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 __WIN32__
|
||||
static inline uint16_t msgpack_betoh16(uint16_t x) {
|
||||
return ((x << 8) & 0xff00U) |
|
||||
((x >> 8) & 0x00ffU);
|
||||
}
|
||||
static inline uint32_t msgpack_betoh32(uint32_t x) {
|
||||
return ((x << 24) & 0xff000000UL ) |
|
||||
((x << 8) & 0x00ff0000UL ) |
|
||||
((x >> 8) & 0x0000ff00UL ) |
|
||||
((x >> 24) & 0x000000ffUL );
|
||||
}
|
||||
#else
|
||||
#define msgpack_betoh16(x) ntohs(x)
|
||||
#define msgpack_betoh32(x) ntohl(x)
|
||||
#endif
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
#if defined(__bswap_64)
|
||||
# define msgpack_betoh64(x) __bswap_64(x)
|
||||
#elif defined(__DARWIN_OSSwapInt64)
|
||||
# define msgpack_betoh64(x) __DARWIN_OSSwapInt64(x)
|
||||
#else
|
||||
static inline uint64_t msgpack_betoh64(uint64_t x) {
|
||||
return ((x << 56) & 0xff00000000000000ULL ) |
|
||||
((x << 40) & 0x00ff000000000000ULL ) |
|
||||
((x << 24) & 0x0000ff0000000000ULL ) |
|
||||
((x << 8) & 0x000000ff00000000ULL ) |
|
||||
((x >> 8) & 0x00000000ff000000ULL ) |
|
||||
((x >> 24) & 0x0000000000ff0000ULL ) |
|
||||
((x >> 40) & 0x000000000000ff00ULL ) |
|
||||
((x >> 56) & 0x00000000000000ffULL ) ;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#define msgpack_betoh64(x) (x)
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
CS_HEADER = 0x00, // nil
|
||||
|
||||
//CS_ = 0x01,
|
||||
//CS_ = 0x02, // false
|
||||
//CS_ = 0x03, // true
|
||||
|
||||
//CS_ = 0x04,
|
||||
//CS_ = 0x05,
|
||||
//CS_ = 0x06,
|
||||
//CS_ = 0x07,
|
||||
|
||||
//CS_ = 0x08,
|
||||
//CS_ = 0x09,
|
||||
CS_FLOAT = 0x0a,
|
||||
CS_DOUBLE = 0x0b,
|
||||
CS_UINT_8 = 0x0c,
|
||||
CS_UINT_16 = 0x0d,
|
||||
CS_UINT_32 = 0x0e,
|
||||
CS_UINT_64 = 0x0f,
|
||||
CS_INT_8 = 0x10,
|
||||
CS_INT_16 = 0x11,
|
||||
CS_INT_32 = 0x12,
|
||||
CS_INT_64 = 0x13,
|
||||
|
||||
//CS_ = 0x14,
|
||||
//CS_ = 0x15,
|
||||
//CS_BIG_INT_16 = 0x16,
|
||||
//CS_BIG_INT_32 = 0x17,
|
||||
//CS_BIG_FLOAT_16 = 0x18,
|
||||
//CS_BIG_FLOAT_32 = 0x19,
|
||||
CS_RAW_16 = 0x1a,
|
||||
CS_RAW_32 = 0x1b,
|
||||
CS_ARRAY_16 = 0x1c,
|
||||
CS_ARRAY_32 = 0x1d,
|
||||
CS_MAP_16 = 0x1e,
|
||||
CS_MAP_32 = 0x1f,
|
||||
|
||||
//ACS_BIG_INT_VALUE,
|
||||
//ACS_BIG_FLOAT_VALUE,
|
||||
ACS_RAW_VALUE,
|
||||
} msgpack_unpack_state;
|
||||
|
||||
|
||||
typedef enum {
|
||||
CT_ARRAY_ITEM,
|
||||
CT_MAP_KEY,
|
||||
CT_MAP_VALUE,
|
||||
} msgpack_container_type;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/unpack_define.h */
|
||||
|
@@ -1,366 +0,0 @@
|
||||
/*
|
||||
* MessagePack unpacking 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.
|
||||
*/
|
||||
|
||||
#ifndef msgpack_unpack_func
|
||||
#error msgpack_unpack_func template is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_unpack_callback
|
||||
#error msgpack_unpack_callback template is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_unpack_struct
|
||||
#error msgpack_unpack_struct template is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_unpack_struct_decl
|
||||
#define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name)
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_unpack_object
|
||||
#error msgpack_unpack_object type is not defined
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_unpack_user
|
||||
#error msgpack_unpack_user type is not defined
|
||||
#endif
|
||||
|
||||
|
||||
msgpack_unpack_struct_decl(_stack) {
|
||||
msgpack_unpack_object obj;
|
||||
size_t count;
|
||||
unsigned int ct;
|
||||
|
||||
union {
|
||||
size_t curr;
|
||||
msgpack_unpack_object map_key;
|
||||
};
|
||||
};
|
||||
|
||||
msgpack_unpack_struct_decl(_context) {
|
||||
msgpack_unpack_user user;
|
||||
unsigned int cs;
|
||||
unsigned int trail;
|
||||
unsigned int top;
|
||||
msgpack_unpack_struct(_stack) stack[MSGPACK_MAX_STACK_SIZE];
|
||||
};
|
||||
|
||||
|
||||
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
|
||||
{
|
||||
ctx->cs = CS_HEADER;
|
||||
ctx->trail = 0;
|
||||
ctx->top = 0;
|
||||
ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user);
|
||||
}
|
||||
|
||||
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx)
|
||||
{
|
||||
return (ctx)->stack[0].obj;
|
||||
}
|
||||
|
||||
|
||||
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
|
||||
{
|
||||
assert(len >= *off);
|
||||
|
||||
const unsigned char* p = (unsigned char*)data + *off;
|
||||
const unsigned char* const pe = (unsigned char*)data + len;
|
||||
const void* n = NULL;
|
||||
|
||||
unsigned int trail = ctx->trail;
|
||||
unsigned int cs = ctx->cs;
|
||||
unsigned int top = ctx->top;
|
||||
msgpack_unpack_struct(_stack)* stack = ctx->stack;
|
||||
msgpack_unpack_user* user = &ctx->user;
|
||||
|
||||
msgpack_unpack_object obj;
|
||||
msgpack_unpack_struct(_stack)* c = NULL;
|
||||
|
||||
int ret;
|
||||
|
||||
#define push_simple_value(func) \
|
||||
if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
|
||||
goto _push
|
||||
#define push_fixed_value(func, arg) \
|
||||
if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
|
||||
goto _push
|
||||
#define push_variable_value(func, base, pos, len) \
|
||||
if(msgpack_unpack_callback(func)(user, \
|
||||
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
||||
goto _push
|
||||
|
||||
#define again_fixed_trail(_cs, trail_len) \
|
||||
trail = trail_len; \
|
||||
cs = _cs; \
|
||||
goto _fixed_trail_again
|
||||
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
|
||||
trail = trail_len; \
|
||||
if(trail == 0) { goto ifzero; } \
|
||||
cs = _cs; \
|
||||
goto _fixed_trail_again
|
||||
|
||||
#define start_container(func, count_, ct_) \
|
||||
if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
||||
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
|
||||
if(top >= MSGPACK_MAX_STACK_SIZE) { goto _failed; } \
|
||||
stack[top].ct = ct_; \
|
||||
stack[top].curr = 0; \
|
||||
stack[top].count = count_; \
|
||||
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
||||
/*printf("stack push %d\n", top);*/ \
|
||||
++top; \
|
||||
goto _header_again
|
||||
|
||||
#define NEXT_CS(p) \
|
||||
((unsigned int)*p & 0x1f)
|
||||
|
||||
#define PTR_CAST_8(ptr) (*(uint8_t*)ptr)
|
||||
#define PTR_CAST_16(ptr) msgpack_betoh16(*(uint16_t*)ptr)
|
||||
#define PTR_CAST_32(ptr) msgpack_betoh32(*(uint32_t*)ptr)
|
||||
#define PTR_CAST_64(ptr) msgpack_betoh64(*(uint64_t*)ptr)
|
||||
|
||||
if(p == pe) { goto _out; }
|
||||
do {
|
||||
switch(cs) {
|
||||
case CS_HEADER:
|
||||
switch(*p) {
|
||||
case 0x00 ... 0x7f: // Positive Fixnum
|
||||
push_fixed_value(_uint8, *(uint8_t*)p);
|
||||
case 0xe0 ... 0xff: // Negative Fixnum
|
||||
push_fixed_value(_int8, *(int8_t*)p);
|
||||
case 0xc0 ... 0xdf: // Variable
|
||||
switch(*p) {
|
||||
case 0xc0: // nil
|
||||
push_simple_value(_nil);
|
||||
//case 0xc1: // string
|
||||
// again_terminal_trail(NEXT_CS(p), p+1);
|
||||
case 0xc2: // false
|
||||
push_simple_value(_false);
|
||||
case 0xc3: // true
|
||||
push_simple_value(_true);
|
||||
//case 0xc4:
|
||||
//case 0xc5:
|
||||
//case 0xc6:
|
||||
//case 0xc7:
|
||||
//case 0xc8:
|
||||
//case 0xc9:
|
||||
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
|
||||
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
|
||||
//case 0xd4:
|
||||
//case 0xd5:
|
||||
//case 0xd6: // big integer 16
|
||||
//case 0xd7: // big integer 32
|
||||
//case 0xd8: // big float 16
|
||||
//case 0xd9: // big float 32
|
||||
case 0xda: // raw 16
|
||||
case 0xdb: // raw 32
|
||||
case 0xdc: // array 16
|
||||
case 0xdd: // array 32
|
||||
case 0xde: // map 16
|
||||
case 0xdf: // map 32
|
||||
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
|
||||
default:
|
||||
goto _failed;
|
||||
}
|
||||
case 0xa0 ... 0xbf: // FixRaw
|
||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
||||
case 0x90 ... 0x9f: // FixArray
|
||||
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
||||
case 0x80 ... 0x8f: // FixMap
|
||||
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
||||
|
||||
default:
|
||||
goto _failed;
|
||||
}
|
||||
// end CS_HEADER
|
||||
|
||||
|
||||
_fixed_trail_again:
|
||||
++p;
|
||||
|
||||
default:
|
||||
if((size_t)(pe - p) < trail) { goto _out; }
|
||||
n = p; p += trail - 1;
|
||||
switch(cs) {
|
||||
//case CS_
|
||||
//case CS_
|
||||
case CS_FLOAT: {
|
||||
union { uint32_t num; char buf[4]; } f;
|
||||
f.num = PTR_CAST_32(n); // FIXME
|
||||
push_fixed_value(_float, *((float*)f.buf)); }
|
||||
case CS_DOUBLE: {
|
||||
union { uint64_t num; char buf[8]; } f;
|
||||
f.num = PTR_CAST_64(n); // FIXME
|
||||
push_fixed_value(_double, *((double*)f.buf)); }
|
||||
case CS_UINT_8:
|
||||
push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n));
|
||||
case CS_UINT_16:
|
||||
push_fixed_value(_uint16, (uint16_t)PTR_CAST_16(n));
|
||||
case CS_UINT_32:
|
||||
push_fixed_value(_uint32, (uint32_t)PTR_CAST_32(n));
|
||||
case CS_UINT_64:
|
||||
push_fixed_value(_uint64, (uint64_t)PTR_CAST_64(n));
|
||||
|
||||
case CS_INT_8:
|
||||
push_fixed_value(_int8, (int8_t)PTR_CAST_8(n));
|
||||
case CS_INT_16:
|
||||
push_fixed_value(_int16, (int16_t)PTR_CAST_16(n));
|
||||
case CS_INT_32:
|
||||
push_fixed_value(_int32, (int32_t)PTR_CAST_32(n));
|
||||
case CS_INT_64:
|
||||
push_fixed_value(_int64, (int64_t)PTR_CAST_64(n));
|
||||
|
||||
//case CS_
|
||||
//case CS_
|
||||
//case CS_BIG_INT_16:
|
||||
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint16_t)PTR_CAST_16(n), _big_int_zero);
|
||||
//case CS_BIG_INT_32:
|
||||
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint32_t)PTR_CAST_32(n), _big_int_zero);
|
||||
//case ACS_BIG_INT_VALUE:
|
||||
//_big_int_zero:
|
||||
// // FIXME
|
||||
// push_variable_value(_big_int, data, n, trail);
|
||||
|
||||
//case CS_BIG_FLOAT_16:
|
||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero);
|
||||
//case CS_BIG_FLOAT_32:
|
||||
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint32_t)PTR_CAST_32(n), _big_float_zero);
|
||||
//case ACS_BIG_FLOAT_VALUE:
|
||||
//_big_float_zero:
|
||||
// // FIXME
|
||||
// push_variable_value(_big_float, data, n, trail);
|
||||
|
||||
case CS_RAW_16:
|
||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero);
|
||||
case CS_RAW_32:
|
||||
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero);
|
||||
case ACS_RAW_VALUE:
|
||||
_raw_zero:
|
||||
push_variable_value(_raw, data, n, trail);
|
||||
|
||||
case CS_ARRAY_16:
|
||||
start_container(_array, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM);
|
||||
case CS_ARRAY_32:
|
||||
/* FIXME security guard */
|
||||
start_container(_array, (uint32_t)PTR_CAST_32(n), CT_ARRAY_ITEM);
|
||||
|
||||
case CS_MAP_16:
|
||||
start_container(_map, (uint16_t)PTR_CAST_16(n), CT_MAP_KEY);
|
||||
case CS_MAP_32:
|
||||
/* FIXME security guard */
|
||||
start_container(_map, (uint32_t)PTR_CAST_32(n), CT_MAP_KEY);
|
||||
|
||||
default:
|
||||
goto _failed;
|
||||
}
|
||||
}
|
||||
|
||||
_push:
|
||||
if(top == 0) { goto _finish; }
|
||||
c = &stack[top-1];
|
||||
switch(c->ct) {
|
||||
case CT_ARRAY_ITEM:
|
||||
if(msgpack_unpack_callback(_array_item)(user, c->curr, &c->obj, obj) < 0) { goto _failed; }
|
||||
if(++c->curr == c->count) {
|
||||
obj = c->obj;
|
||||
--top;
|
||||
/*printf("stack pop %d\n", top);*/
|
||||
goto _push;
|
||||
}
|
||||
goto _header_again;
|
||||
case CT_MAP_KEY:
|
||||
c->map_key = obj;
|
||||
c->ct = CT_MAP_VALUE;
|
||||
goto _header_again;
|
||||
case CT_MAP_VALUE:
|
||||
if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
||||
if(--c->count == 0) {
|
||||
obj = c->obj;
|
||||
--top;
|
||||
/*printf("stack pop %d\n", top);*/
|
||||
goto _push;
|
||||
}
|
||||
c->ct = CT_MAP_KEY;
|
||||
goto _header_again;
|
||||
|
||||
default:
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
_header_again:
|
||||
cs = CS_HEADER;
|
||||
++p;
|
||||
} while(p != pe);
|
||||
goto _out;
|
||||
|
||||
|
||||
_finish:
|
||||
stack[0].obj = obj;
|
||||
++p;
|
||||
ret = 1;
|
||||
/*printf("-- finish --\n"); */
|
||||
goto _end;
|
||||
|
||||
_failed:
|
||||
/*printf("** FAILED **\n"); */
|
||||
ret = -1;
|
||||
goto _end;
|
||||
|
||||
_out:
|
||||
ret = 0;
|
||||
goto _end;
|
||||
|
||||
_end:
|
||||
ctx->cs = cs;
|
||||
ctx->trail = trail;
|
||||
ctx->top = top;
|
||||
*off = p - (const unsigned char*)data;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#undef msgpack_unpack_func
|
||||
#undef msgpack_unpack_callback
|
||||
#undef msgpack_unpack_struct
|
||||
#undef msgpack_unpack_object
|
||||
#undef msgpack_unpack_user
|
||||
|
||||
#undef push_simple_value
|
||||
#undef push_fixed_value
|
||||
#undef push_variable_value
|
||||
#undef again_fixed_trail
|
||||
#undef again_fixed_trail_if_zero
|
||||
#undef start_container
|
||||
|
||||
#undef NEXT_CS
|
||||
#undef PTR_CAST_8
|
||||
#undef PTR_CAST_16
|
||||
#undef PTR_CAST_32
|
||||
#undef PTR_CAST_64
|
||||
|
@@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
#from Cython.Distutils import build_ext
|
||||
import os
|
||||
|
||||
version = '0.1.1'
|
||||
|
||||
msgpack_mod = Extension('msgpack._msgpack',
|
||||
#sources=['msgpack/_msgpack.pyx']
|
||||
sources=['msgpack/_msgpack.c']
|
||||
)
|
||||
|
||||
desc = 'MessagePack (de)serializer.'
|
||||
long_desc = desc + """
|
||||
|
||||
MessagePack_ (de)serializer for Python.
|
||||
|
||||
.. _MessagePack: http://msgpack.sourceforge.jp/
|
||||
|
||||
What's MessagePack? (from http://msgpack.sourceforge.jp/)
|
||||
|
||||
MessagePack is a binary-based efficient data interchange format that is
|
||||
focused on high performance. It is like JSON, but very fast and small.
|
||||
"""
|
||||
|
||||
setup(name='msgpack',
|
||||
author='Naoki INADA',
|
||||
author_email='songofacandy@gmail.com',
|
||||
version=version,
|
||||
#cmdclass={'build_ext': build_ext},
|
||||
ext_modules=[msgpack_mod],
|
||||
packages=['msgpack'],
|
||||
description=desc,
|
||||
long_description=long_desc,
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
]
|
||||
)
|
@@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
from Cython.Distutils import build_ext
|
||||
import os
|
||||
|
||||
version = '0.1.1dev'
|
||||
|
||||
msgpack_mod = Extension('msgpack._msgpack',
|
||||
sources=['msgpack/_msgpack.pyx']
|
||||
)
|
||||
|
||||
desc = 'MessagePack (de)serializer.'
|
||||
long_desc = desc + """
|
||||
|
||||
MessagePack_ (de)serializer for Python.
|
||||
|
||||
.. _MessagePack: http://msgpack.sourceforge.jp/
|
||||
|
||||
What's MessagePack? (from http://msgpack.sourceforge.jp/)
|
||||
|
||||
MessagePack is a binary-based efficient data interchange format that is
|
||||
focused on high performance. It is like JSON, but very fast and small.
|
||||
"""
|
||||
|
||||
setup(name='msgpack',
|
||||
author='Naoki INADA',
|
||||
author_email='songofacandy@gmail.com',
|
||||
version=version,
|
||||
cmdclass={'build_ext': build_ext},
|
||||
ext_modules=[msgpack_mod],
|
||||
packages=['msgpack'],
|
||||
description=desc,
|
||||
long_description=long_desc,
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
]
|
||||
)
|
@@ -1,101 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
from msgpack import packs, unpacks
|
||||
|
||||
def check(length, obj):
|
||||
v = packs(obj)
|
||||
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
|
||||
assert_equal(unpacks(v), obj)
|
||||
|
||||
def test_1():
|
||||
for o in [None, True, False, 0, 1, (1 << 6), (1 << 7) - 1, -1,
|
||||
-((1<<5)-1), -(1<<5)]:
|
||||
check(1, o)
|
||||
|
||||
def test_2():
|
||||
for o in [1 << 7, (1 << 8) - 1,
|
||||
-((1<<5)+1), -(1<<7)
|
||||
]:
|
||||
check(2, o)
|
||||
|
||||
def test_3():
|
||||
for o in [1 << 8, (1 << 16) - 1,
|
||||
-((1<<7)+1), -(1<<15)]:
|
||||
check(3, o)
|
||||
|
||||
def test_5():
|
||||
for o in [1 << 16, (1 << 32) - 1,
|
||||
-((1<<15)+1), -(1<<31)]:
|
||||
check(5, o)
|
||||
|
||||
def test_9():
|
||||
for o in [1 << 32, (1 << 64) - 1,
|
||||
-((1<<31)+1), -(1<<63),
|
||||
1.0, 0.1, -0.1, -1.0]:
|
||||
check(9, o)
|
||||
|
||||
|
||||
def check_raw(overhead, num):
|
||||
check(num + overhead, " " * num)
|
||||
|
||||
def test_fixraw():
|
||||
check_raw(1, 0)
|
||||
check_raw(1, (1<<5) - 1)
|
||||
|
||||
def test_raw16():
|
||||
check_raw(3, 1<<5)
|
||||
check_raw(3, (1<<16) - 1)
|
||||
|
||||
def test_raw32():
|
||||
check_raw(5, 1<<16)
|
||||
|
||||
|
||||
def check_array(overhead, num):
|
||||
check(num + overhead, [None] * num)
|
||||
|
||||
def test_fixarray():
|
||||
check_array(1, 0)
|
||||
check_array(1, (1 << 4) - 1)
|
||||
|
||||
def test_array16():
|
||||
check_array(3, 1 << 4)
|
||||
check_array(3, (1<<16)-1)
|
||||
|
||||
def test_array32():
|
||||
check_array(5, (1<<16))
|
||||
|
||||
|
||||
def match(obj, buf):
|
||||
assert_equal(packs(obj), buf)
|
||||
assert_equal(unpacks(buf), obj)
|
||||
|
||||
def test_match():
|
||||
cases = [
|
||||
(None, '\xc0'),
|
||||
(False, '\xc2'),
|
||||
(True, '\xc3'),
|
||||
(0, '\x00'),
|
||||
(127, '\x7f'),
|
||||
(128, '\xcc\x80'),
|
||||
(256, '\xcd\x01\x00'),
|
||||
(-1, '\xff'),
|
||||
(-33, '\xd0\xdf'),
|
||||
(-129, '\xd1\xff\x7f'),
|
||||
({1:1}, '\x81\x01\x01'),
|
||||
(1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"),
|
||||
([], '\x90'),
|
||||
(range(15),"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"),
|
||||
(range(16),"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"),
|
||||
({}, '\x80'),
|
||||
(dict([(x,x) for x in range(15)]), '\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e'),
|
||||
(dict([(x,x) for x in range(16)]), '\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f'),
|
||||
]
|
||||
|
||||
for v, p in cases:
|
||||
match(v, p)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,74 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
from msgpack import unpacks
|
||||
|
||||
def check(src, should):
|
||||
assert_equal(unpacks(src), should)
|
||||
|
||||
def testSimpleValue():
|
||||
check("\x93\xc0\xc2\xc3",
|
||||
[None, False, True])
|
||||
|
||||
def testFixnum():
|
||||
check("\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff",
|
||||
[[0,64,127], [-32,-16,-1]]
|
||||
)
|
||||
|
||||
def testFixArray():
|
||||
check("\x92\x90\x91\x91\xc0",
|
||||
[[],[[None]]],
|
||||
)
|
||||
|
||||
def testFixRaw():
|
||||
check("\x94\xa0\xa1a\xa2bc\xa3def",
|
||||
["", "a", "bc", "def"],
|
||||
)
|
||||
|
||||
def testFixMap():
|
||||
check(
|
||||
"\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80",
|
||||
{False: {None: None}, True:{None:{}}},
|
||||
)
|
||||
|
||||
def testUnsignedInt():
|
||||
check(
|
||||
"\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00"
|
||||
"\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00"
|
||||
"\xce\xff\xff\xff\xff",
|
||||
[0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295],
|
||||
)
|
||||
|
||||
def testSignedInt():
|
||||
check("\x99\xd0\x00\xd0\x80\xd0\xff\xd1\x00\x00\xd1\x80\x00"
|
||||
"\xd1\xff\xff\xd2\x00\x00\x00\x00\xd2\x80\x00\x00\x00"
|
||||
"\xd2\xff\xff\xff\xff",
|
||||
[0, -128, -1, 0, -32768, -1, 0, -2147483648, -1])
|
||||
|
||||
def testRaw():
|
||||
check("\x96\xda\x00\x00\xda\x00\x01a\xda\x00\x02ab\xdb\x00\x00"
|
||||
"\x00\x00\xdb\x00\x00\x00\x01a\xdb\x00\x00\x00\x02ab",
|
||||
["", "a", "ab", "", "a", "ab"])
|
||||
|
||||
def testArray():
|
||||
check("\x96\xdc\x00\x00\xdc\x00\x01\xc0\xdc\x00\x02\xc2\xc3\xdd\x00"
|
||||
"\x00\x00\x00\xdd\x00\x00\x00\x01\xc0\xdd\x00\x00\x00\x02"
|
||||
"\xc2\xc3",
|
||||
[[], [None], [False,True], [], [None], [False,True]])
|
||||
|
||||
def testMap():
|
||||
check(
|
||||
"\x96"
|
||||
"\xde\x00\x00"
|
||||
"\xde\x00\x01\xc0\xc2"
|
||||
"\xde\x00\x02\xc0\xc2\xc3\xc2"
|
||||
"\xdf\x00\x00\x00\x00"
|
||||
"\xdf\x00\x00\x00\x01\xc0\xc2"
|
||||
"\xdf\x00\x00\x00\x02\xc0\xc2\xc3\xc2",
|
||||
[{}, {None: False}, {True: False, None: False}, {},
|
||||
{None: False}, {True: False, None: False}])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
|
||||
from msgpack import packs, unpacks
|
||||
|
||||
def check(data):
|
||||
re = unpacks(packs(data))
|
||||
assert_equal(re, data)
|
||||
|
||||
def testPack():
|
||||
test_data = [
|
||||
0, 1, 127, 128, 255, 256, 65535, 65536,
|
||||
-1, -32, -33, -128, -129, -32768, -32769,
|
||||
1.0,
|
||||
"", "a", "a"*31, "a"*32,
|
||||
None, True, False,
|
||||
[], [[]], [[], None],
|
||||
{None: 0},
|
||||
(1<<23),
|
||||
]
|
||||
for td in test_data:
|
||||
check(td)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
from msgpack import Unpacker
|
||||
|
||||
def test_foobar():
|
||||
unpacker = Unpacker(read_size=3)
|
||||
unpacker.feed(b'foobar')
|
||||
assert unpacker.unpack() == ord('f')
|
||||
assert unpacker.unpack() == ord('o')
|
||||
assert unpacker.unpack() == ord('o')
|
||||
assert unpacker.unpack() == ord('b')
|
||||
assert unpacker.unpack() == ord('a')
|
||||
assert unpacker.unpack() == ord('r')
|
||||
try:
|
||||
o = unpacker.unpack()
|
||||
print("Oops!", o)
|
||||
assert 0
|
||||
except StopIteration:
|
||||
assert 1
|
||||
else:
|
||||
assert 0
|
||||
unpacker.feed(b'foo')
|
||||
unpacker.feed(b'bar')
|
||||
|
||||
k = 0
|
||||
for o, e in zip(unpacker, b'foobarbaz'):
|
||||
assert o == ord(e)
|
||||
k += 1
|
||||
assert k == len(b'foobar')
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_foobar()
|
||||
|
@@ -1,70 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'json'
|
||||
require 'msgpack'
|
||||
|
||||
def show10(str)
|
||||
puts "#{str.length/1024} KB"
|
||||
puts str[0, 10].unpack('C*').map{|x|"%02x"%x}.join(' ') + " ..."
|
||||
end
|
||||
|
||||
ary = []
|
||||
i = 0
|
||||
while i < (1<<24)
|
||||
#ary << (1<<24)
|
||||
ary << i
|
||||
i += 1
|
||||
end
|
||||
|
||||
GC.start
|
||||
|
||||
puts "----"
|
||||
puts "MessagePack"
|
||||
a = Time.now
|
||||
packed = MessagePack::pack(ary)
|
||||
b = Time.now
|
||||
show10(packed)
|
||||
sec = b - a
|
||||
puts "#{sec} sec."
|
||||
puts "#{packed.length.to_f / sec / 1024 / 1024 * 8} Mbps"
|
||||
|
||||
GC.start
|
||||
|
||||
=begin
|
||||
puts "----"
|
||||
puts "JSON"
|
||||
a = Time.now
|
||||
json = ary.to_json
|
||||
b = Time.now
|
||||
show10(json)
|
||||
puts "#{b-a} sec."
|
||||
|
||||
ary = nil
|
||||
GC.start
|
||||
=end
|
||||
|
||||
|
||||
puts "----"
|
||||
puts "MessagePack"
|
||||
a = Time.now
|
||||
ary = MessagePack::unpack(packed)
|
||||
b = Time.now
|
||||
sec = b - a
|
||||
puts "#{sec} sec."
|
||||
puts "#{packed.length.to_f / sec / 1024 / 1024 * 8} Mbps"
|
||||
|
||||
p ary.size
|
||||
p (1<<24)
|
||||
|
||||
ary = nil
|
||||
GC.start
|
||||
|
||||
|
||||
=begin
|
||||
puts "----"
|
||||
puts "JSON"
|
||||
a = Time.now
|
||||
ary = JSON::load(json)
|
||||
b = Time.now
|
||||
puts "#{b-a} sec."
|
||||
=end
|
||||
|
@@ -1,4 +0,0 @@
|
||||
require 'mkmf'
|
||||
$CFLAGS << " -I.. -Wall -O4"
|
||||
create_makefile('msgpack')
|
||||
|
@@ -1,29 +0,0 @@
|
||||
|
||||
= MessagePack
|
||||
|
||||
|
||||
== Description
|
||||
|
||||
|
||||
== Installation
|
||||
|
||||
=== Archive Installation
|
||||
|
||||
rake install
|
||||
|
||||
=== Gem Installation
|
||||
|
||||
gem install msgpack
|
||||
|
||||
|
||||
== Features/Problems
|
||||
|
||||
|
||||
== Synopsis
|
||||
|
||||
|
||||
== Copyright
|
||||
|
||||
Author:: frsyuki <frsyuki@users.sourceforge.jp>
|
||||
Copyright:: Copyright (c) 2008-2009 frsyuki
|
||||
License:: Apache License, Version 2.0
|
@@ -1,133 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'rake'
|
||||
require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
require 'rake/packagetask'
|
||||
require 'rake/gempackagetask'
|
||||
require 'rake/rdoctask'
|
||||
require 'rake/contrib/rubyforgepublisher'
|
||||
require 'rake/contrib/sshpublisher'
|
||||
require 'fileutils'
|
||||
include FileUtils
|
||||
|
||||
NAME = "msgpack"
|
||||
AUTHOR = "FURUHASHI Sadayuki"
|
||||
EMAIL = "frsyuki _at_ users.sourceforge.jp"
|
||||
DESCRIPTION = "Binary-based efficient data interchange format."
|
||||
RUBYFORGE_PROJECT = "msgpack"
|
||||
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
||||
BIN_FILES = %w( )
|
||||
VERS = "0.3.1"
|
||||
|
||||
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
||||
REV = nil
|
||||
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
||||
RDOC_OPTS = [
|
||||
'--title', "#{NAME} documentation",
|
||||
"--charset", "utf-8",
|
||||
"--opname", "index.html",
|
||||
"--line-numbers",
|
||||
"--main", "README",
|
||||
"--inline-source",
|
||||
]
|
||||
|
||||
task :default => [:test]
|
||||
task :package => [:clean]
|
||||
|
||||
Rake::TestTask.new("test") do |t|
|
||||
t.libs << "test"
|
||||
t.pattern = "test/**/*_test.rb"
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
spec = Gem::Specification.new do |s|
|
||||
s.name = NAME
|
||||
s.version = VERS
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.has_rdoc = true
|
||||
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
|
||||
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
||||
s.summary = DESCRIPTION
|
||||
s.description = DESCRIPTION
|
||||
s.author = AUTHOR
|
||||
s.email = EMAIL
|
||||
s.homepage = HOMEPATH
|
||||
s.executables = BIN_FILES
|
||||
s.rubyforge_project = RUBYFORGE_PROJECT
|
||||
s.bindir = "bin"
|
||||
s.require_path = "ext"
|
||||
s.autorequire = ""
|
||||
s.test_files = Dir["test/test_*.rb"]
|
||||
|
||||
#s.add_dependency('activesupport', '>=1.3.1')
|
||||
#s.required_ruby_version = '>= 1.8.2'
|
||||
|
||||
s.files = %w(README ChangeLog Rakefile) +
|
||||
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
||||
Dir.glob("ext/**/*.{h,c,rb}") +
|
||||
Dir.glob("examples/**/*.rb") +
|
||||
Dir.glob("tools/*.rb") +
|
||||
Dir.glob("msgpack/*.h")
|
||||
|
||||
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
||||
end
|
||||
|
||||
Rake::GemPackageTask.new(spec) do |p|
|
||||
p.need_tar = true
|
||||
p.gem_spec = spec
|
||||
end
|
||||
|
||||
task :install do
|
||||
name = "#{NAME}-#{VERS}.gem"
|
||||
sh %{rake package}
|
||||
sh %{sudo gem install pkg/#{name}}
|
||||
end
|
||||
|
||||
task :uninstall => [:clean] do
|
||||
sh %{sudo gem uninstall #{NAME}}
|
||||
end
|
||||
|
||||
|
||||
#Rake::RDocTask.new do |rdoc|
|
||||
# rdoc.rdoc_dir = 'html'
|
||||
# rdoc.options += RDOC_OPTS
|
||||
# rdoc.template = "resh"
|
||||
# #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
||||
# if ENV['DOC_FILES']
|
||||
# rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
||||
# else
|
||||
# rdoc.rdoc_files.include('README', 'ChangeLog')
|
||||
# rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
# rdoc.rdoc_files.include('ext/**/*.c')
|
||||
# end
|
||||
#end
|
||||
|
||||
desc "Publish to RubyForge"
|
||||
task :rubyforge => [:rdoc, :package] do
|
||||
require 'rubyforge'
|
||||
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'frsyuki').upload
|
||||
end
|
||||
|
||||
desc 'Package and upload the release to rubyforge.'
|
||||
task :release => [:clean, :package] do |t|
|
||||
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
||||
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
||||
pkg = "pkg/#{NAME}-#{VERS}"
|
||||
|
||||
rf = RubyForge.new
|
||||
puts "Logging in"
|
||||
rf.login
|
||||
|
||||
c = rf.userconfig
|
||||
# c["release_notes"] = description if description
|
||||
# c["release_changes"] = changes if changes
|
||||
c["preformatted"] = true
|
||||
|
||||
files = [
|
||||
"#{pkg}.tgz",
|
||||
"#{pkg}.gem"
|
||||
].compact
|
||||
|
||||
puts "Releasing #{NAME} v. #{VERS}"
|
||||
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
||||
end
|
@@ -1,3 +0,0 @@
|
||||
require 'test/unit'
|
||||
require File.dirname(__FILE__) + '/../ext/msgpack'
|
||||
|
@@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p gem/ext
|
||||
mkdir -p gem/msgpack
|
||||
cp extconf.rb gem/ext/
|
||||
cp pack.c gem/ext/
|
||||
cp pack.h gem/ext/
|
||||
cp rbinit.c gem/ext/
|
||||
cp unpack.c gem/ext/
|
||||
cp unpack.h gem/ext/
|
||||
cat test_case.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > gem/test/msgpack_test.rb
|
||||
cp ../AUTHORS gem/AUTHORS
|
||||
cp ../ChangeLog gem/ChangeLog
|
||||
cp ../msgpack/pack_define.h gem/msgpack/
|
||||
cp ../msgpack/pack_template.h gem/msgpack/
|
||||
cp ../msgpack/unpack_define.h gem/msgpack/
|
||||
cp ../msgpack/unpack_template.h gem/msgpack/
|
||||
|
||||
cd gem && rake --trace package
|
||||
|
@@ -1,12 +0,0 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.platform = Gem::Platform::CURRENT
|
||||
s.name = "msgpack"
|
||||
s.version = "0.3.1"
|
||||
s.summary = "MessagePack"
|
||||
s.author = "FURUHASHI Sadayuki"
|
||||
s.email = "frsyuki@users.sourceforge.jp"
|
||||
s.homepage = "http://msgpack.sourceforge.jp/"
|
||||
s.rubyforge_project = "msgpack"
|
||||
s.require_paths = ["lib", "ext"]
|
||||
s.files = ["lib/**/*", "ext/**/*"].map {|g| Dir.glob(g) }.flatten
|
||||
end
|
165
ruby/pack.c
165
ruby/pack.c
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* MessagePack for Ruby packing 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.
|
||||
*/
|
||||
#include "ruby.h"
|
||||
#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
|
||||
|
||||
#define msgpack_pack_user VALUE
|
||||
|
||||
#define msgpack_pack_append_buffer(user, buf, len) \
|
||||
rb_str_buf_cat(user, (const void*)buf, len)
|
||||
|
||||
#include "msgpack/pack_template.h"
|
||||
|
||||
|
||||
#ifndef RUBY_VM
|
||||
#include "st.h" // ruby hash
|
||||
#endif
|
||||
|
||||
static ID s_to_msgpack;
|
||||
|
||||
#define ARG_BUFFER(name, argc, argv) \
|
||||
VALUE name; \
|
||||
if(argc == 1) { \
|
||||
name = argv[0]; \
|
||||
} else if(argc == 0) { \
|
||||
name = rb_str_buf_new(0); \
|
||||
} else { \
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); \
|
||||
}
|
||||
|
||||
static VALUE MessagePack_NilClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_nil(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_TrueClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_true(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_false(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_long(out, FIX2LONG(self));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
#ifndef RBIGNUM_SIGN // Ruby 1.8
|
||||
#define RBIGNUM_SIGN(b) (RBIGNUM(b)->sign)
|
||||
#endif
|
||||
|
||||
static VALUE MessagePack_Bignum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
// FIXME bignum
|
||||
if(RBIGNUM_SIGN(self)) { // positive
|
||||
msgpack_pack_uint64(out, rb_big2ull(self));
|
||||
} else { // negative
|
||||
msgpack_pack_int64(out, rb_big2ll(self));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Float_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_double(out, rb_num2dbl(self));
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_String_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_raw(out, RSTRING_LEN(self));
|
||||
msgpack_pack_raw_body(out, RSTRING_PTR(self), RSTRING_LEN(self));
|
||||
return out;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_array(out, RARRAY_LEN(self));
|
||||
VALUE* p = RARRAY_PTR(self);
|
||||
VALUE* const pend = p + RARRAY_LEN(self);
|
||||
for(;p != pend; ++p) {
|
||||
rb_funcall(*p, s_to_msgpack, 1, out);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#ifndef RHASH_SIZE // Ruby 1.8
|
||||
#define RHASH_SIZE(h) (RHASH(h)->tbl ? RHASH(h)->tbl->num_entries : 0)
|
||||
#endif
|
||||
|
||||
static int MessagePack_Hash_to_msgpack_foreach(VALUE key, VALUE value, VALUE out)
|
||||
{
|
||||
if (key == Qundef) { return ST_CONTINUE; }
|
||||
rb_funcall(key, s_to_msgpack, 1, out);
|
||||
rb_funcall(value, s_to_msgpack, 1, out);
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Hash_to_msgpack(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
ARG_BUFFER(out, argc, argv);
|
||||
msgpack_pack_map(out, RHASH_SIZE(self));
|
||||
rb_hash_foreach(self, MessagePack_Hash_to_msgpack_foreach, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
static VALUE MessagePack_pack(VALUE self, VALUE data)
|
||||
{
|
||||
return rb_funcall(data, s_to_msgpack, 0);
|
||||
}
|
||||
|
||||
|
||||
void Init_msgpack_pack(VALUE mMessagePack)
|
||||
{
|
||||
s_to_msgpack = rb_intern("to_msgpack");
|
||||
rb_define_method_id(rb_cNilClass, s_to_msgpack, MessagePack_NilClass_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cTrueClass, s_to_msgpack, MessagePack_TrueClass_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cFalseClass, s_to_msgpack, MessagePack_FalseClass_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cFixnum, s_to_msgpack, MessagePack_Fixnum_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cBignum, s_to_msgpack, MessagePack_Bignum_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cFloat, s_to_msgpack, MessagePack_Float_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cString, s_to_msgpack, MessagePack_String_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cArray, s_to_msgpack, MessagePack_Array_to_msgpack, -1);
|
||||
rb_define_method_id(rb_cHash, s_to_msgpack, MessagePack_Hash_to_msgpack, -1);
|
||||
rb_define_module_function(mMessagePack, "pack", MessagePack_pack, 1);
|
||||
}
|
||||
|
@@ -1,225 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'msgpack'
|
||||
require 'test/unit'
|
||||
|
||||
class MessagePackTestFormat < Test::Unit::TestCase
|
||||
def self.it(name, &block)
|
||||
define_method("test_#{name}", &block)
|
||||
end
|
||||
|
||||
it "nil" do
|
||||
check 1, nil
|
||||
end
|
||||
|
||||
it "true" do
|
||||
check 1, true
|
||||
end
|
||||
|
||||
it "false" do
|
||||
check 1, false
|
||||
end
|
||||
|
||||
it "zero" do
|
||||
check 1, 0
|
||||
end
|
||||
|
||||
it "positive fixnum" do
|
||||
check 1, 1
|
||||
check 1, (1<<6)
|
||||
check 1, (1<<7)-1
|
||||
end
|
||||
|
||||
it "positive int 8" do
|
||||
check 1, -1
|
||||
check 2, (1<<7)
|
||||
check 2, (1<<8)-1
|
||||
end
|
||||
|
||||
it "positive int 16" do
|
||||
check 3, (1<<8)
|
||||
check 3, (1<<16)-1
|
||||
end
|
||||
|
||||
it "positive int 32" do
|
||||
check 5, (1<<16)
|
||||
check 5, (1<<32)-1
|
||||
end
|
||||
|
||||
it "positive int 64" do
|
||||
check 9, (1<<32)
|
||||
check 9, (1<<64)-1
|
||||
end
|
||||
|
||||
it "negative fixnum" do
|
||||
check 1, -1
|
||||
check 1, -((1<<5)-1)
|
||||
check 1, -(1<<5)
|
||||
end
|
||||
|
||||
it "negative int 8" do
|
||||
check 2, -((1<<5)+1)
|
||||
check 2, -(1<<7)
|
||||
end
|
||||
|
||||
it "negative int 16" do
|
||||
check 3, -((1<<7)+1)
|
||||
check 3, -(1<<15)
|
||||
end
|
||||
|
||||
it "negative int 32" do
|
||||
check 5, -((1<<15)+1)
|
||||
check 5, -(1<<31)
|
||||
end
|
||||
|
||||
it "negative int 64" do
|
||||
check 9, -((1<<31)+1)
|
||||
check 9, -(1<<63)
|
||||
end
|
||||
|
||||
it "double" do
|
||||
check 9, 1.0
|
||||
check 9, 0.1
|
||||
check 9, -0.1
|
||||
check 9, -1.0
|
||||
end
|
||||
|
||||
it "fixraw" do
|
||||
check_raw 1, 0
|
||||
check_raw 1, (1<<5)-1
|
||||
end
|
||||
|
||||
it "raw 16" do
|
||||
check_raw 3, (1<<5)
|
||||
check_raw 3, (1<<16)-1
|
||||
end
|
||||
|
||||
it "raw 32" do
|
||||
check_raw 5, (1<<16)
|
||||
#check_raw 5, (1<<32)-1 # memory error
|
||||
end
|
||||
|
||||
it "fixarray" do
|
||||
check_array 1, 0
|
||||
check_array 1, (1<<4)-1
|
||||
end
|
||||
|
||||
it "array 16" do
|
||||
check_array 3, (1<<4)
|
||||
check_array 3, (1<<16)-1
|
||||
end
|
||||
|
||||
it "array 32" do
|
||||
check_array 5, (1<<16)
|
||||
#check_array 5, (1<<32)-1 # memory error
|
||||
end
|
||||
|
||||
it "nil" do
|
||||
match nil, "\xc0"
|
||||
end
|
||||
|
||||
it "false" do
|
||||
match false, "\xc2"
|
||||
end
|
||||
|
||||
it "true" do
|
||||
match true, "\xc3"
|
||||
end
|
||||
|
||||
it "0" do
|
||||
match 0, "\x00"
|
||||
end
|
||||
|
||||
it "127" do
|
||||
match 127, "\x7f"
|
||||
end
|
||||
|
||||
it "128" do
|
||||
match 128, "\xcc\x80"
|
||||
end
|
||||
|
||||
it "256" do
|
||||
match 256, "\xcd\x01\x00"
|
||||
end
|
||||
|
||||
it "-1" do
|
||||
match -1, "\xff"
|
||||
end
|
||||
|
||||
it "-33" do
|
||||
match -33, "\xd0\xdf"
|
||||
end
|
||||
|
||||
it "-129" do
|
||||
match -129, "\xd1\xff\x7f"
|
||||
end
|
||||
|
||||
it "{1=>1}" do
|
||||
match ({1=>1}), "\x81\x01\x01"
|
||||
end
|
||||
|
||||
it "1.0" do
|
||||
match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
|
||||
end
|
||||
|
||||
it "[]" do
|
||||
match [], "\x90"
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 14]" do
|
||||
match (0..14).to_a, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
|
||||
end
|
||||
|
||||
it "[0, 1, ..., 15]" do
|
||||
match (0..15).to_a, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
end
|
||||
|
||||
it "{}" do
|
||||
match ({}), "\x80"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 14=>14}" do
|
||||
a = (0..14).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 15=>15}" do
|
||||
a = (0..15).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
|
||||
end
|
||||
|
||||
# it "fixmap" do
|
||||
# check_map 1, 0
|
||||
# check_map 1, (1<<4)-1
|
||||
# end
|
||||
#
|
||||
# it "map 16" do
|
||||
# check_map 3, (1<<4)
|
||||
# check_map 3, (1<<16)-1
|
||||
# end
|
||||
#
|
||||
# it "map 32" do
|
||||
# check_map 5, (1<<16)
|
||||
# #check_map 5, (1<<32)-1 # memory error
|
||||
# end
|
||||
|
||||
private
|
||||
def check(len, obj)
|
||||
v = obj.to_msgpack
|
||||
assert_equal(v.length, len)
|
||||
assert_equal(MessagePack.unpack(v), obj)
|
||||
end
|
||||
|
||||
def check_raw(overhead, num)
|
||||
check num+overhead, " "*num
|
||||
end
|
||||
|
||||
def check_array(overhead, num)
|
||||
check num+overhead, Array.new(num)
|
||||
end
|
||||
|
||||
def match(obj, buf)
|
||||
assert_equal(obj.to_msgpack, buf)
|
||||
assert_equal(MessagePack::unpack(buf), obj)
|
||||
end
|
||||
end
|
||||
|
@@ -1,122 +0,0 @@
|
||||
require 'msgpack'
|
||||
|
||||
@up = MessagePack::Unpacker.new
|
||||
|
||||
def check(bytes, should)
|
||||
puts "----"
|
||||
@up.reset
|
||||
src = bytes.pack('C*')
|
||||
ret = @up.execute(src, 0)
|
||||
if ret != src.length
|
||||
puts "** EXTRA BYTES **"
|
||||
end
|
||||
puts bytes.map{|x|"%x"%x}.join(' ')
|
||||
data = @up.data
|
||||
p data
|
||||
if data != should
|
||||
puts "** TEST FAILED **"
|
||||
p should
|
||||
end
|
||||
end
|
||||
|
||||
# SimpleValue
|
||||
check([
|
||||
0x93, 0xc0, 0xc2, 0xc3,
|
||||
], [nil,false,true])
|
||||
|
||||
# Fixnum
|
||||
check([
|
||||
0x92,
|
||||
0x93, 0x00, 0x40, 0x7f,
|
||||
0x93, 0xe0, 0xf0, 0xff,
|
||||
], [[0,64,127], [-32,-16,-1]])
|
||||
|
||||
# FixArray
|
||||
check([
|
||||
0x92,
|
||||
0x90,
|
||||
0x91,
|
||||
0x91, 0xc0,
|
||||
], [[],[[nil]]])
|
||||
|
||||
|
||||
# FixRaw
|
||||
check([
|
||||
0x94,
|
||||
0xa0,
|
||||
0xa1, ?a,
|
||||
0xa2, ?b, ?c,
|
||||
0xa3, ?d, ?e, ?f,
|
||||
], ["","a","bc","def"])
|
||||
|
||||
# FixMap
|
||||
check([
|
||||
0x82,
|
||||
0xc2, 0x81,
|
||||
0xc0, 0xc0,
|
||||
0xc3, 0x81,
|
||||
0xc0, 0x80,
|
||||
], {false=>{nil=>nil}, true=>{nil=>{}}})
|
||||
|
||||
# unsigned int
|
||||
check([
|
||||
0x99,
|
||||
0xcc, 0,
|
||||
0xcc, 128,
|
||||
0xcc, 255,
|
||||
0xcd, 0x00, 0x00,
|
||||
0xcd, 0x80, 0x00,
|
||||
0xcd, 0xff, 0xff,
|
||||
0xce, 0x00, 0x00, 0x00, 0x00,
|
||||
0xce, 0x80, 0x00, 0x00, 0x00,
|
||||
0xce, 0xff, 0xff, 0xff, 0xff,
|
||||
], [0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295])
|
||||
|
||||
# signed int
|
||||
check([
|
||||
0x99,
|
||||
0xd0, 0,
|
||||
0xd0, 128,
|
||||
0xd0, 255,
|
||||
0xd1, 0x00, 0x00,
|
||||
0xd1, 0x80, 0x00,
|
||||
0xd1, 0xff, 0xff,
|
||||
0xd2, 0x00, 0x00, 0x00, 0x00,
|
||||
0xd2, 0x80, 0x00, 0x00, 0x00,
|
||||
0xd2, 0xff, 0xff, 0xff, 0xff,
|
||||
], [0, -128, -1, 0, -32768, -1, 0, -2147483648, -1])
|
||||
|
||||
# raw
|
||||
check([
|
||||
0x96,
|
||||
0xda, 0x00, 0x00,
|
||||
0xda, 0x00, 0x01, ?a,
|
||||
0xda, 0x00, 0x02, ?a, ?b,
|
||||
0xdb, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdb, 0x00, 0x00, 0x00, 0x01, ?a,
|
||||
0xdb, 0x00, 0x00, 0x00, 0x02, ?a, ?b,
|
||||
], ["", "a", "ab", "", "a", "ab"])
|
||||
|
||||
# array
|
||||
check([
|
||||
0x96,
|
||||
0xdc, 0x00, 0x00,
|
||||
0xdc, 0x00, 0x01, 0xc0,
|
||||
0xdc, 0x00, 0x02, 0xc2, 0xc3,
|
||||
0xdd, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdd, 0x00, 0x00, 0x00, 0x01, 0xc0,
|
||||
0xdd, 0x00, 0x00, 0x00, 0x02, 0xc2, 0xc3
|
||||
], [[], [nil], [false,true], [], [nil], [false,true]])
|
||||
|
||||
# map
|
||||
check([
|
||||
0x96,
|
||||
0xde, 0x00, 0x00,
|
||||
0xde, 0x00, 0x01, 0xc0, 0xc2,
|
||||
0xde, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
|
||||
0xdf, 0x00, 0x00, 0x00, 0x00,
|
||||
0xdf, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xc2,
|
||||
0xdf, 0x00, 0x00, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2,
|
||||
], [{}, {nil=>false}, {true=>false, nil=>false}, {}, {nil=>false}, {true=>false, nil=>false}])
|
||||
|
||||
|
@@ -1,58 +0,0 @@
|
||||
require 'msgpack'
|
||||
|
||||
def check(data)
|
||||
puts "---"
|
||||
pack = data.to_msgpack
|
||||
p data
|
||||
puts pack.unpack('C*').map{|x|"%02x"%x}.join(' ')
|
||||
re = MessagePack::unpack(pack)
|
||||
if re != data
|
||||
p re
|
||||
puts "** TEST FAILED **"
|
||||
end
|
||||
end
|
||||
|
||||
check 0
|
||||
check 1
|
||||
check 127
|
||||
check 128
|
||||
check 255
|
||||
check 256
|
||||
check 65535
|
||||
check 65536
|
||||
check -1
|
||||
check -32
|
||||
check -33
|
||||
check -128
|
||||
check -129
|
||||
check -32768
|
||||
check -32769
|
||||
|
||||
check 1.0
|
||||
|
||||
check ""
|
||||
check "a"
|
||||
check "a"*31
|
||||
check "a"*32
|
||||
|
||||
check nil
|
||||
check true
|
||||
check false
|
||||
|
||||
check []
|
||||
check [[]]
|
||||
check [[], nil]
|
||||
|
||||
check( {nil=>0} )
|
||||
|
||||
check (1<<23)
|
||||
__END__
|
||||
|
||||
ary = []
|
||||
i = 0
|
||||
while i < (1<<16)
|
||||
ary << i
|
||||
i += 1
|
||||
end
|
||||
check ary
|
||||
|
318
ruby/unpack.c
318
ruby/unpack.c
@@ -1,318 +0,0 @@
|
||||
/*
|
||||
* MessagePack for Ruby 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.
|
||||
*/
|
||||
#include "ruby.h"
|
||||
#include "msgpack/unpack_define.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
int finished;
|
||||
VALUE source;
|
||||
} unpack_user;
|
||||
|
||||
|
||||
#define msgpack_unpack_struct(name) \
|
||||
struct template ## name
|
||||
|
||||
#define msgpack_unpack_func(ret, name) \
|
||||
ret template ## name
|
||||
|
||||
#define msgpack_unpack_callback(name) \
|
||||
template_callback ## name
|
||||
|
||||
#define msgpack_unpack_object VALUE
|
||||
|
||||
#define msgpack_unpack_user unpack_user
|
||||
|
||||
|
||||
struct template_context;
|
||||
typedef struct template_context msgpack_unpack_t;
|
||||
|
||||
static void template_init(msgpack_unpack_t* u);
|
||||
|
||||
static VALUE template_data(msgpack_unpack_t* u);
|
||||
|
||||
static int template_execute(msgpack_unpack_t* u,
|
||||
const char* data, size_t len, size_t* off);
|
||||
|
||||
|
||||
static inline VALUE template_callback_root(unpack_user* u)
|
||||
{ return Qnil; }
|
||||
|
||||
static inline int template_callback_uint8(unpack_user* u, uint8_t d, VALUE* o)
|
||||
{ *o = INT2FIX(d); return 0; }
|
||||
|
||||
static inline int template_callback_uint16(unpack_user* u, uint16_t d, VALUE* o)
|
||||
{ *o = INT2FIX(d); return 0; }
|
||||
|
||||
static inline int template_callback_uint32(unpack_user* u, uint32_t d, VALUE* o)
|
||||
{ *o = UINT2NUM(d); return 0; }
|
||||
|
||||
static inline int template_callback_uint64(unpack_user* u, uint64_t d, VALUE* o)
|
||||
{ *o = rb_ull2inum(d); return 0; }
|
||||
|
||||
static inline int template_callback_int8(unpack_user* u, int8_t d, VALUE* o)
|
||||
{ *o = INT2FIX((long)d); return 0; }
|
||||
|
||||
static inline int template_callback_int16(unpack_user* u, int16_t d, VALUE* o)
|
||||
{ *o = INT2FIX((long)d); return 0; }
|
||||
|
||||
static inline int template_callback_int32(unpack_user* u, int32_t d, VALUE* o)
|
||||
{ *o = INT2NUM((long)d); return 0; }
|
||||
|
||||
static inline int template_callback_int64(unpack_user* u, int64_t d, VALUE* o)
|
||||
{ *o = rb_ll2inum(d); return 0; }
|
||||
|
||||
static inline int template_callback_float(unpack_user* u, float d, VALUE* o)
|
||||
{ *o = rb_float_new(d); return 0; }
|
||||
|
||||
static inline int template_callback_double(unpack_user* u, double d, VALUE* o)
|
||||
{ *o = rb_float_new(d); return 0; }
|
||||
|
||||
static inline int template_callback_nil(unpack_user* u, VALUE* o)
|
||||
{ *o = Qnil; return 0; }
|
||||
|
||||
static inline int template_callback_true(unpack_user* u, VALUE* o)
|
||||
{ *o = Qtrue; return 0; }
|
||||
|
||||
static inline int template_callback_false(unpack_user* u, VALUE* o)
|
||||
{ *o = Qfalse; return 0;}
|
||||
|
||||
static inline int template_callback_array(unpack_user* u, unsigned int n, VALUE* o)
|
||||
{ *o = rb_ary_new2(n); return 0; }
|
||||
|
||||
static inline int template_callback_array_item(unpack_user* u, VALUE* c, VALUE o)
|
||||
{ rb_ary_push(*c, o); return 0; } // FIXME set value directry RARRAY_PTR(obj)[RARRAY_LEN(obj)++]
|
||||
|
||||
static inline int template_callback_map(unpack_user* u, unsigned int n, VALUE* o)
|
||||
{ *o = rb_hash_new(); return 0; }
|
||||
|
||||
static inline int template_callback_map_item(unpack_user* u, VALUE* c, VALUE k, VALUE v)
|
||||
{ rb_hash_aset(*c, k, v); return 0; }
|
||||
|
||||
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, VALUE* o)
|
||||
{ *o = (l == 0) ? rb_str_new(0,0) : rb_str_substr(u->source, p - b, l); return 0; }
|
||||
|
||||
|
||||
#include "msgpack/unpack_template.h"
|
||||
|
||||
|
||||
#define UNPACKER(from, name) \
|
||||
msgpack_unpack_t *name = NULL; \
|
||||
Data_Get_Struct(from, msgpack_unpack_t, name); \
|
||||
if(name == NULL) { \
|
||||
rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
|
||||
}
|
||||
|
||||
#define CHECK_STRING_TYPE(value) \
|
||||
value = rb_check_string_type(value); \
|
||||
if( NIL_P(value) ) { \
|
||||
rb_raise(rb_eTypeError, "instance of String needed"); \
|
||||
}
|
||||
|
||||
static VALUE cUnpacker;
|
||||
static VALUE eUnpackError;
|
||||
|
||||
static void MessagePack_Unpacker_free(void* data)
|
||||
{
|
||||
if(data) { free(data); }
|
||||
}
|
||||
|
||||
static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0; i < mp->top; ++i) {
|
||||
rb_gc_mark(mp->stack[i].obj);
|
||||
rb_gc_mark(mp->stack[i].map_key);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_alloc(VALUE klass)
|
||||
{
|
||||
VALUE obj;
|
||||
msgpack_unpack_t* mp = ALLOC_N(msgpack_unpack_t, 1);
|
||||
obj = Data_Wrap_Struct(klass, MessagePack_Unpacker_mark,
|
||||
MessagePack_Unpacker_free, mp);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_reset(VALUE self)
|
||||
{
|
||||
UNPACKER(self, mp);
|
||||
template_init(mp);
|
||||
unpack_user u = {0, Qnil};
|
||||
mp->user = u;
|
||||
return self;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_initialize(VALUE self)
|
||||
{
|
||||
return MessagePack_Unpacker_reset(self);
|
||||
}
|
||||
|
||||
|
||||
static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
|
||||
{
|
||||
VALUE self = ((VALUE*)args)[0];
|
||||
VALUE data = ((VALUE*)args)[1];
|
||||
|
||||
UNPACKER(self, mp);
|
||||
size_t from = NUM2UINT(((VALUE*)args)[2]);
|
||||
char* dptr = RSTRING_PTR(data);
|
||||
long dlen = FIX2LONG(((VALUE*)args)[3]);
|
||||
int ret;
|
||||
|
||||
if(from >= dlen) {
|
||||
rb_raise(eUnpackError, "offset is bigger than data buffer size.");
|
||||
}
|
||||
|
||||
mp->user.source = data;
|
||||
ret = template_execute(mp, dptr, (size_t)dlen, &from);
|
||||
mp->user.source = Qnil;
|
||||
|
||||
if(ret < 0) {
|
||||
rb_raise(eUnpackError, "parse error.");
|
||||
} else if(ret > 0) {
|
||||
mp->user.finished = 1;
|
||||
return ULONG2NUM(from);
|
||||
} else {
|
||||
mp->user.finished = 0;
|
||||
return ULONG2NUM(from);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
|
||||
{
|
||||
rb_gc_enable();
|
||||
#ifdef RUBY_VM
|
||||
rb_exc_raise(rb_errinfo());
|
||||
#else
|
||||
rb_exc_raise(ruby_errinfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
|
||||
VALUE off, VALUE limit)
|
||||
{
|
||||
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
||||
rb_gc_disable();
|
||||
VALUE args[4] = {self, data, off, limit};
|
||||
VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
|
||||
MessagePack_Unpacker_execute_rescue, Qnil);
|
||||
rb_gc_enable();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
||||
{
|
||||
return MessagePack_Unpacker_execute_limit(self, data, off,
|
||||
LONG2FIX(RSTRING_LEN(data)));
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
||||
{
|
||||
UNPACKER(self, mp);
|
||||
if(mp->user.finished) {
|
||||
return Qtrue;
|
||||
}
|
||||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_Unpacker_data(VALUE self)
|
||||
{
|
||||
UNPACKER(self, mp);
|
||||
return template_data(mp);
|
||||
}
|
||||
|
||||
|
||||
static VALUE MessagePack_unpack_impl(VALUE args)
|
||||
{
|
||||
msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
|
||||
VALUE data = ((VALUE*)args)[1];
|
||||
|
||||
size_t from = 0;
|
||||
char* dptr = RSTRING_PTR(data);
|
||||
long dlen = FIX2LONG(((VALUE*)args)[2]);
|
||||
int ret;
|
||||
|
||||
mp->user.source = data;
|
||||
ret = template_execute(mp, dptr, (size_t)dlen, &from);
|
||||
mp->user.source = Qnil;
|
||||
|
||||
if(ret < 0) {
|
||||
rb_raise(eUnpackError, "parse error.");
|
||||
} else if(ret == 0) {
|
||||
rb_raise(eUnpackError, "insufficient bytes.");
|
||||
} else {
|
||||
if(from < dlen) {
|
||||
rb_raise(eUnpackError, "extra bytes.");
|
||||
}
|
||||
return template_data(mp);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE MessagePack_unpack_rescue(VALUE args)
|
||||
{
|
||||
rb_gc_enable();
|
||||
#ifdef RUBY_VM
|
||||
rb_exc_raise(rb_errinfo());
|
||||
#else
|
||||
rb_exc_raise(ruby_errinfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
|
||||
{
|
||||
CHECK_STRING_TYPE(data);
|
||||
|
||||
msgpack_unpack_t mp;
|
||||
template_init(&mp);
|
||||
unpack_user u = {0, Qnil};
|
||||
mp.user = u;
|
||||
|
||||
rb_gc_disable();
|
||||
VALUE args[3] = {(VALUE)&mp, data, limit};
|
||||
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
||||
MessagePack_unpack_rescue, Qnil);
|
||||
rb_gc_enable();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
||||
{
|
||||
return MessagePack_unpack_limit(self, data,
|
||||
LONG2FIX(RSTRING_LEN(data)));
|
||||
}
|
||||
|
||||
|
||||
void Init_msgpack_unpack(VALUE mMessagePack)
|
||||
{
|
||||
eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
|
||||
cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
|
||||
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
||||
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
|
||||
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
|
||||
rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
|
||||
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
|
||||
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
|
||||
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
|
||||
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
|
||||
rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
|
||||
}
|
||||
|
||||
|
109
src/Makefile.am
Normal file
109
src/Makefile.am
Normal file
@@ -0,0 +1,109 @@
|
||||
|
||||
lib_LTLIBRARIES = libmsgpack.la
|
||||
|
||||
libmsgpack_la_SOURCES = \
|
||||
unpack.c \
|
||||
objectc.c \
|
||||
version.c \
|
||||
vrefbuffer.c \
|
||||
zone.c
|
||||
|
||||
if ENABLE_CXX
|
||||
libmsgpack_la_SOURCES += \
|
||||
object.cpp
|
||||
endif
|
||||
|
||||
if ENABLE_GCC_CXX_ATOMIC
|
||||
libmsgpack_la_SOURCES += \
|
||||
gcc_atomic.cpp
|
||||
endif
|
||||
|
||||
|
||||
# -version-info CURRENT:REVISION:AGE
|
||||
libmsgpack_la_LDFLAGS = -version-info 3:0:0 -no-undefined
|
||||
|
||||
|
||||
# backward compatibility
|
||||
lib_LTLIBRARIES += libmsgpackc.la
|
||||
|
||||
libmsgpackc_la_SOURCES = \
|
||||
unpack.c \
|
||||
objectc.c \
|
||||
version.c \
|
||||
vrefbuffer.c \
|
||||
zone.c
|
||||
|
||||
libmsgpackc_la_LDFLAGS = -version-info 2:0:0 -no-undefined
|
||||
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
msgpack/pack_define.h \
|
||||
msgpack/pack_template.h \
|
||||
msgpack/unpack_define.h \
|
||||
msgpack/unpack_template.h \
|
||||
msgpack/sysdep.h \
|
||||
msgpack.h \
|
||||
msgpack/sbuffer.h \
|
||||
msgpack/version.h \
|
||||
msgpack/vrefbuffer.h \
|
||||
msgpack/zbuffer.h \
|
||||
msgpack/fbuffer.h \
|
||||
msgpack/pack.h \
|
||||
msgpack/unpack.h \
|
||||
msgpack/object.h \
|
||||
msgpack/zone.h
|
||||
|
||||
if ENABLE_CXX
|
||||
nobase_include_HEADERS += \
|
||||
msgpack.hpp \
|
||||
msgpack/sbuffer.hpp \
|
||||
msgpack/vrefbuffer.hpp \
|
||||
msgpack/zbuffer.hpp \
|
||||
msgpack/fbuffer.hpp \
|
||||
msgpack/pack.hpp \
|
||||
msgpack/unpack.hpp \
|
||||
msgpack/object.hpp \
|
||||
msgpack/zone.hpp \
|
||||
msgpack/type.hpp \
|
||||
msgpack/type/bool.hpp \
|
||||
msgpack/type/deque.hpp \
|
||||
msgpack/type/float.hpp \
|
||||
msgpack/type/fixint.hpp \
|
||||
msgpack/type/int.hpp \
|
||||
msgpack/type/list.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
|
||||
endif
|
||||
|
||||
EXTRA_DIST = \
|
||||
msgpack/version.h.in \
|
||||
msgpack/zone.hpp.erb \
|
||||
msgpack/type/define.hpp.erb \
|
||||
msgpack/type/tuple.hpp.erb
|
||||
|
||||
|
||||
doxygen_c:
|
||||
cat ../Doxyfile > Doxyfile_c
|
||||
echo "FILE_PATTERNS = *.h" >> Doxyfile_c
|
||||
echo "OUTPUT_DIRECTORY = doc_c" >> Doxyfile_c
|
||||
echo "PROJECT_NAME = \"MessagePack for C\"" >> Doxyfile_c
|
||||
doxygen Doxyfile_c
|
||||
|
||||
doxygen_cpp:
|
||||
cat ../Doxyfile > Doxyfile_cpp
|
||||
echo "FILE_PATTERNS = *.hpp" >> Doxyfile_cpp
|
||||
echo "OUTPUT_DIRECTORY = doc_cpp" >> Doxyfile_cpp
|
||||
echo "PROJECT_NAME = \"MessagePack for C++\"" >> Doxyfile_cpp
|
||||
doxygen Doxyfile_cpp
|
||||
|
||||
doxygen: doxygen_c doxygen_cpp
|
||||
|
35
src/gcc_atomic.cpp
Normal file
35
src/gcc_atomic.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// MessagePack for C++ atomic operations
|
||||
//
|
||||
// Copyright (C) 2008-2013 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.
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
||||
|
||||
#include "gcc_atomic.h"
|
||||
#include <bits/atomicity.h>
|
||||
|
||||
int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
|
||||
{
|
||||
return __gnu_cxx::__exchange_and_add(ptr, -1) - 1;
|
||||
}
|
||||
|
||||
int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
|
||||
{
|
||||
return __gnu_cxx::__exchange_and_add(ptr, 1) + 1;
|
||||
}
|
||||
|
||||
|
||||
#endif // old gcc workaround
|
@@ -1,8 +1,4 @@
|
||||
/*
|
||||
* MessagePack for Ruby
|
||||
*
|
||||
* 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
|
||||
@@ -15,15 +11,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pack.h"
|
||||
#include "unpack.h"
|
||||
|
||||
static VALUE mMessagePack;
|
||||
#ifndef MSGPACK_GCC_ATOMIC_H__
|
||||
#define MSGPACK_GCC_ATOMIC_H__
|
||||
|
||||
void Init_msgpack(void)
|
||||
{
|
||||
mMessagePack = rb_define_module("MessagePack");
|
||||
Init_msgpack_unpack(mMessagePack);
|
||||
Init_msgpack_pack(mMessagePack);
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int _msgpack_atomic_counter_t;
|
||||
|
||||
int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
|
||||
int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // MSGPACK_GCC_ATOMIC_H__
|
@@ -15,9 +15,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @defgroup msgpack MessagePack C
|
||||
* @{
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "msgpack/object.h"
|
||||
#include "msgpack/zone.h"
|
||||
#include "msgpack/pack.h"
|
||||
#include "msgpack/unpack.h"
|
||||
#include "msgpack/sbuffer.h"
|
||||
#include "msgpack/vrefbuffer.h"
|
||||
#include "msgpack/version.h"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user