mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
Compare commits
1259 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 | ||
![]() |
a5705183d6 | ||
![]() |
95a6316cc7 | ||
![]() |
be32e3b1fb | ||
![]() |
b4cb5e23c0 | ||
![]() |
1375732c80 | ||
![]() |
7fbe845434 | ||
![]() |
3afa9f265e | ||
![]() |
ec8932d6a1 | ||
![]() |
f7a9805f7b | ||
![]() |
aaef612a05 | ||
![]() |
da9b75f553 | ||
![]() |
d3906bd1ab | ||
![]() |
4db90d23ac | ||
![]() |
bb455c1f71 | ||
![]() |
3275eee281 | ||
![]() |
0fe79a7752 | ||
![]() |
794adf9469 | ||
![]() |
718227bc2c | ||
![]() |
390c5ad8a0 | ||
![]() |
2da4b17d0b | ||
![]() |
d19c488929 | ||
![]() |
0db5e0439d | ||
![]() |
6083bad5ff | ||
![]() |
63a507a123 | ||
![]() |
294e3fe7ab | ||
![]() |
e5c49dae13 | ||
![]() |
900785e1aa | ||
![]() |
979efbb950 | ||
![]() |
7da1a9b3cf | ||
![]() |
661f273481 | ||
![]() |
cb5c878b77 | ||
![]() |
34ed3bc9e3 | ||
![]() |
ad7cf12128 | ||
![]() |
6fb6283463 | ||
![]() |
b45dc8db61 | ||
![]() |
3397d261d8 | ||
![]() |
eaa8be8ddd | ||
![]() |
0f9dcb8610 | ||
![]() |
3446c475d7 | ||
![]() |
ffef0a0b6f | ||
![]() |
580fbe77e9 | ||
![]() |
e92e99c4d1 | ||
![]() |
c3f793aa09 | ||
![]() |
3d9908c8e5 | ||
![]() |
7b198d5966 | ||
![]() |
601209c83c | ||
![]() |
78db826a75 | ||
![]() |
c2a63b2c54 | ||
![]() |
7c27624161 | ||
![]() |
d86b90e663 | ||
![]() |
d72bef9f9a | ||
![]() |
37972dfe3e | ||
![]() |
c6496ddf13 | ||
![]() |
a95e8c790c | ||
![]() |
03942a1b90 | ||
![]() |
d4317fdc85 | ||
![]() |
b5010c71a9 | ||
![]() |
9015bd4ecf | ||
![]() |
fe2421275d | ||
![]() |
257270c1eb | ||
![]() |
0b33a634a6 | ||
![]() |
3e396ef146 | ||
![]() |
1b07b61c04 | ||
![]() |
fa2efcdb5b | ||
![]() |
a345131aaa | ||
![]() |
ffc16736ba | ||
![]() |
3c3df3133c | ||
![]() |
16a208243b | ||
![]() |
dd407410d2 | ||
![]() |
8f52ed26c7 | ||
![]() |
479263989b | ||
![]() |
87e1adcb40 | ||
![]() |
8e166de1d1 | ||
![]() |
3aef3edbad | ||
![]() |
b2fdaac99e | ||
![]() |
9a342ab7f8 | ||
![]() |
8596d36d02 | ||
![]() |
423e5132a1 | ||
![]() |
1581acfd14 | ||
![]() |
5d4189306a | ||
![]() |
f61b282886 | ||
![]() |
3fd28d0792 | ||
![]() |
dd53b141ef | ||
![]() |
99d0a41ec6 | ||
![]() |
b8e5b918a3 | ||
![]() |
71af62c1df | ||
![]() |
7d5f04917e | ||
![]() |
46d7c65621 | ||
![]() |
87f5df1503 | ||
![]() |
9a77ab57f6 | ||
![]() |
20a7ff0be8 | ||
![]() |
075081a521 | ||
![]() |
f4387e9746 | ||
![]() |
0d14239c21 | ||
![]() |
2475187c7d | ||
![]() |
4d6e9ffaa2 | ||
![]() |
6184e17a42 | ||
![]() |
e814986b4e | ||
![]() |
3a9f74e79c | ||
![]() |
a1fb1507d4 | ||
![]() |
85ca594118 | ||
![]() |
9c9393bff9 | ||
![]() |
560bd901f8 | ||
![]() |
114ef92d42 | ||
![]() |
1840ef70ae | ||
![]() |
935db853f0 | ||
![]() |
17d2ca2d63 | ||
![]() |
c930f5367b | ||
![]() |
d8a3bc920c | ||
![]() |
711e4817a5 | ||
![]() |
7cd359c1fd | ||
![]() |
2598d98922 | ||
![]() |
8617213149 | ||
![]() |
3628ea22d4 | ||
![]() |
6a0729ea91 | ||
![]() |
b0062a7f6f | ||
![]() |
b140b27b9a | ||
![]() |
e0bd2a2911 | ||
![]() |
ea41db4cc7 | ||
![]() |
5a201be844 | ||
![]() |
28e113fd00 | ||
![]() |
5710b87b06 | ||
![]() |
8c62d93bca | ||
![]() |
b8cc8b72bd | ||
![]() |
cc7379d532 | ||
![]() |
163fc6f589 | ||
![]() |
c7f193e441 | ||
![]() |
09978e500a | ||
![]() |
2fad10ca3f | ||
![]() |
e707b7a600 | ||
![]() |
e7403013e5 | ||
![]() |
c3f9696268 | ||
![]() |
cb24a0c24f | ||
![]() |
0efb8160b9 | ||
![]() |
bf13ba72b5 | ||
![]() |
6fc38d1669 | ||
![]() |
879c70f93a | ||
![]() |
6fda01111e | ||
![]() |
4f4fa39cd5 | ||
![]() |
c60b6be548 | ||
![]() |
9b4b49a6a8 | ||
![]() |
c0baf9b873 | ||
![]() |
65ef9cab66 | ||
![]() |
6ffee9e54a | ||
![]() |
43360e3786 | ||
![]() |
4d708aa4da | ||
![]() |
5d51129e65 | ||
![]() |
a0b82e39e1 | ||
![]() |
9642368835 | ||
![]() |
cbf7afc1cc |
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.
|
||||
|
||||
|
61
Makefile.am
61
Makefile.am
@@ -1,48 +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 = \
|
||||
ruby/bench.rb \
|
||||
ruby/extconf.rb \
|
||||
ruby/gem/README \
|
||||
ruby/gem/Rakefile \
|
||||
ruby/gem/test/test_helper.rb \
|
||||
ruby/gengem.sh \
|
||||
ruby/msgpack.gemspec \
|
||||
ruby/pack.c \
|
||||
ruby/pack.h \
|
||||
ruby/rbinit.c \
|
||||
ruby/test_case.rb \
|
||||
ruby/test_format.rb \
|
||||
ruby/test_pack.rb \
|
||||
ruby/unpack.c \
|
||||
ruby/unpack.h \
|
||||
perl/Makefile.PL \
|
||||
perl/MessagePack.c \
|
||||
perl/benchmark/deserialize.pl \
|
||||
perl/benchmark/serialize.pl \
|
||||
perl/lib/Data/MessagePack.pm \
|
||||
perl/lib/Data/MessagePack \
|
||||
perl/lib/Data/MessagePack/Unpacker.pod \
|
||||
perl/pack.c \
|
||||
perl/ppport.h \
|
||||
perl/t/00_compile.t \
|
||||
perl/t/01_pack.t \
|
||||
perl/t/02_unpack.t \
|
||||
perl/t/03_stream_unpack.t \
|
||||
perl/t/04_invert.t \
|
||||
perl/t/Util.pm \
|
||||
perl/t/data.pl \
|
||||
perl/unpack.c \
|
||||
perl/xt/99_pod.t
|
||||
$(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.2)
|
||||
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,47 +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
|
||||
|
||||
# FIXME
|
||||
object.lo: msgpack/type/tuple.hpp msgpack/zone.hpp
|
||||
|
||||
msgpack/type/tuple.hpp: msgpack/type/tuple.hpp.erb
|
||||
$(ERB) $< > $@.tmp
|
||||
mv $@.tmp $@
|
||||
|
||||
msgpack/zone.hpp: msgpack/zone.hpp.erb
|
||||
$(ERB) $< > $@.tmp
|
||||
mv $@.tmp $@
|
||||
|
||||
MOSTLYCLEANFILES = \
|
||||
msgpack/type/tuple.hpp \
|
||||
msgpack/zone.hpp
|
||||
|
||||
EXTRA_DIST = \
|
||||
msgpack/type/tuple.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 $@
|
||||
|
@@ -1,9 +0,0 @@
|
||||
#include "msgpack/type/array.hpp"
|
||||
#include "msgpack/type/boolean.hpp"
|
||||
#include "msgpack/type/float.hpp"
|
||||
#include "msgpack/type/integer.hpp"
|
||||
#include "msgpack/type/map.hpp"
|
||||
#include "msgpack/type/nil.hpp"
|
||||
#include "msgpack/type/raw.hpp"
|
||||
#include "msgpack/type/tuple.hpp"
|
||||
|
@@ -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
|
||||
|
58
example/custom.cc
Normal file
58
example/custom.cc
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class old_class {
|
||||
public:
|
||||
old_class() : value("default") { }
|
||||
|
||||
std::string value;
|
||||
|
||||
MSGPACK_DEFINE(value);
|
||||
};
|
||||
|
||||
class new_class {
|
||||
public:
|
||||
new_class() : value("default"), flag(-1) { }
|
||||
|
||||
std::string value;
|
||||
int flag;
|
||||
|
||||
MSGPACK_DEFINE(value, flag);
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
{
|
||||
old_class oc;
|
||||
new_class nc;
|
||||
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, oc);
|
||||
|
||||
msgpack::zone zone;
|
||||
msgpack::object obj;
|
||||
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
|
||||
|
||||
obj.convert(&nc);
|
||||
|
||||
std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
new_class nc;
|
||||
old_class oc;
|
||||
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, nc);
|
||||
|
||||
msgpack::zone zone;
|
||||
msgpack::object obj;
|
||||
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
|
||||
|
||||
obj.convert(&oc);
|
||||
|
||||
std::cout << obj << " value=" << oc.value << std::endl;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
@@ -22,25 +22,22 @@ public:
|
||||
ssize_t count =
|
||||
read(m_sock, m_pac.buffer(), m_pac.buffer_capacity());
|
||||
|
||||
if(count < 0) {
|
||||
if(count <= 0) {
|
||||
if(count == 0) {
|
||||
throw std::runtime_error("connection closed");
|
||||
}
|
||||
if(errno == EAGAIN || errno == EINTR) {
|
||||
return;
|
||||
} else {
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
} else if(count == 0) {
|
||||
throw std::runtime_error("connection closed");
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
|
||||
m_pac.buffer_consumed(count);
|
||||
|
||||
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>
|
@@ -1,34 +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";
|
||||
|
||||
my $ccflags = '-I../ ';
|
||||
|
||||
makemaker_args(
|
||||
OBJECT => '$(O_FILES)',
|
||||
LIBS => [''],
|
||||
CCFLAGS => $ccflags,
|
||||
clean => {
|
||||
FILES => q{
|
||||
*.stackdump
|
||||
*.gcov *.gcda *.gcno
|
||||
*.out
|
||||
nytprof
|
||||
cover_db
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
tests 't/*.t';
|
||||
author_tests('xt');
|
||||
|
||||
auto_set_repository;
|
||||
build_requires 'Test::More';
|
||||
use_test_base;
|
||||
auto_include;
|
||||
WriteAll;
|
||||
|
@@ -1,40 +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(boot_Data__MessagePack) {
|
||||
dXSARGS;
|
||||
HV * stash;
|
||||
|
||||
newXS("Data::MessagePack::pack", xs_pack, __FILE__);
|
||||
newXS("Data::MessagePack::unpack", xs_unpack, __FILE__);
|
||||
stash = gv_stashpvn("Data::MessagePack", strlen("Data::MessagePack"), TRUE);
|
||||
newCONSTSUB(stash, "true", &PL_sv_yes);
|
||||
newCONSTSUB(stash, "false", &PL_sv_no);
|
||||
|
||||
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__);
|
||||
|
||||
}
|
||||
|
@@ -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,33 +0,0 @@
|
||||
package Data::MessagePack;
|
||||
use strict;
|
||||
use warnings;
|
||||
use XSLoader;
|
||||
|
||||
our $VERSION = 0.01;
|
||||
|
||||
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 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>
|
||||
|
155
perl/pack.c
155
perl/pack.c
@@ -1,155 +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;
|
||||
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 */
|
||||
|
||||
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 void _msgpack_pack_sv(enc_t *enc, SV* val) {
|
||||
if (val==NULL) {
|
||||
msgpack_pack_nil(enc);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (SvTYPE(val)) {
|
||||
case SVt_NULL:
|
||||
msgpack_pack_nil(enc);
|
||||
break;
|
||||
case SVt_IV:
|
||||
if (SvIOK_UV(val)) {
|
||||
msgpack_pack_uint32(enc, SvUV(val));
|
||||
} else {
|
||||
PACK_WRAPPER(IVTYPE)(enc, SvIV(val));
|
||||
}
|
||||
break;
|
||||
case SVt_PVNV:
|
||||
{
|
||||
STRLEN len = 0;
|
||||
char *pv = SvPV(val, len);
|
||||
if (len == 1 && *pv == '1') {
|
||||
msgpack_pack_true(enc);
|
||||
} else if (len == 0 && *pv==0) {
|
||||
msgpack_pack_false(enc);
|
||||
} else {
|
||||
msgpack_pack_nil(enc);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SVt_PV:
|
||||
{
|
||||
STRLEN len;
|
||||
char * cval = SvPV(val, len);
|
||||
msgpack_pack_raw(enc, len);
|
||||
msgpack_pack_raw_body(enc, cval, len);
|
||||
}
|
||||
break;
|
||||
case SVt_NV:
|
||||
PACK_WRAPPER(NVTYPE)(enc, SvNV(val));
|
||||
break;
|
||||
case SVt_PVAV:
|
||||
{
|
||||
AV* ary = (AV*)val;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SVt_PVHV:
|
||||
{
|
||||
HV* hval = (HV*)val;
|
||||
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));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SVt_RV:
|
||||
_msgpack_pack_sv(enc, SvRV(val));
|
||||
break;
|
||||
default:
|
||||
sv_dump(val);
|
||||
Perl_croak(aTHX_ "msgpack for perl doesn't supported this type: %d\n", SvTYPE(val));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
6984
perl/ppport.h
6984
perl/ppport.h
File diff suppressed because it is too large
Load Diff
@@ -1,6 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 1;
|
||||
|
||||
use_ok 'Data::MessagePack';
|
||||
|
@@ -1,60 +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',
|
||||
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',
|
||||
"", '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,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,15 +0,0 @@
|
||||
no warnings 'uninitialized'; # 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}],
|
||||
)
|
290
perl/unpack.c
290
perl/unpack.c
@@ -1,290 +0,0 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.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
|
||||
|
||||
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 = &PL_sv_yes; return 0; }
|
||||
|
||||
static inline int template_callback_false(unpack_user* u, SV** o)
|
||||
{ *o = &PL_sv_no; 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);
|
||||
}
|
||||
|
@@ -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,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"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* MessagePack for Ruby unpacking routine
|
||||
* MessagePack for C FILE* buffer adaptor
|
||||
*
|
||||
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
* Copyright (C) 2013 Vladimir Volodko
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,12 +15,33 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef UNPACK_H__
|
||||
#define UNPACK_H__
|
||||
#ifndef MSGPACK_FBUFFER_H__
|
||||
#define MSGPACK_FBUFFER_H__
|
||||
|
||||
#include "ruby.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void Init_msgpack_unpack(VALUE mMessagePack);
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* unpack.h */
|
||||
|
||||
/**
|
||||
* @defgroup msgpack_fbuffer FILE* buffer
|
||||
* @ingroup msgpack_buffer
|
||||
* @{
|
||||
*/
|
||||
|
||||
static inline int msgpack_fbuffer_write(void* data, const char* buf, unsigned int len)
|
||||
{
|
||||
return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/fbuffer.h */
|
||||
|
56
src/msgpack/fbuffer.hpp
Normal file
56
src/msgpack/fbuffer.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// MessagePack for C++ FILE* buffer adaptor
|
||||
//
|
||||
// Copyright (C) 2013 Vladimir Volodko
|
||||
//
|
||||
// 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_FBUFFER_HPP__
|
||||
#define MSGPACK_FBUFFER_HPP__
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
class fbuffer {
|
||||
public:
|
||||
explicit fbuffer(FILE* file) : m_file(file) { }
|
||||
|
||||
public:
|
||||
void write(const char* buf, unsigned int len)
|
||||
{
|
||||
if (1 != fwrite(buf, len, 1, m_file)) {
|
||||
throw std::runtime_error("fwrite() failed");
|
||||
}
|
||||
}
|
||||
|
||||
FILE* file() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
private:
|
||||
fbuffer(const fbuffer&);
|
||||
fbuffer& operator= (const fbuffer&);
|
||||
|
||||
private:
|
||||
FILE* m_file;
|
||||
};
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/fbuffer.hpp */
|
||||
|
@@ -18,10 +18,7 @@
|
||||
#ifndef MSGPACK_OBJECT_H__
|
||||
#define MSGPACK_OBJECT_H__
|
||||
|
||||
#include "msgpack/zone.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "zone.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -29,15 +26,21 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup msgpack_object Dynamically typed object
|
||||
* @ingroup msgpack
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
MSGPACK_OBJECT_NIL = 0x01,
|
||||
MSGPACK_OBJECT_BOOLEAN = 0x02,
|
||||
MSGPACK_OBJECT_POSITIVE_INTEGER = 0x03,
|
||||
MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x04,
|
||||
MSGPACK_OBJECT_DOUBLE = 0x05,
|
||||
MSGPACK_OBJECT_RAW = 0x06,
|
||||
MSGPACK_OBJECT_ARRAY = 0x07,
|
||||
MSGPACK_OBJECT_MAP = 0x08,
|
||||
MSGPACK_OBJECT_NIL = 0x00,
|
||||
MSGPACK_OBJECT_BOOLEAN = 0x01,
|
||||
MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02,
|
||||
MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03,
|
||||
MSGPACK_OBJECT_DOUBLE = 0x04,
|
||||
MSGPACK_OBJECT_RAW = 0x05,
|
||||
MSGPACK_OBJECT_ARRAY = 0x06,
|
||||
MSGPACK_OBJECT_MAP = 0x07,
|
||||
} msgpack_object_type;
|
||||
|
||||
|
||||
@@ -82,6 +85,10 @@ typedef struct msgpack_object_kv {
|
||||
|
||||
void msgpack_object_print(FILE* out, msgpack_object o);
|
||||
|
||||
bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,9 @@
|
||||
#ifndef MSGPACK_OBJECT_HPP__
|
||||
#define MSGPACK_OBJECT_HPP__
|
||||
|
||||
#include "msgpack/object.h"
|
||||
#include "msgpack/pack.hpp"
|
||||
#include <stdint.h>
|
||||
#include "object.h"
|
||||
#include "pack.hpp"
|
||||
#include "zone.hpp"
|
||||
#include <string.h>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
@@ -35,14 +35,14 @@ class type_error : public std::bad_cast { };
|
||||
|
||||
namespace type {
|
||||
enum object_type {
|
||||
NIL = 0x01,
|
||||
BOOLEAN = 0x02,
|
||||
POSITIVE_INTEGER = 0x03,
|
||||
NEGATIVE_INTEGER = 0x04,
|
||||
DOUBLE = 0x05,
|
||||
RAW = 0x06,
|
||||
ARRAY = 0x07,
|
||||
MAP = 0x08,
|
||||
NIL = MSGPACK_OBJECT_NIL,
|
||||
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
|
||||
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
|
||||
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
|
||||
DOUBLE = MSGPACK_OBJECT_DOUBLE,
|
||||
RAW = MSGPACK_OBJECT_RAW,
|
||||
ARRAY = MSGPACK_OBJECT_ARRAY,
|
||||
MAP = MSGPACK_OBJECT_MAP,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,8 +89,21 @@ struct object {
|
||||
void convert(T* v) const;
|
||||
|
||||
object();
|
||||
object(msgpack_object obj);
|
||||
operator msgpack_object();
|
||||
|
||||
object(msgpack_object o);
|
||||
|
||||
template <typename T>
|
||||
explicit object(const T& v);
|
||||
|
||||
template <typename T>
|
||||
object(const T& v, zone* z);
|
||||
|
||||
template <typename T>
|
||||
object& operator=(const T& v);
|
||||
|
||||
operator msgpack_object() const;
|
||||
|
||||
struct with_zone;
|
||||
|
||||
private:
|
||||
struct implicit_type;
|
||||
@@ -104,18 +117,44 @@ struct object_kv {
|
||||
object val;
|
||||
};
|
||||
|
||||
struct object::with_zone : object {
|
||||
with_zone(msgpack::zone* zone) : zone(zone) { }
|
||||
msgpack::zone* zone;
|
||||
private:
|
||||
with_zone();
|
||||
};
|
||||
|
||||
|
||||
bool operator==(const object x, const object y);
|
||||
bool operator!=(const object x, const object y);
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const object x, const T& y);
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const T& y, const object x);
|
||||
|
||||
template <typename T>
|
||||
bool operator!=(const object x, const T& y);
|
||||
|
||||
template <typename T>
|
||||
bool operator!=(const T& y, const object x);
|
||||
|
||||
std::ostream& operator<< (std::ostream& s, const object o);
|
||||
|
||||
|
||||
// serialize operator
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const T& v);
|
||||
|
||||
// convert operator
|
||||
template <typename T>
|
||||
T& operator>> (object o, T& v);
|
||||
|
||||
// deconvert operator
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const T& v);
|
||||
|
||||
|
||||
struct object::implicit_type {
|
||||
implicit_type(object o) : obj(o) { }
|
||||
@@ -129,6 +168,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename Type>
|
||||
class define : public Type {
|
||||
public:
|
||||
@@ -172,33 +212,56 @@ inline T& operator>> (object o, T& v)
|
||||
return v;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template <typename Stream, typename T>
|
||||
struct packer_serializer {
|
||||
static packer<Stream>& pack(packer<Stream>& o, const T& v) {
|
||||
v.msgpack_pack(o);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const T& v)
|
||||
{
|
||||
v.msgpack_pack(o);
|
||||
return o;
|
||||
return detail::packer_serializer<Stream, T>::pack(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const T& v)
|
||||
{
|
||||
v.msgpack_object(static_cast<object*>(&o), o.zone);
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==(const object x, const object y)
|
||||
{
|
||||
return msgpack_object_equal(x, y);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const object x, const T& y)
|
||||
try {
|
||||
return x == object(y);
|
||||
} catch (msgpack::type_error&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool operator!=(const object x, const object y)
|
||||
{ return !(x == y); }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const T& y, const object x)
|
||||
{ return x == y; }
|
||||
|
||||
inline object::object() { }
|
||||
template <typename T>
|
||||
inline bool operator!=(const object x, const T& y)
|
||||
{ return !(x == y); }
|
||||
|
||||
inline object::object(msgpack_object obj)
|
||||
{
|
||||
// FIXME beter way?
|
||||
::memcpy(this, &obj, sizeof(obj));
|
||||
}
|
||||
|
||||
inline object::operator msgpack_object()
|
||||
{
|
||||
// FIXME beter way?
|
||||
msgpack_object obj;
|
||||
::memcpy(&obj, this, sizeof(obj));
|
||||
return obj;
|
||||
}
|
||||
template <typename T>
|
||||
inline bool operator!=(const T& y, const object x)
|
||||
{ return x != y; }
|
||||
|
||||
|
||||
inline object::implicit_type object::convert() const
|
||||
@@ -221,6 +284,55 @@ inline T object::as() const
|
||||
}
|
||||
|
||||
|
||||
inline object::object()
|
||||
{
|
||||
type = type::NIL;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline object::object(const T& v)
|
||||
{
|
||||
*this << v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline object& object::operator=(const T& v)
|
||||
{
|
||||
*this = object(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
object::object(const T& v, zone* z)
|
||||
{
|
||||
with_zone oz(z);
|
||||
oz << v;
|
||||
type = oz.type;
|
||||
via = oz.via;
|
||||
}
|
||||
|
||||
|
||||
inline object::object(msgpack_object o)
|
||||
{
|
||||
// FIXME beter way?
|
||||
::memcpy(this, &o, sizeof(o));
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, msgpack_object v)
|
||||
{
|
||||
// FIXME beter way?
|
||||
::memcpy(&o, &v, sizeof(v));
|
||||
}
|
||||
|
||||
inline object::operator msgpack_object() const
|
||||
{
|
||||
// FIXME beter way?
|
||||
msgpack_object obj;
|
||||
::memcpy(&obj, this, sizeof(obj));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename T>
|
||||
inline void convert(T& v, object o)
|
||||
@@ -260,35 +372,15 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||
return o;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
if(v.via.u64 <= (uint64_t)std::numeric_limits<uint16_t>::max()) {
|
||||
if(v.via.u64 <= (uint16_t)std::numeric_limits<uint8_t>::max()) {
|
||||
o.pack_uint8(v.via.u64);
|
||||
} else {
|
||||
o.pack_uint16(v.via.u64);
|
||||
}
|
||||
} else {
|
||||
if(v.via.u64 <= (uint64_t)std::numeric_limits<uint32_t>::max()) {
|
||||
o.pack_uint32(v.via.u64);
|
||||
} else {
|
||||
o.pack_uint64(v.via.u64);
|
||||
}
|
||||
}
|
||||
o.pack_uint64(v.via.u64);
|
||||
return o;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
if(v.via.i64 >= (int64_t)std::numeric_limits<int16_t>::min()) {
|
||||
if(v.via.i64 >= (int64_t)std::numeric_limits<int8_t>::min()) {
|
||||
o.pack_int8(v.via.i64);
|
||||
} else {
|
||||
o.pack_int16(v.via.i64);
|
||||
}
|
||||
} else {
|
||||
if(v.via.i64 >= (int64_t)std::numeric_limits<int32_t>::min()) {
|
||||
o.pack_int64(v.via.i64);
|
||||
} else {
|
||||
o.pack_int64(v.via.i64);
|
||||
}
|
||||
}
|
||||
o.pack_int64(v.via.i64);
|
||||
return o;
|
||||
|
||||
case type::DOUBLE:
|
||||
o.pack_double(v.via.dec);
|
||||
return o;
|
||||
|
||||
case type::RAW:
|
@@ -18,18 +18,29 @@
|
||||
#ifndef MSGPACK_PACK_H__
|
||||
#define MSGPACK_PACK_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "pack_define.h"
|
||||
#include "object.h"
|
||||
#include <stdlib.h>
|
||||
#include "msgpack/pack_define.h"
|
||||
#include "msgpack/object.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len);
|
||||
/**
|
||||
* @defgroup msgpack_buffer Buffers
|
||||
* @ingroup msgpack
|
||||
* @{
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup msgpack_pack Serializer
|
||||
* @ingroup msgpack
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef int (*msgpack_packer_write)(void* data, const char* buf, size_t len);
|
||||
|
||||
typedef struct msgpack_packer {
|
||||
void* data;
|
||||
@@ -41,10 +52,14 @@ static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_w
|
||||
static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback);
|
||||
static void msgpack_packer_free(msgpack_packer* pk);
|
||||
|
||||
static int msgpack_pack_char(msgpack_packer* pk, char d);
|
||||
|
||||
static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d);
|
||||
static int msgpack_pack_short(msgpack_packer* pk, short d);
|
||||
static int msgpack_pack_int(msgpack_packer* pk, int d);
|
||||
static int msgpack_pack_long(msgpack_packer* pk, long d);
|
||||
static int msgpack_pack_long_long(msgpack_packer* pk, long long d);
|
||||
static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d);
|
||||
static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
|
||||
static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
|
||||
static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
|
||||
@@ -59,6 +74,15 @@ static int msgpack_pack_int16(msgpack_packer* pk, int16_t d);
|
||||
static int msgpack_pack_int32(msgpack_packer* pk, int32_t d);
|
||||
static int msgpack_pack_int64(msgpack_packer* pk, int64_t d);
|
||||
|
||||
static int msgpack_pack_fix_uint8(msgpack_packer* pk, uint8_t d);
|
||||
static int msgpack_pack_fix_uint16(msgpack_packer* pk, uint16_t d);
|
||||
static int msgpack_pack_fix_uint32(msgpack_packer* pk, uint32_t d);
|
||||
static int msgpack_pack_fix_uint64(msgpack_packer* pk, uint64_t d);
|
||||
static int msgpack_pack_fix_int8(msgpack_packer* pk, int8_t d);
|
||||
static int msgpack_pack_fix_int16(msgpack_packer* pk, int16_t d);
|
||||
static int msgpack_pack_fix_int32(msgpack_packer* pk, int32_t d);
|
||||
static int msgpack_pack_fix_int64(msgpack_packer* pk, int64_t d);
|
||||
|
||||
static int msgpack_pack_float(msgpack_packer* pk, float d);
|
||||
static int msgpack_pack_double(msgpack_packer* pk, double d);
|
||||
|
||||
@@ -66,9 +90,9 @@ static int msgpack_pack_nil(msgpack_packer* pk);
|
||||
static int msgpack_pack_true(msgpack_packer* pk);
|
||||
static int msgpack_pack_false(msgpack_packer* pk);
|
||||
|
||||
static int msgpack_pack_array(msgpack_packer* pk, unsigned int n);
|
||||
static int msgpack_pack_array(msgpack_packer* pk, size_t n);
|
||||
|
||||
static int msgpack_pack_map(msgpack_packer* pk, unsigned int n);
|
||||
static int msgpack_pack_map(msgpack_packer* pk, size_t n);
|
||||
|
||||
static int msgpack_pack_raw(msgpack_packer* pk, size_t l);
|
||||
static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l);
|
||||
@@ -76,6 +100,8 @@ static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l);
|
||||
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#define msgpack_pack_inline_func(name) \
|
||||
inline int msgpack_pack ## name
|
||||
@@ -83,12 +109,15 @@ int msgpack_pack_object(msgpack_packer* pk, msgpack_object d);
|
||||
#define msgpack_pack_inline_func_cint(name) \
|
||||
inline int msgpack_pack ## name
|
||||
|
||||
#define msgpack_pack_inline_func_fixint(name) \
|
||||
inline int msgpack_pack_fix ## name
|
||||
|
||||
#define msgpack_pack_user msgpack_packer*
|
||||
|
||||
#define msgpack_pack_append_buffer(user, buf, len) \
|
||||
return (*(user)->callback)((user)->data, (const char*)buf, len)
|
||||
|
||||
#include "msgpack/pack_template.h"
|
||||
#include "pack_template.h"
|
||||
|
||||
inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback)
|
||||
{
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ serializing routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +18,9 @@
|
||||
#ifndef MSGPACK_PACK_HPP__
|
||||
#define MSGPACK_PACK_HPP__
|
||||
|
||||
#include <arpa/inet.h> // __BYTE_ORDER
|
||||
#include "pack_define.h"
|
||||
#include <stdexcept>
|
||||
#include <limits.h>
|
||||
#include "msgpack/pack_define.h"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
@@ -29,6 +28,7 @@ namespace msgpack {
|
||||
template <typename Stream>
|
||||
class packer {
|
||||
public:
|
||||
packer(Stream* s);
|
||||
packer(Stream& s);
|
||||
~packer();
|
||||
|
||||
@@ -40,15 +40,27 @@ public:
|
||||
packer<Stream>& pack_uint16(uint16_t d);
|
||||
packer<Stream>& pack_uint32(uint32_t d);
|
||||
packer<Stream>& pack_uint64(uint64_t d);
|
||||
packer<Stream>& pack_int8(uint8_t d);
|
||||
packer<Stream>& pack_int16(uint16_t d);
|
||||
packer<Stream>& pack_int32(uint32_t d);
|
||||
packer<Stream>& pack_int64(uint64_t d);
|
||||
packer<Stream>& pack_int8(int8_t d);
|
||||
packer<Stream>& pack_int16(int16_t d);
|
||||
packer<Stream>& pack_int32(int32_t d);
|
||||
packer<Stream>& pack_int64(int64_t d);
|
||||
|
||||
packer<Stream>& pack_short(int d);
|
||||
packer<Stream>& pack_fix_uint8(uint8_t d);
|
||||
packer<Stream>& pack_fix_uint16(uint16_t d);
|
||||
packer<Stream>& pack_fix_uint32(uint32_t d);
|
||||
packer<Stream>& pack_fix_uint64(uint64_t d);
|
||||
packer<Stream>& pack_fix_int8(int8_t d);
|
||||
packer<Stream>& pack_fix_int16(int16_t d);
|
||||
packer<Stream>& pack_fix_int32(int32_t d);
|
||||
packer<Stream>& pack_fix_int64(int64_t d);
|
||||
|
||||
packer<Stream>& pack_char(char d);
|
||||
packer<Stream>& pack_signed_char(signed char d);
|
||||
packer<Stream>& pack_short(short d);
|
||||
packer<Stream>& pack_int(int d);
|
||||
packer<Stream>& pack_long(long d);
|
||||
packer<Stream>& pack_long_long(long long d);
|
||||
packer<Stream>& pack_unsigned_char(unsigned char d);
|
||||
packer<Stream>& pack_unsigned_short(unsigned short d);
|
||||
packer<Stream>& pack_unsigned_int(unsigned int d);
|
||||
packer<Stream>& pack_unsigned_long(unsigned long d);
|
||||
@@ -61,9 +73,9 @@ public:
|
||||
packer<Stream>& pack_true();
|
||||
packer<Stream>& pack_false();
|
||||
|
||||
packer<Stream>& pack_array(unsigned int n);
|
||||
packer<Stream>& pack_array(size_t n);
|
||||
|
||||
packer<Stream>& pack_map(unsigned int n);
|
||||
packer<Stream>& pack_map(size_t n);
|
||||
|
||||
packer<Stream>& pack_raw(size_t l);
|
||||
packer<Stream>& pack_raw_body(const char* b, size_t l);
|
||||
@@ -78,10 +90,23 @@ private:
|
||||
static void _pack_int32(Stream& x, int32_t d);
|
||||
static void _pack_int64(Stream& x, int64_t d);
|
||||
|
||||
static void _pack_fix_uint8(Stream& x, uint8_t d);
|
||||
static void _pack_fix_uint16(Stream& x, uint16_t d);
|
||||
static void _pack_fix_uint32(Stream& x, uint32_t d);
|
||||
static void _pack_fix_uint64(Stream& x, uint64_t d);
|
||||
static void _pack_fix_int8(Stream& x, int8_t d);
|
||||
static void _pack_fix_int16(Stream& x, int16_t d);
|
||||
static void _pack_fix_int32(Stream& x, int32_t d);
|
||||
static void _pack_fix_int64(Stream& x, int64_t d);
|
||||
|
||||
static void _pack_char(Stream& x, char d);
|
||||
|
||||
static void _pack_signed_char(Stream& x, signed char d);
|
||||
static void _pack_short(Stream& x, short d);
|
||||
static void _pack_int(Stream& x, int d);
|
||||
static void _pack_long(Stream& x, long d);
|
||||
static void _pack_long_long(Stream& x, long long d);
|
||||
static void _pack_unsigned_char(Stream& x, unsigned char d);
|
||||
static void _pack_unsigned_short(Stream& x, unsigned short d);
|
||||
static void _pack_unsigned_int(Stream& x, unsigned int d);
|
||||
static void _pack_unsigned_long(Stream& x, unsigned long d);
|
||||
@@ -94,14 +119,14 @@ private:
|
||||
static void _pack_true(Stream& x);
|
||||
static void _pack_false(Stream& x);
|
||||
|
||||
static void _pack_array(Stream& x, unsigned int n);
|
||||
static void _pack_array(Stream& x, size_t n);
|
||||
|
||||
static void _pack_map(Stream& x, unsigned int n);
|
||||
static void _pack_map(Stream& x, size_t n);
|
||||
|
||||
static void _pack_raw(Stream& x, size_t l);
|
||||
static void _pack_raw_body(Stream& x, const void* b, size_t l);
|
||||
|
||||
static void append_buffer(Stream& x, const unsigned char* buf, unsigned int len)
|
||||
static void append_buffer(Stream& x, const unsigned char* buf, size_t len)
|
||||
{ x.write((const char*)buf, len); }
|
||||
|
||||
private:
|
||||
@@ -112,6 +137,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline void pack(Stream* s, const T& v)
|
||||
{
|
||||
packer<Stream>(s).pack(v);
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline void pack(Stream& s, const T& v)
|
||||
{
|
||||
@@ -127,19 +158,27 @@ inline void pack(Stream& s, const T& v)
|
||||
template <typename Stream> \
|
||||
inline void packer<Stream>::_pack ## name
|
||||
|
||||
#define msgpack_pack_inline_func_fixint(name) \
|
||||
template <typename Stream> \
|
||||
inline void packer<Stream>::_pack_fix ## name
|
||||
|
||||
#define msgpack_pack_user Stream&
|
||||
|
||||
#define msgpack_pack_append_buffer append_buffer
|
||||
|
||||
#include "msgpack/pack_template.h"
|
||||
#include "pack_template.h"
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>::packer(Stream* s) : m_stream(*s) { }
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>::packer(Stream& s) : m_stream(s) { }
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>::~packer() { }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_uint8(uint8_t d)
|
||||
{ _pack_uint8(m_stream, d); return *this; }
|
||||
@@ -157,24 +196,65 @@ inline packer<Stream>& packer<Stream>::pack_uint64(uint64_t d)
|
||||
{ _pack_uint64(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_int8(uint8_t d)
|
||||
inline packer<Stream>& packer<Stream>::pack_int8(int8_t d)
|
||||
{ _pack_int8(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_int16(uint16_t d)
|
||||
inline packer<Stream>& packer<Stream>::pack_int16(int16_t d)
|
||||
{ _pack_int16(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_int32(uint32_t d)
|
||||
inline packer<Stream>& packer<Stream>::pack_int32(int32_t d)
|
||||
{ _pack_int32(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_int64(uint64_t d)
|
||||
inline packer<Stream>& packer<Stream>::pack_int64(int64_t d)
|
||||
{ _pack_int64(m_stream, d); return *this;}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_short(int d)
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint8(uint8_t d)
|
||||
{ _pack_fix_uint8(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint16(uint16_t d)
|
||||
{ _pack_fix_uint16(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint32(uint32_t d)
|
||||
{ _pack_fix_uint32(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint64(uint64_t d)
|
||||
{ _pack_fix_uint64(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int8(int8_t d)
|
||||
{ _pack_fix_int8(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int16(int16_t d)
|
||||
{ _pack_fix_int16(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int32(int32_t d)
|
||||
{ _pack_fix_int32(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
|
||||
{ _pack_fix_int64(m_stream, d); return *this;}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_char(char d)
|
||||
{ _pack_char(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_signed_char(signed char d)
|
||||
{ _pack_signed_char(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_short(short d)
|
||||
{ _pack_short(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
@@ -189,6 +269,10 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
||||
{ _pack_long_long(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_char(unsigned char d)
|
||||
{ _pack_unsigned_char(m_stream, d); return *this; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
||||
{ _pack_unsigned_short(m_stream, d); return *this; }
|
||||
@@ -229,12 +313,12 @@ inline packer<Stream>& packer<Stream>::pack_false()
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_array(unsigned int n)
|
||||
inline packer<Stream>& packer<Stream>::pack_array(size_t n)
|
||||
{ _pack_array(m_stream, n); return *this; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_map(unsigned int n)
|
||||
inline packer<Stream>& packer<Stream>::pack_map(size_t n)
|
||||
{ _pack_map(m_stream, n); return *this; }
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* MessagePack unpacking routine template
|
||||
*
|
||||
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,9 @@
|
||||
#ifndef MSGPACK_PACK_DEFINE_H__
|
||||
#define MSGPACK_PACK_DEFINE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "msgpack/sysdep.h"
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#endif /* msgpack/pack_define.h */
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* MessagePack packing routine template
|
||||
*
|
||||
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,88 +16,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN__
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#define STORE8_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE16_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE16_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE32_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE32_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#define STORE64_BE8(d) \
|
||||
((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE16(d) \
|
||||
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE32(d) \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
#define STORE64_BE64(d) \
|
||||
((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \
|
||||
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
||||
|
||||
|
||||
#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]
|
||||
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
#define TAKE8_8(d) ((uint8_t*)&d)[0]
|
||||
#define TAKE8_16(d) ((uint8_t*)&d)[0]
|
||||
#define TAKE8_32(d) ((uint8_t*)&d)[0]
|
||||
#define TAKE8_64(d) ((uint8_t*)&d)[0]
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
#define TAKE8_8(d) ((uint8_t*)&d)[0]
|
||||
#define TAKE8_16(d) ((uint8_t*)&d)[1]
|
||||
#define TAKE8_32(d) ((uint8_t*)&d)[3]
|
||||
#define TAKE8_64(d) ((uint8_t*)&d)[7]
|
||||
#endif
|
||||
|
||||
#ifndef msgpack_pack_inline_func
|
||||
@@ -121,10 +49,10 @@
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} while(0)
|
||||
@@ -133,14 +61,15 @@ do { \
|
||||
do { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
||||
} else if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} while(0)
|
||||
@@ -150,20 +79,22 @@ do { \
|
||||
if(d < (1<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
@@ -172,26 +103,29 @@ do { \
|
||||
#define msgpack_pack_real_uint64(x, d) \
|
||||
do { \
|
||||
if(d < (1ULL<<8)) { \
|
||||
if(d < (1<<7)) { \
|
||||
if(d < (1ULL<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
||||
} else { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1ULL<<16)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
/* unsigned 16 */ \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else if(d < (1ULL<<32)) { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
/* unsigned 32 */ \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* signed 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
||||
/* unsigned 64 */ \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
@@ -201,11 +135,11 @@ do { \
|
||||
do { \
|
||||
if(d < -(1<<5)) { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@@ -214,24 +148,26 @@ do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} \
|
||||
@@ -242,32 +178,36 @@ do { \
|
||||
if(d < -(1<<5)) { \
|
||||
if(d < -(1<<15)) { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
||||
} else { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else if(d < (1<<16)) { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} \
|
||||
@@ -279,46 +219,52 @@ do { \
|
||||
if(d < -(1LL<<15)) { \
|
||||
if(d < -(1LL<<31)) { \
|
||||
/* signed 64 */ \
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} else { \
|
||||
/* signed 32 */ \
|
||||
const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < -(1<<7)) { \
|
||||
/* signed 16 */ \
|
||||
const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} else { \
|
||||
/* signed 8 */ \
|
||||
const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} \
|
||||
} \
|
||||
} else if(d < (1<<7)) { \
|
||||
/* fixnum */ \
|
||||
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
||||
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
||||
} else { \
|
||||
if(d < (1LL<<16)) { \
|
||||
if(d < (1<<8)) { \
|
||||
/* unsigned 8 */ \
|
||||
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
||||
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
||||
msgpack_pack_append_buffer(x, buf, 2); \
|
||||
} else { \
|
||||
/* unsigned 16 */ \
|
||||
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
||||
unsigned char buf[3]; \
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 3); \
|
||||
} \
|
||||
} else { \
|
||||
if(d < (1LL<<32)) { \
|
||||
/* unsigned 32 */ \
|
||||
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
||||
unsigned char buf[5]; \
|
||||
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
|
||||
msgpack_pack_append_buffer(x, buf, 5); \
|
||||
} else { \
|
||||
/* unsigned 64 */ \
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
||||
unsigned char buf[9]; \
|
||||
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
||||
msgpack_pack_append_buffer(x, buf, 9); \
|
||||
} \
|
||||
} \
|
||||
@@ -326,57 +272,63 @@ do { \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifdef msgpack_pack_inline_func_fastint
|
||||
#ifdef msgpack_pack_inline_func_fixint
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||
msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d)
|
||||
{
|
||||
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)};
|
||||
unsigned char buf[2] = {0xcc, TAKE8_8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||
msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)};
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xce, STORE32_BE32(d)};
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xce; _msgpack_store32(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)};
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
||||
msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d)
|
||||
{
|
||||
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)};
|
||||
unsigned char buf[2] = {0xd0, TAKE8_8(d)};
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
||||
msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d)
|
||||
{
|
||||
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)};
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
||||
msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d)
|
||||
{
|
||||
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)};
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
||||
msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d)
|
||||
{
|
||||
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)};
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
#undef msgpack_pack_inline_func_fastint
|
||||
#undef msgpack_pack_inline_func_fixint
|
||||
#endif
|
||||
|
||||
|
||||
@@ -420,19 +372,51 @@ msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
|
||||
msgpack_pack_real_int64(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d)
|
||||
{
|
||||
#if defined(CHAR_MIN)
|
||||
#if CHAR_MIN < 0
|
||||
msgpack_pack_real_int8(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint8(x, d);
|
||||
#endif
|
||||
#else
|
||||
#error CHAR_MIN is not defined
|
||||
#endif
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d)
|
||||
{
|
||||
msgpack_pack_real_int8(x, d);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d)
|
||||
{
|
||||
msgpack_pack_real_uint8(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
|
||||
#if defined(SIZEOF_SHORT)
|
||||
#if SIZEOF_SHORT == 2
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_SHORT == 4 || SHRT_MAX == 0x7fffffff
|
||||
#elif SIZEOF_SHORT == 4
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(SHRT_MAX)
|
||||
#if SHRT_MAX == 0x7fff
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif 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);
|
||||
@@ -446,14 +430,24 @@ if(sizeof(short) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_INT)
|
||||
#if SIZEOF_INT == 2
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_INT == 4 || INT_MAX == 0x7fffffff
|
||||
#elif SIZEOF_INT == 4
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(INT_MAX)
|
||||
#if INT_MAX == 0x7fff
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif 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);
|
||||
@@ -467,14 +461,24 @@ if(sizeof(int) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_LONG)
|
||||
#if SIZEOF_LONG == 2
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_LONG == 4 || LONG_MAX == 0x7fffffffL
|
||||
#elif SIZEOF_LONG == 4
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(LONG_MAX)
|
||||
#if LONG_MAX == 0x7fffL
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif 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);
|
||||
@@ -488,14 +492,24 @@ if(sizeof(long) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_LONG_LONG)
|
||||
#if SIZEOF_LONG_LONG == 2
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif SIZEOF_LONG_LONG == 4 || LLONG_MAX == 0x7fffffffL
|
||||
#elif SIZEOF_LONG_LONG == 4
|
||||
msgpack_pack_real_int32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_int64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(LLONG_MAX)
|
||||
#if LLONG_MAX == 0x7fffL
|
||||
msgpack_pack_real_int16(x, d);
|
||||
#elif 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);
|
||||
@@ -509,14 +523,24 @@ if(sizeof(long long) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_SHORT)
|
||||
#if SIZEOF_SHORT == 2
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_SHORT == 4 || USHRT_MAX == 0xffffffffU
|
||||
#elif SIZEOF_SHORT == 4
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(USHRT_MAX)
|
||||
#if USHRT_MAX == 0xffffU
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif 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);
|
||||
@@ -530,14 +554,24 @@ if(sizeof(unsigned short) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_INT)
|
||||
#if SIZEOF_INT == 2
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_INT == 4 || UINT_MAX == 0xffffffffU
|
||||
#elif SIZEOF_INT == 4
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(UINT_MAX)
|
||||
#if UINT_MAX == 0xffffU
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif 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);
|
||||
@@ -551,18 +585,28 @@ if(sizeof(unsigned int) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_LONG)
|
||||
#if SIZEOF_LONG == 2
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_LONG == 4 || ULONG_MAX == 0xffffffffUL
|
||||
#elif SIZEOF_LONG == 4
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
#else
|
||||
if(sizeof(unsigned int) == 2) {
|
||||
|
||||
#elif defined(ULONG_MAX)
|
||||
#if ULONG_MAX == 0xffffUL
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned int) == 4) {
|
||||
#elif ULONG_MAX == 0xffffffffUL
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
|
||||
#else
|
||||
if(sizeof(unsigned long) == 2) {
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
} else if(sizeof(unsigned long) == 4) {
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
} else {
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
@@ -572,14 +616,24 @@ if(sizeof(unsigned int) == 2) {
|
||||
|
||||
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
|
||||
#if defined(SIZEOF_LONG_LONG)
|
||||
#if SIZEOF_LONG_LONG == 2
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif SIZEOF_LONG_LONG == 4 || ULLONG_MAX == 0xffffffffUL
|
||||
#elif SIZEOF_LONG_LONG == 4
|
||||
msgpack_pack_real_uint32(x, d);
|
||||
#else
|
||||
msgpack_pack_real_uint64(x, d);
|
||||
#endif
|
||||
|
||||
#elif defined(ULLONG_MAX)
|
||||
#if ULLONG_MAX == 0xffffUL
|
||||
msgpack_pack_real_uint16(x, d);
|
||||
#elif 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);
|
||||
@@ -602,17 +656,24 @@ if(sizeof(unsigned long long) == 2) {
|
||||
|
||||
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
||||
{
|
||||
union { char buf[4]; uint32_t num; } f;
|
||||
*((float*)&f.buf) = d; // FIXME
|
||||
const unsigned char buf[5] = {0xca, STORE32_BE32(f.num)};
|
||||
unsigned char buf[5];
|
||||
union { float f; uint32_t i; } mem;
|
||||
mem.f = d;
|
||||
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
||||
{
|
||||
union { char buf[8]; uint64_t num; } f;
|
||||
*((double*)&f.buf) = d; // FIXME
|
||||
const unsigned char buf[9] = {0xcb, STORE64_BE64(f.num)};
|
||||
unsigned char buf[9];
|
||||
union { double f; uint64_t i; } mem;
|
||||
mem.f = d;
|
||||
buf[0] = 0xcb;
|
||||
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
||||
// https://github.com/msgpack/msgpack-perl/pull/1
|
||||
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
||||
#endif
|
||||
_msgpack_store64(&buf[1], mem.i);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
@@ -649,18 +710,18 @@ msgpack_pack_inline_func(_false)(msgpack_pack_user x)
|
||||
* Array
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
||||
msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
|
||||
{
|
||||
if(n < 16) {
|
||||
unsigned char d = 0x90 | n;
|
||||
unsigned char d = 0x90 | (uint8_t)n;
|
||||
msgpack_pack_append_buffer(x, &d, 1);
|
||||
} else if(n < 65536) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xdc, STORE16_BE16(d)};
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdd, STORE32_BE32(d)};
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -670,18 +731,18 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
||||
* Map
|
||||
*/
|
||||
|
||||
msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
||||
msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n)
|
||||
{
|
||||
if(n < 16) {
|
||||
unsigned char d = 0x80 | n;
|
||||
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
|
||||
unsigned char d = 0x80 | (uint8_t)n;
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
||||
} else if(n < 65536) {
|
||||
uint16_t d = (uint16_t)n;
|
||||
unsigned char buf[3] = {0xde, STORE16_BE16(d)};
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)n;
|
||||
unsigned char buf[5] = {0xdf, STORE32_BE32(d)};
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -694,15 +755,15 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
||||
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);
|
||||
unsigned char d = 0xa0 | (uint8_t)l;
|
||||
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
||||
} else if(l < 65536) {
|
||||
uint16_t d = (uint16_t)l;
|
||||
unsigned char buf[3] = {0xda, STORE16_BE16(d)};
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else {
|
||||
uint32_t d = (uint32_t)l;
|
||||
unsigned char buf[5] = {0xdb, STORE32_BE32(d)};
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -716,19 +777,10 @@ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l
|
||||
#undef msgpack_pack_user
|
||||
#undef msgpack_pack_append_buffer
|
||||
|
||||
#undef STORE8_BE8
|
||||
|
||||
#undef STORE16_BE8
|
||||
#undef STORE16_BE16
|
||||
|
||||
#undef STORE32_BE8
|
||||
#undef STORE32_BE16
|
||||
#undef STORE32_BE32
|
||||
|
||||
#undef STORE64_BE8
|
||||
#undef STORE64_BE16
|
||||
#undef STORE64_BE32
|
||||
#undef STORE64_BE64
|
||||
#undef TAKE8_8
|
||||
#undef TAKE8_16
|
||||
#undef TAKE8_32
|
||||
#undef TAKE8_64
|
||||
|
||||
#undef msgpack_pack_real_uint8
|
||||
#undef msgpack_pack_real_uint16
|
@@ -21,14 +21,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef MSGPACK_SBUFFER_INIT_SIZE
|
||||
#define MSGPACK_SBUFFER_INIT_SIZE 2048
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup msgpack_sbuffer Simple buffer
|
||||
* @ingroup msgpack_buffer
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct msgpack_sbuffer {
|
||||
size_t size;
|
||||
char* data;
|
||||
@@ -45,17 +48,34 @@ static inline void msgpack_sbuffer_destroy(msgpack_sbuffer* sbuf)
|
||||
free(sbuf->data);
|
||||
}
|
||||
|
||||
static inline int msgpack_sbuffer_write(void* data, const char* buf, unsigned int len)
|
||||
static inline msgpack_sbuffer* msgpack_sbuffer_new(void)
|
||||
{
|
||||
return (msgpack_sbuffer*)calloc(1, sizeof(msgpack_sbuffer));
|
||||
}
|
||||
|
||||
static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
|
||||
{
|
||||
if(sbuf == NULL) { return; }
|
||||
msgpack_sbuffer_destroy(sbuf);
|
||||
free(sbuf);
|
||||
}
|
||||
|
||||
#ifndef MSGPACK_SBUFFER_INIT_SIZE
|
||||
#define MSGPACK_SBUFFER_INIT_SIZE 8192
|
||||
#endif
|
||||
|
||||
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
|
||||
{
|
||||
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
|
||||
|
||||
if(sbuf->alloc - sbuf->size < len) {
|
||||
void* tmp;
|
||||
size_t nsize = (sbuf->alloc) ?
|
||||
sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
||||
|
||||
while(nsize < sbuf->size + len) { nsize *= 2; }
|
||||
|
||||
void* tmp = realloc(sbuf->data, nsize);
|
||||
tmp = realloc(sbuf->data, nsize);
|
||||
if(!tmp) { return -1; }
|
||||
|
||||
sbuf->data = (char*)tmp;
|
||||
@@ -76,6 +96,13 @@ static inline char* msgpack_sbuffer_release(msgpack_sbuffer* sbuf)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static inline void msgpack_sbuffer_clear(msgpack_sbuffer* sbuf)
|
||||
{
|
||||
sbuf->size = 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -18,7 +18,7 @@
|
||||
#ifndef MSGPACK_SBUFFER_HPP__
|
||||
#define MSGPACK_SBUFFER_HPP__
|
||||
|
||||
#include "msgpack/sbuffer.h"
|
||||
#include "sbuffer.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace msgpack {
|
||||
@@ -28,9 +28,13 @@ class sbuffer : public msgpack_sbuffer {
|
||||
public:
|
||||
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE)
|
||||
{
|
||||
base::data = (char*)::malloc(initsz);
|
||||
if(!base::data) {
|
||||
throw std::bad_alloc();
|
||||
if(initsz == 0) {
|
||||
base::data = NULL;
|
||||
} else {
|
||||
base::data = (char*)::malloc(initsz);
|
||||
if(!base::data) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
}
|
||||
|
||||
base::size = 0;
|
||||
@@ -43,7 +47,7 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
void write(const char* buf, unsigned int len)
|
||||
void write(const char* buf, size_t len)
|
||||
{
|
||||
if(base::alloc - base::size < len) {
|
||||
expand_buffer(len);
|
||||
@@ -72,10 +76,15 @@ public:
|
||||
return msgpack_sbuffer_release(this);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
msgpack_sbuffer_clear(this);
|
||||
}
|
||||
|
||||
private:
|
||||
void expand_buffer(size_t len)
|
||||
{
|
||||
size_t nsize = (base::alloc) ?
|
||||
size_t nsize = (base::alloc > 0) ?
|
||||
base::alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
||||
|
||||
while(nsize < base::size + len) { nsize *= 2; }
|
208
src/msgpack/sysdep.h
Normal file
208
src/msgpack/sysdep.h
Normal file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* MessagePack system dependencies
|
||||
*
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MSGPACK_SYSDEP_H__
|
||||
#define MSGPACK_SYSDEP_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1600
|
||||
typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#elif defined(_MSC_VER) // && _MSC_VER >= 1600
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _msgpack_atomic_counter_header <windows.h>
|
||||
typedef long _msgpack_atomic_counter_t;
|
||||
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
||||
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
||||
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
||||
#define _msgpack_atomic_counter_header "gcc_atomic.h"
|
||||
#else
|
||||
typedef unsigned int _msgpack_atomic_counter_t;
|
||||
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
||||
#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* numeric_limits<T>::min,max */
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <arpa/inet.h> /* __BYTE_ORDER */
|
||||
#endif
|
||||
|
||||
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN__
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN__
|
||||
#elif _WIN32
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(ntohs)
|
||||
# define _msgpack_be16(x) ntohs(x)
|
||||
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
||||
# else
|
||||
# define _msgpack_be16(x) ( \
|
||||
((((uint16_t)x) << 8) ) | \
|
||||
((((uint16_t)x) >> 8) ) )
|
||||
# endif
|
||||
#else
|
||||
# define _msgpack_be16(x) ntohs(x)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(ntohl)
|
||||
# define _msgpack_be32(x) ntohl(x)
|
||||
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
||||
# else
|
||||
# define _msgpack_be32(x) \
|
||||
( ((((uint32_t)x) << 24) ) | \
|
||||
((((uint32_t)x) << 8) & 0x00ff0000U ) | \
|
||||
((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
|
||||
((((uint32_t)x) >> 24) ) )
|
||||
# endif
|
||||
#else
|
||||
# define _msgpack_be32(x) ntohl(x)
|
||||
#endif
|
||||
|
||||
#if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
||||
#elif defined(bswap_64)
|
||||
# define _msgpack_be64(x) bswap_64(x)
|
||||
#elif defined(__DARWIN_OSSwapInt64)
|
||||
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
||||
#else
|
||||
#define _msgpack_be64(x) \
|
||||
( ((((uint64_t)x) << 56) ) | \
|
||||
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
||||
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
||||
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
||||
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
||||
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
||||
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
||||
((((uint64_t)x) >> 56) ) )
|
||||
#endif
|
||||
|
||||
#define _msgpack_load16(cast, from) ((cast)( \
|
||||
(((uint16_t)((uint8_t*)(from))[0]) << 8) | \
|
||||
(((uint16_t)((uint8_t*)(from))[1]) ) ))
|
||||
|
||||
#define _msgpack_load32(cast, from) ((cast)( \
|
||||
(((uint32_t)((uint8_t*)(from))[0]) << 24) | \
|
||||
(((uint32_t)((uint8_t*)(from))[1]) << 16) | \
|
||||
(((uint32_t)((uint8_t*)(from))[2]) << 8) | \
|
||||
(((uint32_t)((uint8_t*)(from))[3]) ) ))
|
||||
|
||||
#define _msgpack_load64(cast, from) ((cast)( \
|
||||
(((uint64_t)((uint8_t*)(from))[0]) << 56) | \
|
||||
(((uint64_t)((uint8_t*)(from))[1]) << 48) | \
|
||||
(((uint64_t)((uint8_t*)(from))[2]) << 40) | \
|
||||
(((uint64_t)((uint8_t*)(from))[3]) << 32) | \
|
||||
(((uint64_t)((uint8_t*)(from))[4]) << 24) | \
|
||||
(((uint64_t)((uint8_t*)(from))[5]) << 16) | \
|
||||
(((uint64_t)((uint8_t*)(from))[6]) << 8) | \
|
||||
(((uint64_t)((uint8_t*)(from))[7]) ) ))
|
||||
|
||||
#else
|
||||
|
||||
#define _msgpack_be16(x) (x)
|
||||
#define _msgpack_be32(x) (x)
|
||||
#define _msgpack_be64(x) (x)
|
||||
|
||||
#define _msgpack_load16(cast, from) ((cast)( \
|
||||
(((uint16_t)((uint8_t*)from)[0]) << 8) | \
|
||||
(((uint16_t)((uint8_t*)from)[1]) ) ))
|
||||
|
||||
#define _msgpack_load32(cast, from) ((cast)( \
|
||||
(((uint32_t)((uint8_t*)from)[0]) << 24) | \
|
||||
(((uint32_t)((uint8_t*)from)[1]) << 16) | \
|
||||
(((uint32_t)((uint8_t*)from)[2]) << 8) | \
|
||||
(((uint32_t)((uint8_t*)from)[3]) ) ))
|
||||
|
||||
#define _msgpack_load64(cast, from) ((cast)( \
|
||||
(((uint64_t)((uint8_t*)from)[0]) << 56) | \
|
||||
(((uint64_t)((uint8_t*)from)[1]) << 48) | \
|
||||
(((uint64_t)((uint8_t*)from)[2]) << 40) | \
|
||||
(((uint64_t)((uint8_t*)from)[3]) << 32) | \
|
||||
(((uint64_t)((uint8_t*)from)[4]) << 24) | \
|
||||
(((uint64_t)((uint8_t*)from)[5]) << 16) | \
|
||||
(((uint64_t)((uint8_t*)from)[6]) << 8) | \
|
||||
(((uint64_t)((uint8_t*)from)[7]) ) ))
|
||||
#endif
|
||||
|
||||
|
||||
#define _msgpack_store16(to, num) \
|
||||
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
|
||||
#define _msgpack_store32(to, num) \
|
||||
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
|
||||
#define _msgpack_store64(to, num) \
|
||||
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
|
||||
|
||||
/*
|
||||
#define _msgpack_load16(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
|
||||
#define _msgpack_load32(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
|
||||
#define _msgpack_load64(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(__cplusplus) && defined(_MSC_VER)
|
||||
#if !defined(FALSE)
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
#if !defined(TRUE)
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
#define bool int
|
||||
#define true TRUE
|
||||
#define false FALSE
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/sysdep.h */
|
||||
|
17
src/msgpack/type.hpp
Normal file
17
src/msgpack/type.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "type/bool.hpp"
|
||||
#include "type/deque.hpp"
|
||||
#include "type/fixint.hpp"
|
||||
#include "type/float.hpp"
|
||||
#include "type/int.hpp"
|
||||
#include "type/list.hpp"
|
||||
#include "type/map.hpp"
|
||||
#include "type/nil.hpp"
|
||||
#include "type/pair.hpp"
|
||||
#include "type/raw.hpp"
|
||||
#include "type/set.hpp"
|
||||
#include "type/string.hpp"
|
||||
#include "type/vector.hpp"
|
||||
#include "type/tuple.hpp"
|
||||
#include "type/define.hpp"
|
||||
#include "type/tr1/unordered_map.hpp"
|
||||
#include "type/tr1/unordered_set.hpp"
|
@@ -15,8 +15,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_BOOLEAN_HPP__
|
||||
#define MSGPACK_TYPE_BOOLEAN_HPP__
|
||||
#ifndef MSGPACK_TYPE_BOOL_HPP__
|
||||
#define MSGPACK_TYPE_BOOL_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <vector>
|
||||
@@ -31,7 +31,6 @@ inline bool& operator>> (object o, bool& v)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v)
|
||||
{
|
||||
@@ -40,6 +39,15 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v)
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, bool v)
|
||||
{
|
||||
o.type = type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, bool v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
3465
src/msgpack/type/define.hpp
Normal file
3465
src/msgpack/type/define.hpp
Normal file
File diff suppressed because it is too large
Load Diff
148
src/msgpack/type/define.hpp.erb
Normal file
148
src/msgpack/type/define.hpp.erb
Normal file
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_DEFINE_HPP__
|
||||
#define MSGPACK_TYPE_DEFINE_HPP__
|
||||
|
||||
#define MSGPACK_DEFINE(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object o) \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone* z) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum) \
|
||||
namespace msgpack { \
|
||||
template <> \
|
||||
inline enum& operator>> (object o, enum& v) \
|
||||
{ \
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum>(tmp); \
|
||||
return v; \
|
||||
} \
|
||||
template <> \
|
||||
inline void operator<< (object::with_zone& o, const enum& v) \
|
||||
{ \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
namespace detail { \
|
||||
template <typename Stream> \
|
||||
struct packer_serializer<Stream, enum> { \
|
||||
static packer<Stream>& pack(packer<Stream>& o, const enum& v) { \
|
||||
return o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
namespace type {
|
||||
|
||||
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define;
|
||||
|
||||
|
||||
template <>
|
||||
struct define<> {
|
||||
typedef define<> value_type;
|
||||
typedef tuple<> tuple_type;
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(0);
|
||||
}
|
||||
void msgpack_unpack(msgpack::object o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone* z) const
|
||||
{
|
||||
o->type = type::ARRAY;
|
||||
o->via.array.ptr = NULL;
|
||||
o->via.array.size = 0;
|
||||
}
|
||||
};
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
typedef define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
|
||||
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> tuple_type;
|
||||
define(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) :
|
||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(<%=i+1%>);
|
||||
<%0.upto(i) {|j|%>
|
||||
pk.pack(a<%=j%>);<%}%>
|
||||
}
|
||||
void msgpack_unpack(msgpack::object o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
const size_t size = o.via.array.size;
|
||||
if(size > 0) {
|
||||
msgpack::object *ptr = o.via.array.ptr;
|
||||
switch(size) {
|
||||
default:<%(i).downto(0) {|j|%>
|
||||
case <%=j+1%>: ptr[<%=j%>].convert(&a<%=j%>);<%}%>
|
||||
}
|
||||
}
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone* z) const
|
||||
{
|
||||
o->type = type::ARRAY;
|
||||
o->via.array.ptr = (object*)z->malloc(sizeof(object)*<%=i+1%>);
|
||||
o->via.array.size = <%=i+1%>;
|
||||
<%0.upto(i) {|j|%>
|
||||
o->via.array.ptr[<%=j%>] = object(a<%=j%>, z);<%}%>
|
||||
}
|
||||
<%0.upto(i) {|j|%>
|
||||
A<%=j%>& a<%=j%>;<%}%>
|
||||
};
|
||||
<%}%>
|
||||
|
||||
inline define<> make_define()
|
||||
{
|
||||
return define<>();
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>)
|
||||
{
|
||||
return define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
} // namespace type
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif /* msgpack/type/define.hpp */
|
||||
|
77
src/msgpack/type/deque.hpp
Normal file
77
src/msgpack/type/deque.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_DEQUE_HPP__
|
||||
#define MSGPACK_TYPE_DEQUE_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <deque>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline std::deque<T>& operator>> (object o, std::deque<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::deque<T>::iterator it = v.begin();
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->convert(&*it);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::deque<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = NULL;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = (object*)o.zone->malloc(sizeof(object)*v.size());
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::deque<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/deque.hpp */
|
||||
|
172
src/msgpack/type/fixint.hpp
Normal file
172
src/msgpack/type/fixint.hpp
Normal file
@@ -0,0 +1,172 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2020 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_FIXINT_HPP__
|
||||
#define MSGPACK_TYPE_FIXINT_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/type/int.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct fix_int {
|
||||
fix_int() : value(0) { }
|
||||
fix_int(T value) : value(value) { }
|
||||
|
||||
operator T() const { return value; }
|
||||
|
||||
T get() const { return value; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
};
|
||||
|
||||
|
||||
typedef fix_int<uint8_t> fix_uint8;
|
||||
typedef fix_int<uint16_t> fix_uint16;
|
||||
typedef fix_int<uint32_t> fix_uint32;
|
||||
typedef fix_int<uint64_t> fix_uint64;
|
||||
|
||||
typedef fix_int<int8_t> fix_int8;
|
||||
typedef fix_int<int16_t> fix_int16;
|
||||
typedef fix_int<int32_t> fix_int32;
|
||||
typedef fix_int<int64_t> fix_int64;
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline type::fix_int8& operator>> (object o, type::fix_int8& v)
|
||||
{ v = type::detail::convert_integer<int8_t>(o); return v; }
|
||||
|
||||
inline type::fix_int16& operator>> (object o, type::fix_int16& v)
|
||||
{ v = type::detail::convert_integer<int16_t>(o); return v; }
|
||||
|
||||
inline type::fix_int32& operator>> (object o, type::fix_int32& v)
|
||||
{ v = type::detail::convert_integer<int32_t>(o); return v; }
|
||||
|
||||
inline type::fix_int64& operator>> (object o, type::fix_int64& v)
|
||||
{ v = type::detail::convert_integer<int64_t>(o); return v; }
|
||||
|
||||
|
||||
inline type::fix_uint8& operator>> (object o, type::fix_uint8& v)
|
||||
{ v = type::detail::convert_integer<uint8_t>(o); return v; }
|
||||
|
||||
inline type::fix_uint16& operator>> (object o, type::fix_uint16& v)
|
||||
{ v = type::detail::convert_integer<uint16_t>(o); return v; }
|
||||
|
||||
inline type::fix_uint32& operator>> (object o, type::fix_uint32& v)
|
||||
{ v = type::detail::convert_integer<uint32_t>(o); return v; }
|
||||
|
||||
inline type::fix_uint64& operator>> (object o, type::fix_uint64& v)
|
||||
{ v = type::detail::convert_integer<uint64_t>(o); return v; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int8& v)
|
||||
{ o.pack_fix_int8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int16& v)
|
||||
{ o.pack_fix_int16(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int32& v)
|
||||
{ o.pack_fix_int32(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v)
|
||||
{ o.pack_fix_int64(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v)
|
||||
{ o.pack_fix_uint8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint16& v)
|
||||
{ o.pack_fix_uint16(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint32& v)
|
||||
{ o.pack_fix_uint32(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
|
||||
{ o.pack_fix_uint64(v); return o; }
|
||||
|
||||
|
||||
inline void operator<< (object& o, type::fix_int8 v)
|
||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_int16 v)
|
||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_int32 v)
|
||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_int64 v)
|
||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint8 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint16 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint32 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint64 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int8 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int16 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int32 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int64 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint8 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint16 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint32 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint64 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/fixint.hpp */
|
||||
|
@@ -29,12 +29,21 @@ namespace msgpack {
|
||||
|
||||
inline float& operator>> (object o, float& v)
|
||||
{
|
||||
if(o.type != type::DOUBLE) { throw type_error(); }
|
||||
v = o.via.dec;
|
||||
if(o.type == type::DOUBLE) {
|
||||
v = (float)o.via.dec;
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = (float)o.via.u64;
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = (float)o.via.i64;
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
|
||||
{
|
||||
@@ -45,12 +54,21 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
|
||||
|
||||
inline double& operator>> (object o, double& v)
|
||||
{
|
||||
if(o.type != type::DOUBLE) { throw type_error(); }
|
||||
v = o.via.dec;
|
||||
if(o.type == type::DOUBLE) {
|
||||
v = o.via.dec;
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = (double)o.via.u64;
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = (double)o.via.i64;
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
|
||||
{
|
||||
@@ -59,6 +77,25 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
|
||||
}
|
||||
|
||||
|
||||
inline void operator<< (object& o, float v)
|
||||
{
|
||||
o.type = type::DOUBLE;
|
||||
o.via.dec = (double)v;
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, double v)
|
||||
{
|
||||
o.type = type::DOUBLE;
|
||||
o.via.dec = v;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, float v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, double v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/float.hpp */
|
276
src/msgpack/type/int.hpp
Normal file
276
src/msgpack/type/int.hpp
Normal file
@@ -0,0 +1,276 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_INT_HPP__
|
||||
#define MSGPACK_TYPE_INT_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
namespace type {
|
||||
namespace detail {
|
||||
template <typename T, bool Signed>
|
||||
struct convert_integer_sign;
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, true> {
|
||||
static inline T convert(object o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
|
||||
{ throw type_error(); }
|
||||
return (T)o.via.u64;
|
||||
} else if(o.type == type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < (int64_t)std::numeric_limits<T>::min())
|
||||
{ throw type_error(); }
|
||||
return (T)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 (T)o.via.u64;
|
||||
}
|
||||
throw type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_signed {
|
||||
static const bool value = std::numeric_limits<T>::is_signed;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline T convert_integer(object o)
|
||||
{
|
||||
return detail::convert_integer_sign<T, is_signed<T>::value>::convert(o);
|
||||
}
|
||||
|
||||
template <bool Signed>
|
||||
struct pack_char_sign;
|
||||
|
||||
template <>
|
||||
struct pack_char_sign<true> {
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||
o.pack_int8(v); return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack_char_sign<false> {
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||
o.pack_uint8(v); return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack_char(packer<Stream>& o, char v) {
|
||||
return pack_char_sign<is_signed<char>::value>::pack(o, v);
|
||||
}
|
||||
|
||||
template <bool Signed>
|
||||
struct object_char_sign;
|
||||
|
||||
template <>
|
||||
struct object_char_sign<true> {
|
||||
static inline void make(object& o, char v) {
|
||||
v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v
|
||||
: o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_char_sign<false> {
|
||||
static inline void make(object& o, char v) {
|
||||
o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
}
|
||||
};
|
||||
|
||||
static inline void object_char(object& o, char v) {
|
||||
return object_char_sign<is_signed<char>::value>::make(o, v);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace type
|
||||
|
||||
inline char& operator>> (object const& o, char& v)
|
||||
{ v = type::detail::convert_integer<char>(o); return v; }
|
||||
|
||||
|
||||
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, char v)
|
||||
{ return type::detail::pack_char(o, v); }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed char v)
|
||||
{ o.pack_int8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed short v)
|
||||
{ o.pack_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed int v)
|
||||
{ o.pack_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed long v)
|
||||
{ o.pack_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed long long v)
|
||||
{ o.pack_long_long(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned char v)
|
||||
{ o.pack_uint8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned short v)
|
||||
{ o.pack_unsigned_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned int v)
|
||||
{ o.pack_unsigned_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long v)
|
||||
{ o.pack_unsigned_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long long v)
|
||||
{ o.pack_unsigned_long_long(v); return o; }
|
||||
|
||||
|
||||
inline void operator<< (object& o, char v)
|
||||
{ type::detail::object_char(o, v); }
|
||||
|
||||
|
||||
inline void operator<< (object& o, signed char v)
|
||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, signed short v)
|
||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, signed int v)
|
||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, signed long v)
|
||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, signed long long v)
|
||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
|
||||
inline void operator<< (object& o, unsigned char v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned short v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned int v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned long v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned long long v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed short v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed int v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed long v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, const signed long long& v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned short v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned int v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned long v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, const unsigned long long& v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/int.hpp */
|
||||
|
@@ -15,43 +15,63 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_ARRAY_HPP__
|
||||
#define MSGPACK_TYPE_ARRAY_HPP__
|
||||
#ifndef MSGPACK_TYPE_LIST_HPP__
|
||||
#define MSGPACK_TYPE_LIST_HPP__
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline std::vector<T> operator>> (object o, std::vector<T>& v)
|
||||
inline std::list<T>& operator>> (object o, std::list<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
T* it = &v.front();
|
||||
typename std::list<T>::iterator it = v.begin();
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->convert(it);
|
||||
p->convert(&*it);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::list<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = NULL;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = (object*)o.zone->malloc(sizeof(object)*v.size());
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::list<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/array.hpp */
|
||||
#endif /* msgpack/type/list.hpp */
|
||||
|
@@ -70,6 +70,28 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const type::assoc_vector<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = NULL;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename type::assoc_vector<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline std::map<K, V> operator>> (object o, std::map<K, V>& v)
|
||||
@@ -104,6 +126,28 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v)
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const std::map<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = NULL;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename std::map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline std::multimap<K, V> operator>> (object o, std::multimap<K, V>& v)
|
||||
@@ -132,6 +176,28 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>&
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const std::multimap<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = NULL;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename std::multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
@@ -42,6 +42,22 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil& v)
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, type::nil v)
|
||||
{
|
||||
o.type = type::NIL;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::nil v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
template <>
|
||||
inline void object::as<void>() const
|
||||
{
|
||||
msgpack::type::nil v;
|
||||
convert(&v);
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user