Compare commits

..

575 Commits

Author SHA1 Message Date
frsyuki
076bd07f39 cpp: version 0.5.6 2011-04-24 00:23:08 +09:00
FURUHASHI Sadayuki
00e897503b java: fixes typo on CHANGES.txt 2011-04-24 00:11:34 +09:00
FURUHASHI Sadayuki
2f3c47f385 java: version 0.5.2-devel 2011-04-23 23:57:27 +09:00
Muga Nishizawa
2b28211701 MSGPACK-6 added new TemplatePrecompiler function 2011-04-23 22:47:44 +09:00
Muga Nishizawa
46c794fc2e java: added test program for TemplatePrecompiler 2011-04-23 22:37:08 +09:00
Muga Nishizawa
0408738b48 java: write test program for TemplatePrecompiler 2011-04-23 19:19:05 +09:00
frsyuki
eb8a338a0e cpp: unpacker::release_zone() calls msgpack_unpacker_release_zone() #42 2011-04-17 08:25:55 +09:00
frsyuki
23480bfe8a cpp: fixed missing ctx.user.z = z and release_zone uses pointer swapp instead of copying #42 2011-04-17 08:24:33 +09:00
frsyuki
3384dbc92d cpp: fixes test/streaming_c.cc #42 2011-04-17 08:21:52 +09:00
frsyuki
8446549ed8 Merge branch 'master' of github.com:msgpack/msgpack 2011-04-17 06:49:36 +09:00
frsyuki
6a9f3ae71d c: fixed a double-free problem on msgpack_unpacker_release_zone #42 (aikar++) 2011-04-17 06:48:36 +09:00
FURUHASHI Sadayuki
c58ce1a975 MSGPACK-7 added -source 1.5 -target 1.5 options to javac 2011-04-12 18:41:08 +09:00
FURUHASHI Sadayuki
c6d9bbd7b0 MSGPACK-7 fixed test cases; iteration order of HashMap is not defined by JDK 5/6 specification 2011-04-12 18:39:54 +09:00
Muga Nishizawa
65ddd1a455 java: add test program for TemplatePrecompiler 2011-04-10 02:33:46 +09:00
Muga Nishizawa
58c0fe0f91 java: Refactored template builders again 2011-04-09 21:10:15 +09:00
Muga Nishizawa
b96b62f2ac scala: deleted the AUTHORS file 2011-04-08 16:20:28 +09:00
Muga Nishizawa
43fc0a52a6 scala: added a new AUTHORS file and edited pom.xml 2011-04-08 16:17:25 +09:00
Muga Nishizawa
4f3d9a1ded Refactored programs related to TemplateBuilder.java 2011-04-08 16:13:29 +09:00
FURUHASHI Sadayuki
b50ff920f0 MSGPACK-5 added test cases for Unpacker.unpackXxx() methods 2011-04-07 23:21:56 +09:00
FURUHASHI Sadayuki
983ae0c5a2 MSGPACK-4 BufferedUnapckerImpl.unpackInt: more(4)+advance(4) -> more(5)+advance(5) 2011-04-07 23:21:30 +09:00
FURUHASHI Sadayuki
9d4db84987 MSGPACK-4 BufferedUnpackerImpl.unpackLong: more(4)+advance(4) -> more(5)+advance(5) 2011-04-07 22:32:59 +09:00
Muga Nishizawa
dfaa281476 java: Fixed TemplateClassWriter.java but, it doesn't work. 2011-04-07 00:38:21 +09:00
Muga Nishizawa
c1c25c455c scala: Modified pom.xml. I changed version of 'MessagePack for Java' from 0.5.1-devel to 0.5.2-SNAPSHOT 2011-04-06 08:52:14 +09:00
Muga Nishizawa
e65197f386 Merge branch 'master' of https://github.com/watabiki/msgpack 2011-04-06 01:18:12 +09:00
Muga Nishizawa
ecbb8f8711 java: Merged takezoux2's branch for 'MessagePack for Scala' 2011-04-06 00:50:58 +09:00
Watabiki Naoya
03aa736199 java: update BigDecimalTemplate, TestPackConvert and TestPackUnpack 2011-04-05 23:26:53 +09:00
Muga Nishizawa
821b1f0384 Merge branch 'master' of git@github.com:msgpack/msgpack 2011-04-05 03:35:08 +09:00
Muga Nishizawa
233ad3aaff java: Updated several property files in .settings 2011-04-05 03:34:11 +09:00
Muga Nishizawa
9c4812f4d4 java: Fixed RawType's bug that hash values of same byte arrays (raw data) are different 2011-04-05 03:30:43 +09:00
Muga Nishizawa
337cc9fa78 java: Fixed a bug that NullPointerException occurs within DefaultTemplate.java 2011-04-05 01:27:51 +09:00
Muga Nishizawa
dfe29a0329 Merge branch 'master' of git@github.com:msgpack/msgpack 2011-04-05 00:52:30 +09:00
Muga Nishizawa
85e90aa81e java: Improved DefaultTemplate.java. It allows displaying details of exception messages 2011-04-05 00:51:53 +09:00
Hideyuki Tanaka
86d30fe571 haskell: reduce dependency of template-haskell 2011-04-04 23:33:02 +09:00
mzp
173302267f ocaml: upadte build file 2011-04-04 18:28:37 +09:00
Muga Nishizawa
8e3ea8d26c java: edit TemplateRegistry.java 2011-04-04 02:28:24 +09:00
Muga Nishizawa
cb065563c2 Merge branch 'master' of git@github.com:msgpack/msgpack 2011-04-04 01:59:34 +09:00
Muga Nishizawa
27b89b237b java: prototyped TemplateClassWriter, which is program for writing class file of generated tmplate class 2011-04-04 01:59:13 +09:00
takeshita
21f0d0bfc4 Delete moved class.
(TemplateBuilder.java is moved to org.msgpack.template.builder)
2011-04-04 01:46:29 +09:00
takeshita
d5e583b09e Implement Scala MessagePack.
Change Java MessagePack to fit Scala's.
Minor version up for Java's MessagePack.
2011-04-04 01:37:24 +09:00
UENISHI Kota
15fb9bbcb2 Merge branch 'master' of https://github.com/moriyoshi/msgpack 2011-04-03 19:52:34 +09:00
Muga Nishizawa
a03418ab12 java: edit BuiltInTemplateLoader.java 2011-04-03 19:42:43 +09:00
Muga Nishizawa
035513844d Merge branch 'master' of git@github.com:msgpack/msgpack 2011-04-03 19:11:56 +09:00
Muga Nishizawa
193906b8ce java: insert codes for initializing BigDecimalTemplate and DateTemplate instances to Templates.java 2011-04-03 19:10:34 +09:00
Moriyoshi Koizumi
d354f2e8c2 Documentation. 2011-04-03 19:09:14 +09:00
Watabiki Naoya
24a8ee436f add DateTemplate and BigDecimalTemplate 2011-04-03 18:39:41 +09:00
mzp
6e5f9404b7 ocaml: initial commit 2011-04-03 17:11:53 +09:00
Moriyoshi Koizumi
64fe90aabb Add TestUnpackFloat(). 2011-04-03 15:34:37 +09:00
Moriyoshi Koizumi
7e31d487e0 float type was gone from go language at some time I don't know. 2011-04-03 14:06:08 +09:00
moriyoshi
ee16e2eb30 Handle unsupported typecode 2011-04-03 11:14:49 +09:00
moriyoshi
003fb3392f Byte arrays in Go should not be serialized as arrays. 2011-04-03 11:14:49 +09:00
moriyoshi
0e82278cd5 Fix: InterfaceValue wasnt' correctly unwrapped when passed to PackValue() 2011-04-03 11:14:49 +09:00
moriyoshi
5b544248bc Add new API function UnpackReflected() that returns multiple reflect.Value for unpacked elements of arrays or maps. 2011-04-03 11:14:49 +09:00
moriyoshi
d4d7495c0a Forgot to support map16 / map32 2011-04-03 11:14:48 +09:00
moriyoshi
8325cce44c Adapt to new reflection API (notified by mattn. thanks) 2011-04-03 11:14:48 +09:00
moriyoshi
ee0debc5b3 Add .gitignore 2011-04-03 11:14:48 +09:00
moriyoshi
8f1bd12a17 Improve testsuite. 2011-04-03 11:14:10 +09:00
moriyoshi
fccf1016e4 Fix bugs in unpacker. 2011-04-03 11:14:10 +09:00
moriyoshi
1b010a082b Add go binding. 2011-04-03 11:14:10 +09:00
Hideyuki Tanaka
324f215316 haskell: version bump 2011-03-29 16:17:46 +09:00
Hideyuki Tanaka
ace4f1e7f0 fix encoding unicode strings, and Text support 2011-03-29 16:15:29 +09:00
Hideyuki Tanaka
5c5f16f148 haskell: version bump 2011-03-18 00:46:43 +09:00
Hideyuki Tanaka
f50855d5c0 fix for packing and unpacking Object 2011-03-18 00:44:15 +09:00
Muga Nishizawa
86917b0ba7 improved constructor in JavassistTemplateBuilder class. This improvement is based on https://github.com/msgpack/msgpack-rpc/issues#issue/13. 2011-03-11 12:24:09 +09:00
Hideyuki Tanaka
7201fcbe0f remove Iteratee dependency 2011-03-10 22:17:15 +09:00
Hideyuki Tanaka
83f1735fbb fix description 2011-03-09 18:06:57 +09:00
Hideyuki Tanaka
80fd8e70f0 update library version. 2011-03-09 17:02:01 +09:00
Hideyuki Tanaka
698c1c2b7a Merge git://github.com/xanxys/msgpack into pull-master 2011-03-09 16:19:19 +09:00
Yuto Hayamizu
5d3287f5aa gtest requires pthread 2011-03-03 06:42:14 +09:00
Yuto Hayamizu
6990fe6f51 remove duplicated code 2011-03-03 06:38:09 +09:00
Yuto Hayamizu
0b81068368 /cpp/preprocess: fix string comp. operator 2011-03-03 06:27:31 +09:00
FURUHASHI Sadayuki
5b1851ae22 cpp: version 0.5.5 2011-02-24 00:35:00 +09:00
FURUHASHI Sadayuki
0d5708a01d cpp: fixes problem that InterlockedIncrement/Decrement are not found on _WIN32 platform 2011-02-24 00:21:54 +09:00
FURUHASHI Sadayuki
67ab510b5d cpp: fixes some implicit cast warnings 2011-02-23 23:48:26 +09:00
FURUHASHI Sadayuki
d1264a1289 cpp: fixes msgpack_vc.postbuild.bat 2011-02-23 23:47:33 +09:00
FURUHASHI Sadayuki
3b973021a1 sysdep.h: eliminated #include <winsock2.h> 2011-02-23 23:46:39 +09:00
INADA Naoki
182624895f python: Remove UnpackIterator. Unpacker is iterator of itself. 2011-01-30 10:45:39 +09:00
INADA Naoki
548de3739c python: Disable gc while deserializing. 2011-01-29 23:23:56 +09:00
INADA Naoki
718a3efd64 python: Fix segmentation fault when default returns it's argument. 2011-01-29 23:22:41 +09:00
INADA Naoki
76b8c3250b Merge branch 'master' of github.com:msgpack/msgpack 2011-01-29 07:31:59 +09:00
INADA Naoki
dafaa8bd8c python: 0.1.9 2011-01-29 07:31:06 +09:00
INADA Naoki
9c9b2c25ea python: refactoring. 2011-01-29 07:27:10 +09:00
INADA Naoki
e89cd81022 Add use_list option to unpack and unpackb 2011-01-28 18:59:05 +09:00
advect
5debbd2be8 php: added unpack of class object converter 2011-01-16 17:35:10 +09:00
INADA Naoki
fe26df5355 python: Add memory error check. 2011-01-10 20:47:23 +09:00
INADA Naoki
85778494e4 python: Check if (m|re)alloc's return value is NULL. (Thanks to Mateusz) 2011-01-10 05:07:07 +09:00
INADA Naoki
a94ce3c715 python: Fix typo in docstring. (thanks to Mateusz.) 2011-01-10 05:05:14 +09:00
INADA Naoki
a440ff1117 python: Change URL in setup.py from sf.net to msgpack.org 2011-01-10 00:10:29 +09:00
INADA Naoki
8195137bc5 python: msgpack-python-0.1.8 2011-01-09 23:58:26 +09:00
INADA Naoki
3e2bd25e4e python: Fix another segv. 2011-01-09 23:54:06 +09:00
INADA Naoki
ffd0c2f624 python: Fix segv on unpacking from stream. 2011-01-09 23:40:09 +09:00
INADA Naoki
23333c98d7 python: Add test for issue29. 2011-01-09 23:29:18 +09:00
INADA Naoki
5a12ab98c4 python: Make aliases for API compatibility to pickle.
``dumps`` is alias of ``packb`` and ``loads`` is alias of ``unpacks``.
2011-01-09 23:17:20 +09:00
INADA Naoki
0b327a63fc python: Don't use `from __future__ import unicode_literals`.
Python 2.5 or older doesn't support it.
2011-01-09 23:13:35 +09:00
INADA Naoki
15b28a245c python: Update ChangeLog. 2011-01-09 23:06:56 +09:00
INADA Naoki
6ef5684797 Merge branch 'master' of github.com:msgpack/msgpack 2011-01-08 17:45:13 +09:00
xanxys
d439b1495b haskell: add ObjectFloat to send floats, and Assoc to make map (un)packing explicit 2010-12-28 19:22:37 +09:00
advect
9e096a3f0e php: version 0.3.4: supported Windows building 2010-12-28 16:09:13 +09:00
advect
0acf6ec150 php: version 0.3.3 2010-12-27 11:09:14 +09:00
Muga Nishizawa
4b36340474 java: refactor JavassistTemplateBuilder.java 2010-12-23 15:51:04 +09:00
FURUHASHI Sadayuki
910e642a8b java: version 0.5.1 2010-12-14 18:21:53 +09:00
FURUHASHI Sadayuki
9f571146fb java: fixes cast error on GenericArrayType 2010-12-14 17:47:45 +09:00
FURUHASHI Sadayuki
339725f73d java: throws MessagePackException if target==null on *ArrayTemplate 2010-12-13 18:52:25 +09:00
Muga Nishizawa
aff964c58b java: fixed a bug within CollectionTemplate.java 2010-12-12 00:48:31 +09:00
Muga Nishizawa
0c07e745f8 java: change spec. of pack methods in ListTemplate and MapTemplate as follow: If user passes null object to the pack method, MessageTypeException is thrown. 2010-12-12 00:47:20 +09:00
Muga Nishizawa
419d2e9564 java: change spec. of pack methods in several template classes as follow: If user passes null object to the pack method, MessageTypeException is thrown. 2010-12-12 00:46:05 +09:00
Muga Nishizawa
f936a307c6 java: add test methods for CollectionTemplate and change spec. of several test methods 2010-12-12 00:38:13 +09:00
Muga Nishizawa
4e4678edfa java: add packByteBuffer method in Packer.java because I needed non-nullcheck pack(ByteBuffer) for refining ByteBufferTemplate.java 2010-12-12 00:35:43 +09:00
FURUHASHI Sadayuki
cb7a4b3116 java: version 0.5.0 2010-12-09 23:36:27 +09:00
FURUHASHI Sadayuki
5ca4c42a74 Merge branch 'master' of github.com:msgpack/msgpack 2010-12-09 23:28:23 +09:00
FURUHASHI Sadayuki
1238a7ca07 java: adds AUTHORS file 2010-12-09 23:28:16 +09:00
Muga Nishizawa
a9db60a73d java: replace reflective method calls with base-level method calls in JavassistTemplateBuilder.java 2010-12-09 23:25:11 +09:00
FURUHASHI Sadayuki
bd32ac19d4 java: removes old benchmark codes 2010-12-09 23:01:04 +09:00
FURUHASHI Sadayuki
eaf9944e43 java: added ElementType.PARAMETER to the target of @Ignore, @Index, @Nulable, @Optional and @Required annotations for RPC 2010-12-09 17:31:29 +09:00
FURUHASHI Sadayuki
703fdbc01d java: array type support 2010-12-08 19:38:12 +09:00
FURUHASHI Sadayuki
2daa08b0e7 java: disabled ObjectArrayTempalte - it doesn't work 2010-12-06 00:13:05 +09:00
FURUHASHI Sadayuki
05d9d22d9e java: fixes native zero-copy unpacking routines of ByteBuffer 2010-12-03 22:56:04 +09:00
FURUHASHI Sadayuki
8b7894f9bd java: fixes comments in TemplateBuffer.java 2010-12-03 22:54:20 +09:00
Muga Nishizawa
a71439607f java: performance improvement for ByteBufferTemplate 2010-12-03 21:53:29 +09:00
Muga Nishizawa
aca0d7f969 java: refactor ByteBufferTemplate.java 2010-12-02 01:11:55 +09:00
Muga Nishizawa
310a8e4342 Merge branch 'master' of git@github.com:msgpack/msgpack
Conflicts:
	java/src/main/java/org/msgpack/MessagePack.java
2010-12-02 00:54:28 +09:00
FURUHASHI Sadayuki
24fbe1ef5b java: uses ReflectionTemplateBuilder instead of JavassistTempalteBuilder where System.getProperty("java.vm.name") == "Dalvik" 2010-12-01 23:27:36 +09:00
FURUHASHI Sadayuki
33d8faa35d java: JavassistTemplateBuilder: fixes comments 2010-12-01 23:15:55 +09:00
FURUHASHI Sadayuki
44be714f65 java: adds JavassistTemplateBuilder.addClassLoader method 2010-12-01 22:59:33 +09:00
FURUHASHI Sadayuki
0df3da6b10 java: adds TemplateRegistry.setTemplateBuilder method 2010-12-01 22:59:20 +09:00
FURUHASHI Sadayuki
79197b6ec7 java: more test cases of TemplateBuilder 2010-12-01 22:44:38 +09:00
FURUHASHI Sadayuki
353b6b51cb java: adds TemplateBuildException 2010-12-01 22:44:24 +09:00
FURUHASHI Sadayuki
bd9a2c0d3a java: migrates from util.codegen to TemplateBuilder 2010-12-01 22:42:55 +09:00
Muga Nishizawa
53b0ee6536 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-12-01 21:20:10 +09:00
FURUHASHI Sadayuki
78daac0f1b java: adds type.RawTemplate 2010-12-01 20:49:41 +09:00
FURUHASHI Sadayuki
b970b9b9a8 java: adds JavassistTemplateBuilder 2010-12-01 20:39:11 +09:00
FURUHASHI Sadayuki
0339db57f1 java: adds TemplateBuilder and ReflectionTemplateBUilder 2010-12-01 20:38:58 +09:00
FURUHASHI Sadayuki
461b147897 java: uses TemplateRepostry as default 2010-12-01 20:37:32 +09:00
FURUHASHI Sadayuki
a3cd13b399 java: adds actual generic templates 2010-12-01 20:36:52 +09:00
FURUHASHI Sadayuki
eb5d326a1e java: adds GenericTemplates 2010-12-01 20:34:33 +09:00
FURUHASHI Sadayuki
cce6eb94e2 java: adds DefaultTemplate 2010-12-01 20:34:23 +09:00
FURUHASHI Sadayuki
8311c72c69 java: adds BultInTemplateLoader 2010-12-01 20:33:38 +09:00
FURUHASHI Sadayuki
9a059285d9 java: registers buit-in templates to TemplateRegistry 2010-12-01 20:32:22 +09:00
FURUHASHI Sadayuki
469ac7891d java adds TemplateRegistry that replaces CustomMessage 2010-12-01 20:25:06 +09:00
FURUHASHI Sadayuki
16264a5693 java: adds array templates 2010-12-01 20:24:36 +09:00
FURUHASHI Sadayuki
6eedb50f56 java: adds TemplateBuilder and ReflectionTemplateBuilder 2010-11-30 21:59:07 +09:00
FURUHASHI Sadayuki
5f07215662 java: adds @Requred, @Ignore and @Index annotations 2010-11-30 21:58:24 +09:00
FURUHASHI Sadayuki
d3a02fb2ca java: @MessagePackMessage(default field option) 2010-11-30 21:57:12 +09:00
FURUHASHI Sadayuki
2c823f1aaa java: uses bit shift operations instead of ByteBuffer.putXxx 2010-11-30 21:55:45 +09:00
FURUHASHI Sadayuki
706293aadc java: adds type.Raw 2010-11-30 15:34:32 +09:00
FURUHASHI Sadayuki
dfdceb4258 java: updates VectoredByteBuffer 2010-11-29 18:37:47 +09:00
FURUHASHI Sadayuki
0014b7fdb9 java: adds VectoredByteBuffer 2010-11-29 18:01:39 +09:00
FURUHASHI Sadayuki
3b28f1f8af ruby: buffer size limit (disabled at present) 2010-11-28 23:13:53 +09:00
FURUHASHI Sadayuki
c689d476ca Merge remote branch 'egtra/master' 2010-11-24 18:05:50 +09:00
FURUHASHI Sadayuki
cc534fd21f ruby: adds Unpacker#feed_each 2010-11-24 17:24:55 +09:00
egtra
124efcf247 improve msvc support 2010-11-23 23:32:55 +09:00
Muga Nishizawa
dd452b05e3 java: rollback MessagePack.java 2010-11-19 02:57:42 +09:00
Muga Nishizawa
b5617f7df9 java: refactor register method in MessagePack.java for TemplateProvider 2010-11-19 01:58:30 +09:00
Muga Nishizawa
b73ca1ba3a java: edit MessagePack.java for TemplateProvider 2010-11-19 01:46:31 +09:00
Muga Nishizawa
39ad071c4f java: fixed a bug that javassist cannot find class files that were loaded by custom class loader 2010-11-18 22:26:58 +09:00
Muga Nishizawa
fa0b576a45 java: Fixed a bug that ClassTemplate cannot pack a ByteBuffer object but, it is a temporary impl. 2010-11-11 13:38:15 +09:00
frsyuki
c2c7591987 java: version 0.4.3-devel 2010-11-10 00:54:49 +09:00
frsyuki
3e939e3775 java: fixes MessagePackObject.convert(Template, T) 2010-11-10 00:53:15 +09:00
frsyuki
f6384e10bc java: adds test for DynamicOrdinalEnumTemplate 2010-11-10 00:32:25 +09:00
frsyuki
c283842563 java: MessagePackOptional -> Optional, MessagePackNullable -> Nullable 2010-11-10 00:16:23 +09:00
frsyuki
1135976225 java: adds MessagePack.unpack(Class<?>, FieldList) 2010-11-09 23:51:58 +09:00
frsyuki
76679d33df java: changes Template interface: unpack(Unpacker, Object to = null), convert(MessagePackObject from, Object to = null) 2010-11-09 23:43:16 +09:00
frsyuki
e9d44b90bc java: adds FieldList class 2010-11-09 22:11:47 +09:00
Muga Nishizawa
8a7a391166 java: delete ByteBufferTemplate.java in org.msgpack.util.codegen package 2010-11-09 10:13:55 +09:00
Muga Nishizawa
d6c5a9eece delete a dead code within DynamicCodeGen.java 2010-11-09 09:57:23 +09:00
Muga Nishizawa
56ad6915d0 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-11-09 09:28:38 +09:00
frsyuki
466c260782 java: version 0.4.2-devel 2010-11-09 03:16:00 +09:00
frsyuki
d8e2d1725a java: MessagePack.unpack(InputStream) throws IOException 2010-11-09 02:57:49 +09:00
frsyuki
33b43d03ac java: adds MessagePackNullable annotation 2010-11-09 02:46:23 +09:00
frsyuki
517509db6e java: adds NullableTemplate 2 2010-11-09 02:07:53 +09:00
frsyuki
95f01a5976 java: adds MessagePackObject.unpack(Class<T> klass) 2010-11-09 02:07:50 +09:00
frsyuki
d08d3bf56d java: adds NullableTemplate 2010-11-09 01:07:25 +09:00
frsyuki
587fd669e8 java: adds ByteBufferTemplate 2010-11-08 23:20:27 +09:00
Muga Nishizawa
e3553b87fe java: move ByteBufferTemplate.java to org.msgpack.util.codegen package 2010-11-06 11:31:40 +09:00
Muga Nishizawa
a078d2360c java: add temporal implementation of ByteBufferTemplate.java 2010-11-06 00:59:32 +09:00
frsyuki
2d3abf8e6e java: version 0.4.1-devel 2010-11-05 19:21:27 +09:00
Muga Nishizawa
cacae0fb7d java: refactor DynamicCodeGen.java and Constants.java. Thanks frsyuki for fixing a bug in DynamicCodeGen.java 2010-11-04 02:00:34 +09:00
INADA Naoki
d7fc215c16 python: 0.1.7 2010-11-03 03:43:49 +09:00
INADA Naoki
bb69aa18f2 python: Add ws2_32 library if platform is win32. 2010-11-03 03:35:52 +09:00
INADA Naoki
e4f515166a python: Add ChangeLog.rst 2010-11-03 03:26:33 +09:00
INADA Naoki
f325acb0ea Merge branch 'master' of github.com:msgpack/msgpack 2010-11-03 03:19:28 +09:00
INADA Naoki
d1b6e65dd8 python: Port some tests from 2 to 3. 2010-11-03 03:15:12 +09:00
INADA Naoki
4688252bd4 python: Support old buffer protocol when unpack. (experimental) 2010-11-03 03:11:00 +09:00
INADA Naoki
b1df5d3ad7 python: Add test for unpacking buffer object. 2010-11-02 14:09:50 +09:00
INADA Naoki
09bad2938e python: Add msgpack/_msgpack.c to .gitignore 2010-11-02 14:02:10 +09:00
advect
bad69fd397 php: fiexed unpacker 2010-10-30 16:06:50 +09:00
Fuji, Goro
b4ae6bf82c perl: disable warnings 2010-10-30 13:04:30 +09:00
Fuji, Goro
eac0f83864 perl: check data strictly; which is slow, but required 2010-10-30 12:38:32 +09:00
Fuji, Goro
3f16f080ac perl: add failing tests for PP 2010-10-30 01:09:12 +09:00
Fuji, Goro
5de2b974fb perl: ord(substr(...)) *is* faster than unpack() 2010-10-30 00:42:00 +09:00
Fuji, Goro
6a9cb51828 perl: modify internal names for the next refactoring 2010-10-30 00:31:41 +09:00
Fuji, Goro
f1c294ca50 perl: make error messages compatible with XS 2010-10-30 00:28:53 +09:00
Fuji, Goro
c320e44a23 perl: update Unpacker.pod 2010-10-28 17:26:04 +09:00
Fuji, Goro
ea36ef3107 perl: tests 2010-10-28 17:05:41 +09:00
Fuji, Goro
fedc37d079 Revert "perl: cleanup"
This reverts commit bc8d8ab65a.
2010-10-28 16:31:19 +09:00
Fuji, Goro
86ccfcc03c perl: changelogging 2010-10-28 16:25:19 +09:00
Fuji, Goro
bc8d8ab65a Revert "Revert "perl: cleanup""
This reverts commit a7a23d3bc8.
2010-10-28 16:17:53 +09:00
Fuji, Goro
a7a23d3bc8 Revert "perl: cleanup"
This reverts commit 82d33944e6.
2010-10-28 16:16:12 +09:00
Fuji, Goro
82d33944e6 perl: cleanup 2010-10-28 16:08:20 +09:00
Fuji, Goro
8a629ad6fb Fix streaming unpacking for splitted packed data 2010-10-28 15:49:22 +09:00
INADA Naoki
e1711ffcf2 Add list_hook option to unpacker. 2010-10-26 02:09:52 +09:00
INADA Naoki
063d51c662 Add check for recursion limit and default hook result. 2010-10-26 01:49:00 +09:00
INADA Naoki
d8e3575a46 Remove unnecessary refcount manipulation. 2010-10-26 01:32:08 +09:00
INADA Naoki
6fa609be3f Add test for Python3. 2010-10-26 01:31:27 +09:00
INADA Naoki
70982e204c Add object_hook option to unpack and default option to pack.
(see simplejson for how to use).
2010-10-26 01:26:06 +09:00
frsyuki
2af7df5865 java: fixes MessagePack.unpack method 2010-10-25 14:49:14 +09:00
frsyuki
59610e81de java: DynamicCodeGen::insertCodeOfUnpackMethodBody unpacks last optional field of classes correctly 2010-10-25 14:18:41 +09:00
Muga Nishizawa
cdfac703ef java: merge CustomMessage.java and DynamicCodeGenBase.java that can be not merged automatically 2010-10-24 23:24:27 +09:00
Muga Nishizawa
ad5ebd007e java: refactor org.msgpack.util.codegen.*.java 2010-10-24 23:10:07 +09:00
frsyuki
1bd347d997 java: fixes CustomMessage class 2010-10-24 21:17:19 +09:00
frsyuki
147056073d java: improves test case of the MessagePack class 2010-10-24 21:04:31 +09:00
frsyuki
1b3231e617 java: improves test case of the MessagePack class 2010-10-24 20:59:19 +09:00
frsyuki
7ac4ad3e38 java: adds MessagePack.register methods 2010-10-24 20:46:22 +09:00
frsyuki
0a345cb12b java: fixes CollectionTemplate 2010-10-24 20:16:37 +09:00
frsyuki
19ff0dd17f java: fixes ListTemplate and MapTemplate 2010-10-24 20:11:39 +09:00
frsyuki
e3bf8a404b java: adds MessagePack class 2010-10-24 19:32:45 +09:00
frsyuki
dbb28d9a8f java: Template extends MessagePacker 2010-10-24 18:46:48 +09:00
frsyuki
19fd4e755c java: removes ReflectionPacker and ReflectionTemplate (replaced by DynamicCodeGen) 2010-10-24 18:45:58 +09:00
Muga Nishizawa
77698cd924 java: change modifiers specified by several methods 2010-10-24 00:59:14 +09:00
Muga Nishizawa
945d279f28 java: fix a bug within a code of DynamicCodeGenBase.java 2010-10-24 00:40:58 +09:00
Muga Nishizawa
645d296841 java: add test programs for org.msgpack.util.codegen.FieldOption.java 2010-10-23 23:13:54 +09:00
Muga Nishizawa
57446de875 java: refactor org.msgpack.util.codegen.*.java 2010-10-23 23:13:17 +09:00
Muga Nishizawa
3473800ab6 java: not use a putIfAbsent method in ConcurrentHashMap class 2010-10-23 23:11:52 +09:00
Muga Nishizawa
7e5c5153a8 java: edit copyright notions in org.msgpack.annotation.*.java and org.msgpack.util.codegen.*.java 2010-10-23 14:50:32 +09:00
Muga Nishizawa
1b8979f285 java: refactor org.msgpack.util.codegen.*.java 2010-10-23 14:39:01 +09:00
Muga Nishizawa
2aac51dd20 java: append getter methods for element templates in org.msgpack.template.ListTemplate.java, MapTemplate.java and OptionalTemplate.java 2010-10-23 14:37:24 +09:00
Muga Nishizawa
69e32d264c java: write test programs for OptionalTemplate.java 2010-10-22 23:23:53 +09:00
frsyuki
71ae75a5bf java: adds OptionalPacker 2010-10-22 16:18:07 +09:00
frsyuki
86043fd87e java: adds OptionalTemplate 2010-10-22 08:31:03 +09:00
Fuji, Goro
d8aaef4f04 perl: tests 2010-10-21 23:35:07 +09:00
Fuji, Goro
7fc34b6369 perl: tweaks 2010-10-21 23:27:26 +09:00
Fuji, Goro
92b346efa7 perl: clean up 2010-10-21 23:26:03 +09:00
Muga Nishizawa
c790735b9f java: add test programs for org.msgpack.util.codegen.*.java 2010-10-21 02:02:23 +09:00
Muga Nishizawa
64711e615e java: write test programs for org.msgpack.util.codegen.*.java 2010-10-20 21:04:37 +09:00
frsyuki
2065affd45 java: adds CollectionTemplate 2010-10-20 16:40:25 +09:00
frsyuki
4067c56b5d java: supports Collection<T> to pack 2010-10-20 16:32:01 +09:00
tokuhirom
65515638aa perl: oops! added settings for shipit 2010-10-19 13:45:44 +09:00
tokuhirom
371ba3ffe3 Checking in changes prior to tagging of version 0.34.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 50177f4..486f1c3 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,6 @@
+0.34
+
+    - do not use the corrupt my_snprintf(%ll[du]) on win32(kazuho)

 0.33
2010-10-18 19:30:08 +09:00
Kazuho Oku
5395b62f2f shorter code, fix comment 2010-10-18 19:26:24 +09:00
Kazuho Oku
3e164eab26 do not use the corrupt my_snprintf(%ll[du]) on win32 2010-10-18 19:22:28 +09:00
Muga Nishizawa
ad85533975 java: add a log4j.properties file for unit testing 2010-10-17 19:23:42 +09:00
Muga Nishizawa
d6c2a97931 java: write test programs for org.msgpack.packer.*.java 2010-10-17 18:57:00 +09:00
Muga Nishizawa
17def94ba4 java: describe test programs for org.msgpack.template.*.java 2010-10-17 18:24:08 +09:00
Muga Nishizawa
cf254ea240 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-10-17 14:37:35 +09:00
Muga Nishizawa
2d05110239 java: refactor DynamicCodeGenBase.java 2010-10-17 14:37:13 +09:00
Fuji, Goro
0017f4fce8 Checking in changes prior to tagging of version 0.33.
Changelog diff is:
2010-10-13 12:46:41 +09:00
Fuji, Goro
02f3dd947a perl: optimize PP 2010-10-13 12:46:11 +09:00
Fuji, Goro
ef0874feba perl: tweaks for PreferInteger 2010-10-13 11:02:57 +09:00
Fuji, Goro
14aa1420f0 perl: comments 2010-10-13 10:54:37 +09:00
Fuji, Goro
c506cd97e0 perl: tests 2010-10-13 10:43:56 +09:00
Fuji, Goro
3761aacb1d perl: cleanup PP 2010-10-13 10:14:31 +09:00
Fuji, Goro
233f13aac5 perl: add tests for unpacking 'float' 2010-10-13 10:03:56 +09:00
Fuji, Goro
0ced3ec2d2 perl: fix tests 2010-10-13 09:38:40 +09:00
Fuji, Goro
5b786f65a4 Checking in changes prior to tagging of version 0.32.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 6e07966..4657079 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,4 +1,8 @@

+0.32
+
+    - add tests to detect Alpha problems reported via CPAN testers (gfx)
+
 0.31

     - update Module::Install::XSUtil for ccache support (gfx)
2010-10-12 23:12:34 +09:00
Fuji, Goro
770542c8c7 perl: add tests 2010-10-12 23:10:59 +09:00
Fuji, Goro
4f1207a38c perl: add a strong assertion 2010-10-12 23:05:58 +09:00
Fuji, Goro
2b65f81e23 Add tests 2010-10-12 22:58:53 +09:00
Muga Nishizawa
c10eb2c17b java: add the code for checking a null pointer to DynamicCodeGen.java 2010-10-11 01:30:42 +09:00
Muga Nishizawa
3f5ac54bf5 java: refactor the programs in a org.msgpack.util.codegen package 2010-10-09 21:53:49 +09:00
Muga Nishizawa
790f9409b1 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-10-07 23:53:22 +09:00
Muga Nishizawa
a3d831b723 java: refactor DynamicCodeGen.java 2010-10-07 23:53:01 +09:00
Fuji, Goro
b9483deea3 Checking in changes prior to tagging of version 0.31.
Changelog diff is:
2010-10-07 17:06:45 +09:00
Fuji, Goro
c211d2ac45 Merge commit 'perl-0.30' 2010-10-07 17:05:37 +09:00
Fuji, Goro
119a03dd5f perl: changelogging 2010-10-07 16:56:36 +09:00
Fuji, Goro
f3fbb7e1f6 perl: Update Makefile.PL using M::I::XSUtil 0.36 (support for ccache) 2010-10-07 16:54:49 +09:00
Fuji, Goro
2be98e8467 perl: changelogging 2010-10-07 16:18:47 +09:00
Fuji, Goro
91b1806e9d perl: add XS_VERSION_BOOTCHECK for safety 2010-10-07 16:16:59 +09:00
Fuji, Goro
8548b3645a perl: cleanup 2010-10-07 16:13:56 +09:00
Muga Nishizawa
4bbfb3f9a3 java: refactor DynamicCodeGen.java 2010-10-07 15:27:11 +09:00
Muga Nishizawa
98eec72522 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-10-07 13:01:33 +09:00
Muga Nishizawa
562d50df4d java: refactor several programs in a org.msgpack.util.codegen package 2010-10-07 13:01:06 +09:00
frsyuki
f3ee5ab372 cpp: fixes ./bootstrap to surely run ./preprocess 2010-10-07 06:28:12 +09:00
INADA Naoki
aa2a3e5b07 Add unicode testcase for Python2. 2010-10-07 03:07:52 +09:00
INADA Naoki
8467307239 Fix testcase for unicode. 2010-10-07 03:04:00 +09:00
INADA Naoki
90da951a6f Use PyUnicode_AsUTF8String() instead of o.encode('utf-8'). 2010-10-07 03:02:02 +09:00
tokuhirom
59f81b331c Checking in changes prior to tagging of version 0.30.
Changelog diff is:
2010-10-06 18:00:00 +09:00
Fuji, Goro
77a7d3d26a perl: Fix utf8 mode not to be reseted by $unpacker->reset method 2010-10-06 17:52:32 +09:00
tokuhirom
4321b80999 Checking in changes prior to tagging of version 0.29.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index b506234..333a824 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.29
+
+    - add $unpacker->utf8 mode, decoding strings as UTF-8.
+
 0.28

     - added more tests(gfx)
2010-10-06 12:29:31 +09:00
tokuhirom
4b93b06323 perl: regenerated README file 2010-10-06 12:27:41 +09:00
tokuhirom
96fb2e4b7c Merge branch 'perl-utf8-mode' of github.com:msgpack/msgpack 2010-10-06 12:24:36 +09:00
Muga Nishizawa
3dc1048dfb Merge branch 'master' of git@github.com:msgpack/msgpack 2010-10-05 20:47:41 +09:00
Muga Nishizawa
28f4bd5a67 java: edit test programs for org.msgpack.util.codegen.* 2010-10-05 20:47:03 +09:00
Muga Nishizawa
b01c270889 java: refactor the programs in a org.msgpack.util.codegen package 2010-10-05 20:45:51 +09:00
Fuji, Goro
7c92f8a90b perl: improve docs 2010-10-05 17:47:27 +09:00
Fuji, Goro
a4a04872a3 perl: add $unpacker->utf8 mode, decoding strings as UTF-8. 2010-10-05 17:10:10 +09:00
Fuji, Goro
f2d13cd647 perl: make test code more simple 2010-10-05 15:58:49 +09:00
Fuji, Goro
9346908485 perl: remove tricky hacks 2010-10-05 15:55:38 +09:00
Fuji, Goro
b3a7ba14f7 Merge branch 'master' of github.com:msgpack/msgpack 2010-10-05 15:53:57 +09:00
frsyuki
524ef9553c Merge branch 'master' of http://github.com/advect/msgpack into advect-master 2010-10-03 16:55:59 +09:00
Muga Nishizawa
a85f6e72fe java: edit DynamicCodeGen.java 2010-10-03 02:09:01 +09:00
Muga Nishizawa
1ae6a41336 java: edit BasicConstants.java in org.msgpack.util.codegen 2010-10-02 23:37:08 +09:00
Muga Nishizawa
3ec55791c6 java: refactor DynamicCodeGen.java 2010-10-02 22:12:40 +09:00
Muga Nishizawa
a3accd28ea java: insert logging codes into CustomConverter.java, CustomPacker.java, CustomUnpacker.java and util.codegen programs 2010-10-02 21:28:21 +09:00
Muga Nishizawa
fc5bc84207 java: add a log4j.properties file in src/main/java/resources 2010-10-02 21:25:30 +09:00
Muga Nishizawa
d8b4051d6d java: edit pom.xml to enable to using slf4j logger 2010-10-02 21:24:22 +09:00
Muga Nishizawa
804a1cc22d Merge branch 'master' of git@github.com:msgpack/msgpack 2010-10-02 17:44:00 +09:00
Muga Nishizawa
cdd60e5f9c add a packer and unpacker for Enum types 2010-10-02 17:43:31 +09:00
frsyuki
7c76f07384 java: adds standard packer classes 2010-10-01 13:12:31 +09:00
frsyuki
a3b1ef9527 java: Packer: supports Set 2010-10-01 12:51:09 +09:00
Muga Nishizawa
0bd4150a80 java: changes several methods declared in a DynamicCodeGen class 2010-09-30 01:17:44 +09:00
Muga Nishizawa
7f7f5253f2 java: adds a test program of the DynamicCodeGen class for packing and unpacking an object that has a field anntated by @MessagePackMessage 2010-09-30 00:55:56 +09:00
advect
2a0a847634 php: update 0.3.0 2010-09-29 08:47:06 +09:00
Muga Nishizawa
92ddb37ed3 java: add test programs for DynamicCodeGenPacker, Unpacker, Converter classes 2010-09-28 22:51:38 +09:00
Fuji, Goro
01f944e6bd perl: tiny tweaks 2010-09-28 20:35:05 +09:00
Muga Nishizawa
732c8d7350 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-09-28 19:12:17 +09:00
Muga Nishizawa
21678aeef5 java: moves a TestDynamicCodeGenPackerTemplate.java file to org.msgpack.util.codegen 2010-09-28 19:11:54 +09:00
tokuhirom
cda1ca35a4 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-28 16:02:29 +09:00
Muga Nishizawa
923580d2cd write a simple test program for a DynamicCodeGenPacker class 2010-09-28 15:31:55 +09:00
Muga Nishizawa
190af1d32b delete old programs: org.msgpack.util.codegen.MessagePackOptional, MessagePackRequired, MessagePackUnpackable, and PackUnpackUtil classes 2010-09-28 15:24:47 +09:00
Muga Nishizawa
bffe0443f9 edit DynamicCodeGenPacker and DynamicCodeGenUnpacker class 2010-09-28 12:17:32 +09:00
Muga Nishizawa
29e99e229b Merge branch 'master' of git@github.com:msgpack/msgpack 2010-09-27 17:56:19 +09:00
Muga Nishizawa
2736b88dd5 edit Packer and Unpacker classes, and move org.msgpack.util.annotation.*.java to org.msgpack.util.codegen.*.java 2010-09-27 17:55:48 +09:00
frsyuki
e739c60e9f java: pom.xml: v0.4 2010-09-27 17:42:22 +09:00
frsyuki
1c0afbc5c5 java: loads template classes when Unpacker, MessagePackObject or ClassTemplate is loaded 2010-09-27 17:42:00 +09:00
Muga Nishizawa
ee1ba5c0f2 java: fixed a bug within a Packer class 2010-09-27 10:16:32 +09:00
Muga Nishizawa
02342ba540 java: refactor a Packer class 2010-09-27 10:10:10 +09:00
Muga Nishizawa
12a130e9bc Merge branch 'master' of git@github.com:msgpack/msgpack 2010-09-27 10:02:03 +09:00
Muga Nishizawa
dfb97e7961 java: adds several annotations in an org.msgpack.annotation package and edits Packer.java and its test program 2010-09-27 10:00:47 +09:00
tokuhirom
54e03a62bd Checking in changes prior to tagging of version 0.28.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 82174fe..b506234 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.28
+
+    - added more tests(gfx)
+    - refactor the PP code(gfx)
+
 0.27

     - * 6d9a629 perl: modified trivial codes in PP::Unpacker(makamaka)
2010-09-27 08:35:26 +09:00
tokuhirom
ec9659ff25 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-27 08:32:10 +09:00
frsyuki
0a41b253f3 java: adds templates for primitive types 2010-09-27 04:27:44 +09:00
frsyuki
002b86198c java: adds ReflectionPacker and ReflectionTemplate 2010-09-27 04:17:20 +09:00
frsyuki
7161a235f1 java: uses CustomMessage class on Packer, Unpacker and ClassTemplate 2010-09-27 03:33:21 +09:00
frsyuki
391034a785 java: adds type-conversion mechanisms 2010-09-27 03:06:06 +09:00
frsyuki
446a7fbd67 java: adds CustomMessage class (currently not implemented on Packer, Unpacker and ClassTemplate) 2010-09-27 03:05:32 +09:00
advect
2ccb09434f Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-26 12:44:05 +09:00
frsyuki
7974060a40 cpp: zone: adds msgpack_zone_swap and msgpack::zone::swap 2010-09-26 11:37:37 +09:00
frsyuki
e8abcc1765 cpp: sbuffer: check initial buffer size != 0 2010-09-26 11:36:57 +09:00
frsyuki
1be1927a1f Merge branch 'master' of github.com:msgpack/msgpack 2010-09-24 16:10:07 +09:00
tanakh
894ff71664 haskell: fix for empty constructor 2010-09-24 03:49:31 +09:00
tanakh
93bed9c5df haskell: finish template-haskell deriving implement 2010-09-24 01:24:13 +09:00
Muga Nishizawa
34c008adce java: refactor annotation-utilities 2010-09-23 20:40:50 +09:00
Muga Nishizawa
22ddd91b1f java: add several API to annotation-utilities 2010-09-23 20:38:54 +09:00
Muga Nishizawa
e121f34407 java: refactor annotation-utilities and edit those test programs 2010-09-23 17:26:31 +09:00
Muga Nishizawa
df8a3e870a java: refactor annotation-utilities 2010-09-23 16:18:23 +09:00
Muga Nishizawa
13b6708a09 java: append a code for generating a messageConvert method to annotation-utilities 2010-09-23 15:24:12 +09:00
tanakh
6aa196cf55 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-09-23 00:06:26 +09:00
tanakh
142493076a haskell: TH support and refactoring 2010-09-23 00:04:34 +09:00
gfx
3d905a7a4f perl: add tests for 'extra bytes' exceptions 2010-09-22 16:14:55 +09:00
gfx
0a8a6ed168 perl: cleanup PP 2010-09-22 15:59:21 +09:00
gfx
68b6fa46e6 perl: add tests for boolean values 2010-09-22 15:28:14 +09:00
gfx
80f7c54e4d perl: make scopes 2010-09-22 15:25:08 +09:00
tokuhirom
c0e2041006 Checking in changes prior to tagging of version 0.27.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index b717a82..82174fe 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.27
+
+    - * 6d9a629 perl: modified trivial codes in PP::Unpacker(makamaka)
+    - * ead8edc modified be unpack_(u)int64 in PP(makamaka)
+
 0.26

     - fixed a serious code typo in PP(makamaka)
2010-09-22 15:12:51 +09:00
tokuhirom
f6d2cd7704 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-22 15:09:03 +09:00
makamaka
6d9a629b15 perl: modified trivial codes in PP::Unpacker 2010-09-22 14:19:09 +09:00
makamaka
ead8edc7cd modified be unpack_(u)int64 in PP 2010-09-22 14:12:19 +09:00
tokuhirom
664eefdddb Checking in changes prior to tagging of version 0.26.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 3d455cb..b717a82 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.26
+
+    - fixed a serious code typo in PP(makamaka)
+
 0.25

     (NO FEATURE CHANGES)
2010-09-20 23:40:12 +09:00
tokuhirom
220d76c974 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-20 23:36:50 +09:00
makamaka
d973192b5e perl: modified a serious code typo in PP 2010-09-20 11:49:52 +09:00
tokuhirom
978bb5059f Checking in changes prior to tagging of version 0.25.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index d338cf8..3d455cb 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.25
+
+    (NO FEATURE CHANGES)
+    - oops. I failed releng.

 0.24
     - Fixed a lot of streaming unpacking issues (tokuhirom, gfx)
2010-09-20 09:54:25 +09:00
tokuhirom
f59178bc33 Checking in changes prior to tagging of version 0.24.
Changelog diff is:
2010-09-20 09:30:26 +09:00
gfx
53899cc492 perl: tweaks for Makefile.PL 2010-09-19 22:12:28 +09:00
gfx
6379d0fe0f perl: more tests for nil/true/false entities 2010-09-19 15:53:54 +09:00
gfx
a1c4d8696a Merge branch 'master' of github.com:msgpack/msgpack 2010-09-19 15:49:32 +09:00
gfx
7f42ed86f2 More tests 2010-09-19 15:47:32 +09:00
frsyuki
6bb8b4c994 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-19 15:41:46 +09:00
gfx
afefbe4e56 perl: update .gitignore and MANIFEST.SKIP 2010-09-19 15:21:25 +09:00
gfx
5cd37e5505 perl: always unpacking 64 bit ints as a string on 32 bit perls 2010-09-19 15:20:03 +09:00
gfx
d6a825981d perl: fix unpacking int64_t in PP (based on makamaka's patch) 2010-09-19 15:16:08 +09:00
gfx
a1c01c6722 perl: regen README 2010-09-19 15:15:31 +09:00
gfx
8d182f1d79 perl: Changelogging 2010-09-18 16:30:07 +09:00
gfx
29707bd2ea perl: fix bootstrap 2010-09-18 16:19:16 +09:00
gfx
c2bf2a8174 perl: make pp benchmarks available 2010-09-18 16:16:51 +09:00
gfx
b402849557 perl: docs 2010-09-18 15:54:22 +09:00
gfx
cb85dcfcb8 perl: tweaks for benchmarks 2010-09-18 15:49:25 +09:00
gfx
49379140c7 perl: PERL_ONLY=1 disables XS 2010-09-18 15:14:29 +09:00
gfx
63f6c86b46 perl: add a note about 64 bit integers 2010-09-18 15:05:22 +09:00
gfx
1865898cd4 perl: Fix Makefile.PL 2010-09-18 14:58:32 +09:00
gfx
8935ecfdb8 perl: requires the latest version of Math::BigInt for PP 2010-09-18 14:56:33 +09:00
gfx
4902bed409 perl: more kind testing messages 2010-09-18 14:51:17 +09:00
gfx
e6f6aba207 perl: add portability stuff 2010-09-18 14:50:52 +09:00
gfx
bab622de25 perl: fix max depth checks in PP 2010-09-18 14:46:10 +09:00
gfx
a86c1624a7 perl: More kind error messages in PP 2010-09-18 14:38:35 +09:00
gfx
c707392a5a perl: fix int64_t unpacking in both XS and PP 2010-09-18 14:30:08 +09:00
gfx
1f07721ec4 perl: Scalar::Util is no longer used 2010-09-18 13:33:27 +09:00
gfx
4767e45035 perl: fix a test name 2010-09-18 13:18:25 +09:00
Muga Nishizawa
f2a64ed685 Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-18 10:02:46 +09:00
tokuhirom
2c9966a0a3 perl: fixed stream deserializer in pp. 2010-09-18 09:44:32 +09:00
tokuhirom
953aa95c64 perl: added failing test case for streaming unpacker with PP. 2010-09-18 06:16:26 +09:00
tokuhirom
446266776e perl: regenerate README file 2010-09-18 06:16:17 +09:00
tokuhirom
845af014dc perl: gfx is a author. 2010-09-18 06:15:51 +09:00
gfx
7c8f8703a1 Add TODOs 2010-09-17 18:26:16 +09:00
gfx
a0c18e4380 Docs 2010-09-17 18:16:33 +09:00
gfx
e8d8099563 Fix a macro redefinition 2010-09-17 18:08:34 +09:00
gfx
2c9d90d463 perl: regen README 2010-09-17 18:08:15 +09:00
tokuhirom
130d2064d5 perl: updated benchmark result! gfx++ # performance tuning 2010-09-17 15:28:24 +09:00
gfx
a10eb2a0d7 Changelogging 2010-09-17 14:02:12 +09:00
gfx
b71cc5d7ee chmod -x 2010-09-17 13:59:52 +09:00
gfx
8512f9eda1 Add .gitignore 2010-09-17 13:49:55 +09:00
gfx
80058083b8 Tweaks 2010-09-17 13:49:08 +09:00
gfx
d5a17a3c25 Fix stddata.t 2010-09-17 13:43:42 +09:00
gfx
eab7c87781 Tidy PP 2010-09-17 13:37:17 +09:00
gfx
d2962d8676 Split the boolean class into an outer module 2010-09-17 13:25:23 +09:00
gfx
5e602fb575 Fix tests 2010-09-17 13:10:54 +09:00
gfx
599964ea5f Comments 2010-09-16 21:45:06 +09:00
gfx
562de7926b More tests; some fails now :( 2010-09-16 21:38:17 +09:00
gfx
8eaed95e02 Fix an use of execute() 2010-09-16 20:44:51 +09:00
gfx
3cffd46008 Fix a comment 2010-09-16 20:41:52 +09:00
gfx
e239bfda8a Make leaktrace.t as a regular test 2010-09-16 20:36:07 +09:00
gfx
bd887b660d Preallocate hv keys 2010-09-16 20:31:34 +09:00
gfx
7c1e0ea95d Add binmode() for stream unpacking 2010-09-16 20:27:25 +09:00
gfx
afbddbfcda Fix the stream unpacker 2010-09-16 20:24:01 +09:00
Muga Nishizawa
9eeb702ca5 change an annotation-utility in Java. it allows users to pack and unpack a List object. 2010-09-15 22:28:46 +09:00
gfx
4cb6d6995f Make the code clearer 2010-09-15 15:27:26 +09:00
gfx
fe7e7a8d07 Add leaktrace tests 2010-09-15 15:26:02 +09:00
gfx
f8ee79ab72 Add failing tests 2010-09-15 15:25:48 +09:00
gfx
a11165830b More useful error messages 2010-09-15 15:06:03 +09:00
gfx
11cde61eab No debug output 2010-09-15 14:38:26 +09:00
gfx
cd862409cc Clean up 2010-09-15 14:25:50 +09:00
gfx
7644555d6b Use sv_mortalcopy() 2010-09-15 14:21:44 +09:00
gfx
07e68aa694 Fix an usage message 2010-09-15 14:20:32 +09:00
gfx
0ae206b1bb Revert "The object root can be NULL"
This reverts commit 5bdac96375.
2010-09-15 14:19:22 +09:00
gfx
5bdac96375 The object root can be NULL 2010-09-15 14:18:38 +09:00
gfx
f0e044ecd8 Cleanup 2010-09-15 14:09:03 +09:00
gfx
f32234291e Remove an useless local variable 2010-09-15 14:07:33 +09:00
gfx
83acd6529f Remove an unused user data: source (sv) 2010-09-15 14:06:10 +09:00
gfx
6a60cb4dc0 Add const 2010-09-15 13:54:18 +09:00
gfx
1de03fbe18 Tweaks for unpacker 2010-09-15 13:41:10 +09:00
gfx
0e0a2aa981 Add various integers to benchmarks 2010-09-15 13:34:18 +09:00
gfx
af73b9d11b Shortcut av_push() 2010-09-15 13:22:39 +09:00
gfx
859969241a Tweaks 2010-09-15 13:20:20 +09:00
gfx
6852a8ca9d Remove an unused function: xs_unpack_limit 2010-09-15 13:16:55 +09:00
gfx
c694f1a4a9 Tweaks 2010-09-15 13:16:13 +09:00
gfx
d36543b204 Micro optimizations 2010-09-15 13:12:17 +09:00
gfx
6981234736 Fix a possible mis-unpack on int64 2010-09-15 13:09:14 +09:00
gfx
10bf3ee9de Avoid compiler's warnings 2010-09-15 13:07:44 +09:00
gfx
9953218de1 Tidy 2010-09-15 13:03:47 +09:00
gfx
50c74103aa Avoid compiler's warnings 2010-09-15 12:56:13 +09:00
gfx
c5e15123fd Add an assertion 2010-09-15 12:52:07 +09:00
gfx
4adcdb5ba8 Remove a duplicated depth check 2010-09-15 12:51:33 +09:00
gfx
60b36ffaa3 Micro optimizations 2010-09-15 12:50:11 +09:00
gfx
d86104ed5d Tweaks 2010-09-15 12:48:23 +09:00
gfx
0f02ef20a9 Improve benchmarks 2010-09-15 12:46:11 +09:00
gfx
0768cf17b6 Taking NULL is a bug 2010-09-15 12:36:43 +09:00
gfx
197205853f Use newSV(). NEWSV() is deprecated. 2010-09-15 12:35:10 +09:00
gfx
bebcc24ab8 Depends on XSUtil 0.32 2010-09-15 12:32:01 +09:00
gfx
987248ccbb Use xshelper.h in all the C files 2010-09-15 12:31:01 +09:00
Muga Nishizawa
56ece4db0f fixed a bug the program for packing and unpacking byte[] in annotation-utility 2010-09-14 23:23:09 +09:00
Muga Nishizawa
c7f8b94ccd fixed several bugs of a verify error within annotation-utilities 2010-09-14 22:26:04 +09:00
Muga Nishizawa
95b820305a add a new test program for annotation-utilities 2010-09-14 13:34:11 +09:00
Muga Nishizawa
599b200ca5 change the version of javassist 3.12.1.GA 2010-09-12 23:04:23 +09:00
Muga Nishizawa
a9566b31be add annotation utilities for Java 2010-09-12 22:21:33 +09:00
Muga Nishizawa
f30837d726 Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-12 09:02:40 +09:00
tokuhirom
1242ffa4c6 Checking in changes prior to tagging of version 0.23.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index dd47b98..4120376 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,10 +1,15 @@
+0.23
+
+    (NO FEATURE CHANGES)
+    - fixed english docs(hanekomu++)
+
 0.22

     - fixed issue on ithreads(broken from 0.21)

 0.21

-    - doc enhancment
+    - doc enhancments
     - micro performance tuning.

 0.20
2010-09-12 05:38:15 +09:00
Muga Nishizawa
37c0347c47 Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-12 00:50:26 +09:00
tokuhirom
65befb84a0 Checking in changes prior to tagging of version 0.22.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 5d5a5e2..dd47b98 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.22
+
+    - fixed issue on ithreads(broken from 0.21)
+
 0.21

     - doc enhancment
2010-09-12 00:11:31 +09:00
tokuhirom
a41f7ce3bd oops. 0.21 breakes ithreads support! 2010-09-12 00:09:44 +09:00
Muga Nishizawa
81ced6bf2a Merge branch 'master' of git@github.com:muga/msgpack 2010-09-11 12:13:24 +09:00
Muga Nishizawa
fa8033f998 Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-11 12:12:16 +09:00
Muga Nishizawa
19e3178d0c Merge branch 'master' of http://github.com/msgpack/msgpack 2010-09-10 22:17:06 +09:00
tokuhirom
1e6262f24f Checking in changes prior to tagging of version 0.21.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index dc3dd5c..5d5a5e2 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.21
+
+    - doc enhancment
+    - micro performance tuning.
+
 0.20

     - first production ready release with PP driver.
2010-09-10 21:27:38 +09:00
tokuhirom
beb2284440 perl: added docs for circular reference and blessed object. 2010-09-10 21:25:46 +09:00
tokuhirom
0c4f0de13d perl: inlining the small functions 2010-09-10 21:18:45 +09:00
tokuhirom
0cd31a4b96 perl: inlining utility functions 2010-09-10 21:00:27 +09:00
tokuhirom
ef0a86e7cc perl: more inline 2010-09-10 20:45:17 +09:00
tokuhirom
b79c1345b9 use gfx's standard header. 2010-09-10 20:42:40 +09:00
tokuhirom
5bb8b6f16c perl: ugpraded benchmarking script. and added result to docs. 2010-09-10 20:38:37 +09:00
tokuhirom
f6f675d1e1 updated benchmark script 2010-09-10 20:27:11 +09:00
tokuhirom
9f684e7670 Checking in changes prior to tagging of version 0.20.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 7910882..dc3dd5c 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.20
+
+    - first production ready release with PP driver.
+
 0.16_04

     - no feature changes
2010-09-10 09:35:39 +09:00
tanakh
a998706452 haskell: update cabal file 2010-09-08 13:36:45 +09:00
tanakh
5e19bc6f84 haskell: Object is Eq, Ord, Typeable. 2010-09-07 17:35:24 +09:00
tanakh
169f287970 haskell: Now, Object is an instance of NFData. 2010-09-07 16:14:29 +09:00
tanakh
c56926428c haskell: add packToHandle' 2010-09-07 16:14:00 +09:00
tanakh
43eab5c4e5 Merge branch 'master' of git@github.com:msgpack/msgpack 2010-09-06 23:29:10 +09:00
tanakh
c6424c2ce7 haskell: nonblocking enumerator 2010-09-06 23:27:50 +09:00
tanakh
dfe19d308c haskell: add overlapping instances 2010-09-06 18:14:47 +09:00
tanakh
b75db110dc haskell: add Iteratee interface 2010-09-06 17:00:22 +09:00
tanakh
9e50ba6ec6 haskell: instance tupples and String and lazy ByteString 2010-09-06 16:33:36 +09:00
tanakh
aca2ba13c2 haskell: refactoring 2010-09-06 15:37:55 +09:00
tokuhirom
c5afe7a573 Checking in changes prior to tagging of version 0.16_04.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index a4a3e36..7910882 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,4 +1,4 @@
-0.16_03
+0.16_04

     - no feature changes
2010-09-06 14:35:41 +09:00
tokuhirom
8b90968cb1 Checking in changes prior to tagging of version 0.16_03.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 68b58ba..a4a3e36 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,7 @@
+0.16_03
+
+    - no feature changes
+
 0.16_02

     - document enhancement(tokuhirom)
2010-09-06 14:34:48 +09:00
tokuhirom
9281dba896 Checking in changes prior to tagging of version 0.16_02.
Changelog diff is:

diff --git a/perl/Changes b/perl/Changes
index 9b061cf..68b58ba 100644
--- a/perl/Changes
+++ b/perl/Changes
@@ -1,3 +1,8 @@
+0.16_02
+
+    - document enhancement(tokuhirom)
+    - M::I::XSUtil 0.26 is broken. use 0.27.
+
 0.16_01

     - added PP version (used in cases PERL_DATA_MESSAGEPACK=pp or fail to load XS).
2010-09-06 14:34:04 +09:00
tokuhirom
c7555f1c3c Perl: added link to git repository. 2010-09-06 14:31:53 +09:00
tokuhirom
e781831032 upgraded docs 2010-09-06 14:20:54 +09:00
tokuhirom
8025895168 Checking in changes prior to tagging of version 0.16_01.
Changelog diff is:
2010-09-06 14:20:54 +09:00
tanakh
799935e44c haskel: incr version and update infos. 2010-09-06 14:03:47 +09:00
tanakh
209d8d058c forgot to remove file 2010-09-06 13:57:47 +09:00
tanakh
0368a70dd7 forgot to add file 2010-09-06 13:55:34 +09:00
Hideyuki Tanaka
c3603426de Merge branch 'master' of github.com:msgpack/msgpack 2010-09-06 01:51:18 +09:00
Hideyuki Tanaka
80db9971b5 pure haskell implementation. 2010-09-06 01:50:22 +09:00
tokuhirom
e3e771708e Merge branch 'master' of git://github.com/makamaka/msgpack
Conflicts:
	perl/Changes
2010-09-05 16:18:57 +09:00
tokuhirom
b9bca2a19f bump to 0.16 2010-09-05 16:17:19 +09:00
Muga Nishizawa
ffae70a99a Merge branch 'master' of git@github.com:muga/msgpack 2010-09-05 15:49:42 +09:00
makamaka
10ec1e48b0 modified begin process about byte order 2010-09-05 01:54:44 +09:00
makamaka
84123f5445 fallback PP configuration with c99 unspport compiler 2010-09-04 20:02:46 +09:00
makamaka
25531d8393 modified t/05_preferred_int.t for Win32 2010-09-04 19:54:12 +09:00
makamaka
adfadc542a enable PP to pack/unpack int64 in less than Perl 5.10 2010-09-04 14:35:24 +09:00
makamaka
7682e1cb57 Merge branch 'master' of git://github.com/msgpack/msgpack
Conflicts:
	perl/t/05_preferred_int.t
2010-09-03 15:09:49 +09:00
tokuhirom
1fe4109a42 fixed tests on 64bit machines with -Duselongdouble #60625 2010-09-03 14:50:01 +09:00
makamaka
b97baf4d47 added some comments in Data::MessagePack::PP 2010-09-03 12:53:56 +09:00
makamaka
f91728561f ouch, modified pod 2010-09-02 23:58:40 +09:00
makamaka
2b75d54ce1 modified pod 2010-09-02 23:56:55 +09:00
makamaka
cdc09a7d30 Changes 2010-09-02 23:52:36 +09:00
makamaka
4cc6c3e535 modified t/05_preferred_int.t for Win32 2010-09-02 23:48:57 +09:00
makamaka
8f43e033a4 removed dependency on Data::Float 2010-09-02 23:45:05 +09:00
makamaka
918dbd1926 made Makefile.PL XS/PP configurable 2010-09-02 14:37:22 +09:00
makamaka
8fc86ce7fa removed commented out codes 2010-09-02 14:33:59 +09:00
INADA Naoki
bf0cb40586 python: Add python3 category. 2010-09-02 10:13:49 +09:00
INADA Naoki
a62aefe74b python: Release 0.1.6 - Fix wrong version string. 2010-09-02 10:10:34 +09:00
INADA Naoki
138d232149 python: vesion 0.1.5 2010-09-02 09:58:50 +09:00
INADA Naoki
8fa64e3ab2 Add msgpack.version as version tuple. 2010-09-02 09:54:38 +09:00
INADA Naoki
8d0d2bd3fc python: Add test for python3 and fix found problems. 2010-09-02 02:16:28 +09:00
INADA Naoki
2146f5f623 python: Fix Unpacker.feed doesn't accept bytes on Python3. 2010-09-02 02:02:47 +09:00
INADA Naoki
623df23570 Merge branch 'master' of github.com:msgpack/msgpack 2010-09-02 01:30:32 +09:00
INADA Naoki
4a15d8b6d2 python: Support Python3. 2010-09-02 01:29:57 +09:00
makamaka
af83a62474 modified some codes for test warnings 2010-09-01 16:04:25 +09:00
makamaka
a0705a6c67 added PP backend switch into Data::MessagePack 2010-09-01 11:59:01 +09:00
makamaka
712b8eec3d added pp version 2010-09-01 11:22:43 +09:00
tokuhirom
558e9c21ed Perl: 0.15 2010-09-01 08:19:05 +09:00
tokuhirom
23a7137e6a Perl: better argument validation(patch from dankogai) 2010-08-31 23:42:32 +09:00
frsyuki
71a1cb0184 fixes compatibility with Rubinius 2010-08-31 09:29:01 +09:00
frsyuki
09b47cc536 ruby: fixes compatibility with ruby-1.8.5 2010-08-31 07:00:19 +09:00
frsyuki
b5c78de2dd ruby: converts encodings into UTF-8 on Ruby 1.9 2010-08-31 06:30:16 +09:00
frsyuki
a1bd14e516 template: casts integer types explicitly 2010-08-31 06:27:15 +09:00
frsyuki
9684c8664f cpp: version 0.5.4 2010-08-29 18:27:10 +09:00
frsyuki
3c75361e5a cpp: updates README.md 2010-08-29 18:24:32 +09:00
frsyuki
c44c9ab74d cpp: adds msgpack_vc2008.vcproj file in source package 2010-08-29 18:23:16 +09:00
frsyuki
8cc9c871b7 Merge branch 'master' of github.com:msgpack/msgpack 2010-08-28 11:40:45 +09:00
UENISHI Kota
31d211cded Merge branch 'master' of ssh://github.com/msgpack/msgpack 2010-08-28 00:36:54 +09:00
UENISHI Kota
c42cba1d54 erlang: fixed bug around error case when serializing atom. 2010-08-27 23:02:16 +09:00
frsyuki
c87f7cb9ac cpp: fixes fix_int; updates test/fixint.cc 2010-08-27 20:52:40 +09:00
frsyuki
421bee3871 cpp: version 0.5.3 2010-08-27 17:53:19 +09:00
frsyuki
2c7573a032 cpp: updates msgpack_vc8.postbuild.bat 2010-08-27 17:53:02 +09:00
frsyuki
fe2a0f5089 cpp: adds fixed length serialization for integers 2010-08-27 17:42:05 +09:00
frsyuki
59ba8dec4e cpp: fixes include paths 2010-08-27 16:45:48 +09:00
Muga Nishizawa
ff0e1bbbc0 change the part for creating a new constructor within DynamicCodeGenerator 2010-08-26 17:53:29 +09:00
Muga Nishizawa
18c712cd99 object serialization with reflection and with dynamic code generation 2010-08-25 21:35:52 +09:00
tokuhirom
8de1f764fd Perl: bump up version to 0.14 2010-08-21 16:09:30 +09:00
tokuhirom
a91c1ec6d9 fixed segv on cyclic reference(patch by dankogai) 2010-08-21 16:02:23 +09:00
frsyuki
c8e351b31e java: adds TestMessageUnpackable test 2010-08-21 03:36:44 +09:00
frsyuki
b4c98584db java: adds Unpacker.unpackBigInteger() 2010-08-19 01:19:34 +09:00
frsyuki
1d17836b7d java: NilType::create() returns NilType's one and only instance 2010-08-19 00:54:23 +09:00
frsyuki
193a739749 java: updates TestDirectConversion 2010-08-19 00:05:48 +09:00
frsyuki
48da2b8353 java: adds Packer.pack(<primitive types>) 2010-08-18 23:47:31 +09:00
frsyuki
40dc9de6c9 java: supports packing/unpacking of BigInteger less than 0xffffffffffffffff 2010-08-18 23:37:47 +09:00
frsyuki
d7469e4694 java: fixes cross-language test case 2010-08-18 22:55:50 +09:00
frsyuki
fdfabc9f88 java: adds cross-language test case 2010-08-18 22:51:23 +09:00
frsyuki
5658ca5b90 java: adds ObjectEquals test 2010-08-18 22:24:51 +09:00
frsyuki
8b79e6d3c7 java: uses MessagePackObject instead of Object for type of deserialized objects 2010-08-18 18:10:30 +09:00
frsyuki
8c67087a15 java: adds MessagePackObject.bigIntegerValue(), asBigInteger() and equals() 2010-08-18 16:32:42 +09:00
frsyuki
057f73a73e java: implements MessagePackObject::hashCode() 2010-08-10 14:11:44 +09:00
frsyuki
d3bb37d113 java: fixes MapSchema 2010-08-10 14:11:25 +09:00
frsyuki
6c91b862c9 java: MessagePackObject implements Cloneable and MessagePackable interfaces 2010-07-28 01:17:20 +09:00
frsyuki
cba47b635a java: changed deploy path to ./target/website/maven2 directory. 2010-07-27 09:50:57 +09:00
Kazuki Ohta
cd83388f8b java: fixed repository location. msgpack.sourceforge.net => msgpack.org 2010-07-27 08:59:09 +09:00
frsyuki
02ae247536 java: adds MessagePackObject class 2 2010-07-24 18:20:00 +09:00
frsyuki
1621a68191 Merge branch 'master' of github.com:msgpack/msgpack 2010-07-24 18:08:19 +09:00
frsyuki
2aef495d62 java: adds MessagePackObject class 2010-07-24 18:08:00 +09:00
frsyuki
227c168b65 java: fixes fatal offset calculation bugs on BufferedUnpackerIMPL.unpackInt() 2010-07-24 18:07:22 +09:00
UENISHI Kota
dcbcf5842f erlang: msgpack:unpack_all/1 doc. 2010-07-18 23:55:07 +09:00
UENISHI Kota
8a3ac6d9bd erlang: omake menus added. 2010-07-18 23:50:29 +09:00
UENISHI Kota
6cabad19d5 erlang: unpack_all/1 improve, error handling added. 2010-07-18 23:48:20 +09:00
UENISHI Kota
dad7a03d19 erlang: stopped support for dict() type. 2010-07-18 23:42:23 +09:00
UENISHI Kota
7b152640d9 erlang: 'edoc' document generation 2010-07-18 23:40:25 +09:00
UENISHI Kota
78fddff34e erlang: merged vincent's contribution 2010-07-18 23:01:43 +09:00
advect
78f542f6c0 Update PHP Extension 2010-07-17 18:46:28 +09:00
frsyuki
f8a016edb5 Merge branch 'master' of github.com:msgpack/msgpack 2010-07-14 17:09:34 +09:00
tokuhirom
9ac69337e8 perl: bump up version to 0.13! 2010-07-14 09:58:41 +09:00
tokuhirom
ca0c844f32 clearly specified this distribution requires requires C99. 2010-07-14 09:58:05 +09:00
Vincent de Phily
e629e8784f erlang: Improve documentation
The doc is in edoc format, generated from the source as an html file.
The makefile's default action now also generates the documentation.

I ignored unpack_all/1 and pack(dict()) for now because their future is still uncertain.
2010-07-12 14:08:22 +02:00
Vincent de Phily
e944c1ee93 erlang: Only handle throw() in pack/1 and unpack/1
Rationale: We only use throw/1 for error handling, never erlang:error/1.
           Caller bugs will get a nice {error,...} return while library bugs will
           bubble up in all their uglyness; that's the proper way to do things
           in erlang.
2010-07-09 20:37:06 +02:00
Vincent de Phily
02c882bda3 erlang: Make pack_map/1 api private 2010-07-09 20:34:38 +02:00
Vincent de Phily
2c29377abf erlang: s/short/incomplete/ and s/badarg/{badarg,Term}/
Nicer error returns.
2010-07-09 20:30:17 +02:00
Vincent de Phily
21992f1b9e erlang: fix receiving from port_command in unit tests
Ports can send data bit by bit; make sure we read all the port has to offer in one go.
This should fix the "broken pipe" error we sometime got during testing.
We did not previously check the return of compare_all/2, which is why the bug was not noticed.
Incidentally, this change fixes dialyzer warnings too.
2010-07-09 18:53:24 +02:00
Vincent de Phily
8a3f090684 erlang: Fix some existing specs and add a few other.
dialyzer still complains about dict() and ?assert(false), but I don't think they're real issues.
2010-07-09 17:36:36 +02:00
UENISHI Kota
a4258505a9 erlang: modified wrong testcase. 2010-07-09 23:23:00 +09:00
Vincent de Phily
ba4a971bfa erlang: Remove unecessary 'throw(short)' clause for unpack_{array,map}_/1
Unecessary because unpack_/1 will throw it anyway.
This does mean that we go a tiny bit deeper to find that we don't have enough data,
but that should be a rare code path. Keep the main code path fast and the code clean.

While at it, rename vars to match its sibling function and to avoid thinking that
RestLen is a byte count (it's an item count).
2010-07-09 13:44:02 +02:00
Vincent de Phily
6abc120279 erlang: Fix incomplete/invalid cases of unpack_/1
* fix list of invalid bytes was missing 3 possibilities (see type chart section of msgpack format spec)
* fix matching of invalid bytes to look at 1 byte instead of 2
* simplify 'incomplete' case : anything that's not complete or invalid is by definition incomplete
2010-07-09 13:29:47 +02:00
Vincent de Phily
64c36b7a8f Remove a couple of superfluous 'when' clauses.
The when clause for unpack_/1 has been moved to unpack/1 so that it is performed only once.
2010-07-09 13:06:57 +02:00
Vincent de Phily
64b9f0762c Merge branch 'master' of git://github.com/msgpack/msgpack
Reseting msgpack.erl to upstream version.
2010-07-09 12:35:22 +02:00
UENISHI Kota
e799082e5c erlang: better test cases, except 'Broken pipe' 2010-07-09 01:21:35 +09:00
UENISHI Kota
eab66a022e erlang: added try-catch clause for easy error handling 2010-07-09 01:04:09 +09:00
UENISHI Kota
485915c27a erlang: added simple performance test description. 2010-07-08 23:39:47 +09:00
UENISHI Kota
45fb482ab4 erlang: added simple performance test. 2010-07-08 23:36:18 +09:00
Vincent de Phily
33a7d56042 * Return {more,undefined} instead of {more,integer()}, as we can only know the "minimum bytes needed to continue" instead of the actually usefull "total packet size".
* Merge all {more,...} clauses of unpack_/1 into one.
* Reformat unpack_/1 for readability.
* Fix some specs, error values, and documentation.
2010-06-29 11:59:56 +02:00
Vincent de Phily
8f7f23a0e5 Rewrite unpack_/1 using pattern matching to get a 30-40% speedup.
Simplify pack_* and unpack_{array,map} function clauses to get more readability and a minor speedup.
2010-06-28 18:11:52 +02:00
506 changed files with 76588 additions and 7395 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
*.o
*.so
ruby/Makefile
*.5
*.8
*.6
_obj
_test

View File

@@ -1,4 +1,26 @@
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

View File

@@ -6,7 +6,9 @@ DOC_FILES = \
NOTICE \
msgpack_vc8.vcproj \
msgpack_vc8.sln \
msgpack_vc8.postbuild.bat
msgpack_vc2008.vcproj \
msgpack_vc2008.sln \
msgpack_vc.postbuild.bat
EXTRA_DIST = \
$(DOC_FILES)

View File

@@ -13,9 +13,10 @@ On UNIX-like platform, run ./configure && make && sudo make install:
$ make
$ sudo make install
On Windows, open msgpack_vc8.vcproj file and build it using batch build. DLLs are built on lib folder, and the headers are built on include folder.
On Windows, open msgpack_vc8.vcproj or msgpack_vc2008 file and build it using batch build. DLLs are built on lib folder,
and the headers are built on include folder.
To use the library in your program, include msgpack.hpp header and link msgpack and msgpackc library.
To use the library in your program, include msgpack.hpp header and link "msgpack" library.
## Example
@@ -34,15 +35,9 @@ To use the library in your program, include msgpack.hpp header and link msgpack
msgpack::pack(&buffer, target);
// Deserialize the serialized data.
msgpack::zone mempool; // this manages the life of deserialized object
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(buffer.data, buffer.size, NULL, &mempool, &obj);
if(ret != msgapck::UNPACK_SUCCESS) {
// error check
exit(1);
}
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!"]
@@ -55,24 +50,24 @@ To use the library in your program, include msgpack.hpp header and link msgpack
obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
}
API document and other example codes are available at the [wiki.](http://msgpack.sourceforge.net/start)
API documents and other example codes are available at the [wiki.](http://redmine.msgpack.org/projects/msgpack/wiki)
## License
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.
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.
See also NOTICE file.

View File

@@ -38,7 +38,8 @@ test -f ChangeLog || touch ChangeLog
test -f NEWS || touch NEWS
test -f README || cp -f README.md README
if ! ./preprocess; then
./preprocess
if [ $? -ne 0 ]; then
exit 1
fi

View File

@@ -1,6 +1,6 @@
AC_INIT(src/object.cpp)
AC_CONFIG_AUX_DIR(ac)
AM_INIT_AUTOMAKE(msgpack, 0.5.2)
AM_INIT_AUTOMAKE(msgpack, 0.5.6)
AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)
@@ -55,7 +55,7 @@ if test "$msgpack_cv_atomic_ops" != "yes"; then
Note that gcc < 4.1 is not supported.
If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to
add CFLAGS="--march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows:
add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows:
$ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686"
])

View File

@@ -24,12 +24,13 @@ 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\type\
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\deque.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\
@@ -39,6 +40,6 @@ 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\
copy src\msgpack\type\tr1\unordered_set.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\

View File

@@ -28,7 +28,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Gathering header files"
CommandLine="msgpack_vc8.postbuild.bat"
CommandLine="msgpack_vc.postbuild.bat"
Outputs="include"
/>
<Tool
@@ -96,7 +96,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Gathering header files"
CommandLine="msgpack_vc8.postbuild.bat"
CommandLine="msgpack_vc.postbuild.bat"
Outputs="include"
/>
<Tool

View File

@@ -12,7 +12,7 @@ preprocess() {
fi
}
if [ "$1" == "clean" ];then
if [ "$1" = "clean" ];then
rm -f src/msgpack/type/tuple.hpp
rm -f src/msgpack/type/define.hpp
rm -f src/msgpack/zone.hpp
@@ -29,3 +29,6 @@ cp -f ../msgpack/unpack_template.h src/msgpack/
cp -f ../test/cases.mpac test/
cp -f ../test/cases_compact.mpac test/
sed -e 's/8\.00/9.00/' < msgpack_vc8.vcproj > msgpack_vc2008.vcproj
sed -e 's/9\.00/10.00/' -e 's/msgpack_vc8/msgpack_vc2008/' < msgpack_vc8.sln > msgpack_vc2008.sln

View File

@@ -58,10 +58,11 @@ nobase_include_HEADERS += \
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/deque.hpp \
msgpack/type/map.hpp \
msgpack/type/nil.hpp \
msgpack/type/pair.hpp \

View File

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

View File

@@ -18,9 +18,9 @@
#ifndef MSGPACK_OBJECT_HPP__
#define MSGPACK_OBJECT_HPP__
#include "msgpack/object.h"
#include "msgpack/pack.hpp"
#include "msgpack/zone.hpp"
#include "object.h"
#include "pack.hpp"
#include "zone.hpp"
#include <string.h>
#include <stdexcept>
#include <typeinfo>

View File

@@ -18,8 +18,8 @@
#ifndef MSGPACK_PACK_H__
#define MSGPACK_PACK_H__
#include "msgpack/pack_define.h"
#include "msgpack/object.h"
#include "pack_define.h"
#include "object.h"
#include <stdlib.h>
#ifdef __cplusplus
@@ -70,6 +70,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);
@@ -96,12 +105,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)
{

View File

@@ -18,7 +18,7 @@
#ifndef MSGPACK_PACK_HPP__
#define MSGPACK_PACK_HPP__
#include "msgpack/pack_define.h"
#include "pack_define.h"
#include <stdexcept>
#include <limits.h>
@@ -45,6 +45,15 @@ public:
packer<Stream>& pack_int32(int32_t d);
packer<Stream>& pack_int64(int64_t 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_short(short d);
packer<Stream>& pack_int(int d);
packer<Stream>& pack_long(long d);
@@ -78,6 +87,15 @@ 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_short(Stream& x, short d);
static void _pack_int(Stream& x, int d);
static void _pack_long(Stream& x, long d);
@@ -133,11 +151,15 @@ 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>
@@ -149,6 +171,7 @@ 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; }
@@ -182,6 +205,39 @@ 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_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_short(short d)
{ _pack_short(m_stream, d); return *this; }

View File

@@ -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;
@@ -80,7 +84,7 @@ public:
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; }

View File

@@ -1,15 +1,16 @@
#include "msgpack/type/bool.hpp"
#include "msgpack/type/float.hpp"
#include "msgpack/type/int.hpp"
#include "msgpack/type/list.hpp"
#include "msgpack/type/deque.hpp"
#include "msgpack/type/map.hpp"
#include "msgpack/type/nil.hpp"
#include "msgpack/type/pair.hpp"
#include "msgpack/type/raw.hpp"
#include "msgpack/type/set.hpp"
#include "msgpack/type/string.hpp"
#include "msgpack/type/vector.hpp"
#include "msgpack/type/tuple.hpp"
#include "msgpack/type/define.hpp"
#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"

View 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 */

View File

@@ -30,7 +30,7 @@ namespace msgpack {
inline float& operator>> (object o, float& v)
{
if(o.type != type::DOUBLE) { throw type_error(); }
v = o.via.dec;
v = (float)o.via.dec;
return v;
}
@@ -60,7 +60,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
inline void operator<< (object& o, float v)
{
o.type = type::DOUBLE;
o.via.dec = v;
o.via.dec = (double)v;
}
inline void operator<< (object& o, double v)

View File

@@ -35,11 +35,11 @@ namespace detail {
if(o.type == type::POSITIVE_INTEGER) {
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
{ throw type_error(); }
return o.via.u64;
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 o.via.i64;
return (T)o.via.i64;
}
throw type_error();
}
@@ -51,7 +51,7 @@ namespace detail {
if(o.type == type::POSITIVE_INTEGER) {
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
{ throw type_error(); }
return o.via.u64;
return (T)o.via.u64;
}
throw type_error();
}

View File

@@ -44,7 +44,7 @@ inline void operator<< (object::with_zone& o, const std::string& v)
o.type = type::RAW;
char* ptr = (char*)o.zone->malloc(v.size());
o.via.raw.ptr = ptr;
o.via.raw.size = v.size();
o.via.raw.size = (uint32_t)v.size();
memcpy(ptr, v.data(), v.size());
}
@@ -52,7 +52,7 @@ inline void operator<< (object& o, const std::string& v)
{
o.type = type::RAW;
o.via.raw.ptr = v.data();
o.via.raw.size = v.size();
o.via.raw.size = (uint32_t)v.size();
}

View File

@@ -18,8 +18,8 @@
#ifndef MSGPACK_UNPACKER_H__
#define MSGPACK_UNPACKER_H__
#include "msgpack/zone.h"
#include "msgpack/object.h"
#include "zone.h"
#include "object.h"
#include <string.h>
#ifdef __cplusplus

View File

@@ -18,9 +18,9 @@
#ifndef MSGPACK_UNPACK_HPP__
#define MSGPACK_UNPACK_HPP__
#include "msgpack/unpack.h"
#include "msgpack/object.hpp"
#include "msgpack/zone.hpp"
#include "unpack.h"
#include "object.hpp"
#include "zone.hpp"
#include <memory>
#include <stdexcept>
@@ -258,17 +258,7 @@ inline object unpacker::data()
inline zone* unpacker::release_zone()
{
if(!msgpack_unpacker_flush_zone(this)) {
throw std::bad_alloc();
}
zone* r = new zone();
msgpack_zone old = *base::z;
*base::z = *r;
*static_cast<msgpack_zone*>(r) = old;
return r;
return static_cast<msgpack::zone*>(msgpack_unpacker_release_zone(static_cast<msgpack_unpacker*>(this)));
}
inline void unpacker::reset_zone()

View File

@@ -18,7 +18,7 @@
#ifndef MSGPACK_VREFBUFFER_H__
#define MSGPACK_VREFBUFFER_H__
#include "msgpack/zone.h"
#include "zone.h"
#include <stdlib.h>
#ifndef _WIN32

View File

@@ -18,7 +18,7 @@
#ifndef MSGPACK_VREFBUFFER_HPP__
#define MSGPACK_VREFBUFFER_HPP__
#include "msgpack/vrefbuffer.h"
#include "vrefbuffer.h"
#include <stdexcept>
namespace msgpack {

View File

@@ -18,7 +18,7 @@
#ifndef MSGPACK_ZBUFFER_H__
#define MSGPACK_ZBUFFER_H__
#include "msgpack/sysdep.h"
#include "sysdep.h"
#include <stdlib.h>
#include <string.h>
#include <zlib.h>

View File

@@ -18,7 +18,7 @@
#ifndef MSGPACK_ZBUFFER_HPP__
#define MSGPACK_ZBUFFER_HPP__
#include "msgpack/zbuffer.h"
#include "zbuffer.h"
#include <stdexcept>
namespace msgpack {

View File

@@ -1,7 +1,7 @@
/*
* MessagePack for C memory pool implementation
*
* 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,7 +18,7 @@
#ifndef MSGPACK_ZONE_H__
#define MSGPACK_ZONE_H__
#include "msgpack/sysdep.h"
#include "sysdep.h"
#ifdef __cplusplus
extern "C" {
@@ -73,6 +73,8 @@ static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size
static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone,
void (*func)(void* data), void* data);
static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b);
bool msgpack_zone_is_empty(msgpack_zone* zone);
void msgpack_zone_clear(msgpack_zone* zone);
@@ -129,6 +131,13 @@ bool msgpack_zone_push_finalizer(msgpack_zone* zone,
return true;
}
void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b)
{
msgpack_zone tmp = *a;
*a = *b;
*b = tmp;
}
#ifdef __cplusplus
}

View File

@@ -1,7 +1,7 @@
//
// MessagePack for C++ memory pool
//
// 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,7 +18,7 @@
#ifndef MSGPACK_ZONE_HPP__
#define MSGPACK_ZONE_HPP__
#include "msgpack/zone.h"
#include "zone.h"
#include <cstdlib>
#include <memory>
#include <vector>
@@ -43,6 +43,8 @@ public:
void clear();
void swap(zone& o);
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
T* allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>);
@@ -111,6 +113,11 @@ inline void zone::clear()
msgpack_zone_clear(this);
}
inline void zone::swap(zone& o)
{
msgpack_zone_swap(this, &o);
}
template <typename T>
void zone::object_destructor(void* obj)
{

View File

@@ -164,7 +164,7 @@ void msgpack_object_print(FILE* out, msgpack_object o)
default:
// FIXME
fprintf(out, "#<UNKNOWN %hu %"PRIu64">", o.type, o.via.u64);
fprintf(out, "#<UNKNOWN %i %"PRIu64">", o.type, o.via.u64);
}
}

View File

@@ -19,6 +19,10 @@
#include "msgpack/unpack_define.h"
#include <stdlib.h>
#ifdef _msgpack_atomic_counter_header
#include _msgpack_atomic_counter_header
#endif
typedef struct {
msgpack_zone* z;
@@ -333,6 +337,7 @@ msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac)
msgpack_zone* old = mpac->z;
mpac->z = r;
CTX_CAST(mpac->ctx)->user.z = mpac->z;
return old;
}

View File

@@ -1,7 +1,7 @@
AM_CPPFLAGS = -I../src
AM_C_CPPFLAGS = -I../src
AM_LDFLAGS = ../src/libmsgpack.la -lgtest_main
AM_LDFLAGS = ../src/libmsgpack.la -lgtest_main -pthread
check_PROGRAMS = \
zone \
@@ -13,6 +13,8 @@ check_PROGRAMS = \
convert \
buffer \
cases \
fixint \
fixint_c \
version \
msgpackc_test \
msgpack_test
@@ -38,6 +40,10 @@ buffer_LDADD = -lz
cases_SOURCES = cases.cc
fixint_SOURCES = fixint.cc
fixint_c_SOURCES = fixint_c.cc
version_SOURCES = version.cc
msgpackc_test_SOURCES = msgpackc_test.cpp

View File

@@ -32,5 +32,7 @@ TEST(cases, format)
EXPECT_TRUE( pac_compact.next(&result_compact) );
EXPECT_EQ(result_compact.get(), result.get());
}
EXPECT_FALSE( pac_compact.next(&result) );
}

55
cpp/test/fixint.cc Normal file
View File

@@ -0,0 +1,55 @@
#include <msgpack.hpp>
#include <gtest/gtest.h>
template <typename T>
void check_size(size_t size) {
T v(0);
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, v);
EXPECT_EQ(size, sbuf.size());
}
TEST(fixint, size)
{
check_size<msgpack::type::fix_int8>(2);
check_size<msgpack::type::fix_int16>(3);
check_size<msgpack::type::fix_int32>(5);
check_size<msgpack::type::fix_int64>(9);
check_size<msgpack::type::fix_uint8>(2);
check_size<msgpack::type::fix_uint16>(3);
check_size<msgpack::type::fix_uint32>(5);
check_size<msgpack::type::fix_uint64>(9);
}
template <typename T>
void check_convert() {
T v1(-11);
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, v1);
msgpack::unpacked msg;
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
T v2;
msg.get().convert(&v2);
EXPECT_EQ(v1.get(), v2.get());
EXPECT_EQ(msg.get(), msgpack::object(T(v1.get())));
}
TEST(fixint, convert)
{
check_convert<msgpack::type::fix_int8>();
check_convert<msgpack::type::fix_int16>();
check_convert<msgpack::type::fix_int32>();
check_convert<msgpack::type::fix_int64>();
check_convert<msgpack::type::fix_uint8>();
check_convert<msgpack::type::fix_uint16>();
check_convert<msgpack::type::fix_uint32>();
check_convert<msgpack::type::fix_uint64>();
}

32
cpp/test/fixint_c.cc Normal file
View File

@@ -0,0 +1,32 @@
#include <msgpack.hpp>
#include <gtest/gtest.h>
TEST(fixint, size)
{
msgpack_sbuffer* sbuf = msgpack_sbuffer_new();
msgpack_packer* pk = msgpack_packer_new(sbuf, msgpack_sbuffer_write);
size_t sum = 0;
EXPECT_EQ(0, msgpack_pack_fix_int8(pk, 0));
EXPECT_EQ(sum+=2, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_int16(pk, 0));
EXPECT_EQ(sum+=3, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_int32(pk, 0));
EXPECT_EQ(sum+=5, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_int64(pk, 0));
EXPECT_EQ(sum+=9, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_uint8(pk, 0));
EXPECT_EQ(sum+=2, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_uint16(pk, 0));
EXPECT_EQ(sum+=3, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_uint32(pk, 0));
EXPECT_EQ(sum+=5, sbuf->size);
EXPECT_EQ(0, msgpack_pack_fix_uint64(pk, 0));
EXPECT_EQ(sum+=9, sbuf->size);
msgpack_sbuffer_free(sbuf);
msgpack_packer_free(pk);
}

View File

@@ -7,9 +7,21 @@ TEST(streaming, basic)
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
// 1, 2, 3, "raw", ["data"], {0.3: 0.4}
EXPECT_EQ(0, msgpack_pack_int(pk, 1));
EXPECT_EQ(0, msgpack_pack_int(pk, 2));
EXPECT_EQ(0, msgpack_pack_int(pk, 3));
EXPECT_EQ(0, msgpack_pack_raw(pk, 3));
EXPECT_EQ(0, msgpack_pack_raw_body(pk, "raw", 3));
EXPECT_EQ(0, msgpack_pack_array(pk, 1));
EXPECT_EQ(0, msgpack_pack_raw(pk, 4));
EXPECT_EQ(0, msgpack_pack_raw_body(pk, "data", 4));
EXPECT_EQ(0, msgpack_pack_map(pk, 1));
EXPECT_EQ(0, msgpack_pack_float(pk, 0.4));
EXPECT_EQ(0, msgpack_pack_double(pk, 0.8));
int max_count = 6;
msgpack_packer_free(pk);
const char* input = buffer->data;
@@ -22,36 +34,65 @@ TEST(streaming, basic)
msgpack_unpacked_init(&result);
int count = 0;
while(count < 3) {
while(count < max_count) {
bool unpacked = false;
msgpack_unpacker_reserve_buffer(&pac, 32*1024);
/* read buffer into msgpack_unapcker_buffer(&pac) upto
* msgpack_unpacker_buffer_capacity(&pac) bytes. */
size_t len = 1;
memcpy(msgpack_unpacker_buffer(&pac), input, len);
input += len;
while(!unpacked) {
/* read buffer into msgpack_unapcker_buffer(&pac) upto
* msgpack_unpacker_buffer_capacity(&pac) bytes. */
memcpy(msgpack_unpacker_buffer(&pac), input, 1);
input += 1;
msgpack_unpacker_buffer_consumed(&pac, len);
EXPECT_TRUE(input <= eof);
while(msgpack_unpacker_next(&pac, &result)) {
msgpack_object obj = result.data;
switch(count++) {
case 0:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type);
EXPECT_EQ(1, result.data.via.u64);
break;
case 1:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type);
EXPECT_EQ(2, result.data.via.u64);
break;
case 2:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, result.data.type);
EXPECT_EQ(3, result.data.via.u64);
return;
msgpack_unpacker_buffer_consumed(&pac, 1);
while(msgpack_unpacker_next(&pac, &result)) {
unpacked = 1;
msgpack_object obj = result.data;
msgpack_object e;
switch(count++) {
case 0:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type);
EXPECT_EQ(1, obj.via.u64);
break;
case 1:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type);
EXPECT_EQ(2, obj.via.u64);
break;
case 2:
EXPECT_EQ(MSGPACK_OBJECT_POSITIVE_INTEGER, obj.type);
EXPECT_EQ(3, obj.via.u64);
break;
case 3:
EXPECT_EQ(MSGPACK_OBJECT_RAW, obj.type);
EXPECT_EQ(std::string("raw",3), std::string(obj.via.raw.ptr, obj.via.raw.size));
break;
case 4:
EXPECT_EQ(MSGPACK_OBJECT_ARRAY, obj.type);
EXPECT_EQ(1, obj.via.array.size);
e = obj.via.array.ptr[0];
EXPECT_EQ(MSGPACK_OBJECT_RAW, e.type);
EXPECT_EQ(std::string("data",4), std::string(e.via.raw.ptr, e.via.raw.size));
break;
case 5:
EXPECT_EQ(MSGPACK_OBJECT_MAP, obj.type);
EXPECT_EQ(1, obj.via.map.size);
e = obj.via.map.ptr[0].key;
EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, e.type);
ASSERT_FLOAT_EQ(0.4, (float)e.via.dec);
e = obj.via.map.ptr[0].val;
EXPECT_EQ(MSGPACK_OBJECT_DOUBLE, e.type);
ASSERT_DOUBLE_EQ(0.8, e.via.dec);
break;
}
}
}
EXPECT_TRUE(input < eof);
}
msgpack_unpacker_destroy(&pac);
msgpack_unpacked_destroy(&result);
}

1
erlang/.gitignore vendored
View File

@@ -2,3 +2,4 @@ MANIFEST
*.beam
.omakedb*
*.omc
*~

View File

@@ -22,7 +22,7 @@
# Phony targets are scoped, so you probably want to declare them first.
#
.PHONY: all clean test #install
.PHONY: all clean test edoc dialyzer #install
########################################################################
# Subdirectories.
@@ -33,10 +33,19 @@
.DEFAULT: msgpack.beam
msgpack.beam: msgpack.erl
erlc $<
erlc -Wall +debug_info $<
msgpack.html: msgpack.erl
erl -noshell -run edoc_run file $<
test: msgpack.beam
erl -noshell -s msgpack test -s init stop
edoc: msgpack.erl
erl -noshell -eval 'ok=edoc:files(["msgpack.erl"], [{dir, "edoc"}]).' -s init stop
dialyzer: msgpack.erl
dialyzer --src $<
clean:
-rm *.beam
-rm -f *.beam *.html

4
erlang/edoc/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.html
*.css
*.png
edoc-info

View File

@@ -15,89 +15,121 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% @doc <a href="http://msgpack.org/">MessagePack</a> codec for Erlang.
%%
%% APIs are almost compatible with <a href="http://redmine.msgpack.org/projects/msgpack/wiki/QuickStartC">C API</a>
%% except for buffering functions (both copying and zero-copying), which are unavailable.
%%
%% <table border="1">
%% <caption>Equivalence between Erlang and <a href="http://msgpack.sourceforge.jp/spec">Msgpack type</a> :</caption>
%% <tr><th> erlang </th><th> msgpack </th></tr>
%% <tr><td> integer() </td><td> pos_fixnum/neg_fixnum/uint8/uint16/uint32/uint64/int8/int16/int32/int64 </td></tr>
%% <tr><td> float() </td><td> float/double </td></tr>
%% <tr><td> nil </td><td> nil </td></tr>
%% <tr><td> boolean() </td><td> boolean </td></tr>
%% <tr><td> binary() </td><td> fix_raw/raw16/raw32 </td></tr>
%% <tr><td> list() </td><td> fix_array/array16/array32 </td></tr>
%% <tr><td> {proplist()} </td><td> fix_map/map16/map32 </td></tr>
%% </table>
%% @end
-module(msgpack).
-author('kuenishi+msgpack@gmail.com').
%% tuples, atoms are not supported. lists, integers, double, and so on.
%% see http://msgpack.sourceforge.jp/spec for
%% supported formats. APIs are almost compatible
%% for C API (http://msgpack.sourceforge.jp/c:doc)
%% except buffering functions (both copying and zero-copying).
-export([pack/1, unpack/1, unpack_all/1]).
-export([pack_map/1]).
% compile:
% erl> c(msgpack).
% erl> S = <some term>.
% erl> {S, <<>>} = msgpack:unpack( msgpack:pack(S) ).
-type reason() :: enomem | badarg | no_code_matches.
% @type msgpack_term() = [msgpack_term()]
% | {[{msgpack_term(),msgpack_term()}]}
% | integer() | float() | binary().
% Erlang representation of msgpack data.
-type msgpack_term() :: [msgpack_term()]
| {[{msgpack_term(),msgpack_term()}]}
| integer() | float() | binary().
% ===== external APIs ===== %
-spec pack(Term::msgpack_term()) -> binary().
pack(I) when is_integer(I) andalso I < 0 ->
pack_int_(I);
pack(I) when is_integer(I) ->
pack_uint_(I);
pack(F) when is_float(F) ->
pack_double(F);
pack(nil) ->
<< 16#C0:8 >>;
pack(true) ->
<< 16#C3:8 >>;
pack(false) ->
<< 16#C2:8 >>;
pack(Bin) when is_binary(Bin) ->
pack_raw(Bin);
pack(List) when is_list(List) ->
pack_array(List);
pack({Map}) when is_list(Map) ->
pack_map(Map);
pack(Map) when is_tuple(Map), element(1,Map)=:=dict ->
pack_map(dict:to_list(Map));
pack(_Other) ->
{error, undefined}.
% unpacking.
% if failed in decoding and not end, get more data
% and feed more Bin into this function.
% TODO: error case for imcomplete format when short for any type formats.
-spec unpack( Bin::binary() )-> {msgpack_term(), binary()} |
{more, non_neg_integer()} | {more, undefined} |
{error, reason()}.
unpack(Bin) when not is_binary(Bin)->
{error, badarg};
unpack(Bin) when bit_size(Bin) >= 8 ->
unpack_(Bin);
unpack(<<>>)->
{more, 1};
unpack(_) ->
{more, undefined}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% external APIs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec unpack_all( binary() ) -> [msgpack_term()].
% @doc Encode an erlang term into an msgpack binary.
% Returns {error, {badarg, term()}} if the input is illegal.
% @spec pack(Term::msgpack_term()) -> binary() | {error, {badarg, term()}}
-spec pack(Term::msgpack_term()) -> binary() | {error, {badarg, term()}}.
pack(Term)->
try
pack_(Term)
catch
throw:Exception ->
{error, Exception}
end.
% @doc Decode an msgpack binary into an erlang term.
% It only decodes the first msgpack packet contained in the binary; the rest is returned as is.
% Returns {error, {badarg, term()}} if the input is corrupted.
% Returns {error, incomplete} if the input is not a full msgpack packet (caller should gather more data and try again).
% @spec unpack(Bin::binary()) -> {msgpack_term(), binary()} | {error, incomplete} | {error, {badarg, term()}}
-spec unpack(Bin::binary()) -> {msgpack_term(), binary()} | {error, incomplete} | {error, {badarg, term()}}.
unpack(Bin) when is_binary(Bin) ->
try
unpack_(Bin)
catch
throw:Exception ->
{error, Exception}
end;
unpack(Other) ->
{error, {badarg, Other}}.
% @doc Decode an msgpack binary into an erlang terms.
% It only decodes ALL msgpack packets contained in the binary. No packets should not remain.
% Returns {error, {badarg, term()}} if the input is corrupted.
% Returns {error, incomplete} if the input is not a full msgpack packet (caller should gather more data and try again).
% @spec unpack_all(binary()) -> [msgpack_term()] | {error, incomplete} | {error, {badarg, term()}}
-spec unpack_all(binary()) -> [msgpack_term()] | {error, incomplete} | {error, {badarg, term()}}.
unpack_all(Data)->
case unpack(Data) of
{ Term, Binary } when bit_size(Binary) =:= 0 ->
try
unpack_all_(Data)
catch
throw:Exception ->
{error, Exception}
end.
unpack_all_(Data)->
case unpack_(Data) of
{ Term, <<>> } ->
[Term];
{ Term, Binary } when is_binary(Binary) ->
[Term|unpack_all(Binary)]
[Term|unpack_all_(Binary)]
end.
-spec pack_map(M::[{msgpack_term(),msgpack_term()}])-> binary().
pack_map(M)->
case length(M) of
Len when Len < 16 ->
<< 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>;
Len when Len < 16#10000 -> % 65536
<< 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>;
Len ->
<< 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% internal APIs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ===== internal APIs ===== %
% pack them all
-spec pack_(msgpack_term()) -> binary() | no_return().
pack_(I) when is_integer(I) andalso I < 0 ->
pack_int_(I);
pack_(I) when is_integer(I) ->
pack_uint_(I);
pack_(F) when is_float(F) ->
pack_double(F);
pack_(nil) ->
<< 16#C0:8 >>;
pack_(true) ->
<< 16#C3:8 >>;
pack_(false) ->
<< 16#C2:8 >>;
pack_(Bin) when is_binary(Bin) ->
pack_raw(Bin);
pack_(List) when is_list(List) ->
pack_array(List);
pack_({Map}) when is_list(Map) ->
pack_map(Map);
pack_(Other) ->
throw({badarg, Other}).
-spec pack_uint_(non_neg_integer()) -> binary().
% positive fixnum
pack_uint_(N) when N < 128 ->
<< 2#0:1, N:7 >>;
@@ -114,8 +146,9 @@ pack_uint_(N) when N < 16#FFFFFFFF->
pack_uint_(N) ->
<< 16#CF:8, N:64/big-unsigned-integer-unit:1 >>.
-spec pack_int_(integer()) -> binary().
% negative fixnum
pack_int_(N) when is_integer(N) , N >= -32->
pack_int_(N) when N >= -32->
<< 2#111:3, N:5 >>;
% int 8
pack_int_(N) when N > -128 ->
@@ -130,14 +163,18 @@ pack_int_(N) when N > -16#FFFFFFFF ->
pack_int_(N) ->
<< 16#D3:8, N:64/big-signed-integer-unit:1 >>.
-spec pack_double(float()) -> binary().
% float : erlang's float is always IEEE 754 64bit format.
%pack_float(F) when is_float(F)->
% pack_float(F) when is_float(F)->
% << 16#CA:8, F:32/big-float-unit:1 >>.
% pack_double(F).
% double
pack_double(F) ->
<< 16#CB:8, F:64/big-float-unit:1 >>.
-spec pack_raw(binary()) -> binary().
% raw bytes
pack_raw(Bin) ->
case byte_size(Bin) of
@@ -149,53 +186,59 @@ pack_raw(Bin) ->
<< 16#DB:8, Len:32/big-unsigned-integer-unit:1, Bin/binary >>
end.
% list / tuple
-spec pack_array([msgpack_term()]) -> binary() | no_return().
% list
pack_array(L) ->
case length(L) of
Len when Len < 16 ->
<< 2#1001:4, Len:4/integer-unit:1, (pack_array_(L, <<>>))/binary >>;
Len when Len < 16#10000 -> % 65536
<< 16#DC:8, Len:16/big-unsigned-integer-unit:1,(pack_array_(L, <<>>))/binary >>;
<< 16#DC:8, Len:16/big-unsigned-integer-unit:1, (pack_array_(L, <<>>))/binary >>;
Len ->
<< 16#DD:8, Len:32/big-unsigned-integer-unit:1,(pack_array_(L, <<>>))/binary >>
<< 16#DD:8, Len:32/big-unsigned-integer-unit:1, (pack_array_(L, <<>>))/binary >>
end.
pack_array_([], Acc) -> Acc;
pack_array_([Head|Tail], Acc) ->
pack_array_(Tail, <<Acc/binary, (pack(Head))/binary>>).
pack_array_(Tail, <<Acc/binary, (pack_(Head))/binary>>).
% FIXME! this should be without lists:reverse/1
unpack_array_(<<>>, 0, RetList) -> {lists:reverse(RetList), <<>>};
unpack_array_(Remain, 0, RetList) when is_binary(Remain)-> {lists:reverse(RetList), Remain};
unpack_array_(<<>>, RestLen, _RetList) when RestLen > 0 -> {more, undefined};
unpack_array_(Bin, RestLen, RetList) when is_binary(Bin)->
case unpack(Bin) of
{more, _} -> {more, undefined};
{Term, Rest}-> unpack_array_(Rest, RestLen-1, [Term|RetList])
% Users SHOULD NOT send too long list: this uses lists:reverse/1
-spec unpack_array_(binary(), non_neg_integer(), [msgpack_term()]) -> {[msgpack_term()], binary()} | no_return().
unpack_array_(Bin, 0, Acc) -> {lists:reverse(Acc), Bin};
unpack_array_(Bin, Len, Acc) ->
{Term, Rest} = unpack_(Bin),
unpack_array_(Rest, Len-1, [Term|Acc]).
-spec pack_map(M::[{msgpack_term(),msgpack_term()}]) -> binary() | no_return().
pack_map(M)->
case length(M) of
Len when Len < 16 ->
<< 2#1000:4, Len:4/integer-unit:1, (pack_map_(M, <<>>))/binary >>;
Len when Len < 16#10000 -> % 65536
<< 16#DE:8, Len:16/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>;
Len ->
<< 16#DF:8, Len:32/big-unsigned-integer-unit:1, (pack_map_(M, <<>>))/binary >>
end.
pack_map_([], Acc) -> Acc;
pack_map_([{Key,Value}|Tail], Acc) ->
pack_map_(Tail, << Acc/binary, (pack(Key))/binary, (pack(Value))/binary>>).
pack_map_(Tail, << Acc/binary, (pack_(Key))/binary, (pack_(Value))/binary>>).
% FIXME! this should be without lists:reverse/1
-spec unpack_map_(binary(), non_neg_integer(), [{term(), msgpack_term()}])->
{more, non_neg_integer()} | { any(), binary()}.
unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin};
% Users SHOULD NOT send too long list: this uses lists:reverse/1
-spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}]) ->
{{[{msgpack_term(), msgpack_term()}]}, binary()} | no_return().
unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin};
unpack_map_(Bin, Len, Acc) ->
case unpack(Bin) of
{more, _} -> {more, undefined};
{Key, Rest} ->
case unpack(Rest) of
{more, _} -> {more, undefined};
{Value, Rest2} ->
unpack_map_(Rest2,Len-1,[{Key,Value}|Acc])
end
end.
{Key, Rest} = unpack_(Bin),
{Value, Rest2} = unpack_(Rest),
unpack_map_(Rest2, Len-1, [{Key,Value}|Acc]).
-spec unpack_(Payload::binary()) ->
{more, pos_integer()} | {msgpack_term(), binary()} | {error, reason()}.
unpack_(Binary)->
case Binary of
% unpack them all
-spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | no_return().
unpack_(Bin) ->
case Bin of
% ATOMS
<<16#C0, Rest/binary>> -> {nil, Rest};
<<16#C2, Rest/binary>> -> {false, Rest};
@@ -229,48 +272,46 @@ unpack_(Binary)->
<<2#101:3, L:5, V:L/binary, Rest/binary>> -> {V, Rest}; % raw bytes
<<2#1001:4, L:4, Rest/binary>> -> unpack_array_(Rest, L, []); % array
<<2#1000:4, L:4, Rest/binary>> -> unpack_map_(Rest, L, []); % map
% Incomplete / invalid data
<<16#CA, Rest/binary>> -> {more, 4-byte_size(Rest)};
<<16#CB, Rest/binary>> -> {more, 8-byte_size(Rest)};
<<16#CC>> -> {more, 1};
<<16#CD, Rest/binary>> -> {more, 2-byte_size(Rest)};
<<16#CE, Rest/binary>> -> {more, 4-byte_size(Rest)};
<<16#CF, Rest/binary>> -> {more, 8-byte_size(Rest)};
<<16#D0>> -> {more, 1};
<<16#D1, Rest/binary>> -> {more, 2-byte_size(Rest)};
<<16#D2, Rest/binary>> -> {more, 4-byte_size(Rest)};
<<16#D3, Rest/binary>> -> {more, 8-byte_size(Rest)};
<<16#DA, Rest/binary>> -> {more, 16-byte_size(Rest)};
<<16#DB, Rest/binary>> -> {more, 32-byte_size(Rest)};
<<16#DC, Rest/binary>> -> {more, 2-byte_size(Rest)};
<<16#DD, Rest/binary>> -> {more, 4-byte_size(Rest)};
<<16#DE, Rest/binary>> -> {more, 2-byte_size(Rest)};
<<16#DF, Rest/binary>> -> {more, 4-byte_size(Rest)};
<<2#101:3, L:5, Rest/binary>> -> {more, L-byte_size(Rest)};
<<>> -> {more, 1};
<<2#101:3, _/binary>> -> {more, undefined};
<<F:8, Rest/binary>> when F==16#C1;
F==16#C7; F==16#C8; F==16#C9; F==16#D5;
F==16#D6; F==16#D7; F==16#D8; F==16#D9->
{error, {badarg, <<F, Rest/binary>>}};
Other ->
{error, {badarg, Other}}
% Invalid data
<<F, R/binary>> when F==16#C1;
F==16#C4; F==16#C5; F==16#C6; F==16#C7; F==16#C8; F==16#C9;
F==16#D4; F==16#D5; F==16#D6; F==16#D7; F==16#D8; F==16#D9 ->
throw({badarg, <<F, R/binary>>});
% Incomplete data (we've covered every complete/invalid case; anything left is incomplete)
_ ->
throw(incomplete)
end.
% ===== test codes ===== %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% unit tests
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-include_lib("eunit/include/eunit.hrl").
-ifdef(EUNIT).
compare_all([], [])-> ok;
compare_all([], R)-> {toomuchrhs, R};
compare_all(L, [])-> {toomuchlhs, L};
compare_all([], R)-> {toomuchrhs, R};
compare_all(L, [])-> {toomuchlhs, L};
compare_all([LH|LTL], [RH|RTL]) ->
LH=RH,
?assertEqual(LH, RH),
compare_all(LTL, RTL).
port_receive(Port) ->
port_receive(Port, <<>>).
port_receive(Port, Acc) ->
receive
{Port, {data, Data}} -> port_receive(Port, <<Acc/binary, Data/binary>>);
{Port, eof} -> Acc
after 1000 -> Acc
end.
test_([]) -> 0;
test_([Term|Rest])->
Pack = msgpack:pack(Term),
?assertEqual({Term, <<>>}, msgpack:unpack( Pack )),
1+test_(Rest).
test_data()->
[true, false, nil,
0, 1, 2, 123, 512, 1230, 678908, 16#FFFFFFFFFF,
@@ -291,24 +332,18 @@ basic_test()->
port_test()->
Tests = test_data(),
{[Tests],<<>>} = msgpack:unpack(msgpack:pack([Tests])),
Port = open_port({spawn, "ruby ../test/crosslang.rb"}, [binary]),
true = port_command(Port, msgpack:pack(Tests) ),
receive
{Port, {data, Data}}-> {Tests, <<>>}=msgpack:unpack(Data)
after 1024-> ?assert(false) end,
?assertEqual({[Tests],<<>>}, msgpack:unpack(msgpack:pack([Tests]))),
Port = open_port({spawn, "ruby ../test/crosslang.rb"}, [binary, eof]),
true = port_command(Port, msgpack:pack(Tests)),
?assertEqual({Tests, <<>>}, msgpack:unpack(port_receive(Port))),
port_close(Port).
test_p(Len,Term,OrigBin,Len) ->
{Term, <<>>}=msgpack:unpack(OrigBin);
test_p(I,_,OrigBin,Len) when I < Len->
<<Bin:I/binary, _/binary>> = OrigBin,
case msgpack:unpack(Bin) of
{more, N} when not is_integer(N) ->
?assertEqual(undefined, N);
{more, N} ->
?assert( N < Len )
end.
?assertEqual({error,incomplete}, msgpack:unpack(Bin)).
partial_test()-> % error handling test.
Term = lists:seq(0, 45),
@@ -318,10 +353,7 @@ partial_test()-> % error handling test.
long_test()->
Longer = lists:seq(0, 655),
% Longest = lists:seq(0,12345),
{Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)),
% {Longest, <<>>} = msgpack:unpack(msgpack:pack(Longest)).
ok.
{Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)).
map_test()->
Ints = lists:seq(0, 65),
@@ -331,6 +363,7 @@ map_test()->
ok.
unknown_test()->
Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary, eof]),
Tests = [0, 1, 2, 123, 512, 1230, 678908,
-1, -23, -512, -1230, -567898,
<<"hogehoge">>, <<"243546rf7g68h798j">>,
@@ -338,25 +371,25 @@ unknown_test()->
-234.4355, 1.0e-34, 1.0e64,
[23, 234, 0.23],
[0,42,<<"sum">>, [1,2]], [1,42, nil, [3]],
{[{1,2},{<<"hoge">>,nil}]},
{[{1,2},{<<"hoge">>,nil}]}, % map
-234, -50000,
42
],
Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]),
receive
{Port, {data, Data}}->
compare_all(Tests, msgpack:unpack_all(Data))
after 1024-> ?assert(false) end,
?assertEqual(ok, compare_all(Tests, msgpack:unpack_all(port_receive(Port)))),
port_close(Port).
test_([]) -> 0;
test_([Before|Rest])->
Pack = msgpack:pack(Before),
{After, <<>>} = msgpack:unpack( Pack ),
?assertEqual(Before, After),
1+test_(Rest).
other_test()->
{more,1}=msgpack:unpack(<<>>).
?assertEqual({error,incomplete},msgpack:unpack(<<>>)).
benchmark_test()->
Data=[test_data() || _ <- lists:seq(0, 10000)],
S=?debugTime(" serialize", msgpack:pack(Data)),
{Data,<<>>}=?debugTime("deserialize", msgpack:unpack(S)),
?debugFmt("for ~p KB test data.", [byte_size(S) div 1024]).
error_test()->
?assertEqual({error,{badarg, atom}}, msgpack:pack(atom)),
Term = {"hoge", "hage", atom},
?assertEqual({error,{badarg, Term}}, msgpack:pack(Term)).
-endif.

11
go/Makefile Normal file
View File

@@ -0,0 +1,11 @@
include $(GOROOT)/src/Make.inc
TARG=msgpack
GOFILES=pack.go unpack.go
include $(GOROOT)/src/Make.pkg
%: install %.go
$(GC) $*.go
$(LD) -o $@ $*.$O

218
go/msgpack_test.go Normal file
View File

@@ -0,0 +1,218 @@
package msgpack_test
import (
. "msgpack"
"testing"
"bytes"
"reflect"
"math"
);
func equal(lhs reflect.Value, rhs reflect.Value) bool {
{
_rhs, ok := rhs.(*reflect.InterfaceValue)
if ok { return equal(lhs, _rhs.Elem()) }
}
switch _lhs := lhs.(type) {
case *reflect.InterfaceValue:
return equal(_lhs.Elem(), rhs)
case *reflect.BoolValue:
_rhs, ok := rhs.(*reflect.BoolValue)
return ok && _lhs.Get() == _rhs.Get()
case *reflect.UintValue:
_rhs, ok := rhs.(*reflect.UintValue)
return ok && _lhs.Get() == _rhs.Get()
case *reflect.IntValue:
_rhs, ok := rhs.(*reflect.IntValue)
return ok && _lhs.Get() == _rhs.Get()
case *reflect.FloatValue:
_rhs, ok := rhs.(*reflect.FloatValue)
return ok && _lhs.Get() == _rhs.Get()
case reflect.ArrayOrSliceValue:
_rhs := rhs.(reflect.ArrayOrSliceValue)
if _lhs.Len() != _rhs.Len() { return false; }
for i := 0; i < _lhs.Len(); i++ {
if !equal(_lhs.Elem(i), _rhs.Elem(i)) { return false; }
}
return true;
case *reflect.MapValue:
_rhs := rhs.(*reflect.MapValue)
if _lhs.Len() != _rhs.Len() { return false; }
for _, k := range _lhs.Keys() {
lv, rv := _lhs.Elem(k), _rhs.Elem(k)
if lv == nil || rv == nil || !equal(lv, rv) { return false; }
}
return true;
}
return false;
}
func TestPackUint8(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []uint8 { 0, 1, 2, 125, 126, 127, 128, 253, 254, 255 } {
_, err := PackUint8(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0x00, 0x01, 0x02, 0x7d, 0x7e, 0x7f, 0xcc, 0x80, 0xcc, 0xfd, 0xcc, 0xfe, 0xcc, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackUint16(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []uint16 { 0, 1, 2, 125, 126, 127, 128, 253, 254, 255, 256, 65533, 65534, 65535 } {
_, err := PackUint16(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0x00, 0x01, 0x02, 0x7d, 0x7e, 0x7f, 0xcc, 0x80, 0xcc, 0xfd, 0xcc, 0xfe, 0xcc, 0xff, 0xcd, 0x01, 0x00, 0xcd, 0xff, 0xfd, 0xcd, 0xff, 0xfe, 0xcd, 0xff, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackUint32(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []uint32 { 0, 1, 2, 125, 126, 127, 128, 253, 254, 255, 256, 65533, 65534, 65535, 65536, 4294967293, 4294967294, 4294967295 } {
_, err := PackUint32(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0x00, 0x01, 0x02, 0x7d, 0x7e, 0x7f, 0xcc, 0x80, 0xcc, 0xfd, 0xcc, 0xfe, 0xcc, 0xff, 0xcd, 0x01, 0x00, 0xcd, 0xff, 0xfd, 0xcd, 0xff, 0xfe, 0xcd, 0xff, 0xff, 0xce, 0x00, 0x01, 0x00, 0x00, 0xce, 0xff, 0xff, 0xff, 0xfd, 0xce, 0xff, 0xff, 0xff, 0xfe, 0xce, 0xff, 0xff, 0xff, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackUint64(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []uint64 { 0, 1, 2, 125, 126, 127, 128, 253, 254, 255, 256, 65533, 65534, 65535, 65536, 4294967293, 4294967294, 4294967295, 4294967296, 18446744073709551613, 18446744073709551614, 18446744073709551615 } {
_, err := PackUint64(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0x00, 0x01, 0x02, 0x7d, 0x7e, 0x7f, 0xcc, 0x80, 0xcc, 0xfd, 0xcc, 0xfe, 0xcc, 0xff, 0xcd, 0x01, 0x00, 0xcd, 0xff, 0xfd, 0xcd, 0xff, 0xfe, 0xcd, 0xff, 0xff, 0xce, 0x00, 0x01, 0x00, 0x00, 0xce, 0xff, 0xff, 0xff, 0xfd, 0xce, 0xff, 0xff, 0xff, 0xfe, 0xce, 0xff, 0xff, 0xff, 0xff, 0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackInt8(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []int8 { -128, -127, -34, -33, -32, -31, 0, 1, 126, 127 } {
_, err := PackInt8(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xd0, 0x80, 0xd0, 0x81, 0xd0, 0xde, 0xd0, 0xdf, 0xe0, 0xe1, 0x00, 0x01, 0x7e, 0x7f }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackInt16(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []int16 { -32768, -32767, -131, -130, -129, -128, -127, -34, -33, -32, -31, 0, 1, 126, 127, 128, 129, 130, 32765, 32766, 32767 } {
_, err := PackInt16(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xd1, 0x80, 0x00, 0xd1, 0x80, 0x01, 0xd1, 0xff, 0x7d, 0xd1, 0xff, 0x7e, 0xd1, 0xff, 0x7f, 0xd0, 0x80, 0xd0, 0x81, 0xd0, 0xde, 0xd0, 0xdf, 0xe0, 0xe1, 0x00, 0x01, 0x7e, 0x7f, 0xd1, 0x00, 0x80, 0xd1, 0x00, 0x81, 0xd1, 0x00, 0x82, 0xd1, 0x7f, 0xfd, 0xd1, 0x7f, 0xfe, 0xd1, 0x7f, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackInt32(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []int32 { -2147483648, -2147483647, -2147483646, -32771, -32770, -32769, -32768, -32767, -131, -130, -129, -128, -127, -34, -33, -32, -31, 0, 1, 126, 127, 128, 129, 130, 32765, 32766, 32767, 32768, 32769, 32770, 2147483645, 2147483646, 2147483647 } {
_, err := PackInt32(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xd2, 0x80, 0x00, 0x00, 0x00, 0xd2, 0x80, 0x00, 0x00, 0x01, 0xd2, 0x80, 0x00, 0x00, 0x02, 0xd2, 0xff, 0xff, 0x7f, 0xfd, 0xd2, 0xff, 0xff, 0x7f, 0xfe, 0xd2, 0xff, 0xff, 0x7f, 0xff, 0xd1, 0x80, 0x00, 0xd1, 0x80, 0x01, 0xd1, 0xff, 0x7d, 0xd1, 0xff, 0x7e, 0xd1, 0xff, 0x7f, 0xd0, 0x80, 0xd0, 0x81, 0xd0, 0xde, 0xd0, 0xdf, 0xe0, 0xe1, 0x00, 0x01, 0x7e, 0x7f, 0xd1, 0x00, 0x80, 0xd1, 0x00, 0x81, 0xd1, 0x00, 0x82, 0xd1, 0x7f, 0xfd, 0xd1, 0x7f, 0xfe, 0xd1, 0x7f, 0xff, 0xd2, 0x00, 0x00, 0x80, 0x00, 0xd2, 0x00, 0x00, 0x80, 0x01, 0xd2, 0x00, 0x00, 0x80, 0x02, 0xd2, 0x7f, 0xff, 0xff, 0xfd, 0xd2, 0x7f, 0xff, 0xff, 0xfe, 0xd2, 0x7f, 0xff, 0xff, 0xff }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackInt64(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []int64 { -9223372036854775808, -9223372036854775807, -9223372036854775806, -2147483651, -2147483650, -2147483649, -2147483648, -2147483647, -2147483646, -32771, -32770, -32769, -32768, -32767, -131, -130, -129, -128, -127, -34, -33, -32, -31, 0, 1, 126, 127, 128, 129, 130, 32765, 32766, 32767, 32768, 32769, 32770, 2147483645, 2147483646, 2147483647, 2147483648, 2147483649, 2147483650, 4294967296, 4294967297, 4294967298 } {
_, err := PackInt64(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xd3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xd3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xd3, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xfd, 0xd3, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xfe, 0xd3, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xd2, 0x80, 0x00, 0x00, 0x00, 0xd2, 0x80, 0x00, 0x00, 0x01, 0xd2, 0x80, 0x00, 0x00, 0x02, 0xd2, 0xff, 0xff, 0x7f, 0xfd, 0xd2, 0xff, 0xff, 0x7f, 0xfe, 0xd2, 0xff, 0xff, 0x7f, 0xff, 0xd1, 0x80, 0x00, 0xd1, 0x80, 0x01, 0xd1, 0xff, 0x7d, 0xd1, 0xff, 0x7e, 0xd1, 0xff, 0x7f, 0xd0, 0x80, 0xd0, 0x81, 0xd0, 0xde, 0xd0, 0xdf, 0xe0, 0xe1, 0x00, 0x01, 0x7e, 0x7f, 0xd1, 0x00, 0x80, 0xd1, 0x00, 0x81, 0xd1, 0x00, 0x82, 0xd1, 0x7f, 0xfd, 0xd1, 0x7f, 0xfe, 0xd1, 0x7f, 0xff, 0xd2, 0x00, 0x00, 0x80, 0x00, 0xd2, 0x00, 0x00, 0x80, 0x01, 0xd2, 0x00, 0x00, 0x80, 0x02, 0xd2, 0x7f, 0xff, 0xff, 0xfd, 0xd2, 0x7f, 0xff, 0xff, 0xfe, 0xd2, 0x7f, 0xff, 0xff, 0xff, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x02, 0xd3, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xd3, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackNil(t *testing.T) {
b := &bytes.Buffer{}
nbyteswrite, err := PackNil(b)
if nbyteswrite != 1 { t.Error("nbyteswrite != 1") }
if err != nil { t.Error("err != nil") }
if bytes.Compare(b.Bytes(), []byte { 0xc0 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackBool(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range []bool { false, true } {
nbyteswrite, err := PackBool(b, i)
if nbyteswrite != 1 { t.Error("nbyteswrite != 1") }
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xc2, 0xc3 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackInt32Array(t *testing.T) {
b := &bytes.Buffer{}
_, err := PackInt32Array(b, []int32 {})
if err != nil { t.Error("err != nil") }
_, err = PackInt32Array(b, []int32 { 0 })
if err != nil { t.Error("err != nil") }
_, err = PackInt32Array(b, []int32 { 0, 1 })
if err != nil { t.Error("err != nil") }
_, err = PackInt32Array(b, []int32 { 0, 1, 2 })
if err != nil { t.Error("err != nil") }
if bytes.Compare(b.Bytes(), []byte { 0x90, 0x91, 0x00, 0x92, 0x00, 0x01, 0x93, 0x00, 0x01, 0x02 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackArray(t *testing.T) {
b := &bytes.Buffer{}
_, err := PackArray(b, reflect.NewValue([]int32 {}).(reflect.ArrayOrSliceValue))
if err != nil { t.Error("err != nil") }
_, err = PackArray(b, reflect.NewValue([]int32 { 0 }).(reflect.ArrayOrSliceValue))
if err != nil { t.Error("err != nil") }
_, err = PackArray(b, reflect.NewValue([]int32 { 0, 1 }).(reflect.ArrayOrSliceValue))
if err != nil { t.Error("err != nil") }
_, err = PackArray(b, reflect.NewValue([]int32 { 0, 1, 2 }).(reflect.ArrayOrSliceValue))
if err != nil { t.Error("err != nil") }
if bytes.Compare(b.Bytes(), []byte { 0x90, 0x91, 0x00, 0x92, 0x00, 0x01, 0x93, 0x00, 0x01, 0x02 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPackMap(t *testing.T) {
b := &bytes.Buffer{}
_, err := PackMap(b, reflect.NewValue(map[int] int { 0: 1, 2: 3, 4: 5 }).(*reflect.MapValue))
if err != nil { t.Error("err != nil") }
if bytes.Compare(b.Bytes(), []byte { 0x83, 0x00, 0x01, 0x04, 0x05, 0x02, 0x03 }) != 0 { t.Error("wrong output", b.Bytes()) }
}
func TestPack(t *testing.T) {
b := &bytes.Buffer{}
for _, i := range [](interface{}) { nil, false, true, 0, 1, 2, 3, 127, -32, -1, -33, 128 } {
_, err := Pack(b, i)
if err != nil { t.Error("err != nil") }
}
if bytes.Compare(b.Bytes(), []byte { 0xc0, 0xc2, 0xc3, 0x00, 0x01, 0x02, 0x03, 0x7f, 0xf0, 0xff, 0xd0, 0xef, 0xd1, 0x00, 0x80 }) == 0 { t.Error("wrong output") }
}
func TestUnpackArray(t *testing.T) {
b := bytes.NewBuffer([]byte { 0x90, 0x91, 0x00, 0x92, 0x00, 0x01, 0x93, 0xd1, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, 0x01, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xdc, 0x00, 0x02, 0x00, 0x01, 0xdd, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x02, 0x03 })
for _, v := range [](interface{}) { [](interface{}) {}, [](interface{}) { int8(0) }, [](interface{}) { int8(0), int8(1) }, [](interface{}) { int16(0), int32(1), int64(2) }, [](interface{}){ int8(0), int8(1) }, [](interface{}) { int8(0), int8(1), int8(2), int8(3) } } {
retval, _, e := Unpack(b)
if e != nil { t.Error("err != nil") }
if !equal(reflect.NewValue(retval.Interface()), reflect.NewValue(v)) { t.Errorf("%s != %s", retval.Interface(), v) }
}
}
func TestUnpackInt(t *testing.T) {
b := bytes.NewBuffer([]byte { 0xff, 0xe0, 0x00, 0x01, 0x02, 0x7d, 0x7e, 0x7f, 0xd0, 0x01, 0xd0, 0x80, 0xd0, 0xff, 0xcc, 0x80, 0xcc, 0xfd, 0xcc, 0xfe, 0xcc, 0xff, 0xd1, 0x00, 0x00, 0xd1, 0x7f, 0xff, 0xd1, 0xff, 0xff, 0xcd, 0x80, 0x00, 0xcd, 0xff, 0xff, 0xd2, 0x7f, 0xff, 0xff, 0xff, 0xce, 0x7f, 0xff, 0xff, 0xff, 0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff })
for _, v := range [](interface{}) {
int8(-1), int8(-32), int8(0), int8(1), int8(2), int8(125), int8(126), int8(127), int8(1), int8(-128), int8(-1), uint8(128), uint8(253), uint8(254), uint8(255), int16(0), int16(32767), int16(-1), uint16(32768), uint16(65535), int32(2147483647), uint32(2147483647), int64(9223372036854775807), uint64(18446744073709551615) } {
retval, _, e := Unpack(b)
if e != nil { t.Error("err != nil") }
if retval.Interface() != v { t.Errorf("%u != %u", retval.Interface(), v) }
}
}
func TestUnpackFloat(t *testing.T) {
b := bytes.NewBuffer([]byte { 0xca, 0x3d, 0xcc, 0xcc, 0xcd, 0xca, 0x3e, 0x4c, 0xcc, 0xcd, 0xca, 0xbd, 0xcc, 0xcc, 0xcd, 0xca, 0xbe, 0x4c, 0xcc, 0xcd, 0xca, 0x7f, 0x80, 0x00, 0x00, 0xca, 0xff, 0x80, 0x00, 0x00, 0xca, 0xff, 0xc0, 0x00, 0x0, 0xcb, 0x3f, 0xb9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0x3f, 0xc9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0xbf, 0xb9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0xbf, 0xc9, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a, 0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0xcb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
for _, v := range [](interface{}) { float32(.1), float32(.2), float32(-.1), float32(-.2), float32(math.Inf(1)), float32(math.Inf(-1)), float32(math.NaN()), float64(.1), float64(.2), float64(-.1), float64(-.2) } {
retval, _, e := Unpack(b)
if e != nil { t.Error("err != nil") }
isnan := false
if _v, ok := v.(float64); ok {
isnan = math.IsNaN(_v)
} else if _v, ok := v.(float32); ok {
isnan = math.IsNaN(float64(_v))
}
if isnan {
if retval.Interface() == v { t.Errorf("[NaN] %u == %u", retval.Interface(), v) }
} else {
if retval.Interface() != v { t.Errorf("%u != %u", retval.Interface(), v) }
}
}
}

591
go/pack.go Normal file
View File

@@ -0,0 +1,591 @@
package msgpack
import (
"io"
"os"
"unsafe"
"reflect"
);
// Packs a given value and writes it into the specified writer.
func PackUint8(writer io.Writer, value uint8) (n int, err os.Error) {
if value < 128 {
return writer.Write([]byte { byte(value) })
}
return writer.Write([]byte { 0xcc, byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackUint16(writer io.Writer, value uint16) (n int, err os.Error) {
if value < 128 {
return writer.Write([]byte { byte(value) })
} else if value < 256 {
return writer.Write([]byte { 0xcc, byte(value) })
}
return writer.Write([]byte { 0xcd, byte(value >> 8), byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackUint32(writer io.Writer, value uint32) (n int, err os.Error) {
if value < 128 {
return writer.Write([]byte { byte(value) })
} else if value < 256 {
return writer.Write([]byte { 0xcc, byte(value) })
} else if value < 65536 {
return writer.Write([]byte { 0xcd, byte(value >> 8), byte(value) })
}
return writer.Write([]byte { 0xce, byte(value >> 24), byte(value >> 16), byte(value >> 8), byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackUint64(writer io.Writer, value uint64) (n int, err os.Error) {
if value < 128 {
return writer.Write([]byte { byte(value) })
} else if value < 256 {
return writer.Write([]byte { 0xcc, byte(value) })
} else if value < 65536 {
return writer.Write([]byte { 0xcd, byte(value >> 8), byte(value) })
} else if value < 4294967296 {
return writer.Write([]byte { 0xce, byte(value >> 24), byte(value >> 16), byte(value >> 8), byte(value) })
}
return writer.Write([]byte { 0xcf, byte(value >> 56), byte(value >> 48), byte(value >> 40), byte(value >> 32), byte(value >> 24), byte(value >> 16), byte(value >> 8), byte(value) })
}
func PackUint(writer io.Writer, value uint) (n int, err os.Error) {
// Packs a given value and writes it into the specified writer.
switch unsafe.Sizeof(value) {
case 4:
return PackUint32(writer, *(*uint32)(unsafe.Pointer(&value)))
case 8:
return PackUint64(writer, *(*uint64)(unsafe.Pointer(&value)))
}
return 0, os.ENOENT // never get here
}
// Packs a given value and writes it into the specified writer.
func PackInt8(writer io.Writer, value int8) (n int, err os.Error) {
if value < -32 {
return writer.Write([]byte { 0xd0, byte(value) })
}
return writer.Write([]byte { byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackInt16(writer io.Writer, value int16) (n int, err os.Error) {
if value < -128 || value >= 128 {
return writer.Write([]byte { 0xd1, byte(uint16(value) >> 8), byte(value) })
} else if value < -32 {
return writer.Write([]byte { 0xd0, byte(value) })
}
return writer.Write([]byte { byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackInt32(writer io.Writer, value int32) (n int, err os.Error) {
if value < -32768 || value >= 32768 {
return writer.Write([]byte { 0xd2, byte(uint32(value) >> 24), byte(uint32(value) >> 16), byte(uint32(value) >> 8), byte(value) })
} else if value < -128 {
return writer.Write([]byte { 0xd1, byte(uint32(value) >> 8), byte(value) })
} else if value < -32 {
return writer.Write([]byte { 0xd0, byte(value) })
} else if value >= 128 {
return writer.Write([]byte { 0xd1, byte(uint32(value) >> 8), byte(value) })
}
return writer.Write([]byte { byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackInt64(writer io.Writer, value int64) (n int, err os.Error) {
if value < -2147483648 || value >= 2147483648 {
return writer.Write([]byte { 0xd3, byte(uint64(value) >> 56), byte(uint64(value) >> 48), byte(uint64(value) >> 40), byte(uint64(value) >> 32), byte(uint64(value) >> 24), byte(uint64(value) >> 16), byte(uint64(value) >> 8), byte(value) })
} else if value < -32768 || value >= 32768 {
return writer.Write([]byte { 0xd2, byte(uint64(value) >> 24), byte(uint64(value) >> 16), byte(uint64(value) >> 8), byte(value) })
} else if value < -128 || value >= 128 {
return writer.Write([]byte { 0xd1, byte(uint64(value) >> 8), byte(value) })
} else if value < -32 {
return writer.Write([]byte { 0xd0, byte(value) })
}
return writer.Write([]byte { byte(value) })
}
// Packs a given value and writes it into the specified writer.
func PackInt(writer io.Writer, value int) (n int, err os.Error) {
switch unsafe.Sizeof(value) {
case 4:
return PackInt32(writer, *(*int32)(unsafe.Pointer(&value)))
case 8:
return PackInt64(writer, *(*int64)(unsafe.Pointer(&value)))
}
return 0, os.ENOENT // never get here
}
// Packs a given value and writes it into the specified writer.
func PackNil(writer io.Writer) (n int, err os.Error) {
return writer.Write([]byte{ 0xc0 })
}
// Packs a given value and writes it into the specified writer.
func PackBool(writer io.Writer, value bool) (n int, err os.Error) {
var code byte;
if value {
code = 0xc3
} else {
code = 0xc2
}
return writer.Write([]byte{ code })
}
// Packs a given value and writes it into the specified writer.
func PackFloat32(writer io.Writer, value float32) (n int, err os.Error) {
return PackUint32(writer, *(*uint32)(unsafe.Pointer(&value)))
}
// Packs a given value and writes it into the specified writer.
func PackFloat64(writer io.Writer, value float64) (n int, err os.Error) {
return PackUint64(writer, *(*uint64)(unsafe.Pointer(&value)))
}
// Packs a given value and writes it into the specified writer.
func PackBytes(writer io.Writer, value []byte) (n int, err os.Error) {
if len(value) < 32 {
n1, err := writer.Write([]byte { 0xa0 | uint8(len(value)) })
if err != nil { return n1, err }
n2, err := writer.Write(value)
return n1 + n2, err
} else if len(value) < 65536 {
n1, err := writer.Write([]byte { 0xda, byte(len(value) >> 16), byte(len(value)) })
if err != nil { return n1, err }
n2, err := writer.Write(value)
return n1 + n2, err
}
n1, err := writer.Write([]byte { 0xdb, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n1, err }
n2, err := writer.Write(value)
return n1 + n2, err
}
// Packs a given value and writes it into the specified writer.
func PackUint16Array(writer io.Writer, value []uint16) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint16(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint16(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint16(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackUint32Array(writer io.Writer, value []uint32) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint32(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint32(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint32(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackUint64Array(writer io.Writer, value []uint64) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint64(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint64(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackUint64(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackUintArray(writer io.Writer, value []uint) (n int, err os.Error) {
switch unsafe.Sizeof(0) {
case 4:
return PackUint32Array(writer, *(*[]uint32)(unsafe.Pointer(&value)))
case 8:
return PackUint64Array(writer, *(*[]uint64)(unsafe.Pointer(&value)))
}
return 0, os.ENOENT // never get here
}
// Packs a given value and writes it into the specified writer.
func PackInt8Array(writer io.Writer, value []int8) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt8(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt8(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt8(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackInt16Array(writer io.Writer, value []int16) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt16(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt16(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt16(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackInt32Array(writer io.Writer, value []int32) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt32(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt32(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt32(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackInt64Array(writer io.Writer, value []int64) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt64(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt64(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackInt64(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackIntArray(writer io.Writer, value []int) (n int, err os.Error) {
switch unsafe.Sizeof(0) {
case 4:
return PackInt32Array(writer, *(*[]int32)(unsafe.Pointer(&value)))
case 8:
return PackInt64Array(writer, *(*[]int64)(unsafe.Pointer(&value)))
}
return 0, os.ENOENT // never get here
}
// Packs a given value and writes it into the specified writer.
func PackFloat32Array(writer io.Writer, value []float32) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat32(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat32(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat32(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackFloat64Array(writer io.Writer, value []float64) (n int, err os.Error) {
if len(value) < 16 {
n, err := writer.Write([]byte { 0x90 | byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat64(writer, i)
if err != nil { return n, err }
n += _n
}
} else if len(value) < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat64(writer, i)
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(len(value) >> 24), byte(len(value) >> 16), byte(len(value) >> 8), byte(len(value)) })
if err != nil { return n, err }
for _, i := range value {
_n, err := PackFloat64(writer, i)
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackArray(writer io.Writer, value reflect.ArrayOrSliceValue) (n int, err os.Error) {
{
elemType, ok := value.Type().(reflect.ArrayOrSliceType).Elem().(*reflect.UintType)
if ok && elemType.Kind() == reflect.Uint8 {
return PackBytes(writer, value.Interface().([]byte))
}
}
l := value.Len()
if l < 16 {
n, err := writer.Write([]byte { 0x90 | byte(l) })
if err != nil { return n, err }
for i := 0; i < l; i++ {
_n, err := PackValue(writer, value.Elem(i))
if err != nil { return n, err }
n += _n
}
} else if l < 65536 {
n, err := writer.Write([]byte { 0xdc, byte(l >> 8), byte(l) })
if err != nil { return n, err }
for i := 0; i < l; i++ {
_n, err := PackValue(writer, value.Elem(i))
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdd, byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l) })
if err != nil { return n, err }
for i := 0; i < l; i++ {
_n, err := PackValue(writer, value.Elem(i))
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackMap(writer io.Writer, value *reflect.MapValue) (n int, err os.Error) {
keys := value.Keys()
if value.Len() < 16 {
n, err := writer.Write([]byte { 0x80 | byte(len(keys)) })
if err != nil { return n, err }
for _, k := range keys {
_n, err := PackValue(writer, k)
if err != nil { return n, err }
n += _n
_n, err = PackValue(writer, value.Elem(k))
if err != nil { return n, err }
n += _n
}
} else if value.Len() < 65536 {
n, err := writer.Write([]byte { 0xde, byte(len(keys) >> 8), byte(len(keys)) })
if err != nil { return n, err }
for _, k := range keys {
_n, err := PackValue(writer, k)
if err != nil { return n, err }
n += _n
_n, err = PackValue(writer, value.Elem(k))
if err != nil { return n, err }
n += _n
}
} else {
n, err := writer.Write([]byte { 0xdf, byte(len(keys) >> 24), byte(len(keys) >> 16), byte(len(keys) >> 8), byte(len(keys)) })
if err != nil { return n, err }
for _, k := range keys {
_n, err := PackValue(writer, k)
if err != nil { return n, err }
n += _n
_n, err = PackValue(writer, value.Elem(k))
if err != nil { return n, err }
n += _n
}
}
return n, nil
}
// Packs a given value and writes it into the specified writer.
func PackValue(writer io.Writer, value reflect.Value) (n int, err os.Error) {
if value == nil || value.Type() == nil { return PackNil(writer) }
switch _value := value.(type) {
case *reflect.BoolValue: return PackBool(writer, _value.Get())
case *reflect.UintValue: return PackUint64(writer, _value.Get())
case *reflect.IntValue: return PackInt64(writer, _value.Get())
case *reflect.FloatValue: return PackFloat64(writer, _value.Get())
case *reflect.ArrayValue: return PackArray(writer, _value)
case *reflect.SliceValue: return PackArray(writer, _value)
case *reflect.MapValue: return PackMap(writer, _value)
case *reflect.InterfaceValue:
__value := reflect.NewValue(_value.Interface())
_, ok := __value.(*reflect.InterfaceValue)
if !ok {
return PackValue(writer, __value)
}
}
panic("unsupported type: " + value.Type().String())
}
// Packs a given value and writes it into the specified writer.
func Pack(writer io.Writer, value interface{}) (n int, err os.Error) {
if value == nil { return PackNil(writer) }
switch _value := value.(type) {
case bool: return PackBool(writer, _value)
case uint8: return PackUint8(writer, _value)
case uint16: return PackUint16(writer, _value)
case uint32: return PackUint32(writer, _value)
case uint64: return PackUint64(writer, _value)
case uint: return PackUint(writer, _value)
case int8: return PackInt8(writer, _value)
case int16: return PackInt16(writer, _value)
case int32: return PackInt32(writer, _value)
case int64: return PackInt64(writer, _value)
case int: return PackInt(writer, _value)
case float32: return PackFloat32(writer, _value)
case float64: return PackFloat64(writer, _value)
case []byte: return PackBytes(writer, _value)
case []uint16: return PackUint16Array(writer, _value)
case []uint32: return PackUint32Array(writer, _value)
case []uint64: return PackUint64Array(writer, _value)
case []uint: return PackUintArray(writer, _value)
case []int8: return PackInt8Array(writer, _value)
case []int16: return PackInt16Array(writer, _value)
case []int32: return PackInt32Array(writer, _value)
case []int64: return PackInt64Array(writer, _value)
case []int: return PackIntArray(writer, _value)
case []float32: return PackFloat32Array(writer, _value)
case []float64: return PackFloat64Array(writer, _value)
default:
return PackValue(writer, reflect.NewValue(value))
}
return 0, nil // never get here
}

288
go/unpack.go Normal file
View File

@@ -0,0 +1,288 @@
package msgpack
import (
"io"
"os"
"unsafe"
"strconv"
"reflect"
)
func readByte(reader io.Reader) (v uint8, err os.Error) {
data := [1]byte{}
_, e := reader.Read(data[0:])
if e != nil { return 0, e }
return data[0], nil
}
func readUint16(reader io.Reader) (v uint16, n int, err os.Error) {
data := [2]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (uint16(data[0]) << 8) | uint16(data[1]), n, nil
}
func readUint32(reader io.Reader) (v uint32, n int, err os.Error) {
data := [4]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (uint32(data[0]) << 24) | (uint32(data[1]) << 16) | (uint32(data[2]) << 8) | uint32(data[3]), n, nil
}
func readUint64(reader io.Reader) (v uint64, n int, err os.Error) {
data := [8]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (uint64(data[0]) << 56) | (uint64(data[1]) << 48) | (uint64(data[2]) << 40) | (uint64(data[3]) << 32) | (uint64(data[4]) << 24) | (uint64(data[5]) << 16) | (uint64(data[6]) << 8) | uint64(data[7]), n, nil
}
func readInt16(reader io.Reader) (v int16, n int, err os.Error) {
data := [2]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (int16(data[0]) << 8) | int16(data[1]), n, nil
}
func readInt32(reader io.Reader) (v int32, n int, err os.Error) {
data := [4]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (int32(data[0]) << 24) | (int32(data[1]) << 16) | (int32(data[2]) << 8) | int32(data[3]), n, nil
}
func readInt64(reader io.Reader) (v int64, n int, err os.Error) {
data := [8]byte{}
n, e := reader.Read(data[0:])
if e != nil { return 0, n, e }
return (int64(data[0]) << 56) | (int64(data[1]) << 48) | (int64(data[2]) << 40) | (int64(data[3]) << 32) | (int64(data[4]) << 24) | (int64(data[5]) << 16) | (int64(data[6]) << 8) | int64(data[7]), n, nil
}
func unpackArray(reader io.Reader, nelems uint) (v reflect.Value, n int, err os.Error) {
retval := make([]interface{}, nelems)
nbytesread := 0
var i uint
for i = 0; i < nelems; i++ {
v, n, e := Unpack(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval[i] = v.Interface()
}
return reflect.NewValue(retval), nbytesread, nil
}
func unpackArrayReflected(reader io.Reader, nelems uint) (v reflect.Value, n int, err os.Error) {
retval := make([]reflect.Value, nelems)
nbytesread := 0
var i uint
for i = 0; i < nelems; i++ {
v, n, e := UnpackReflected(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval[i] = v
}
return reflect.NewValue(retval), nbytesread, nil
}
func unpackMap(reader io.Reader, nelems uint) (v reflect.Value, n int, err os.Error) {
retval := make(map [interface{}] interface{})
nbytesread := 0
var i uint
for i = 0; i < nelems; i++ {
k, n, e := Unpack(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
v, n, e := Unpack(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval[k.Interface()] = v.Interface()
}
return reflect.NewValue(retval), nbytesread, nil
}
func unpackMapReflected(reader io.Reader, nelems uint) (v reflect.Value, n int, err os.Error) {
retval := make(map [reflect.Value] reflect.Value)
nbytesread := 0
var i uint
for i = 0; i < nelems; i++ {
k, n, e := UnpackReflected(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
v, n, e := UnpackReflected(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval[k] = v
}
return reflect.NewValue(retval), nbytesread, nil
}
func unpack(reader io.Reader, reflected bool) (v reflect.Value, n int, err os.Error) {
var retval reflect.Value
var nbytesread int = 0
c, e := readByte(reader)
if e != nil { return nil, 0, e }
nbytesread += 1
if c < 0x80 || c >= 0xe0 {
retval = reflect.NewValue(int8(c))
} else if c >= 0x80 && c <= 0x8f {
if reflected {
retval, n, e = unpackMapReflected(reader, uint(c & 0xf))
} else {
retval, n, e = unpackMap(reader, uint(c & 0xf))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
nbytesread += n
} else if c >= 0x90 && c <= 0x9f {
if reflected {
retval, n, e = unpackArrayReflected(reader, uint(c & 0xf))
} else {
retval, n, e = unpackArray(reader, uint(c & 0xf))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
nbytesread += n
} else if c >= 0xa0 && c <= 0xbf {
data := make([]byte, c & 0xf);
n, e := reader.Read(data)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
} else {
switch c {
case 0xc0: retval = reflect.NewValue(nil)
case 0xc2: retval = reflect.NewValue(false)
case 0xc3: retval = reflect.NewValue(true)
case 0xca:
data, n, e := readUint32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(*(*float32)(unsafe.Pointer(&data)))
case 0xcb:
data, n, e := readUint64(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(*(*float64)(unsafe.Pointer(&data)))
case 0xcc:
data, e := readByte(reader)
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(uint8(data))
nbytesread += 1
case 0xcd:
data, n, e := readUint16(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xce:
data, n, e := readUint32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xcf:
data, n, e := readUint64(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xd0:
data, e := readByte(reader)
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(int8(data))
nbytesread += 1
case 0xd1:
data, n, e := readInt16(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xd2:
data, n, e := readInt32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xd3:
data, n, e := readInt64(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xda:
nbytestoread, n, e := readUint16(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
data := make([]byte, nbytestoread)
n, e = reader.Read(data)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xdb:
nbytestoread, n, e := readUint32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
data := make([]byte, nbytestoread)
n, e = reader.Read(data)
nbytesread += n
if e != nil { return nil, nbytesread, e }
retval = reflect.NewValue(data)
case 0xdc:
nelemstoread, n, e := readUint16(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
if reflected {
retval, n, e = unpackArrayReflected(reader, uint(nelemstoread))
} else {
retval, n, e = unpackArray(reader, uint(nelemstoread))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
case 0xdd:
nelemstoread, n, e := readUint32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
if reflected {
retval, n, e = unpackArrayReflected(reader, uint(nelemstoread))
} else {
retval, n, e = unpackArray(reader, uint(nelemstoread))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
case 0xde:
nelemstoread, n, e := readUint16(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
if reflected {
retval, n, e = unpackMapReflected(reader, uint(nelemstoread))
} else {
retval, n, e = unpackMap(reader, uint(nelemstoread))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
case 0xdf:
nelemstoread, n, e := readUint32(reader)
nbytesread += n
if e != nil { return nil, nbytesread, e }
if reflected {
retval, n, e = unpackMapReflected(reader, uint(nelemstoread))
} else {
retval, n, e = unpackMap(reader, uint(nelemstoread))
}
nbytesread += n
if e != nil { return nil, nbytesread, e }
default:
panic("unsupported code: " + strconv.Itoa(int(c)))
}
}
return retval, nbytesread, nil
}
// Reads a value from the reader, unpack and returns it.
func Unpack(reader io.Reader) (v reflect.Value, n int, err os.Error) {
return unpack(reader, false)
}
// Reads unpack a value from the reader, unpack and returns it. When the
// value is an array or map, leaves the elements wrapped by corresponding
// wrapper objects defined in reflect package.
func UnpackReflected(reader io.Reader) (v reflect.Value, n int, err os.Error) {
return unpack(reader, true)
}

View File

@@ -1,4 +1,4 @@
Copyright (c) 2009, Hideyuki Tanaka
Copyright (c) 2009-2010, Hideyuki Tanaka
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,137 +0,0 @@
#include <msgpack.h>
void msgpack_sbuffer_init_wrap(msgpack_sbuffer* sbuf)
{
msgpack_sbuffer_init(sbuf);
}
void msgpack_sbuffer_destroy_wrap(msgpack_sbuffer* sbuf)
{
msgpack_sbuffer_destroy(sbuf);
}
int msgpack_sbuffer_write_wrap(void* data, const char* buf, unsigned int len)
{
return msgpack_sbuffer_write(data, buf, len);
}
msgpack_packer* msgpack_packer_new_wrap(void *data, msgpack_packer_write callback)
{
return msgpack_packer_new(data, callback);
}
void msgpack_packer_free_wrap(msgpack_packer* pk)
{
msgpack_packer_free(pk);
}
int msgpack_pack_uint8_wrap(msgpack_packer* pk, uint8_t d)
{
return msgpack_pack_uint8(pk, d);
}
int msgpack_pack_uint16_wrap(msgpack_packer* pk, uint16_t d)
{
return msgpack_pack_uint16(pk, d);
}
int msgpack_pack_uint32_wrap(msgpack_packer* pk, uint32_t d)
{
return msgpack_pack_uint32(pk, d);
}
int msgpack_pack_uint64_wrap(msgpack_packer* pk, uint64_t d)
{
return msgpack_pack_uint64(pk, d);
}
int msgpack_pack_int8_wrap(msgpack_packer* pk, int8_t d)
{
return msgpack_pack_int8(pk, d);
}
int msgpack_pack_int16_wrap(msgpack_packer* pk, int16_t d)
{
return msgpack_pack_int16(pk, d);
}
int msgpack_pack_int32_wrap(msgpack_packer* pk, int32_t d)
{
return msgpack_pack_int32(pk, d);
}
int msgpack_pack_int64_wrap(msgpack_packer* pk, int64_t d)
{
return msgpack_pack_int64(pk, d);
}
int msgpack_pack_double_wrap(msgpack_packer* pk, double d)
{
return msgpack_pack_double(pk, d);
}
int msgpack_pack_nil_wrap(msgpack_packer* pk)
{
return msgpack_pack_nil(pk);
}
int msgpack_pack_true_wrap(msgpack_packer* pk)
{
return msgpack_pack_true(pk);
}
int msgpack_pack_false_wrap(msgpack_packer* pk)
{
return msgpack_pack_false(pk);
}
int msgpack_pack_array_wrap(msgpack_packer* pk, unsigned int n)
{
return msgpack_pack_array(pk, n);
}
int msgpack_pack_map_wrap(msgpack_packer* pk, unsigned int n)
{
return msgpack_pack_map(pk, n);
}
int msgpack_pack_raw_wrap(msgpack_packer* pk, size_t l)
{
return msgpack_pack_raw(pk, l);
}
int msgpack_pack_raw_body_wrap(msgpack_packer* pk, const void *b, size_t l)
{
return msgpack_pack_raw_body(pk, b, l);
}
bool msgpack_unpacker_reserve_buffer_wrap(msgpack_unpacker *mpac, size_t size)
{
return msgpack_unpacker_reserve_buffer(mpac, size);
}
char *msgpack_unpacker_buffer_wrap(msgpack_unpacker *mpac)
{
return msgpack_unpacker_buffer(mpac);
}
size_t msgpack_unpacker_buffer_capacity_wrap(const msgpack_unpacker *mpac)
{
return msgpack_unpacker_buffer_capacity(mpac);
}
void msgpack_unpacker_buffer_consumed_wrap(msgpack_unpacker *mpac, size_t size)
{
msgpack_unpacker_buffer_consumed(mpac, size);
}
void msgpack_unpacker_data_wrap(msgpack_unpacker *mpac, msgpack_object *obj)
{
*obj=msgpack_unpacker_data(mpac);
}
size_t msgpack_unpacker_message_size_wrap(const msgpack_unpacker *mpac)
{
return msgpack_unpacker_message_size(mpac);
}

View File

@@ -1,32 +1,50 @@
Name: msgpack
Version: 0.2.2
License: BSD3
License-File: LICENSE
Author: Hideyuki Tanaka
Maintainer: Hideyuki Tanaka <tanaka.hideyuki@gmail.com>
Category: Data
Synopsis: A Haskell binding to MessagePack
Name: msgpack
Version: 0.6.1.1
Synopsis: A Haskell implementation of MessagePack
Description:
A Haskell binding to MessagePack <http://msgpack.sourceforge.jp/>
Homepage: http://github.com/tanakh/hsmsgpack
Stability: Experimental
Tested-with: GHC==6.10.4
Cabal-Version: >=1.2
Build-Type: Simple
A Haskell implementation of MessagePack <http://msgpack.org/>
library
build-depends: base>=4 && <5, mtl, bytestring
ghc-options: -O2 -Wall
hs-source-dirs: src
extra-libraries: msgpackc
License: BSD3
License-File: LICENSE
Copyright: Copyright (c) 2009-2011, Hideyuki Tanaka
Category: Data
Author: Hideyuki Tanaka
Maintainer: Hideyuki Tanaka <tanaka.hideyuki@gmail.com>
Homepage: http://github.com/msgpack/msgpack
Stability: Experimental
Cabal-Version: >= 1.6
Build-Type: Simple
Extra-source-files:
test/Test.hs
test/UserData.hs
Library
Build-depends: base >=4 && <5,
transformers >= 0.2 && < 0.3,
bytestring >= 0.9 && < 0.10,
text >= 0.11 && < 0.12,
vector >= 0.7 && < 0.8,
attoparsec >= 0.8 && < 0.9,
binary >= 0.5.0 && < 0.5.1,
data-binary-ieee754 >= 0.4 && < 0.5,
deepseq >= 1.1 && <1.2,
template-haskell >= 2.4 && < 2.6
Ghc-options: -Wall
Hs-source-dirs: src
Exposed-modules:
Data.MessagePack
Data.MessagePack.Base
Data.MessagePack.Class
Data.MessagePack.Feed
Data.MessagePack.Monad
Data.MessagePack.Stream
Data.MessagePack.Assoc
Data.MessagePack.Pack
Data.MessagePack.Unpack
Data.MessagePack.Object
Data.MessagePack.Derive
C-Sources:
cbits/msgpack.c
Other-modules:
Data.MessagePack.Internal.Utf8
Source-repository head
Type: git
Location: git://github.com/msgpack/msgpack.git

View File

@@ -1,7 +1,7 @@
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack
-- Copyright : (c) Hideyuki Tanaka, 2009
-- Copyright : (c) Hideyuki Tanaka, 2009-2010
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
@@ -13,51 +13,15 @@
--------------------------------------------------------------------
module Data.MessagePack(
module Data.MessagePack.Base,
module Data.MessagePack.Class,
module Data.MessagePack.Feed,
module Data.MessagePack.Monad,
module Data.MessagePack.Stream,
-- * Pack and Unpack
packb,
unpackb,
-- * Pure version of Pack and Unpack
packb',
unpackb',
module Data.MessagePack.Assoc,
module Data.MessagePack.Pack,
module Data.MessagePack.Unpack,
module Data.MessagePack.Object,
module Data.MessagePack.Derive,
) where
import Data.ByteString (ByteString)
import System.IO.Unsafe
import Data.MessagePack.Base
import Data.MessagePack.Class
import Data.MessagePack.Feed
import Data.MessagePack.Monad
import Data.MessagePack.Stream
-- | Pack Haskell data to MessagePack string.
packb :: OBJECT a => a -> IO ByteString
packb dat = do
sb <- newSimpleBuffer
pc <- newPacker sb
pack pc dat
simpleBufferData sb
-- | Unpack MessagePack string to Haskell data.
unpackb :: OBJECT a => ByteString -> IO (Result a)
unpackb bs = do
withZone $ \z -> do
r <- unpackObject z bs
return $ case r of
Left err -> Left (show err)
Right (_, dat) -> fromObject dat
-- | Pure version of 'packb'.
packb' :: OBJECT a => a -> ByteString
packb' dat = unsafePerformIO $ packb dat
-- | Pure version of 'unpackb'.
unpackb' :: OBJECT a => ByteString -> Result a
unpackb' bs = unsafePerformIO $ unpackb bs
import Data.MessagePack.Assoc
import Data.MessagePack.Pack
import Data.MessagePack.Unpack
import Data.MessagePack.Object
import Data.MessagePack.Derive

View File

@@ -0,0 +1,28 @@
{-# Language DeriveDataTypeable #-}
{-# Language GeneralizedNewtypeDeriving #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Assoc
-- Copyright : (c) Daiki Handa, 2010
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- MessagePack map labeling type
--
--------------------------------------------------------------------
module Data.MessagePack.Assoc (
Assoc(..)
) where
import Control.DeepSeq
import Data.Typeable
-- not defined for general Functor for performance reason.
-- (ie. you would want to write custom instances for each type using specialized mapM-like functions)
newtype Assoc a=Assoc{unAssoc :: a} deriving(Show,Eq,Ord,Typeable,NFData)

View File

@@ -1,584 +0,0 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Base
-- Copyright : (c) Hideyuki Tanaka, 2009
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- Low Level Interface to MessagePack C API
--
--------------------------------------------------------------------
module Data.MessagePack.Base(
-- * Simple Buffer
SimpleBuffer,
newSimpleBuffer,
simpleBufferData,
-- * Serializer
Packer,
newPacker,
packU8,
packU16,
packU32,
packU64,
packS8,
packS16,
packS32,
packS64,
packTrue,
packFalse,
packInt,
packDouble,
packNil,
packBool,
packArray,
packMap,
packRAW,
packRAWBody,
packRAW',
-- * Stream Deserializer
Unpacker,
defaultInitialBufferSize,
newUnpacker,
unpackerReserveBuffer,
unpackerBuffer,
unpackerBufferCapacity,
unpackerBufferConsumed,
unpackerFeed,
unpackerExecute,
unpackerData,
unpackerReleaseZone,
unpackerResetZone,
unpackerReset,
unpackerMessageSize,
-- * MessagePack Object
Object(..),
packObject,
UnpackReturn(..),
unpackObject,
-- * Memory Zone
Zone,
newZone,
freeZone,
withZone,
) where
import Control.Exception
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS hiding (pack, unpack)
import Data.Int
import Data.Word
import Foreign.C
import Foreign.Concurrent
import Foreign.ForeignPtr hiding (newForeignPtr)
import Foreign.Marshal.Alloc
import Foreign.Marshal.Array
import Foreign.Ptr
import Foreign.Storable
#include <msgpack.h>
type SimpleBuffer = ForeignPtr ()
type WriteCallback = Ptr () -> CString -> CUInt -> IO CInt
-- | Create a new Simple Buffer. It will be deleted automatically.
newSimpleBuffer :: IO SimpleBuffer
newSimpleBuffer = do
ptr <- mallocBytes (#size msgpack_sbuffer)
fptr <- newForeignPtr ptr $ do
msgpack_sbuffer_destroy ptr
free ptr
withForeignPtr fptr $ \p ->
msgpack_sbuffer_init p
return fptr
-- | Get data of Simple Buffer.
simpleBufferData :: SimpleBuffer -> IO ByteString
simpleBufferData sb =
withForeignPtr sb $ \ptr -> do
size <- (#peek msgpack_sbuffer, size) ptr
dat <- (#peek msgpack_sbuffer, data) ptr
BS.packCStringLen (dat, fromIntegral (size :: CSize))
foreign import ccall "msgpack_sbuffer_init_wrap" msgpack_sbuffer_init ::
Ptr () -> IO ()
foreign import ccall "msgpack_sbuffer_destroy_wrap" msgpack_sbuffer_destroy ::
Ptr () -> IO ()
foreign import ccall "msgpack_sbuffer_write_wrap" msgpack_sbuffer_write ::
WriteCallback
type Packer = ForeignPtr ()
-- | Create new Packer. It will be deleted automatically.
newPacker :: SimpleBuffer -> IO Packer
newPacker sbuf = do
cb <- wrap_callback msgpack_sbuffer_write
ptr <- withForeignPtr sbuf $ \ptr ->
msgpack_packer_new ptr cb
fptr <- newForeignPtr ptr $ do
msgpack_packer_free ptr
return fptr
foreign import ccall "msgpack_packer_new_wrap" msgpack_packer_new ::
Ptr () -> FunPtr WriteCallback -> IO (Ptr ())
foreign import ccall "msgpack_packer_free_wrap" msgpack_packer_free ::
Ptr () -> IO ()
foreign import ccall "wrapper" wrap_callback ::
WriteCallback -> IO (FunPtr WriteCallback)
packU8 :: Packer -> Word8 -> IO Int
packU8 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_uint8 ptr n
foreign import ccall "msgpack_pack_uint8_wrap" msgpack_pack_uint8 ::
Ptr () -> Word8 -> IO CInt
packU16 :: Packer -> Word16 -> IO Int
packU16 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_uint16 ptr n
foreign import ccall "msgpack_pack_uint16_wrap" msgpack_pack_uint16 ::
Ptr () -> Word16 -> IO CInt
packU32 :: Packer -> Word32 -> IO Int
packU32 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_uint32 ptr n
foreign import ccall "msgpack_pack_uint32_wrap" msgpack_pack_uint32 ::
Ptr () -> Word32 -> IO CInt
packU64 :: Packer -> Word64 -> IO Int
packU64 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_uint64 ptr n
foreign import ccall "msgpack_pack_uint64_wrap" msgpack_pack_uint64 ::
Ptr () -> Word64 -> IO CInt
packS8 :: Packer -> Int8 -> IO Int
packS8 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_int8 ptr n
foreign import ccall "msgpack_pack_int8_wrap" msgpack_pack_int8 ::
Ptr () -> Int8 -> IO CInt
packS16 :: Packer -> Int16 -> IO Int
packS16 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_int16 ptr n
foreign import ccall "msgpack_pack_int16_wrap" msgpack_pack_int16 ::
Ptr () -> Int16 -> IO CInt
packS32 :: Packer -> Int32 -> IO Int
packS32 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_int32 ptr n
foreign import ccall "msgpack_pack_int32_wrap" msgpack_pack_int32 ::
Ptr () -> Int32 -> IO CInt
packS64 :: Packer -> Int64 -> IO Int
packS64 pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_int64 ptr n
foreign import ccall "msgpack_pack_int64_wrap" msgpack_pack_int64 ::
Ptr () -> Int64 -> IO CInt
-- | Pack an integral data.
packInt :: Integral a => Packer -> a -> IO Int
packInt pc n = packS64 pc $ fromIntegral n
-- | Pack a double data.
packDouble :: Packer -> Double -> IO Int
packDouble pc d =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_double ptr (realToFrac d)
foreign import ccall "msgpack_pack_double_wrap" msgpack_pack_double ::
Ptr () -> CDouble -> IO CInt
-- | Pack a nil.
packNil :: Packer -> IO Int
packNil pc =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_nil ptr
foreign import ccall "msgpack_pack_nil_wrap" msgpack_pack_nil ::
Ptr () -> IO CInt
packTrue :: Packer -> IO Int
packTrue pc =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_true ptr
foreign import ccall "msgpack_pack_true_wrap" msgpack_pack_true ::
Ptr () -> IO CInt
packFalse :: Packer -> IO Int
packFalse pc =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_false ptr
foreign import ccall "msgpack_pack_false_wrap" msgpack_pack_false ::
Ptr () -> IO CInt
-- | Pack a bool data.
packBool :: Packer -> Bool -> IO Int
packBool pc True = packTrue pc
packBool pc False = packFalse pc
-- | 'packArray' @p n@ starts packing an array.
-- Next @n@ data will consist this array.
packArray :: Packer -> Int -> IO Int
packArray pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_array ptr (fromIntegral n)
foreign import ccall "msgpack_pack_array_wrap" msgpack_pack_array ::
Ptr () -> CUInt -> IO CInt
-- | 'packMap' @p n@ starts packing a map.
-- Next @n@ pairs of data (2*n data) will consist this map.
packMap :: Packer -> Int -> IO Int
packMap pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_map ptr (fromIntegral n)
foreign import ccall "msgpack_pack_map_wrap" msgpack_pack_map ::
Ptr () -> CUInt -> IO CInt
-- | 'packRAW' @p n@ starts packing a byte sequence.
-- Next total @n@ bytes of 'packRAWBody' call will consist this sequence.
packRAW :: Packer -> Int -> IO Int
packRAW pc n =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
msgpack_pack_raw ptr (fromIntegral n)
foreign import ccall "msgpack_pack_raw_wrap" msgpack_pack_raw ::
Ptr () -> CSize -> IO CInt
-- | Pack a byte sequence.
packRAWBody :: Packer -> ByteString -> IO Int
packRAWBody pc bs =
liftM fromIntegral $ withForeignPtr pc $ \ptr ->
BS.useAsCStringLen bs $ \(str, len) ->
msgpack_pack_raw_body ptr (castPtr str) (fromIntegral len)
foreign import ccall "msgpack_pack_raw_body_wrap" msgpack_pack_raw_body ::
Ptr () -> Ptr () -> CSize -> IO CInt
-- | Pack a single byte stream. It calls 'packRAW' and 'packRAWBody'.
packRAW' :: Packer -> ByteString -> IO Int
packRAW' pc bs = do
_ <- packRAW pc (BS.length bs)
packRAWBody pc bs
type Unpacker = ForeignPtr ()
defaultInitialBufferSize :: Int
defaultInitialBufferSize = 32 * 1024 -- #const MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE
-- | 'newUnpacker' @initialBufferSize@ creates a new Unpacker. It will be deleted automatically.
newUnpacker :: Int -> IO Unpacker
newUnpacker initialBufferSize = do
ptr <- msgpack_unpacker_new (fromIntegral initialBufferSize)
fptr <- newForeignPtr ptr $ do
msgpack_unpacker_free ptr
return fptr
foreign import ccall "msgpack_unpacker_new" msgpack_unpacker_new ::
CSize -> IO (Ptr ())
foreign import ccall "msgpack_unpacker_free" msgpack_unpacker_free ::
Ptr() -> IO ()
-- | 'unpackerReserveBuffer' @up size@ reserves at least @size@ bytes of buffer.
unpackerReserveBuffer :: Unpacker -> Int -> IO Bool
unpackerReserveBuffer up size =
withForeignPtr up $ \ptr ->
liftM (/=0) $ msgpack_unpacker_reserve_buffer ptr (fromIntegral size)
foreign import ccall "msgpack_unpacker_reserve_buffer_wrap" msgpack_unpacker_reserve_buffer ::
Ptr () -> CSize -> IO CChar
-- | Get a pointer of unpacker buffer.
unpackerBuffer :: Unpacker -> IO (Ptr CChar)
unpackerBuffer up =
withForeignPtr up $ \ptr ->
msgpack_unpacker_buffer ptr
foreign import ccall "msgpack_unpacker_buffer_wrap" msgpack_unpacker_buffer ::
Ptr () -> IO (Ptr CChar)
-- | Get size of allocated buffer.
unpackerBufferCapacity :: Unpacker -> IO Int
unpackerBufferCapacity up =
withForeignPtr up $ \ptr ->
liftM fromIntegral $ msgpack_unpacker_buffer_capacity ptr
foreign import ccall "msgpack_unpacker_buffer_capacity_wrap" msgpack_unpacker_buffer_capacity ::
Ptr () -> IO CSize
-- | 'unpackerBufferConsumed' @up size@ notices that writed @size@ bytes to buffer.
unpackerBufferConsumed :: Unpacker -> Int -> IO ()
unpackerBufferConsumed up size =
withForeignPtr up $ \ptr ->
msgpack_unpacker_buffer_consumed ptr (fromIntegral size)
foreign import ccall "msgpack_unpacker_buffer_consumed_wrap" msgpack_unpacker_buffer_consumed ::
Ptr () -> CSize -> IO ()
-- | Write byte sequence to Unpacker. It is utility funciton, calls 'unpackerReserveBuffer', 'unpackerBuffer' and 'unpackerBufferConsumed'.
unpackerFeed :: Unpacker -> ByteString -> IO ()
unpackerFeed up bs =
BS.useAsCStringLen bs $ \(str, len) -> do
True <- unpackerReserveBuffer up len
ptr <- unpackerBuffer up
copyArray ptr str len
unpackerBufferConsumed up len
-- | Execute deserializing. It returns 0 when buffer contains not enough bytes, returns 1 when succeeded, returns negative value when it failed.
unpackerExecute :: Unpacker -> IO Int
unpackerExecute up =
withForeignPtr up $ \ptr ->
liftM fromIntegral $ msgpack_unpacker_execute ptr
foreign import ccall "msgpack_unpacker_execute" msgpack_unpacker_execute ::
Ptr () -> IO CInt
-- | Returns a deserialized object when 'unpackerExecute' returned 1.
unpackerData :: Unpacker -> IO Object
unpackerData up =
withForeignPtr up $ \ptr ->
allocaBytes (#size msgpack_object) $ \pobj -> do
msgpack_unpacker_data ptr pobj
peekObject pobj
foreign import ccall "msgpack_unpacker_data_wrap" msgpack_unpacker_data ::
Ptr () -> Ptr () -> IO ()
-- | Release memory zone. The returned zone must be freed by calling 'freeZone'.
unpackerReleaseZone :: Unpacker -> IO Zone
unpackerReleaseZone up =
withForeignPtr up $ \ptr ->
msgpack_unpacker_release_zone ptr
foreign import ccall "msgpack_unpacker_release_zone" msgpack_unpacker_release_zone ::
Ptr () -> IO (Ptr ())
-- | Free memory zone used by Unapcker.
unpackerResetZone :: Unpacker -> IO ()
unpackerResetZone up =
withForeignPtr up $ \ptr ->
msgpack_unpacker_reset_zone ptr
foreign import ccall "msgpack_unpacker_reset_zone" msgpack_unpacker_reset_zone ::
Ptr () -> IO ()
-- | Reset Unpacker state except memory zone.
unpackerReset :: Unpacker -> IO ()
unpackerReset up =
withForeignPtr up $ \ptr ->
msgpack_unpacker_reset ptr
foreign import ccall "msgpack_unpacker_reset" msgpack_unpacker_reset ::
Ptr () -> IO ()
-- | Returns number of bytes of sequence of deserializing object.
unpackerMessageSize :: Unpacker -> IO Int
unpackerMessageSize up =
withForeignPtr up $ \ptr ->
liftM fromIntegral $ msgpack_unpacker_message_size ptr
foreign import ccall "msgpack_unpacker_message_size_wrap" msgpack_unpacker_message_size ::
Ptr () -> IO CSize
type Zone = Ptr ()
-- | Create a new memory zone. It must be freed manually.
newZone :: IO Zone
newZone =
msgpack_zone_new (#const MSGPACK_ZONE_CHUNK_SIZE)
-- | Free a memory zone.
freeZone :: Zone -> IO ()
freeZone z =
msgpack_zone_free z
-- | Create a memory zone, then execute argument, then free memory zone.
withZone :: (Zone -> IO a) -> IO a
withZone z =
bracket newZone freeZone z
foreign import ccall "msgpack_zone_new" msgpack_zone_new ::
CSize -> IO Zone
foreign import ccall "msgpack_zone_free" msgpack_zone_free ::
Zone -> IO ()
-- | Object Representation of MessagePack data.
data Object =
ObjectNil
| ObjectBool Bool
| ObjectInteger Int
| ObjectDouble Double
| ObjectRAW ByteString
| ObjectArray [Object]
| ObjectMap [(Object, Object)]
deriving (Show)
peekObject :: Ptr a -> IO Object
peekObject ptr = do
typ <- (#peek msgpack_object, type) ptr
case (typ :: CInt) of
(#const MSGPACK_OBJECT_NIL) ->
return ObjectNil
(#const MSGPACK_OBJECT_BOOLEAN) ->
peekObjectBool ptr
(#const MSGPACK_OBJECT_POSITIVE_INTEGER) ->
peekObjectPositiveInteger ptr
(#const MSGPACK_OBJECT_NEGATIVE_INTEGER) ->
peekObjectNegativeInteger ptr
(#const MSGPACK_OBJECT_DOUBLE) ->
peekObjectDouble ptr
(#const MSGPACK_OBJECT_RAW) ->
peekObjectRAW ptr
(#const MSGPACK_OBJECT_ARRAY) ->
peekObjectArray ptr
(#const MSGPACK_OBJECT_MAP) ->
peekObjectMap ptr
_ ->
fail $ "peekObject: unknown object type (" ++ show typ ++ ")"
peekObjectBool :: Ptr a -> IO Object
peekObjectBool ptr = do
b <- (#peek msgpack_object, via.boolean) ptr
return $ ObjectBool $ (b :: CUChar) /= 0
peekObjectPositiveInteger :: Ptr a -> IO Object
peekObjectPositiveInteger ptr = do
n <- (#peek msgpack_object, via.u64) ptr
return $ ObjectInteger $ fromIntegral (n :: Word64)
peekObjectNegativeInteger :: Ptr a -> IO Object
peekObjectNegativeInteger ptr = do
n <- (#peek msgpack_object, via.i64) ptr
return $ ObjectInteger $ fromIntegral (n :: Int64)
peekObjectDouble :: Ptr a -> IO Object
peekObjectDouble ptr = do
d <- (#peek msgpack_object, via.dec) ptr
return $ ObjectDouble $ realToFrac (d :: CDouble)
peekObjectRAW :: Ptr a -> IO Object
peekObjectRAW ptr = do
size <- (#peek msgpack_object, via.raw.size) ptr
p <- (#peek msgpack_object, via.raw.ptr) ptr
bs <- BS.packCStringLen (p, fromIntegral (size :: Word32))
return $ ObjectRAW bs
peekObjectArray :: Ptr a -> IO Object
peekObjectArray ptr = do
csize <- (#peek msgpack_object, via.array.size) ptr
let size = fromIntegral (csize :: Word32)
p <- (#peek msgpack_object, via.array.ptr) ptr
objs <- mapM (\i -> peekObject $ p `plusPtr`
((#size msgpack_object) * i))
[0..size-1]
return $ ObjectArray objs
peekObjectMap :: Ptr a -> IO Object
peekObjectMap ptr = do
csize <- (#peek msgpack_object, via.map.size) ptr
let size = fromIntegral (csize :: Word32)
p <- (#peek msgpack_object, via.map.ptr) ptr
dat <- mapM (\i -> peekObjectKV $ p `plusPtr`
((#size msgpack_object_kv) * i))
[0..size-1]
return $ ObjectMap dat
peekObjectKV :: Ptr a -> IO (Object, Object)
peekObjectKV ptr = do
k <- peekObject $ ptr `plusPtr` (#offset msgpack_object_kv, key)
v <- peekObject $ ptr `plusPtr` (#offset msgpack_object_kv, val)
return (k, v)
-- | Pack a Object.
packObject :: Packer -> Object -> IO ()
packObject pc ObjectNil = packNil pc >> return ()
packObject pc (ObjectBool b) = packBool pc b >> return ()
packObject pc (ObjectInteger n) = packInt pc n >> return ()
packObject pc (ObjectDouble d) = packDouble pc d >> return ()
packObject pc (ObjectRAW bs) = packRAW' pc bs >> return ()
packObject pc (ObjectArray ls) = do
_ <- packArray pc (length ls)
mapM_ (packObject pc) ls
packObject pc (ObjectMap ls) = do
_ <- packMap pc (length ls)
mapM_ (\(a, b) -> packObject pc a >> packObject pc b) ls
data UnpackReturn =
UnpackContinue -- ^ not enough bytes to unpack object
| UnpackParseError -- ^ got invalid bytes
| UnpackError -- ^ other error
deriving (Eq, Show)
-- | Unpack a single MessagePack object from byte sequence.
unpackObject :: Zone -> ByteString -> IO (Either UnpackReturn (Int, Object))
unpackObject z dat =
allocaBytes (#size msgpack_object) $ \ptr ->
BS.useAsCStringLen dat $ \(str, len) ->
alloca $ \poff -> do
poke poff 0
ret <- msgpack_unpack str (fromIntegral len) poff z ptr
case ret of
(#const MSGPACK_UNPACK_SUCCESS) -> do
off <- peek poff
obj <- peekObject ptr
return $ Right (fromIntegral off, obj)
(#const MSGPACK_UNPACK_EXTRA_BYTES) -> do
off <- peek poff
obj <- peekObject ptr
return $ Right (fromIntegral off, obj)
(#const MSGPACK_UNPACK_CONTINUE) ->
return $ Left UnpackContinue
(#const MSGPACK_UNPACK_PARSE_ERROR) ->
return $ Left UnpackParseError
_ ->
return $ Left UnpackError
foreign import ccall "msgpack_unpack" msgpack_unpack ::
Ptr CChar -> CSize -> Ptr CSize -> Zone -> Ptr () -> IO CInt

View File

@@ -1,101 +0,0 @@
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE IncoherentInstances #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Class
-- Copyright : (c) Hideyuki Tanaka, 2009
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- Serializing Haskell values to and from MessagePack Objects.
--
--------------------------------------------------------------------
module Data.MessagePack.Class(
-- * Serialization to and from Object
OBJECT(..),
Result,
pack,
) where
import Control.Monad.Error
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as C8
import Data.MessagePack.Base
-- | The class of types serializable to and from MessagePack object
class OBJECT a where
toObject :: a -> Object
fromObject :: Object -> Result a
-- | A type for parser results
type Result a = Either String a
instance OBJECT Object where
toObject = id
fromObject = Right
fromObjectError :: String
fromObjectError = "fromObject: cannot cast"
instance OBJECT () where
toObject = const ObjectNil
fromObject ObjectNil = Right ()
fromObject _ = Left fromObjectError
instance OBJECT Int where
toObject = ObjectInteger
fromObject (ObjectInteger n) = Right n
fromObject _ = Left fromObjectError
instance OBJECT Bool where
toObject = ObjectBool
fromObject (ObjectBool b) = Right b
fromObject _ = Left fromObjectError
instance OBJECT Double where
toObject = ObjectDouble
fromObject (ObjectDouble d) = Right d
fromObject _ = Left fromObjectError
instance OBJECT ByteString where
toObject = ObjectRAW
fromObject (ObjectRAW bs) = Right bs
fromObject _ = Left fromObjectError
instance OBJECT String where
toObject = toObject . C8.pack
fromObject obj = liftM C8.unpack $ fromObject obj
instance OBJECT a => OBJECT [a] where
toObject = ObjectArray . map toObject
fromObject (ObjectArray arr) =
mapM fromObject arr
fromObject _ =
Left fromObjectError
instance (OBJECT a, OBJECT b) => OBJECT [(a, b)] where
toObject =
ObjectMap . map (\(a, b) -> (toObject a, toObject b))
fromObject (ObjectMap mem) = do
mapM (\(a, b) -> liftM2 (,) (fromObject a) (fromObject b)) mem
fromObject _ =
Left fromObjectError
instance OBJECT a => OBJECT (Maybe a) where
toObject (Just a) = toObject a
toObject Nothing = ObjectNil
fromObject ObjectNil = return Nothing
fromObject obj = liftM Just $ fromObject obj
-- | Pack a serializable Haskell value.
pack :: OBJECT a => Packer -> a -> IO ()
pack pc = packObject pc . toObject

View File

@@ -0,0 +1,106 @@
{-# Language TemplateHaskell #-}
module Data.MessagePack.Derive (
derivePack,
deriveUnpack,
deriveObject,
) where
import Control.Applicative
import Control.Monad
import Language.Haskell.TH
import Data.MessagePack.Pack
import Data.MessagePack.Unpack
import Data.MessagePack.Object
deriveUnpack :: Name -> Q [Dec]
deriveUnpack typName = do
TyConI (DataD _ name _ cons _) <- reify typName
return
[ InstanceD [] (AppT (ConT ''Unpackable) (ConT name))
[ FunD 'get [Clause [] (NormalB $ ch $ map body cons) []]
]]
where
body (NormalC conName elms) =
DoE $
tupOrListP (map VarP names) (VarE 'get) ++
[ NoBindS $ AppE (VarE 'return) $ foldl AppE (ConE conName) $ map VarE names ]
where
names = zipWith (\ix _ -> mkName $ "a" ++ show (ix :: Int)) [1..] elms
body (RecC conName elms) =
body (NormalC conName $ map (\(_, b, c) -> (b, c)) elms)
ch = foldl1 (\e f -> AppE (AppE (VarE '(<|>)) e) f)
derivePack :: Name -> Q [Dec]
derivePack typName = do
TyConI (DataD _ name _ cons _) <- reify typName
return
[ InstanceD [] (AppT (ConT ''Packable) (ConT name))
[ FunD 'put (map body cons)
]]
where
body (NormalC conName elms) =
Clause
[ ConP conName $ map VarP names ]
(NormalB $ AppE (VarE 'put) $ tupOrListE $ map VarE names) []
where
names = zipWith (\ix _ -> mkName $ "a" ++ show (ix :: Int)) [1..] elms
body (RecC conName elms) =
body (NormalC conName $ map (\(_, b, c) -> (b, c)) elms)
deriveObject :: Name -> Q [Dec]
deriveObject typName = do
g <- derivePack typName
p <- deriveUnpack typName
TyConI (DataD _ name _ cons _) <- reify typName
let o = InstanceD [] (AppT (ConT ''OBJECT) (ConT name))
[ FunD 'toObject (map toObjectBody cons),
FunD 'tryFromObject [Clause [ VarP oname ]
(NormalB $ ch $ map tryFromObjectBody cons) []]]
return $ g ++ p ++ [o]
where
toObjectBody (NormalC conName elms) =
Clause
[ ConP conName $ map VarP names ]
(NormalB $ AppE (VarE 'toObject) $ tupOrListE $ map VarE names) []
where
names = zipWith (\ix _ -> mkName $ "a" ++ show (ix :: Int)) [1..] elms
toObjectBody (RecC conName elms) =
toObjectBody (NormalC conName $ map (\(_, b, c) -> (b, c)) elms)
tryFromObjectBody (NormalC conName elms) =
DoE $
tupOrListP (map VarP names) (AppE (VarE 'tryFromObject) (VarE oname)) ++
[ NoBindS $ AppE (VarE 'return) $ foldl AppE (ConE conName) $ map VarE names ]
where
names = zipWith (\ix _ -> mkName $ "a" ++ show (ix :: Int)) [1..] elms
tryFromObjectBody (RecC conName elms) =
tryFromObjectBody (NormalC conName $ map (\(_, b, c) -> (b, c)) elms)
oname = mkName "o"
ch = foldl1 (\e f -> AppE (AppE (VarE '(<|>)) e) f)
tupOrListP :: [Pat] -> Exp -> [Stmt]
tupOrListP ls e
| length ls == 0 =
let lsname = mkName "ls" in
[ BindS (VarP lsname) e
, NoBindS $ AppE (VarE 'guard) $ AppE (VarE 'null) $ SigE (VarE lsname) (AppT ListT (ConT ''())) ]
| length ls == 1 = [ BindS (ListP ls) e ]
| otherwise = [ BindS (TupP ls) e ]
tupOrListE :: [Exp] -> Exp
tupOrListE ls
| length ls == 0 = SigE (ListE []) (AppT ListT (ConT ''()))
| length ls == 1 = ListE ls
| otherwise = TupE ls

View File

@@ -1,62 +0,0 @@
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Feed
-- Copyright : (c) Hideyuki Tanaka, 2009
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- Feeders for Stream Deserializers
--
--------------------------------------------------------------------
module Data.MessagePack.Feed(
-- * Feeder type
Feeder,
-- * Feeders
feederFromHandle,
feederFromFile,
feederFromString,
) where
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.IORef
import System.IO
-- | Feeder returns Just ByteString when bytes remains, otherwise Nothing.
type Feeder = IO (Maybe ByteString)
-- | Feeder from Handle
feederFromHandle :: Handle -> IO Feeder
feederFromHandle h = return $ do
bs <- BS.hGetNonBlocking h bufSize
if BS.length bs > 0
then do return $ Just bs
else do
c <- BS.hGet h 1
if BS.length c > 0
then do return $ Just c
else do
hClose h
return Nothing
where
bufSize = 4096
-- | Feeder from File
feederFromFile :: FilePath -> IO Feeder
feederFromFile path =
openFile path ReadMode >>= feederFromHandle
-- | Feeder from ByteString
feederFromString :: ByteString -> IO Feeder
feederFromString bs = do
r <- newIORef (Just bs)
return $ f r
where
f r = do
mb <- readIORef r
writeIORef r Nothing
return mb

View File

@@ -0,0 +1,28 @@
module Data.MessagePack.Internal.Utf8 (
encodeUtf8,
decodeUtf8,
skipChar,
toLBS,
fromLBS,
) where
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Encoding.Error as T
encodeUtf8 :: String -> B.ByteString
encodeUtf8 = T.encodeUtf8 . T.pack
decodeUtf8 :: B.ByteString -> String
decodeUtf8 = T.unpack . T.decodeUtf8With skipChar
skipChar :: T.OnDecodeError
skipChar _ _ = Nothing
toLBS :: B.ByteString -> BL.ByteString
toLBS bs = BL.fromChunks [bs]
fromLBS :: BL.ByteString -> B.ByteString
fromLBS = B.concat . BL.toChunks

View File

@@ -1,156 +0,0 @@
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Monad
-- Copyright : (c) Hideyuki Tanaka, 2009
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- Monadic Stream Serializers and Deserializers
--
--------------------------------------------------------------------
module Data.MessagePack.Monad(
-- * Classes
MonadPacker(..),
MonadUnpacker(..),
-- * Packer and Unpacker type
PackerT(..),
UnpackerT(..),
-- * Packers
packToString,
packToHandle,
packToFile,
-- * Unpackers
unpackFrom,
unpackFromString,
unpackFromHandle,
unpackFromFile,
) where
import Control.Monad
import Control.Monad.Trans
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import System.IO
import Data.MessagePack.Base hiding (Unpacker)
import qualified Data.MessagePack.Base as Base
import Data.MessagePack.Class
import Data.MessagePack.Feed
class Monad m => MonadPacker m where
-- | Serialize a object
put :: OBJECT a => a -> m ()
class Monad m => MonadUnpacker m where
-- | Deserialize a object
get :: OBJECT a => m a
-- | Serializer Type
newtype PackerT m r = PackerT { runPackerT :: Base.Packer -> m r }
instance Monad m => Monad (PackerT m) where
a >>= b =
PackerT $ \pc -> do
r <- runPackerT a pc
runPackerT (b r) pc
return r =
PackerT $ \_ -> return r
instance MonadTrans PackerT where
lift m = PackerT $ \_ -> m
instance MonadIO m => MonadIO (PackerT m) where
liftIO = lift . liftIO
instance MonadIO m => MonadPacker (PackerT m) where
put v = PackerT $ \pc -> liftIO $ do
pack pc v
-- | Execute given serializer and returns byte sequence.
packToString :: MonadIO m => PackerT m r -> m ByteString
packToString m = do
sb <- liftIO $ newSimpleBuffer
pc <- liftIO $ newPacker sb
_ <- runPackerT m pc
liftIO $ simpleBufferData sb
-- | Execute given serializer and write byte sequence to Handle.
packToHandle :: MonadIO m => Handle -> PackerT m r -> m ()
packToHandle h m = do
sb <- packToString m
liftIO $ BS.hPut h sb
liftIO $ hFlush h
-- | Execute given serializer and write byte sequence to file.
packToFile :: MonadIO m => FilePath -> PackerT m r -> m ()
packToFile p m = do
sb <- packToString m
liftIO $ BS.writeFile p sb
-- | Deserializer type
newtype UnpackerT m r = UnpackerT { runUnpackerT :: Base.Unpacker -> Feeder -> m r }
instance Monad m => Monad (UnpackerT m) where
a >>= b =
UnpackerT $ \up feed -> do
r <- runUnpackerT a up feed
runUnpackerT (b r) up feed
return r =
UnpackerT $ \_ _ -> return r
instance MonadTrans UnpackerT where
lift m = UnpackerT $ \_ _ -> m
instance MonadIO m => MonadIO (UnpackerT m) where
liftIO = lift . liftIO
instance MonadIO m => MonadUnpacker (UnpackerT m) where
get = UnpackerT $ \up feed -> liftIO $ do
executeOne up feed
obj <- unpackerData up
freeZone =<< unpackerReleaseZone up
unpackerReset up
let Right r = fromObject obj
return r
where
executeOne up feed = do
resp <- unpackerExecute up
guard $ resp>=0
when (resp==0) $ do
Just bs <- feed
unpackerFeed up bs
executeOne up feed
-- | Execute deserializer using given feeder.
unpackFrom :: MonadIO m => Feeder -> UnpackerT m r -> m r
unpackFrom f m = do
up <- liftIO $ newUnpacker defaultInitialBufferSize
runUnpackerT m up f
-- | Execute deserializer using given handle.
unpackFromHandle :: MonadIO m => Handle -> UnpackerT m r -> m r
unpackFromHandle h m =
flip unpackFrom m =<< liftIO (feederFromHandle h)
-- | Execute deserializer using given file content.
unpackFromFile :: MonadIO m => FilePath -> UnpackerT m r -> m r
unpackFromFile p m = do
h <- liftIO $ openFile p ReadMode
r <- flip unpackFrom m =<< liftIO (feederFromHandle h)
liftIO $ hClose h
return r
-- | Execute deserializer from given byte sequence.
unpackFromString :: MonadIO m => ByteString -> UnpackerT m r -> m r
unpackFromString bs m = do
flip unpackFrom m =<< liftIO (feederFromString bs)

View File

@@ -0,0 +1,334 @@
{-# Language TypeSynonymInstances #-}
{-# Language FlexibleInstances #-}
{-# Language IncoherentInstances #-}
{-# Language DeriveDataTypeable #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Object
-- Copyright : (c) Hideyuki Tanaka, 2009-2010
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- MessagePack object definition
--
--------------------------------------------------------------------
module Data.MessagePack.Object(
-- * MessagePack Object
Object(..),
-- * Serialization to and from Object
OBJECT(..),
-- Result,
) where
import Control.DeepSeq
import Control.Exception
import Control.Monad
import Control.Monad.Trans.Error ()
import qualified Data.Attoparsec as A
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import Data.Typeable
import Data.MessagePack.Assoc
import Data.MessagePack.Pack
import Data.MessagePack.Unpack
import Data.MessagePack.Internal.Utf8
-- | Object Representation of MessagePack data.
data Object
= ObjectNil
| ObjectBool Bool
| ObjectInteger Int
| ObjectFloat Float
| ObjectDouble Double
| ObjectRAW B.ByteString
| ObjectArray [Object]
| ObjectMap [(Object, Object)]
deriving (Show, Eq, Ord, Typeable)
instance NFData Object where
rnf obj =
case obj of
ObjectNil -> ()
ObjectBool b -> rnf b
ObjectInteger n -> rnf n
ObjectFloat f -> rnf f
ObjectDouble d -> rnf d
ObjectRAW bs -> bs `seq` ()
ObjectArray a -> rnf a
ObjectMap m -> rnf m
instance Unpackable Object where
get =
A.choice
[ liftM ObjectInteger get
, liftM (\() -> ObjectNil) get
, liftM ObjectBool get
, liftM ObjectFloat get
, liftM ObjectDouble get
, liftM ObjectRAW get
, liftM ObjectArray get
, liftM (ObjectMap . unAssoc) get
]
instance Packable Object where
put obj =
case obj of
ObjectInteger n ->
put n
ObjectNil ->
put ()
ObjectBool b ->
put b
ObjectFloat f ->
put f
ObjectDouble d ->
put d
ObjectRAW raw ->
put raw
ObjectArray arr ->
put arr
ObjectMap m ->
put $ Assoc m
-- | The class of types serializable to and from MessagePack object
class (Unpackable a, Packable a) => OBJECT a where
-- | Encode a value to MessagePack object
toObject :: a -> Object
toObject = unpack . pack
-- | Decode a value from MessagePack object
fromObject :: Object -> a
fromObject a =
case tryFromObject a of
Left err ->
throw $ UnpackError err
Right ret ->
ret
-- | Decode a value from MessagePack object
tryFromObject :: Object -> Either String a
tryFromObject = tryUnpack . pack
instance OBJECT Object where
toObject = id
tryFromObject = Right
tryFromObjectError :: Either String a
tryFromObjectError = Left "tryFromObject: cannot cast"
instance OBJECT () where
toObject = const ObjectNil
tryFromObject ObjectNil = Right ()
tryFromObject _ = tryFromObjectError
instance OBJECT Int where
toObject = ObjectInteger
tryFromObject (ObjectInteger n) = Right n
tryFromObject _ = tryFromObjectError
instance OBJECT Bool where
toObject = ObjectBool
tryFromObject (ObjectBool b) = Right b
tryFromObject _ = tryFromObjectError
instance OBJECT Double where
toObject = ObjectDouble
tryFromObject (ObjectDouble d) = Right d
tryFromObject _ = tryFromObjectError
instance OBJECT Float where
toObject = ObjectFloat
tryFromObject (ObjectFloat f) = Right f
tryFromObject _ = tryFromObjectError
instance OBJECT String where
toObject = toObject . encodeUtf8
tryFromObject obj = liftM decodeUtf8 $ tryFromObject obj
instance OBJECT B.ByteString where
toObject = ObjectRAW
tryFromObject (ObjectRAW bs) = Right bs
tryFromObject _ = tryFromObjectError
instance OBJECT BL.ByteString where
toObject = ObjectRAW . fromLBS
tryFromObject (ObjectRAW bs) = Right $ toLBS bs
tryFromObject _ = tryFromObjectError
instance OBJECT T.Text where
toObject = ObjectRAW . T.encodeUtf8
tryFromObject (ObjectRAW bs) = Right $ T.decodeUtf8With skipChar bs
tryFromObject _ = tryFromObjectError
instance OBJECT TL.Text where
toObject = ObjectRAW . fromLBS . TL.encodeUtf8
tryFromObject (ObjectRAW bs) = Right $ TL.decodeUtf8With skipChar $ toLBS bs
tryFromObject _ = tryFromObjectError
instance OBJECT a => OBJECT [a] where
toObject = ObjectArray . map toObject
tryFromObject (ObjectArray arr) =
mapM tryFromObject arr
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2) => OBJECT (a1, a2) where
toObject (a1, a2) = ObjectArray [toObject a1, toObject a2]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
return (v1, v2)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3) => OBJECT (a1, a2, a3) where
toObject (a1, a2, a3) = ObjectArray [toObject a1, toObject a2, toObject a3]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
return (v1, v2, v3)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4) => OBJECT (a1, a2, a3, a4) where
toObject (a1, a2, a3, a4) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
return (v1, v2, v3, v4)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4, OBJECT a5) => OBJECT (a1, a2, a3, a4, a5) where
toObject (a1, a2, a3, a4, a5) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4, toObject a5]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4, o5] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
v5 <- tryFromObject o5
return (v1, v2, v3, v4, v5)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4, OBJECT a5, OBJECT a6) => OBJECT (a1, a2, a3, a4, a5, a6) where
toObject (a1, a2, a3, a4, a5, a6) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4, toObject a5, toObject a6]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4, o5, o6] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
v5 <- tryFromObject o5
v6 <- tryFromObject o6
return (v1, v2, v3, v4, v5, v6)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4, OBJECT a5, OBJECT a6, OBJECT a7) => OBJECT (a1, a2, a3, a4, a5, a6, a7) where
toObject (a1, a2, a3, a4, a5, a6, a7) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4, toObject a5, toObject a6, toObject a7]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4, o5, o6, o7] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
v5 <- tryFromObject o5
v6 <- tryFromObject o6
v7 <- tryFromObject o7
return (v1, v2, v3, v4, v5, v6, v7)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4, OBJECT a5, OBJECT a6, OBJECT a7, OBJECT a8) => OBJECT (a1, a2, a3, a4, a5, a6, a7, a8) where
toObject (a1, a2, a3, a4, a5, a6, a7, a8) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4, toObject a5, toObject a6, toObject a7, toObject a8]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4, o5, o6, o7, o8] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
v5 <- tryFromObject o5
v6 <- tryFromObject o6
v7 <- tryFromObject o7
v8 <- tryFromObject o8
return (v1, v2, v3, v4, v5, v6, v7, v8)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a1, OBJECT a2, OBJECT a3, OBJECT a4, OBJECT a5, OBJECT a6, OBJECT a7, OBJECT a8, OBJECT a9) => OBJECT (a1, a2, a3, a4, a5, a6, a7, a8, a9) where
toObject (a1, a2, a3, a4, a5, a6, a7, a8, a9) = ObjectArray [toObject a1, toObject a2, toObject a3, toObject a4, toObject a5, toObject a6, toObject a7, toObject a8, toObject a9]
tryFromObject (ObjectArray arr) =
case arr of
[o1, o2, o3, o4, o5, o6, o7, o8, o9] -> do
v1 <- tryFromObject o1
v2 <- tryFromObject o2
v3 <- tryFromObject o3
v4 <- tryFromObject o4
v5 <- tryFromObject o5
v6 <- tryFromObject o6
v7 <- tryFromObject o7
v8 <- tryFromObject o8
v9 <- tryFromObject o9
return (v1, v2, v3, v4, v5, v6, v7, v8, v9)
_ ->
tryFromObjectError
tryFromObject _ =
tryFromObjectError
instance (OBJECT a, OBJECT b) => OBJECT (Assoc [(a,b)]) where
toObject =
ObjectMap . map (\(a, b) -> (toObject a, toObject b)) . unAssoc
tryFromObject (ObjectMap mem) = do
liftM Assoc $ mapM (\(a, b) -> liftM2 (,) (tryFromObject a) (tryFromObject b)) mem
tryFromObject _ =
tryFromObjectError
instance OBJECT a => OBJECT (Maybe a) where
toObject (Just a) = toObject a
toObject Nothing = ObjectNil
tryFromObject ObjectNil = return Nothing
tryFromObject obj = liftM Just $ tryFromObject obj

View File

@@ -0,0 +1,204 @@
{-# Language FlexibleInstances #-}
{-# Language IncoherentInstances #-}
{-# Language TypeSynonymInstances #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Pack
-- Copyright : (c) Hideyuki Tanaka, 2009-2010
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- MessagePack Serializer using @Data.Binary.Pack@
--
--------------------------------------------------------------------
module Data.MessagePack.Pack (
-- * Serializable class
Packable(..),
-- * Simple function to pack a Haskell value
pack,
) where
import Data.Binary.Put
import Data.Binary.IEEE754
import Data.Bits
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import qualified Data.Vector as V
import Data.MessagePack.Assoc
import Data.MessagePack.Internal.Utf8
-- | Serializable class
class Packable a where
-- | Serialize a value
put :: a -> Put
-- | Pack Haskell data to MessagePack string.
pack :: Packable a => a -> BL.ByteString
pack = runPut . put
instance Packable Int where
put n =
case n of
_ | n >= 0 && n <= 127 ->
putWord8 $ fromIntegral n
_ | n >= -32 && n <= -1 ->
putWord8 $ fromIntegral n
_ | n >= 0 && n < 0x100 -> do
putWord8 0xCC
putWord8 $ fromIntegral n
_ | n >= 0 && n < 0x10000 -> do
putWord8 0xCD
putWord16be $ fromIntegral n
_ | n >= 0 && n < 0x100000000 -> do
putWord8 0xCE
putWord32be $ fromIntegral n
_ | n >= 0 -> do
putWord8 0xCF
putWord64be $ fromIntegral n
_ | n >= -0x80 -> do
putWord8 0xD0
putWord8 $ fromIntegral n
_ | n >= -0x8000 -> do
putWord8 0xD1
putWord16be $ fromIntegral n
_ | n >= -0x80000000 -> do
putWord8 0xD2
putWord32be $ fromIntegral n
_ -> do
putWord8 0xD3
putWord64be $ fromIntegral n
instance Packable () where
put _ =
putWord8 0xC0
instance Packable Bool where
put True = putWord8 0xC3
put False = putWord8 0xC2
instance Packable Float where
put f = do
putWord8 0xCA
putFloat32be f
instance Packable Double where
put d = do
putWord8 0xCB
putFloat64be d
instance Packable String where
put = putString encodeUtf8 B.length putByteString
instance Packable B.ByteString where
put = putString id B.length putByteString
instance Packable BL.ByteString where
put = putString id (fromIntegral . BL.length) putLazyByteString
instance Packable T.Text where
put = putString T.encodeUtf8 B.length putByteString
instance Packable TL.Text where
put = putString TL.encodeUtf8 (fromIntegral . BL.length) putLazyByteString
putString :: (s -> t) -> (t -> Int) -> (t -> Put) -> s -> Put
putString cnv lf pf str = do
let bs = cnv str
case lf bs of
len | len <= 31 -> do
putWord8 $ 0xA0 .|. fromIntegral len
len | len < 0x10000 -> do
putWord8 0xDA
putWord16be $ fromIntegral len
len -> do
putWord8 0xDB
putWord32be $ fromIntegral len
pf bs
instance Packable a => Packable [a] where
put = putArray length (mapM_ put)
instance Packable a => Packable (V.Vector a) where
put = putArray V.length (V.mapM_ put)
instance (Packable a1, Packable a2) => Packable (a1, a2) where
put = putArray (const 2) f where
f (a1, a2) = put a1 >> put a2
instance (Packable a1, Packable a2, Packable a3) => Packable (a1, a2, a3) where
put = putArray (const 3) f where
f (a1, a2, a3) = put a1 >> put a2 >> put a3
instance (Packable a1, Packable a2, Packable a3, Packable a4) => Packable (a1, a2, a3, a4) where
put = putArray (const 4) f where
f (a1, a2, a3, a4) = put a1 >> put a2 >> put a3 >> put a4
instance (Packable a1, Packable a2, Packable a3, Packable a4, Packable a5) => Packable (a1, a2, a3, a4, a5) where
put = putArray (const 5) f where
f (a1, a2, a3, a4, a5) = put a1 >> put a2 >> put a3 >> put a4 >> put a5
instance (Packable a1, Packable a2, Packable a3, Packable a4, Packable a5, Packable a6) => Packable (a1, a2, a3, a4, a5, a6) where
put = putArray (const 6) f where
f (a1, a2, a3, a4, a5, a6) = put a1 >> put a2 >> put a3 >> put a4 >> put a5 >> put a6
instance (Packable a1, Packable a2, Packable a3, Packable a4, Packable a5, Packable a6, Packable a7) => Packable (a1, a2, a3, a4, a5, a6, a7) where
put = putArray (const 7) f where
f (a1, a2, a3, a4, a5, a6, a7) = put a1 >> put a2 >> put a3 >> put a4 >> put a5 >> put a6 >> put a7
instance (Packable a1, Packable a2, Packable a3, Packable a4, Packable a5, Packable a6, Packable a7, Packable a8) => Packable (a1, a2, a3, a4, a5, a6, a7, a8) where
put = putArray (const 8) f where
f (a1, a2, a3, a4, a5, a6, a7, a8) = put a1 >> put a2 >> put a3 >> put a4 >> put a5 >> put a6 >> put a7 >> put a8
instance (Packable a1, Packable a2, Packable a3, Packable a4, Packable a5, Packable a6, Packable a7, Packable a8, Packable a9) => Packable (a1, a2, a3, a4, a5, a6, a7, a8, a9) where
put = putArray (const 9) f where
f (a1, a2, a3, a4, a5, a6, a7, a8, a9) = put a1 >> put a2 >> put a3 >> put a4 >> put a5 >> put a6 >> put a7 >> put a8 >> put a9
putArray :: (a -> Int) -> (a -> Put) -> a -> Put
putArray lf pf arr = do
case lf arr of
len | len <= 15 ->
putWord8 $ 0x90 .|. fromIntegral len
len | len < 0x10000 -> do
putWord8 0xDC
putWord16be $ fromIntegral len
len -> do
putWord8 0xDD
putWord32be $ fromIntegral len
pf arr
instance (Packable k, Packable v) => Packable (Assoc [(k,v)]) where
put = putMap length (mapM_ putPair) . unAssoc
instance (Packable k, Packable v) => Packable (Assoc (V.Vector (k,v))) where
put = putMap V.length (V.mapM_ putPair) . unAssoc
putPair :: (Packable a, Packable b) => (a, b) -> Put
putPair (a, b) = put a >> put b
putMap :: (a -> Int) -> (a -> Put) -> a -> Put
putMap lf pf m = do
case lf m of
len | len <= 15 ->
putWord8 $ 0x80 .|. fromIntegral len
len | len < 0x10000 -> do
putWord8 0xDE
putWord16be $ fromIntegral len
len -> do
putWord8 0xDF
putWord32be $ fromIntegral len
pf m
instance Packable a => Packable (Maybe a) where
put Nothing = put ()
put (Just a) = put a

View File

@@ -1,82 +0,0 @@
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Stream
-- Copyright : (c) Hideyuki Tanaka, 2009
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- Lazy Stream Serializers and Deserializers
--
--------------------------------------------------------------------
module Data.MessagePack.Stream(
unpackObjects,
unpackObjectsFromFile,
unpackObjectsFromHandle,
unpackObjectsFromString,
) where
import Data.ByteString (ByteString)
import System.IO
import System.IO.Unsafe
import Data.MessagePack.Base
import Data.MessagePack.Feed
-- | Unpack objects using given feeder.
unpackObjects :: Feeder -> IO [Object]
unpackObjects feeder = do
up <- newUnpacker defaultInitialBufferSize
f up
where
f up = unsafeInterleaveIO $ do
mbo <- unpackOnce up
case mbo of
Just o -> do
os <- f up
return $ o:os
Nothing ->
return []
unpackOnce up = do
resp <- unpackerExecute up
case resp of
0 -> do
r <- feedOnce up
if r
then unpackOnce up
else return Nothing
1 -> do
obj <- unpackerData up
freeZone =<< unpackerReleaseZone up
unpackerReset up
return $ Just obj
_ ->
error $ "unpackerExecute fails: " ++ show resp
feedOnce up = do
dat <- feeder
case dat of
Nothing ->
return False
Just bs -> do
unpackerFeed up bs
return True
-- | Unpack objects from file.
unpackObjectsFromFile :: FilePath -> IO [Object]
unpackObjectsFromFile fname =
unpackObjects =<< feederFromFile fname
-- | Unpack objects from handle.
unpackObjectsFromHandle :: Handle -> IO [Object]
unpackObjectsFromHandle h =
unpackObjects =<< feederFromHandle h
-- | Unpack oobjects from given byte sequence.
unpackObjectsFromString :: ByteString -> IO [Object]
unpackObjectsFromString bs =
unpackObjects =<< feederFromString bs

View File

@@ -0,0 +1,323 @@
{-# Language FlexibleInstances #-}
{-# Language IncoherentInstances #-}
{-# Language TypeSynonymInstances #-}
{-# Language DeriveDataTypeable #-}
--------------------------------------------------------------------
-- |
-- Module : Data.MessagePack.Unpack
-- Copyright : (c) Hideyuki Tanaka, 2009-2010
-- License : BSD3
--
-- Maintainer: tanaka.hideyuki@gmail.com
-- Stability : experimental
-- Portability: portable
--
-- MessagePack Deserializer using @Data.Attoparsec@
--
--------------------------------------------------------------------
module Data.MessagePack.Unpack(
-- * MessagePack deserializer
Unpackable(..),
-- * Simple function to unpack a Haskell value
unpack,
tryUnpack,
-- * Unpack exception
UnpackError(..),
-- * ByteString utils
IsByteString(..),
) where
import Control.Exception
import Control.Monad
import qualified Data.Attoparsec as A
import Data.Binary.Get
import Data.Binary.IEEE754
import Data.Bits
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import Data.Int
import Data.Typeable
import qualified Data.Vector as V
import Data.Word
import Text.Printf
import Data.MessagePack.Assoc
import Data.MessagePack.Internal.Utf8
-- | Deserializable class
class Unpackable a where
-- | Deserialize a value
get :: A.Parser a
class IsByteString s where
toBS :: s -> B.ByteString
instance IsByteString B.ByteString where
toBS = id
instance IsByteString BL.ByteString where
toBS = B.concat . BL.toChunks
-- | The exception of unpack
data UnpackError =
UnpackError String
deriving (Show, Typeable)
instance Exception UnpackError
-- | Unpack MessagePack string to Haskell data.
unpack :: (Unpackable a, IsByteString s) => s -> a
unpack bs =
case tryUnpack bs of
Left err ->
throw $ UnpackError err
Right ret ->
ret
-- | Unpack MessagePack string to Haskell data.
tryUnpack :: (Unpackable a, IsByteString s) => s -> Either String a
tryUnpack bs =
case A.parse get (toBS bs) of
A.Fail _ _ err ->
Left err
A.Partial _ ->
Left "not enough input"
A.Done _ ret ->
Right ret
instance Unpackable Int where
get = do
c <- A.anyWord8
case c of
_ | c .&. 0x80 == 0x00 ->
return $ fromIntegral c
_ | c .&. 0xE0 == 0xE0 ->
return $ fromIntegral (fromIntegral c :: Int8)
0xCC ->
return . fromIntegral =<< A.anyWord8
0xCD ->
return . fromIntegral =<< parseUint16
0xCE ->
return . fromIntegral =<< parseUint32
0xCF ->
return . fromIntegral =<< parseUint64
0xD0 ->
return . fromIntegral =<< parseInt8
0xD1 ->
return . fromIntegral =<< parseInt16
0xD2 ->
return . fromIntegral =<< parseInt32
0xD3 ->
return . fromIntegral =<< parseInt64
_ ->
fail $ printf "invlid integer tag: 0x%02X" c
instance Unpackable () where
get = do
c <- A.anyWord8
case c of
0xC0 ->
return ()
_ ->
fail $ printf "invlid nil tag: 0x%02X" c
instance Unpackable Bool where
get = do
c <- A.anyWord8
case c of
0xC3 ->
return True
0xC2 ->
return False
_ ->
fail $ printf "invlid bool tag: 0x%02X" c
instance Unpackable Float where
get = do
c <- A.anyWord8
case c of
0xCA ->
return . runGet getFloat32be . toLBS =<< A.take 4
_ ->
fail $ printf "invlid float tag: 0x%02X" c
instance Unpackable Double where
get = do
c <- A.anyWord8
case c of
0xCB ->
return . runGet getFloat64be . toLBS =<< A.take 8
_ ->
fail $ printf "invlid double tag: 0x%02X" c
instance Unpackable String where
get = parseString (\n -> return . decodeUtf8 =<< A.take n)
instance Unpackable B.ByteString where
get = parseString A.take
instance Unpackable BL.ByteString where
get = parseString (\n -> return . toLBS =<< A.take n)
instance Unpackable T.Text where
get = parseString (\n -> return . T.decodeUtf8With skipChar =<< A.take n)
instance Unpackable TL.Text where
get = parseString (\n -> return . TL.decodeUtf8With skipChar . toLBS =<< A.take n)
parseString :: (Int -> A.Parser a) -> A.Parser a
parseString aget = do
c <- A.anyWord8
case c of
_ | c .&. 0xE0 == 0xA0 ->
aget . fromIntegral $ c .&. 0x1F
0xDA ->
aget . fromIntegral =<< parseUint16
0xDB ->
aget . fromIntegral =<< parseUint32
_ ->
fail $ printf "invlid raw tag: 0x%02X" c
instance Unpackable a => Unpackable [a] where
get = parseArray (flip replicateM get)
instance Unpackable a => Unpackable (V.Vector a) where
get = parseArray (flip V.replicateM get)
instance (Unpackable a1, Unpackable a2) => Unpackable (a1, a2) where
get = parseArray f where
f 2 = get >>= \a1 -> get >>= \a2 -> return (a1, a2)
f n = fail $ printf "wrong tupple size: expected 2 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3) => Unpackable (a1, a2, a3) where
get = parseArray f where
f 3 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> return (a1, a2, a3)
f n = fail $ printf "wrong tupple size: expected 3 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4) => Unpackable (a1, a2, a3, a4) where
get = parseArray f where
f 4 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> return (a1, a2, a3, a4)
f n = fail $ printf "wrong tupple size: expected 4 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4, Unpackable a5) => Unpackable (a1, a2, a3, a4, a5) where
get = parseArray f where
f 5 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> get >>= \a5 -> return (a1, a2, a3, a4, a5)
f n = fail $ printf "wrong tupple size: expected 5 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4, Unpackable a5, Unpackable a6) => Unpackable (a1, a2, a3, a4, a5, a6) where
get = parseArray f where
f 6 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> get >>= \a5 -> get >>= \a6 -> return (a1, a2, a3, a4, a5, a6)
f n = fail $ printf "wrong tupple size: expected 6 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4, Unpackable a5, Unpackable a6, Unpackable a7) => Unpackable (a1, a2, a3, a4, a5, a6, a7) where
get = parseArray f where
f 7 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> get >>= \a5 -> get >>= \a6 -> get >>= \a7 -> return (a1, a2, a3, a4, a5, a6, a7)
f n = fail $ printf "wrong tupple size: expected 7 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4, Unpackable a5, Unpackable a6, Unpackable a7, Unpackable a8) => Unpackable (a1, a2, a3, a4, a5, a6, a7, a8) where
get = parseArray f where
f 8 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> get >>= \a5 -> get >>= \a6 -> get >>= \a7 -> get >>= \a8 -> return (a1, a2, a3, a4, a5, a6, a7, a8)
f n = fail $ printf "wrong tupple size: expected 8 but got " n
instance (Unpackable a1, Unpackable a2, Unpackable a3, Unpackable a4, Unpackable a5, Unpackable a6, Unpackable a7, Unpackable a8, Unpackable a9) => Unpackable (a1, a2, a3, a4, a5, a6, a7, a8, a9) where
get = parseArray f where
f 9 = get >>= \a1 -> get >>= \a2 -> get >>= \a3 -> get >>= \a4 -> get >>= \a5 -> get >>= \a6 -> get >>= \a7 -> get >>= \a8 -> get >>= \a9 -> return (a1, a2, a3, a4, a5, a6, a7, a8, a9)
f n = fail $ printf "wrong tupple size: expected 9 but got " n
parseArray :: (Int -> A.Parser a) -> A.Parser a
parseArray aget = do
c <- A.anyWord8
case c of
_ | c .&. 0xF0 == 0x90 ->
aget . fromIntegral $ c .&. 0x0F
0xDC ->
aget . fromIntegral =<< parseUint16
0xDD ->
aget . fromIntegral =<< parseUint32
_ ->
fail $ printf "invlid array tag: 0x%02X" c
instance (Unpackable k, Unpackable v) => Unpackable (Assoc [(k,v)]) where
get = liftM Assoc $ parseMap (flip replicateM parsePair)
instance (Unpackable k, Unpackable v) => Unpackable (Assoc (V.Vector (k, v))) where
get = liftM Assoc $ parseMap (flip V.replicateM parsePair)
parsePair :: (Unpackable k, Unpackable v) => A.Parser (k, v)
parsePair = do
a <- get
b <- get
return (a, b)
parseMap :: (Int -> A.Parser a) -> A.Parser a
parseMap aget = do
c <- A.anyWord8
case c of
_ | c .&. 0xF0 == 0x80 ->
aget . fromIntegral $ c .&. 0x0F
0xDE ->
aget . fromIntegral =<< parseUint16
0xDF ->
aget . fromIntegral =<< parseUint32
_ ->
fail $ printf "invlid map tag: 0x%02X" c
instance Unpackable a => Unpackable (Maybe a) where
get =
A.choice
[ liftM Just get
, liftM (\() -> Nothing) get ]
parseUint16 :: A.Parser Word16
parseUint16 = do
b0 <- A.anyWord8
b1 <- A.anyWord8
return $ (fromIntegral b0 `shiftL` 8) .|. fromIntegral b1
parseUint32 :: A.Parser Word32
parseUint32 = do
b0 <- A.anyWord8
b1 <- A.anyWord8
b2 <- A.anyWord8
b3 <- A.anyWord8
return $ (fromIntegral b0 `shiftL` 24) .|.
(fromIntegral b1 `shiftL` 16) .|.
(fromIntegral b2 `shiftL` 8) .|.
fromIntegral b3
parseUint64 :: A.Parser Word64
parseUint64 = do
b0 <- A.anyWord8
b1 <- A.anyWord8
b2 <- A.anyWord8
b3 <- A.anyWord8
b4 <- A.anyWord8
b5 <- A.anyWord8
b6 <- A.anyWord8
b7 <- A.anyWord8
return $ (fromIntegral b0 `shiftL` 56) .|.
(fromIntegral b1 `shiftL` 48) .|.
(fromIntegral b2 `shiftL` 40) .|.
(fromIntegral b3 `shiftL` 32) .|.
(fromIntegral b4 `shiftL` 24) .|.
(fromIntegral b5 `shiftL` 16) .|.
(fromIntegral b6 `shiftL` 8) .|.
fromIntegral b7
parseInt8 :: A.Parser Int8
parseInt8 = return . fromIntegral =<< A.anyWord8
parseInt16 :: A.Parser Int16
parseInt16 = return . fromIntegral =<< parseUint16
parseInt32 :: A.Parser Int32
parseInt32 = return . fromIntegral =<< parseUint32
parseInt64 :: A.Parser Int64
parseInt64 = return . fromIntegral =<< parseUint64

View File

@@ -1,16 +1,21 @@
import Control.Monad.Trans
{-# Language OverloadedStrings #-}
import Control.Monad.IO.Class
import qualified Data.ByteString as B
import Data.MessagePack
main = do
sb <- packToString $ do
sb <- return $ packToString $ do
put [1,2,3::Int]
put (3.14 :: Double)
put "Hoge"
put ("Hoge" :: B.ByteString)
print sb
unpackFromString sb $ do
r <- unpackFromString sb $ do
arr <- get
dbl <- get
str <- get
liftIO $ print (arr :: [Int], dbl :: Double, str :: String)
return (arr :: [Int], dbl :: Double, str :: B.ByteString)
print r

View File

@@ -1,14 +0,0 @@
import Control.Applicative
import qualified Data.ByteString as BS
import Data.MessagePack
main = do
sb <- newSimpleBuffer
pc <- newPacker sb
pack pc [1,2,3::Int]
pack pc True
pack pc "hoge"
bs <- simpleBufferData sb
os <- unpackObjectsFromString bs
mapM_ print os

View File

@@ -1,36 +1,70 @@
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck
import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as L
import Data.MessagePack
{-
main = do
sb <- newSimpleBuffer
pc <- newPacker sb
pack pc [(1,2),(2,3),(3::Int,4::Int)]
pack pc [4,5,6::Int]
pack pc "hoge"
bs <- simpleBufferData sb
print bs
up <- newUnpacker defaultInitialBufferSize
unpackerFeed up bs
instance Arbitrary a => Arbitrary (Assoc a) where
arbitrary = liftM Assoc arbitrary
let f = do
res <- unpackerExecute up
when (res==1) $ do
obj <- unpackerData up
print obj
f
f
mid :: (Packable a, Unpackable a) => a -> a
mid = unpack . pack
return ()
-}
prop_mid_int a = a == mid a
where types = a :: Int
prop_mid_nil a = a == mid a
where types = a :: ()
prop_mid_bool a = a == mid a
where types = a :: Bool
prop_mid_double a = a == mid a
where types = a :: Double
prop_mid_string a = a == mid a
where types = a :: String
prop_mid_bytestring a = B.pack a == mid (B.pack a)
where types = a :: String
prop_mid_lazy_bytestring a = (L.pack a) == mid (L.pack a)
where types = a :: String
prop_mid_array_int a = a == mid a
where types = a :: [Int]
prop_mid_array_string a = a == mid a
where types = a :: [String]
prop_mid_pair2 a = a == mid a
where types = a :: (Int, Int)
prop_mid_pair3 a = a == mid a
where types = a :: (Int, Int, Int)
prop_mid_pair4 a = a == mid a
where types = a :: (Int, Int, Int, Int)
prop_mid_pair5 a = a == mid a
where types = a :: (Int, Int, Int, Int, Int)
prop_mid_list_int_double a = a == mid a
where types = a :: [(Int, Double)]
prop_mid_list_string_string a = a == mid a
where types = a :: [(String, String)]
prop_mid_map_string_int a = a == mid a
where types = a :: Assoc [(String,Int)]
main = do
bs <- packb [(1,2),(2,3),(3::Int,4::Int)]
print bs
dat <- unpackb bs
print (dat :: Result [(Int, Int)])
tests =
[ testGroup "simple"
[ testProperty "int" prop_mid_int
, testProperty "nil" prop_mid_nil
, testProperty "bool" prop_mid_bool
, testProperty "double" prop_mid_double
, testProperty "string" prop_mid_string
, testProperty "bytestring" prop_mid_bytestring
, testProperty "lazy-bytestring" prop_mid_lazy_bytestring
, testProperty "[int]" prop_mid_array_int
, testProperty "[string]" prop_mid_array_string
, testProperty "(int, int)" prop_mid_pair2
, testProperty "(int, int, int)" prop_mid_pair3
, testProperty "(int, int, int, int)" prop_mid_pair4
, testProperty "(int, int, int, int, int)" prop_mid_pair5
, testProperty "[(int, double)]" prop_mid_list_int_double
, testProperty "[(string, string)]" prop_mid_list_string_string
, testProperty "Assoc [(string, int)]" prop_mid_map_string_int
]
]
main = defaultMain tests

43
haskell/test/UserData.hs Normal file
View File

@@ -0,0 +1,43 @@
{-# Language TemplateHaskell #-}
import Data.MessagePack
import Data.MessagePack.Derive
data T
= A Int String
| B Double
deriving (Show, Eq)
$(deriveObject ''T)
data U
= C { c1 :: Int, c2 :: String }
| D { d1 :: Double }
deriving (Show, Eq)
$(deriveObject ''U)
data V
= E String | F
deriving (Show, Eq)
$(deriveObject ''V)
test :: (OBJECT a, Show a, Eq a) => a -> IO ()
test v = do
let bs = pack v
print bs
print (unpack bs == v)
let oa = toObject v
print oa
print (fromObject oa == v)
main = do
test $ A 123 "hoge"
test $ B 3.14
test $ C 123 "hoge"
test $ D 3.14
test $ E "hello"
test $ F
return ()

View File

@@ -1,5 +1,13 @@
#Mon Apr 19 22:18:48 JST 2010
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
#Tue Apr 12 19:14:17 JST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,9 @@
#Mon Sep 27 07:43:27 JST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

1
java/AUTHORS Normal file
View File

@@ -0,0 +1 @@
FURUHASHI Sadayuki <frsyuki _at_ users.sourceforge.jp>

View File

@@ -1,3 +1,97 @@
Release 0.5.2 - 2011/04/23
NEW FEATURES
MSGPACK-6 Added TemplatePrecompiler program
Added built-in templates of BigDecimal and Date classes.
Added @MessagePackBeans annotation that enables you to serialize/deserialize
JavaBeans.
BUG FIXES
MSGPACK-4 Fixes the deserialization routine of Long value
IMPROVEMENTS
#35 Improves handling of ClassLoader on Javassist template builder.
MSGPACK-7 Improves compatibility with Java 1.5. Now it runs on JRE 5.
It is tested on Jenkins CI: http://ci.msgpack.org/job/java-jre5/
Release 0.5.1 - 2010/12/14
BUG FIXES
Fixes cast error on GenericArrayType
Throws MessagePackException instead of NullPointerException if target is null
on pack method.
Release 0.5.0 - 2010/12/09
NEW FEATURES
Dynamic template builder is rewritten. New ReflectionTemplateBuilder
supports DalvikVM.
Some optimization for dynamic code generator.
@MessagePackMessage accepts default filed option.
Added new field annotations: @Ignore, @Requred and @Index.
Supported pack/unpack/convertion of arrays including multidimensional arrays.
Added native pack/unpack routine of ByteBuffer. It will be zero-copy optimized
under a specific condition.
Release 0.4.3 - 2010/11/10
NEW FEATURES
Added FieldList class and MessagePack.register(Class<T>, FieldList) method
to specify optional/nullable options on runtime without annotations.
Changed annotation name: @MessagePackNullable -> @Nullable
Changed annotation name: @MessagePackOptional -> @Optional
Supported pack/unpack/convertion of enums.
Added MessagePack.unpack(buffer, T to) and MessagePackObject.convert(T to)
methods. They can unpack/convert buffer/object into existing object and
eliminate re-allocation overhead.
Release 0.4.2 - 2010/11/09
NEW FEATURES
Added MessagePackNullable annotation and Tempalte.tNullable(Template)
method.
Added <T> T MessagePackObject.unpack(Class<T>) method.
Release 0.4.1 - 2010/11/05
BUG FIXES
Fixed dynamic code generation of unpack methods
Release 0.4.0 - 2010/10/25
NEW FEATURES
Added MessagePackObject class and org.msgpack.object package that
represent unpacked (=dynamically typed) objects.
Unpacker.unpack method returns MessagePackObject instead of Object.
Added Templates class and org.msgpack.template package that provide
type conversion feature.
User-defined classes annotated with MessagePackMessage can be
pack/unpack/converted.
User-defined classes registered with MessagePack.register(Class) can be
pack/unpack/converted.
Added dynamic code generation feature for user-defined classes.
Added MessagePackOptional annotation.
Added MessagePack class that implements typical useful methods.
Release 0.3 - 2010/05/23
NEW FEATURES
Added Unbuffered API + Direct Conversion API to the Unpacker.

17
java/msgpack.iml Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.1" level="project" />
</component>
</module>

View File

@@ -3,11 +3,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
<version>0.3</version>
<version>0.5.2-devel</version>
<description>MessagePack for Java</description>
<name>MessagePack for Java</name>
<url>http://msgpack.sourceforge.net/</url>
<url>http://msgpack.org/</url>
<licenses>
<license>
@@ -29,6 +29,22 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@@ -47,8 +63,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
@@ -65,6 +81,20 @@
<connectionUrl>scm:git://github.com/msgpack/msgpack.git</connectionUrl>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@@ -97,29 +127,33 @@
<repositories>
<repository>
<id>msgpack.sourceforge.net</id>
<id>msgpack.org</id>
<name>MessagePack Maven2 Repository</name>
<url>http://msgpack.sourceforge.net/maven2</url>
<url>http://msgpack.org/maven2</url>
</repository>
<repository>
<id>msgpack.sourceforge.net</id>
<name>MessagePack Maven2 Snapshot Repository</name>
<url>http://msgpack.sourceforge.net/maven2-snapshot</url>
<id>repository.jboss.org</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>shell.sourceforge.net</id>
<name>Repository at sourceforge.net</name>
<url>scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2/</url>
<id>msgpack.org</id>
<name>Repository at msgpack.org</name>
<url>file://${project.build.directory}/website/maven2/</url>
<!--<url>${deploy-release-url}</url>-->
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>shell.sourceforge.net</id>
<name>Repository Name</name>
<url>scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2-snapshot/</url>
<id>msgpack.org</id>
<name>Repository at msgpack.org</name>
<url>file://${project.build.directory}/website/maven2/</url>
<!--<url>${deploy-snapshot-url}</url>-->
</snapshotRepository>
</distributionManagement>

View File

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

View File

@@ -19,12 +19,13 @@ package org.msgpack;
import java.io.IOException;
import java.nio.ByteBuffer;
//import java.math.BigInteger;
import java.math.BigInteger;
abstract class BufferedUnpackerImpl extends UnpackerImpl {
int offset = 0;
int filled = 0;
byte[] buffer = null;
boolean bufferReferenced = false; // TODO zero-copy buffer
private ByteBuffer castBuffer = ByteBuffer.allocate(8);
abstract boolean fill() throws IOException;
@@ -47,7 +48,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
offset = noffset;
} while(!super.isFinished());
Object obj = super.getData();
MessagePackObject obj = super.getData();
super.reset();
result.done(obj);
@@ -103,7 +104,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xcc: // unsigned int 8
more(2);
advance(2);
return (int)((short)buffer[offset+1] & 0xff);
return (int)((short)(buffer[offset-1]) & 0xff);
case 0xcd: // unsigned int 16
more(3);
castBuffer.rewind();
@@ -137,7 +138,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xd0: // signed int 8
more(2);
advance(2);
return (int)buffer[offset+1];
return (int)buffer[offset-1];
case 0xd1: // signed int 16
more(3);
castBuffer.rewind();
@@ -145,10 +146,10 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
advance(3);
return (int)castBuffer.getShort(0);
case 0xd2: // signed int 32
more(4);
more(5);
castBuffer.rewind();
castBuffer.put(buffer, offset+1, 4);
advance(4);
advance(5);
return (int)castBuffer.getInt(0);
case 0xd3: // signed int 64
more(9);
@@ -178,7 +179,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xcc: // unsigned int 8
more(2);
advance(2);
return (long)((short)buffer[offset+1] & 0xff);
return (long)((short)(buffer[offset-1]) & 0xff);
case 0xcd: // unsigned int 16
more(3);
castBuffer.rewind();
@@ -198,8 +199,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
{
long o = castBuffer.getLong(0);
if(o < 0) {
// FIXME
throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported");
throw new MessageTypeException();
}
advance(9);
return o;
@@ -207,7 +207,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xd0: // signed int 8
more(2);
advance(2);
return (long)buffer[offset+1];
return (long)buffer[offset-1];
case 0xd1: // signed int 16
more(3);
castBuffer.rewind();
@@ -215,10 +215,10 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
advance(3);
return (long)castBuffer.getShort(0);
case 0xd2: // signed int 32
more(4);
more(5);
castBuffer.rewind();
castBuffer.put(buffer, offset+1, 4);
advance(4);
advance(5);
return (long)castBuffer.getInt(0);
case 0xd3: // signed int 64
more(9);
@@ -231,6 +231,26 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
}
}
final BigInteger unpackBigInteger() throws IOException, MessageTypeException {
more(1);
int b = buffer[offset];
if((b & 0xff) != 0xcf) {
return BigInteger.valueOf(unpackLong());
}
// unsigned int 64
more(9);
castBuffer.rewind();
castBuffer.put(buffer, offset+1, 8);
advance(9);
long o = castBuffer.getLong(0);
if(o < 0) {
return new BigInteger(1, castBuffer.array());
} else {
return BigInteger.valueOf(o);
}
}
final float unpackFloat() throws IOException, MessageTypeException {
more(1);
int b = buffer[offset];
@@ -398,7 +418,18 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
final byte[] unpackByteArray() throws IOException, MessageTypeException {
int length = unpackRaw();
return unpackRawBody(length);
byte[] body = unpackRawBody(length);
return body;
}
final ByteBuffer unpackByteBuffer() throws IOException, MessageTypeException {
// TODO zero-copy buffer
int length = unpackRaw();
more(length);
ByteBuffer buf = ByteBuffer.wrap(buffer, offset, length);
bufferReferenced = true; // TODO fix magical code
advance(length);
return buf;
}
final String unpackString() throws IOException, MessageTypeException {
@@ -414,7 +445,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
return s;
}
final Object unpackObject() throws IOException {
final MessagePackObject unpackObject() throws IOException {
UnpackResult result = new UnpackResult();
if(!next(result)) {
super.reset();

View File

@@ -18,6 +18,6 @@
package org.msgpack;
public interface MessageConvertable {
public void messageConvert(Object obj) throws MessageTypeException;
public void messageConvert(MessagePackObject obj) throws MessageTypeException;
}

View File

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

View File

@@ -0,0 +1,160 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.msgpack.template.TemplateRegistry;
import org.msgpack.template.FieldList;
public class MessagePack {
public static byte[] pack(Object obj) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
new Packer(out).pack(obj);
} catch (IOException e) {
throw new RuntimeException(e);
}
return out.toByteArray();
}
public static void pack(OutputStream out, Object obj) throws IOException {
new Packer(out).pack(obj);
}
public static byte[] pack(Object obj, Template tmpl) throws MessageTypeException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
new Packer(out).pack(obj, tmpl);
} catch (IOException e) {
throw new RuntimeException(e);
}
return out.toByteArray();
}
public static void pack(OutputStream out, Object obj, Template tmpl) throws IOException, MessageTypeException {
new Packer(out).pack(obj, tmpl);
}
public static MessagePackObject unpack(byte[] buffer) throws MessageTypeException {
Unpacker pac = new Unpacker();
pac.wrap(buffer);
try {
return pac.unpackObject();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Object unpack(byte[] buffer, Template tmpl) throws MessageTypeException {
Unpacker pac = new Unpacker();
pac.wrap(buffer);
try {
return pac.unpack(tmpl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(byte[] buffer, Template tmpl, T to) throws MessageTypeException {
Unpacker pac = new Unpacker();
pac.wrap(buffer);
try {
return pac.unpack(tmpl, to);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(byte[] buffer, Class<T> klass) throws MessageTypeException {
Unpacker pac = new Unpacker();
pac.wrap(buffer);
try {
return pac.unpack(klass);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(byte[] buffer, T to) throws MessageTypeException {
Unpacker pac = new Unpacker();
pac.wrap(buffer);
try {
return pac.unpack(to);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static MessagePackObject unpack(InputStream in) throws IOException {
Unpacker pac = new Unpacker(in);
return pac.unpackObject();
}
public static Object unpack(InputStream in, Template tmpl) throws IOException, MessageTypeException {
Unpacker pac = new Unpacker(in);
try {
return pac.unpack(tmpl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(InputStream in, Template tmpl, T to) throws IOException, MessageTypeException {
Unpacker pac = new Unpacker(in);
try {
return pac.unpack(tmpl, to);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(InputStream in, Class<T> klass) throws IOException, MessageTypeException {
Unpacker pac = new Unpacker(in);
try {
return pac.unpack(klass);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static <T> T unpack(InputStream in, T to) throws IOException, MessageTypeException {
Unpacker pac = new Unpacker(in);
try {
return pac.unpack(to);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void register(Class<?> target) {
TemplateRegistry.register(target);
}
public static void register(Class<?> target, FieldList flist) throws NoSuchFieldException {
TemplateRegistry.register(target, flist);
}
public static void register(Class<?> target, Template tmpl) {
TemplateRegistry.register(target, tmpl);
}
}

View File

@@ -0,0 +1,160 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.math.BigInteger;
import org.msgpack.template.TemplateRegistry;
public abstract class MessagePackObject implements Cloneable, MessagePackable {
public boolean isNil() {
return false;
}
public boolean isBooleanType() {
return false;
}
public boolean isIntegerType() {
return false;
}
public boolean isFloatType() {
return false;
}
public boolean isArrayType() {
return false;
}
public boolean isMapType() {
return false;
}
public boolean isRawType() {
return false;
}
public boolean asBoolean() {
throw new MessageTypeException("type error");
}
public byte asByte() {
throw new MessageTypeException("type error");
}
public short asShort() {
throw new MessageTypeException("type error");
}
public int asInt() {
throw new MessageTypeException("type error");
}
public long asLong() {
throw new MessageTypeException("type error");
}
public BigInteger asBigInteger() {
throw new MessageTypeException("type error");
}
public float asFloat() {
throw new MessageTypeException("type error");
}
public double asDouble() {
throw new MessageTypeException("type error");
}
public byte[] asByteArray() {
throw new MessageTypeException("type error");
}
public String asString() {
throw new MessageTypeException("type error");
}
public MessagePackObject[] asArray() {
throw new MessageTypeException("type error");
}
public List<MessagePackObject> asList() {
throw new MessageTypeException("type error");
}
public Map<MessagePackObject, MessagePackObject> asMap() {
throw new MessageTypeException("type error");
}
public byte byteValue() {
throw new MessageTypeException("type error");
}
public short shortValue() {
throw new MessageTypeException("type error");
}
public int intValue() {
throw new MessageTypeException("type error");
}
public long longValue() {
throw new MessageTypeException("type error");
}
public BigInteger bigIntegerValue() {
throw new MessageTypeException("type error");
}
public float floatValue() {
throw new MessageTypeException("type error");
}
public double doubleValue() {
throw new MessageTypeException("type error");
}
abstract public Object clone();
public Object convert(Template tmpl) throws MessageTypeException {
return convert(tmpl, null);
}
public <T> T convert(Template tmpl, T to) throws MessageTypeException {
return (T)tmpl.convert(this, to);
}
public <T> T convert(Class<T> klass) throws MessageTypeException {
return convert(klass, null);
}
public <T> T convert(T to) throws MessageTypeException {
return convert((Class<T>)to.getClass(), to);
}
public <T> T convert(Class<T> klass, T to) throws MessageTypeException {
if(isNil()) {
return null;
}
return (T)convert(TemplateRegistry.lookup(klass), to);
}
}

View File

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

View File

@@ -15,12 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
package org.msgpack;
import org.msgpack.Schema;
import java.io.IOException;
public interface IArraySchema {
public Schema getElementSchema(int index);
public Object createFromArray(Object[] obj);
public interface MessagePacker {
void pack(Packer pk, Object target) throws IOException;
}

View File

@@ -23,15 +23,13 @@ public class MessageTypeException extends RuntimeException {
public MessageTypeException(String s) {
super(s);
}
public static MessageTypeException invalidConvert(Object from, Schema to) {
return new MessageTypeException(from.getClass().getName()+" cannot be convert to "+to.getExpression());
public MessageTypeException(String s, Throwable t) {
super(s, t);
}
/* FIXME
public static MessageTypeException schemaMismatch(Schema to) {
return new MessageTypeException("schema mismatch "+to.getExpression());
public MessageTypeException(Throwable t) {
super(t);
}
*/
}

View File

@@ -15,13 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
package org.msgpack;
import org.msgpack.Schema;
import java.io.IOException;
public interface IMapSchema {
public Schema getKeySchema();
public Schema getValueSchema();
public Object createFromMap(Object[] obj);
public interface MessageUnpacker {
Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException;
}

View File

@@ -21,7 +21,11 @@ import java.io.OutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.Collection;
import java.math.BigInteger;
import org.msgpack.template.TemplateRegistry;
/**
* Packer enables you to serialize objects into OutputStream.
@@ -40,8 +44,10 @@ import java.util.Map;
* You can serialize objects that implements {@link MessagePackable} interface.
*/
public class Packer {
public static void load() { }
protected byte[] castBytes = new byte[9];
protected ByteBuffer castBuffer = ByteBuffer.wrap(castBytes);
//protected ByteBuffer castBuffer = ByteBuffer.wrap(castBytes);
protected OutputStream out;
public Packer(OutputStream out) {
@@ -64,7 +70,9 @@ public class Packer {
if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, d);
// castBuffer.putShort(1, d);
castBytes[1] = (byte)(d >> 8);
castBytes[2] = (byte)(d >> 0);
out.write(castBytes, 0, 3);
} else {
// signed 8
@@ -84,7 +92,9 @@ public class Packer {
} else {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, d);
// castBuffer.putShort(1, d);
castBytes[1] = (byte)(d >> 8);
castBytes[2] = (byte)(d >> 0);
out.write(castBytes, 0, 3);
}
}
@@ -96,12 +106,18 @@ public class Packer {
if(d < -(1<<15)) {
// signed 32
castBytes[0] = (byte)0xd2;
castBuffer.putInt(1, d);
// castBuffer.putInt(1, d);
castBytes[1] = (byte)(d >> 24);
castBytes[2] = (byte)(d >> 16);
castBytes[3] = (byte)(d >> 8);
castBytes[4] = (byte)(d >> 0);
out.write(castBytes, 0, 5);
} else if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, (short)d);
// castBuffer.putShort(1, (short)d);
castBytes[1] = (byte)(d >> 8);
castBytes[2] = (byte)(d >> 0);
out.write(castBytes, 0, 3);
} else {
// signed 8
@@ -121,12 +137,18 @@ public class Packer {
} else if(d < (1<<16)) {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, (short)d);
// castBuffer.putShort(1, (short)d);
castBytes[1] = (byte)(d >> 8);
castBytes[2] = (byte)(d >> 0);
out.write(castBytes, 0, 3);
} else {
// unsigned 32
castBytes[0] = (byte)0xce;
castBuffer.putInt(1, d);
// castBuffer.putInt(1, d);
castBytes[1] = (byte)(d >> 24);
castBytes[2] = (byte)(d >> 16);
castBytes[3] = (byte)(d >> 8);
castBytes[4] = (byte)(d >> 0);
out.write(castBytes, 0, 5);
}
}
@@ -139,19 +161,33 @@ public class Packer {
if(d < -(1L<<31)) {
// signed 64
castBytes[0] = (byte)0xd3;
castBuffer.putLong(1, d);
// castBuffer.putLong(1, d);
castBytes[1] = (byte)(d >> 56);
castBytes[2] = (byte)(d >> 48);
castBytes[3] = (byte)(d >> 40);
castBytes[4] = (byte)(d >> 32);
castBytes[5] = (byte)(d >> 24);
castBytes[6] = (byte)(d >> 16);
castBytes[7] = (byte)(d >> 8);
castBytes[8] = (byte)(d >> 0);
out.write(castBytes, 0, 9);
} else {
// signed 32
castBytes[0] = (byte)0xd2;
castBuffer.putInt(1, (int)d);
// castBuffer.putInt(1, (int)d);
castBytes[1] = (byte)(d >> 24);
castBytes[2] = (byte)(d >> 16);
castBytes[3] = (byte)(d >> 8);
castBytes[4] = (byte)(d >> 0);
out.write(castBytes, 0, 5);
}
} else {
if(d < -(1<<7)) {
// signed 16
castBytes[0] = (byte)0xd1;
castBuffer.putShort(1, (short)d);
// castBuffer.putShort(1, (short)d);
castBytes[1] = (byte)(d >> 8);
castBytes[2] = (byte)(d >> 0);
out.write(castBytes, 0, 3);
} else {
// signed 8
@@ -173,7 +209,9 @@ public class Packer {
} else {
// unsigned 16
castBytes[0] = (byte)0xcd;
castBuffer.putShort(1, (short)d);
// castBuffer.putShort(1, (short)d);
castBytes[1] = (byte)((d & 0x0000ff00) >> 8);
castBytes[2] = (byte)((d & 0x000000ff) >> 0);
out.write(castBytes, 0, 3);
//System.out.println("pack uint 16 "+(short)d);
}
@@ -181,12 +219,24 @@ public class Packer {
if(d < (1L<<32)) {
// unsigned 32
castBytes[0] = (byte)0xce;
castBuffer.putInt(1, (int)d);
// castBuffer.putInt(1, (int)d);
castBytes[1] = (byte)((d & 0xff000000) >> 24);
castBytes[2] = (byte)((d & 0x00ff0000) >> 16);
castBytes[3] = (byte)((d & 0x0000ff00) >> 8);
castBytes[4] = (byte)((d & 0x000000ff) >> 0);
out.write(castBytes, 0, 5);
} else {
// unsigned 64
castBytes[0] = (byte)0xcf;
castBuffer.putLong(1, d);
// castBuffer.putLong(1, d);
castBytes[1] = (byte)(d >> 56);
castBytes[2] = (byte)(d >> 48);
castBytes[3] = (byte)(d >> 40);
castBytes[4] = (byte)(d >> 32);
castBytes[5] = (byte)(d >> 24);
castBytes[6] = (byte)(d >> 16);
castBytes[7] = (byte)(d >> 8);
castBytes[8] = (byte)(d >> 0);
out.write(castBytes, 0, 9);
}
}
@@ -194,16 +244,51 @@ public class Packer {
return this;
}
public Packer packBigInteger(BigInteger d) throws IOException {
if(d.bitLength() <= 63) {
return packLong(d.longValue());
} else if(d.bitLength() <= 64 && d.signum() >= 0) {
castBytes[0] = (byte)0xcf;
byte[] barray = d.toByteArray();
castBytes[1] = barray[barray.length-8];
castBytes[2] = barray[barray.length-7];
castBytes[3] = barray[barray.length-6];
castBytes[4] = barray[barray.length-5];
castBytes[5] = barray[barray.length-4];
castBytes[6] = barray[barray.length-3];
castBytes[7] = barray[barray.length-2];
castBytes[8] = barray[barray.length-1];
out.write(castBytes, 0, 9);
return this;
} else {
throw new MessageTypeException("can't pack BigInteger larger than 0xffffffffffffffff");
}
}
public Packer packFloat(float d) throws IOException {
castBytes[0] = (byte)0xca;
castBuffer.putFloat(1, d);
// castBuffer.putFloat(1, d);
int f = Float.floatToRawIntBits(d);
castBytes[1] = (byte)(f >> 24);
castBytes[2] = (byte)(f >> 16);
castBytes[3] = (byte)(f >> 8);
castBytes[4] = (byte)(f >> 0);
out.write(castBytes, 0, 5);
return this;
}
public Packer packDouble(double d) throws IOException {
castBytes[0] = (byte)0xcb;
castBuffer.putDouble(1, d);
// castBuffer.putDouble(1, d);
long f = Double.doubleToRawLongBits(d);
castBytes[1] = (byte)(f >> 56);
castBytes[2] = (byte)(f >> 48);
castBytes[3] = (byte)(f >> 40);
castBytes[4] = (byte)(f >> 32);
castBytes[5] = (byte)(f >> 24);
castBytes[6] = (byte)(f >> 16);
castBytes[7] = (byte)(f >> 8);
castBytes[8] = (byte)(f >> 0);
out.write(castBytes, 0, 9);
return this;
}
@@ -233,11 +318,17 @@ public class Packer {
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xdc;
castBuffer.putShort(1, (short)n);
// castBuffer.putShort(1, (short)n);
castBytes[1] = (byte)(n >> 8);
castBytes[2] = (byte)(n >> 0);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdd;
castBuffer.putInt(1, n);
// castBuffer.putInt(1, n);
castBytes[1] = (byte)(n >> 24);
castBytes[2] = (byte)(n >> 16);
castBytes[3] = (byte)(n >> 8);
castBytes[4] = (byte)(n >> 0);
out.write(castBytes, 0, 5);
}
return this;
@@ -249,11 +340,17 @@ public class Packer {
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xde;
castBuffer.putShort(1, (short)n);
// castBuffer.putShort(1, (short)n);
castBytes[1] = (byte)(n >> 8);
castBytes[2] = (byte)(n >> 0);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdf;
castBuffer.putInt(1, n);
// castBuffer.putInt(1, n);
castBytes[1] = (byte)(n >> 24);
castBytes[2] = (byte)(n >> 16);
castBytes[3] = (byte)(n >> 8);
castBytes[4] = (byte)(n >> 0);
out.write(castBytes, 0, 5);
}
return this;
@@ -265,11 +362,17 @@ public class Packer {
out.write((byte)d);
} else if(n < 65536) {
castBytes[0] = (byte)0xda;
castBuffer.putShort(1, (short)n);
// castBuffer.putShort(1, (short)n);
castBytes[1] = (byte)(n >> 8);
castBytes[2] = (byte)(n >> 0);
out.write(castBytes, 0, 3);
} else {
castBytes[0] = (byte)0xdb;
castBuffer.putInt(1, n);
// castBuffer.putInt(1, n);
castBytes[1] = (byte)(n >> 24);
castBytes[2] = (byte)(n >> 16);
castBytes[3] = (byte)(n >> 8);
castBytes[4] = (byte)(n >> 0);
out.write(castBytes, 0, 5);
}
return this;
@@ -286,11 +389,20 @@ public class Packer {
}
public Packer packWithSchema(Object o, Schema s) throws IOException {
s.pack(this, o);
return this;
public Packer packByteArray(byte[] b) throws IOException {
packRaw(b.length);
return packRawBody(b, 0, b.length);
}
public Packer packByteArray(byte[] b, int off, int length) throws IOException {
packRaw(length);
return packRawBody(b, off, length);
}
public Packer packByteBuffer(ByteBuffer buf) throws IOException {
packRaw(buf.remaining());
return packRawBody(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining());
}
public Packer packString(String s) throws IOException {
byte[] b = ((String)s).getBytes("UTF-8");
@@ -299,39 +411,36 @@ public class Packer {
}
public Packer pack(String o) throws IOException {
if(o == null) { return packNil(); }
return packString(o);
}
public Packer pack(MessagePackable o) throws IOException {
if(o == null) { return packNil(); }
o.messagePack(this);
return this;
}
public Packer pack(byte[] o) throws IOException {
if(o == null) { return packNil(); }
packRaw(o.length);
return packRawBody(o);
}
public Packer pack(List o) throws IOException {
if(o == null) { return packNil(); }
packArray(o.size());
for(Object i : o) { pack(i); }
return this;
}
@SuppressWarnings("unchecked")
public Packer pack(Map o) throws IOException {
if(o == null) { return packNil(); }
packMap(o.size());
for(Map.Entry e : ((Map<Object,Object>)o).entrySet()) {
pack(e.getKey());
pack(e.getValue());
public Packer pack(boolean o) throws IOException {
if(o) {
return packTrue();
} else {
return packFalse();
}
return this;
}
public Packer pack(byte o) throws IOException {
return packByte(o);
}
public Packer pack(short o) throws IOException {
return packShort(o);
}
public Packer pack(int o) throws IOException {
return packInt(o);
}
public Packer pack(long o) throws IOException {
return packLong(o);
}
public Packer pack(float o) throws IOException {
return packFloat(o);
}
public Packer pack(double o) throws IOException {
return packDouble(o);
}
public Packer pack(Boolean o) throws IOException {
@@ -363,6 +472,11 @@ public class Packer {
return packLong(o);
}
public Packer pack(BigInteger o) throws IOException {
if(o == null) { return packNil(); }
return packBigInteger(o);
}
public Packer pack(Float o) throws IOException {
if(o == null) { return packNil(); }
return packFloat(o);
@@ -373,56 +487,55 @@ public class Packer {
return packDouble(o);
}
public Packer pack(String o) throws IOException {
if(o == null) { return packNil(); }
return packString(o);
}
@SuppressWarnings("unchecked")
public Packer pack(Object o) throws IOException {
if(o == null) {
return packNil();
} else if(o instanceof String) {
byte[] b = ((String)o).getBytes("UTF-8");
packRaw(b.length);
return packRawBody(b);
} else if(o instanceof MessagePackable) {
((MessagePackable)o).messagePack(this);
return this;
} else if(o instanceof byte[]) {
byte[] b = (byte[])o;
packRaw(b.length);
return packRawBody(b);
} else if(o instanceof List) {
List<Object> l = (List<Object>)o;
packArray(l.size());
for(Object i : l) { pack(i); }
return this;
} else if(o instanceof Map) {
Map<Object,Object> m = (Map<Object,Object>)o;
packMap(m.size());
for(Map.Entry e : m.entrySet()) {
pack(e.getKey());
pack(e.getValue());
}
return this;
} else if(o instanceof Boolean) {
if((Boolean)o) {
return packTrue();
} else {
return packFalse();
}
} else if(o instanceof Integer) {
return packInt((Integer)o);
} else if(o instanceof Long) {
return packLong((Long)o);
} else if(o instanceof Short) {
return packShort((Short)o);
} else if(o instanceof Byte) {
return packByte((Byte)o);
} else if(o instanceof Float) {
return packFloat((Float)o);
} else if(o instanceof Double) {
return packDouble((Double)o);
} else {
throw new MessageTypeException("unknown object "+o+" ("+o.getClass()+")");
public Packer pack(byte[] o) throws IOException {
if(o == null) { return packNil(); }
packRaw(o.length);
return packRawBody(o);
}
public Packer pack(ByteBuffer o) throws IOException {
if (o == null) { return packNil(); }
packRaw(o.remaining());
return packRawBody(o.array(), o.arrayOffset() + o.position(), o.remaining());
}
public Packer pack(List o) throws IOException {
if(o == null) { return packNil(); }
packArray(o.size());
for(Object i : o) { pack(i); }
return this;
}
public Packer pack(Map o) throws IOException {
if(o == null) { return packNil(); }
packMap(o.size());
for(Map.Entry<Object,Object> e : ((Map<Object,Object>)o).entrySet()) {
pack(e.getKey());
pack(e.getValue());
}
return this;
}
public Packer pack(MessagePackable o) throws IOException {
if(o == null) { return packNil(); }
o.messagePack(this);
return this;
}
public Packer pack(Object o) throws IOException {
if(o == null) { return packNil(); }
TemplateRegistry.lookup(o.getClass()).pack(this, o);
return this;
}
public Packer pack(Object o, Template tmpl) throws IOException {
tmpl.pack(this, o);
return this;
}
}

View File

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

View File

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

View File

@@ -0,0 +1,119 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
import org.msgpack.template.*;
public class Templates {
public static Template tNullable(Template elementTemplate) {
return new NullableTemplate(elementTemplate);
}
public static final Template TAny = AnyTemplate.getInstance();
public static Template tAny() {
return TAny;
}
public static Template tList(Template elementTemplate) {
return new ListTemplate(elementTemplate);
}
public static Template tMap(Template keyTemplate, Template valueTemplate) {
return new MapTemplate(keyTemplate, valueTemplate);
}
public static Template tCollection(Template elementTemplate) {
return new CollectionTemplate(elementTemplate);
}
public static Template tClass(Class target) {
Template tmpl = TemplateRegistry.lookup(target);
if(tmpl == null) {
// FIXME
}
return tmpl;
}
public static final Template TByte = ByteTemplate.getInstance();
public static Template tByte() {
return TByte;
}
public static final Template TShort = ShortTemplate.getInstance();
public static Template tShort() {
return TShort;
}
public static final Template TInteger = IntegerTemplate.getInstance();
public static Template tInteger() {
return TInteger;
}
public static final Template TLong = LongTemplate.getInstance();
public static Template tLong() {
return TLong;
}
public static final Template TBigInteger = BigIntegerTemplate.getInstance();
public static Template tBigInteger() {
return TBigInteger;
}
public static final Template TBigDecimal = BigDecimalTemplate.getInstance();
public static Template tBigDecimal() {
return TBigDecimal;
}
public static final Template TFloat = FloatTemplate.getInstance();
public static Template tFloat() {
return TFloat;
}
public static final Template TDouble = DoubleTemplate.getInstance();
public static Template tDouble() {
return TDouble;
}
public static final Template TBoolean = BooleanTemplate.getInstance();
public static Template tBoolean() {
return TBoolean;
}
public static final Template TString = StringTemplate.getInstance();
public static Template tString() {
return TString;
}
public static final Template TByteArray = ByteArrayTemplate.getInstance();
public static Template tByteArray() {
return TByteArray;
}
public static final Template TByteBuffer = ByteBufferTemplate.getInstance();
public static Template tByteBuffer() {
return TByteBuffer;
}
public static final Template TDate = DateTemplate.getInstance();
public static Template tDate() {
return TDate;
}
}

View File

@@ -21,7 +21,7 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class UnpackIterator extends UnpackResult implements Iterator<Object> {
public class UnpackIterator extends UnpackResult implements Iterator<MessagePackObject> {
private Unpacker pac;
UnpackIterator(Unpacker pac) {
@@ -38,7 +38,7 @@ public class UnpackIterator extends UnpackResult implements Iterator<Object> {
}
}
public Object next() {
public MessagePackObject next() {
if(!finished && !hasNext()) {
throw new NoSuchElementException();
}

View File

@@ -19,13 +19,13 @@ package org.msgpack;
public class UnpackResult {
protected boolean finished = false;
protected Object data = null;
protected MessagePackObject data = null;
public boolean isFinished() {
return finished;
}
public Object getData() {
public MessagePackObject getData() {
return data;
}
@@ -34,7 +34,7 @@ public class UnpackResult {
data = null;
}
void done(Object obj) {
void done(MessagePackObject obj) {
finished = true;
data = obj;
}

View File

@@ -22,12 +22,14 @@ import java.io.InputStream;
import java.io.IOException;
import java.util.Iterator;
import java.nio.ByteBuffer;
import java.math.BigInteger;
import org.msgpack.template.TemplateRegistry;
/**
* Unpacker enables you to deserialize objects from stream.
*
* Unpacker provides Buffered API, Unbuffered API, Schema API
* and Direct Conversion API.
* Unpacker provides Buffered API, Unbuffered API and
* Direct Conversion API.
*
* Buffered API uses the internal buffer of the Unpacker.
* Following code uses Buffered API with an InputStream:
@@ -39,7 +41,7 @@ import java.nio.ByteBuffer;
* UnpackResult result = pac.next();
*
* // use an iterator.
* for(Object obj : pac) {
* for(MessagePackObject obj : pac) {
* // use MessageConvertable interface to convert the
* // the generic object to the specific type.
* }
@@ -56,7 +58,7 @@ import java.nio.ByteBuffer;
* pac.feed(input_bytes);
*
* // use next() method or iterators.
* for(Object obj : pac) {
* for(MessagePackObject obj : pac) {
* // ...
* }
* </pre>
@@ -75,7 +77,7 @@ import java.nio.ByteBuffer;
* System.in.read(pac.getBuffer(), pac.getBufferOffset(), pac.getBufferCapacity());
*
* // use next() method or iterators.
* for(Object obj : pac) {
* for(MessagePackObject obj : pac) {
* // ...
* }
* </pre>
@@ -96,13 +98,12 @@ import java.nio.ByteBuffer;
*
* // take out object if deserialized object is ready.
* if(pac.isFinished()) {
* Object obj = pac.getData();
* MessagePackObject obj = pac.getData();
* // ...
* }
* </pre>
*/
public class Unpacker implements Iterable<Object> {
public class Unpacker implements Iterable<MessagePackObject> {
// buffer:
// +---------------------------------------------+
// | [object] | [obje| unparsed ... | unused ...|
@@ -170,16 +171,6 @@ public class Unpacker implements Iterable<Object> {
this.stream = stream;
}
/**
* Sets schema to convert deserialized object into specific type.
* Default schema is {@link GenericSchema} that leaves objects for generic type. Use {@link MessageConvertable#messageConvert(Object)} method to convert the generic object.
* @param s schem to use
*/
public Unpacker useSchema(Schema s) {
impl.setSchema(s);
return this;
}
/**
* Gets the input stream.
@@ -241,6 +232,7 @@ public class Unpacker implements Iterable<Object> {
impl.buffer = buffer;
impl.offset = offset;
impl.filled = length;
impl.bufferReferenced = false; // TODO zero-copy buffer
}
/**
@@ -255,7 +247,7 @@ public class Unpacker implements Iterable<Object> {
/**
* Returns the iterator that calls {@link next()} method repeatedly.
*/
public Iterator<Object> iterator() {
public Iterator<MessagePackObject> iterator() {
return new UnpackIterator(this);
}
@@ -285,13 +277,16 @@ public class Unpacker implements Iterable<Object> {
if(impl.buffer == null) {
int nextSize = (bufferReserveSize < require) ? require : bufferReserveSize;
impl.buffer = new byte[nextSize];
impl.bufferReferenced = false; // TODO zero-copy buffer
return;
}
if(impl.filled <= impl.offset) {
// rewind the buffer
impl.filled = 0;
impl.offset = 0;
if(!impl.bufferReferenced) { // TODO zero-copy buffer
if(impl.filled <= impl.offset) {
// rewind the buffer
impl.filled = 0;
impl.offset = 0;
}
}
if(impl.buffer.length - impl.filled >= require) {
@@ -310,6 +305,7 @@ public class Unpacker implements Iterable<Object> {
impl.buffer = tmp;
impl.filled = notParsed;
impl.offset = 0;
impl.bufferReferenced = false; // TODO zero-copy buffer
}
/**
@@ -376,8 +372,7 @@ public class Unpacker implements Iterable<Object> {
* @return offset position that is parsed.
*/
public int execute(byte[] buffer, int offset, int length) throws UnpackException {
int noffset = impl.execute(buffer, offset + impl.offset, length);
impl.offset = noffset - offset;
int noffset = impl.execute(buffer, offset, length);
if(impl.isFinished()) {
impl.resetState();
}
@@ -387,7 +382,7 @@ public class Unpacker implements Iterable<Object> {
/**
* Gets the object deserialized by {@link execute(byte[])} method.
*/
public Object getData() {
public MessagePackObject getData() {
return impl.getData();
}
@@ -462,6 +457,15 @@ public class Unpacker implements Iterable<Object> {
return impl.unpackLong();
}
/**
* Gets one {@code BigInteger} value from the buffer.
* This method calls {@link fill()} method if needed.
* @throws MessageTypeException the first value of the buffer is not a {@code BigInteger}.
*/
public BigInteger unpackBigInteger() throws IOException, MessageTypeException {
return impl.unpackBigInteger();
}
/**
* Gets one {@code float} value from the buffer.
* This method calls {@link fill()} method if needed.
@@ -536,14 +540,23 @@ public class Unpacker implements Iterable<Object> {
return impl.unpackRawBody(length);
}
/**
* Gets one raw bytes from the buffer.
* Gets one raw object (header + body) from the buffer.
* This method calls {@link fill()} method if needed.
*/
public byte[] unpackByteArray() throws IOException {
return impl.unpackByteArray();
}
/**
* Gets one raw object (header + body) from the buffer.
* This method calls {@link fill()} method if needed.
*/
public ByteBuffer unpackByteBuffer() throws IOException {
return impl.unpackByteBuffer();
}
/**
* Gets one {@code String} value from the buffer.
* This method calls {@link fill()} method if needed.
@@ -557,16 +570,41 @@ public class Unpacker implements Iterable<Object> {
* Gets one {@code Object} value from the buffer.
* This method calls {@link fill()} method if needed.
*/
final public Object unpackObject() throws IOException {
final public MessagePackObject unpackObject() throws IOException {
return impl.unpackObject();
}
final public boolean tryUnpackNull() throws IOException {
return impl.tryUnpackNull();
}
final public void unpack(MessageUnpackable obj) throws IOException, MessageTypeException {
obj.messageUnpack(this);
}
final public boolean tryUnpackNull() throws IOException {
return impl.tryUnpackNull();
//final public MessagePackObject unpack() throws IOException {
// return unpackObject();
//}
final public <T> T unpack(T to) throws IOException, MessageTypeException {
return unpack((Class<T>)to.getClass(), to);
}
final public <T> T unpack(Class<T> klass) throws IOException, MessageTypeException {
return unpack(klass, null);
}
final public <T> T unpack(Class<T> klass, T to) throws IOException, MessageTypeException {
if(tryUnpackNull()) { return null; }
return (T)TemplateRegistry.lookup(klass).unpack(this, to);
}
final public Object unpack(Template tmpl) throws IOException, MessageTypeException {
return unpack(tmpl, null);
}
final public <T> T unpack(Template tmpl, T to) throws IOException, MessageTypeException {
return (T)tmpl.unpack(this, to);
}
}

View File

@@ -18,11 +18,8 @@
package org.msgpack;
import java.nio.ByteBuffer;
//import java.math.BigInteger;
import org.msgpack.*;
import org.msgpack.schema.GenericSchema;
import org.msgpack.schema.IMapSchema;
import org.msgpack.schema.IArraySchema;
import java.math.BigInteger;
import org.msgpack.object.*;
public class UnpackerImpl {
static final int CS_HEADER = 0x00;
@@ -55,30 +52,19 @@ public class UnpackerImpl {
private int[] stack_ct = new int[MAX_STACK_SIZE];
private int[] stack_count = new int[MAX_STACK_SIZE];
private Object[] stack_obj = new Object[MAX_STACK_SIZE];
private Schema[] stack_schema = new Schema[MAX_STACK_SIZE];
private int top_ct;
private int top_count;
private Object top_obj;
private Schema top_schema;
private ByteBuffer castBuffer = ByteBuffer.allocate(8);
private boolean finished = false;
private Object data = null;
private static final Schema GENERIC_SCHEMA = new GenericSchema();
private Schema rootSchema;
private MessagePackObject data = null;
public UnpackerImpl()
{
setSchema(GENERIC_SCHEMA);
}
public void setSchema(Schema schema)
{
this.rootSchema = schema;
reset();
}
public final Object getData()
public final MessagePackObject getData()
{
return data;
}
@@ -94,7 +80,6 @@ public class UnpackerImpl {
top_ct = 0;
top_count = 0;
top_obj = null;
top_schema = rootSchema;
}
public final void reset()
@@ -127,20 +112,20 @@ public class UnpackerImpl {
if((b & 0x80) == 0) { // Positive Fixnum
//System.out.println("positive fixnum "+b);
obj = top_schema.createFromByte((byte)b);
obj = IntegerType.create((byte)b);
break _push;
}
if((b & 0xe0) == 0xe0) { // Negative Fixnum
//System.out.println("negative fixnum "+b);
obj = top_schema.createFromByte((byte)b);
obj = IntegerType.create((byte)b);
break _push;
}
if((b & 0xe0) == 0xa0) { // FixRaw
trail = b & 0x1f;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
obj = RawType.create(new byte[0]);
break _push;
}
cs = ACS_RAW_VALUE;
@@ -151,25 +136,20 @@ public class UnpackerImpl {
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
count = b & 0x0f;
//System.out.println("fixarray count:"+count);
obj = new Object[count];
obj = new MessagePackObject[count];
if(count == 0) {
obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
obj = ArrayType.create((MessagePackObject[])obj);
break _push;
}
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
}
@@ -177,13 +157,10 @@ public class UnpackerImpl {
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
count = b & 0x0f;
obj = new Object[count*2];
obj = new MessagePackObject[count*2];
if(count == 0) {
obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
obj = MapType.create((MessagePackObject[])obj);
break _push;
}
//System.out.println("fixmap count:"+count);
@@ -191,23 +168,21 @@ public class UnpackerImpl {
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
}
switch(b & 0xff) { // FIXME
case 0xc0: // nil
obj = top_schema.createFromNil();
obj = NilType.create();
break _push;
case 0xc2: // false
obj = top_schema.createFromBoolean(false);
obj = BooleanType.create(false);
break _push;
case 0xc3: // true
obj = top_schema.createFromBoolean(true);
obj = BooleanType.create(true);
break _push;
case 0xca: // float
case 0xcb: // double
@@ -251,13 +226,13 @@ public class UnpackerImpl {
case CS_FLOAT:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromFloat( castBuffer.getFloat(0) );
obj = FloatType.create( castBuffer.getFloat(0) );
//System.out.println("float "+obj);
break _push;
case CS_DOUBLE:
castBuffer.rewind();
castBuffer.put(src, n, 8);
obj = top_schema.createFromDouble( castBuffer.getDouble(0) );
obj = FloatType.create( castBuffer.getDouble(0) );
//System.out.println("double "+obj);
break _push;
case CS_UINT_8:
@@ -265,7 +240,7 @@ public class UnpackerImpl {
//System.out.println(src[n]);
//System.out.println(src[n+1]);
//System.out.println(src[n-1]);
obj = top_schema.createFromShort( (short)((src[n]) & 0xff) );
obj = IntegerType.create( (short)((src[n]) & 0xff) );
//System.out.println("uint8 "+obj);
break _push;
case CS_UINT_16:
@@ -273,13 +248,13 @@ public class UnpackerImpl {
//System.out.println(src[n+1]);
castBuffer.rewind();
castBuffer.put(src, n, 2);
obj = top_schema.createFromInt( ((int)castBuffer.getShort(0)) & 0xffff );
obj = IntegerType.create( ((int)castBuffer.getShort(0)) & 0xffff );
//System.out.println("uint 16 "+obj);
break _push;
case CS_UINT_32:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromLong( ((long)castBuffer.getInt(0)) & 0xffffffffL );
obj = IntegerType.create( ((long)castBuffer.getInt(0)) & 0xffffffffL );
//System.out.println("uint 32 "+obj);
break _push;
case CS_UINT_64:
@@ -288,38 +263,36 @@ public class UnpackerImpl {
{
long o = castBuffer.getLong(0);
if(o < 0) {
// FIXME
//obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31);
throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported");
obj = IntegerType.create(new BigInteger(1, castBuffer.array()));
} else {
obj = top_schema.createFromLong( o );
obj = IntegerType.create(o);
}
}
break _push;
case CS_INT_8:
obj = top_schema.createFromByte( src[n] );
obj = IntegerType.create( src[n] );
break _push;
case CS_INT_16:
castBuffer.rewind();
castBuffer.put(src, n, 2);
obj = top_schema.createFromShort( castBuffer.getShort(0) );
obj = IntegerType.create( castBuffer.getShort(0) );
break _push;
case CS_INT_32:
castBuffer.rewind();
castBuffer.put(src, n, 4);
obj = top_schema.createFromInt( castBuffer.getInt(0) );
obj = IntegerType.create( castBuffer.getInt(0) );
break _push;
case CS_INT_64:
castBuffer.rewind();
castBuffer.put(src, n, 8);
obj = top_schema.createFromLong( castBuffer.getLong(0) );
obj = IntegerType.create( castBuffer.getLong(0) );
break _push;
case CS_RAW_16:
castBuffer.rewind();
castBuffer.put(src, n, 2);
trail = ((int)castBuffer.getShort(0)) & 0xffff;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
obj = RawType.create(new byte[0]);
break _push;
}
cs = ACS_RAW_VALUE;
@@ -330,77 +303,69 @@ public class UnpackerImpl {
// FIXME overflow check
trail = castBuffer.getInt(0) & 0x7fffffff;
if(trail == 0) {
obj = top_schema.createFromRaw(new byte[0], 0, 0);
obj = RawType.create(new byte[0]);
break _push;
}
cs = ACS_RAW_VALUE;
case ACS_RAW_VALUE:
obj = top_schema.createFromRaw(src, n, trail);
break _fixed_trail_again;
case ACS_RAW_VALUE: {
// TODO zero-copy buffer
byte[] raw = new byte[trail];
System.arraycopy(src, n, raw, 0, trail);
obj = RawType.create(raw);
}
break _push;
case CS_ARRAY_16:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 2);
count = ((int)castBuffer.getShort(0)) & 0xffff;
obj = new Object[count];
obj = new MessagePackObject[count];
if(count == 0) {
obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
obj = ArrayType.create((MessagePackObject[])obj);
break _push;
}
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
case CS_ARRAY_32:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IArraySchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 4);
// FIXME overflow check
count = castBuffer.getInt(0) & 0x7fffffff;
obj = new Object[count];
obj = new MessagePackObject[count];
if(count == 0) {
obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
obj = ArrayType.create((MessagePackObject[])obj);
break _push;
}
++top;
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_ARRAY_ITEM;
top_count = count;
top_schema = ((IArraySchema)top_schema).getElementSchema(0);
break _header_again;
case CS_MAP_16:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 2);
count = ((int)castBuffer.getShort(0)) & 0xffff;
obj = new Object[count*2];
obj = new MessagePackObject[count*2];
if(count == 0) {
obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
obj = MapType.create((MessagePackObject[])obj);
break _push;
}
//System.out.println("fixmap count:"+count);
@@ -408,26 +373,21 @@ public class UnpackerImpl {
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
case CS_MAP_32:
if(top >= MAX_STACK_SIZE) {
throw new UnpackException("parse error");
}
if(!(top_schema instanceof IMapSchema)) {
throw new RuntimeException("type error");
}
castBuffer.rewind();
castBuffer.put(src, n, 4);
// FIXME overflow check
count = castBuffer.getInt(0) & 0x7fffffff;
obj = new Object[count*2];
obj = new MessagePackObject[count*2];
if(count == 0) {
obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
obj = MapType.create((MessagePackObject[])obj);
break _push;
}
//System.out.println("fixmap count:"+count);
@@ -435,11 +395,9 @@ public class UnpackerImpl {
stack_obj[top] = top_obj;
stack_ct[top] = top_ct;
stack_count[top] = top_count;
stack_schema[top] = top_schema;
top_obj = obj;
top_ct = CT_MAP_KEY;
top_count = count;
top_schema = ((IMapSchema)top_schema).getKeySchema();
break _header_again;
default:
throw new UnpackException("parse error");
@@ -454,7 +412,7 @@ public class UnpackerImpl {
//System.out.println("push top:"+top);
if(top == -1) {
++i;
data = obj;
data = (MessagePackObject)obj;
finished = true;
break _out;
}
@@ -468,14 +426,10 @@ public class UnpackerImpl {
top_obj = stack_obj[top];
top_ct = stack_ct[top];
top_count = stack_count[top];
top_schema = stack_schema[top];
obj = ((IArraySchema)top_schema).createFromArray(ar);
obj = ArrayType.create((MessagePackObject[])ar);
stack_obj[top] = null;
stack_schema[top] = null;
--top;
break _push;
} else {
top_schema = ((IArraySchema)stack_schema[top]).getElementSchema(ar.length - top_count);
}
break _header_again;
}
@@ -484,7 +438,6 @@ public class UnpackerImpl {
Object[] mp = (Object[])top_obj;
mp[mp.length - top_count*2] = obj;
top_ct = CT_MAP_VALUE;
top_schema = ((IMapSchema)stack_schema[top]).getValueSchema();
break _header_again;
}
case CT_MAP_VALUE: {
@@ -495,10 +448,8 @@ public class UnpackerImpl {
top_obj = stack_obj[top];
top_ct = stack_ct[top];
top_count = stack_count[top];
top_schema = stack_schema[top];
obj = ((IMapSchema)top_schema).createFromMap(mp);
obj = MapType.create((MessagePackObject[])mp);
stack_obj[top] = null;
stack_schema[top] = null;
--top;
break _push;
}

View File

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

View File

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

View File

@@ -0,0 +1,35 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.msgpack.template.FieldOption;
/**
* Annotation for java beans class
* @author takeshita
*
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MessagePackBeans {
FieldOption value() default FieldOption.DEFAULT;
}

View File

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

View File

@@ -0,0 +1,30 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.msgpack.template.FieldOption;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MessagePackMessage {
FieldOption value() default FieldOption.DEFAULT;
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,462 @@
//
// MessagePack for Java
//
// Copyright (C) 2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.buffer;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.nio.ByteBuffer;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
public class VectoredByteBuffer implements GatheringByteChannel, ScatteringByteChannel {
private List<ByteBuffer> vec = new ArrayList<ByteBuffer>();
private ByteBuffer internalBuffer;
private ByteBuffer lastInternalBuffer;
private int chunkSize;
private int referenceThreshold;
public VectoredByteBuffer() {
this(32*1024);
}
public VectoredByteBuffer(int chunkSize) {
this(chunkSize, 32);
}
public VectoredByteBuffer(int chunkSize, int referenceThreshold) {
this.chunkSize = chunkSize;
this.referenceThreshold = referenceThreshold;
internalBuffer = ByteBuffer.allocateDirect(chunkSize);
}
public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
public int getChunkSize(int chunkSize) {
return this.chunkSize;
}
public void setReferenceThreshold(int referenceThreshold) {
this.referenceThreshold = referenceThreshold;
}
public int getReferenceThreshold(int referenceThreshold) {
return this.referenceThreshold;
}
@Override
public void close() {
reset();
}
@Override
public boolean isOpen() {
return true; // FIXME?
}
public synchronized void reset() {
vec.clear();
lastInternalBuffer = null;
}
public void write(byte[] b) {
write(b, 0, b.length);
}
public void write(byte[] b, int off, int len) {
if(off < 0 || len < 0 || b.length < off+len) {
throw new IndexOutOfBoundsException();
}
if(referenceThreshold >= 0 && len > referenceThreshold) {
writeReference(b, off, len);
} else {
writeCopy(b, off, len);
}
}
public void write(int b) {
byte[] ba = new byte[1];
ba[0] = (byte)b;
write(ba);
}
@Override
public int write(ByteBuffer src) {
int slen = src.remaining();
if(referenceThreshold >= 0 && slen > referenceThreshold) {
writeCopy(src);
} else {
writeReference(src);
}
return slen;
}
@Override
public synchronized long write(ByteBuffer[] srcs) {
return write(srcs, 0, srcs.length);
}
@Override
public synchronized long write(ByteBuffer[] srcs, int offset, int length) {
if(offset < 0 || length < 0 || srcs.length < offset+length) {
throw new IndexOutOfBoundsException();
}
long total = 0;
for(int i=offset; offset < length; offset++) {
ByteBuffer src = srcs[i];
total += write(src);
}
return total;
}
private synchronized void writeCopy(byte[] b, int off, int len) {
int ipos = internalBuffer.position();
if(internalBuffer.capacity() - ipos < len) {
// allocate new buffer
int nsize = chunkSize > len ? chunkSize : len;
internalBuffer = ByteBuffer.allocateDirect(nsize);
ipos = 0;
} else if(internalBuffer == lastInternalBuffer) {
// optimization: concatenates to the last buffer instead
// of adding new reference
ByteBuffer dup = vec.get(vec.size()-1);
internalBuffer.put(b, off, len);
dup.limit(ipos + len);
return;
}
internalBuffer.put(b, off, len);
ByteBuffer dup = internalBuffer.duplicate();
dup.position(ipos);
dup.mark();
dup.limit(ipos + len);
vec.add(dup);
lastInternalBuffer = internalBuffer;
}
private synchronized void writeCopy(ByteBuffer src) {
int slen = src.remaining();
int ipos = internalBuffer.position();
if(internalBuffer.capacity() - ipos < slen) {
// allocate new buffer
int nsize = chunkSize > slen ? chunkSize : slen;
internalBuffer = ByteBuffer.allocateDirect(nsize);
ipos = 0;
} else if(internalBuffer == lastInternalBuffer) {
// optimization: concatenates to the last buffer instead
// of adding new reference
ByteBuffer dup = vec.get(vec.size()-1);
int dpos = dup.position();
internalBuffer.put(src);
ByteBuffer dup2 = internalBuffer.duplicate();
dup2.position(dpos);
dup2.limit(ipos + slen);
vec.set(vec.size()-1, dup2);
return;
}
internalBuffer.put(src);
ByteBuffer dup = internalBuffer.duplicate();
dup.position(ipos);
dup.mark();
dup.limit(ipos + slen);
vec.add(dup);
lastInternalBuffer = internalBuffer;
}
private synchronized void writeReference(byte[] b, int off, int len) {
ByteBuffer buf = ByteBuffer.wrap(b, off, len);
vec.add(buf);
lastInternalBuffer = null;
}
private synchronized void writeReference(ByteBuffer src) {
ByteBuffer buf = src.duplicate();
vec.add(buf);
lastInternalBuffer = null;
}
public synchronized void writeTo(java.io.OutputStream out) throws IOException {
byte[] tmpbuf = null;
for(int i=0; i < vec.size(); i++) {
ByteBuffer r = vec.get(i);
int rpos = r.position();
int rlen = r.limit() - rpos;
if(r.hasArray()) {
byte[] array = r.array();
out.write(array, rpos, rlen);
} else {
if(tmpbuf == null) {
int max = rlen;
for(int j=i+1; j < vec.size(); j++) {
ByteBuffer c = vec.get(j);
int clen = c.remaining();
if(max < clen) {
max = clen;
}
}
tmpbuf = new byte[max];
}
r.get(tmpbuf, 0, rlen);
r.position(rpos);
out.write(tmpbuf, 0, rlen);
}
}
}
public synchronized byte[] toByteArray() {
byte[] out = new byte[available()];
int off = 0;
for(ByteBuffer r: vec) {
int rpos = r.position();
int rlen = r.limit() - rpos;
r.get(out, off, rlen);
r.position(rpos);
off += rlen;
}
return out;
}
public synchronized int available() {
int total = 0;
for(ByteBuffer r : vec) {
total += r.remaining();
}
return total;
}
public synchronized int read(byte[] b) {
return read(b, 0, b.length);
}
public synchronized int read(byte[] b, int off, int len) {
if(off < 0 || len < 0 || b.length < off+len) {
throw new IndexOutOfBoundsException();
}
int start = len;
while(!vec.isEmpty()) {
ByteBuffer r = vec.get(0);
int rlen = r.remaining();
if(rlen <= len) {
r.get(b, off, rlen);
vec.remove(0);
off += rlen;
len -= rlen;
} else {
r.get(b, off, len);
return start;
}
}
return start - len;
}
public synchronized int read() {
byte[] ba = new byte[1];
if(read(ba) >= 1) {
return ba[0];
} else {
return -1;
}
}
@Override
public synchronized int read(ByteBuffer dst) {
int len = dst.remaining();
int start = len;
while(!vec.isEmpty()) {
ByteBuffer r = vec.get(0);
int rlen = r.remaining();
if(rlen <= len) {
dst.put(r);
vec.remove(0);
len -= rlen;
} else {
int blim = r.limit();
r.limit(len);
try {
dst.put(r);
} finally {
r.limit(blim);
}
return start;
}
}
return start - len;
}
@Override
public synchronized long read(ByteBuffer[] dsts) {
return read(dsts, 0, dsts.length);
}
@Override
public synchronized long read(ByteBuffer[] dsts, int offset, int length) {
if(offset < 0 || length < 0 || dsts.length < offset+length) {
throw new IndexOutOfBoundsException();
}
long total = 0;
for(int i=offset; i < length; i++) {
ByteBuffer dst = dsts[i];
int dlen = dst.remaining();
int rlen = read(dsts[i]);
total += rlen;
if(rlen < dlen) {
return total;
}
}
return total;
}
public synchronized long read(GatheringByteChannel to) throws IOException {
long total = to.write(vec.toArray(new ByteBuffer[0]));
while(!vec.isEmpty()) {
ByteBuffer r = vec.get(0);
if(r.remaining() == 0) {
vec.remove(0);
} else {
break;
}
}
return total;
}
public synchronized long skip(long len) {
if(len <= 0) {
return 0;
}
long start = len;
while(!vec.isEmpty()) {
ByteBuffer r = vec.get(0);
int rlen = r.remaining();
if(rlen <= len) {
r.position(r.position()+rlen);
vec.remove(0);
len -= rlen;
} else {
r.position((int)(r.position()+len));
return start;
}
}
return start - len;
}
public final static class OutputStream extends java.io.OutputStream {
private VectoredByteBuffer vbb;
OutputStream(VectoredByteBuffer vbb) {
this.vbb = vbb;
}
@Override
public void write(byte[] b) {
vbb.write(b);
}
@Override
public void write(byte[] b, int off, int len) {
vbb.write(b, off, len);
}
@Override
public void write(int b) {
vbb.write(b);
}
public int write(ByteBuffer src) {
return vbb.write(src);
}
public long write(ByteBuffer[] srcs) {
return vbb.write(srcs);
}
public long write(ByteBuffer[] srcs, int offset, int length) {
return vbb.write(srcs, offset, length);
}
public void writeTo(OutputStream out) throws IOException {
vbb.writeTo(out);
}
public byte[] toByteArray() {
return vbb.toByteArray();
}
}
public final static class InputStream extends java.io.InputStream {
private VectoredByteBuffer vbb;
InputStream(VectoredByteBuffer vbb) {
this.vbb = vbb;
}
@Override
public int available() {
return vbb.available();
}
@Override
public int read(byte[] b) {
return vbb.read(b);
}
@Override
public int read(byte[] b, int off, int len) {
return vbb.read(b, off, len);
}
@Override
public int read() {
return vbb.read();
}
public int read(ByteBuffer dst) {
return vbb.read(dst);
}
public long read(ByteBuffer[] dsts, int offset, int length) {
return vbb.read(dsts, offset, length);
}
public long read(GatheringByteChannel to) throws IOException {
return vbb.read(to);
}
public long skip(long len) {
return vbb.skip(len);
}
}
public OutputStream outputStream() {
return new OutputStream(this);
}
public InputStream inputStream() {
return new InputStream(this);
}
}

View File

@@ -0,0 +1,81 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.object;
import java.util.List;
import java.util.Arrays;
import java.io.IOException;
import org.msgpack.*;
public class ArrayType extends MessagePackObject {
private MessagePackObject[] array;
ArrayType(MessagePackObject[] array) {
this.array = array;
}
public static ArrayType create(MessagePackObject[] array) {
return new ArrayType(array);
}
@Override
public boolean isArrayType() {
return true;
}
@Override
public MessagePackObject[] asArray() {
return array;
}
@Override
public List<MessagePackObject> asList() {
return Arrays.asList(array);
}
@Override
public void messagePack(Packer pk) throws IOException {
pk.packArray(array.length);
for(int i=0; i < array.length; i++) {
array[i].messagePack(pk);
}
}
@Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()) {
return false;
}
return Arrays.equals(((ArrayType)obj).array, array);
}
@Override
public int hashCode() {
return array.hashCode();
}
@Override
public Object clone() {
MessagePackObject[] copy = new MessagePackObject[array.length];
for(int i=0; i < array.length; i++) {
copy[i] = (MessagePackObject)array[i].clone();
}
return copy;
}
}

View File

@@ -0,0 +1,131 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.object;
import java.math.BigInteger;
import java.io.IOException;
import org.msgpack.*;
class BigIntegerTypeIMPL extends IntegerType {
private BigInteger value;
BigIntegerTypeIMPL(BigInteger value) {
this.value = value;
}
@Override
public byte asByte() {
if(value.compareTo(BigInteger.valueOf((long)Byte.MAX_VALUE)) > 0) {
throw new MessageTypeException("type error");
}
return value.byteValue();
}
@Override
public short asShort() {
if(value.compareTo(BigInteger.valueOf((long)Short.MAX_VALUE)) > 0) {
throw new MessageTypeException("type error");
}
return value.shortValue();
}
@Override
public int asInt() {
if(value.compareTo(BigInteger.valueOf((long)Integer.MAX_VALUE)) > 0) {
throw new MessageTypeException("type error");
}
return value.intValue();
}
@Override
public long asLong() {
if(value.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
throw new MessageTypeException("type error");
}
return value.longValue();
}
@Override
public BigInteger asBigInteger() {
return value;
}
@Override
public byte byteValue() {
return value.byteValue();
}
@Override
public short shortValue() {
return value.shortValue();
}
@Override
public int intValue() {
return value.intValue();
}
@Override
public long longValue() {
return value.longValue();
}
@Override
public BigInteger bigIntegerValue() {
return value;
}
@Override
public float floatValue() {
return value.floatValue();
}
@Override
public double doubleValue() {
return value.doubleValue();
}
@Override
public void messagePack(Packer pk) throws IOException {
pk.packBigInteger(value);
}
@Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()) {
if(obj.getClass() == ShortIntegerTypeIMPL.class) {
return BigInteger.valueOf(((ShortIntegerTypeIMPL)obj).longValue()).equals(value);
} else if(obj.getClass() == LongIntegerTypeIMPL.class) {
return BigInteger.valueOf(((LongIntegerTypeIMPL)obj).longValue()).equals(value);
}
return false;
}
return ((BigIntegerTypeIMPL)obj).value.equals(value);
}
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public Object clone() {
return new BigIntegerTypeIMPL(value);
}
}

View File

@@ -15,50 +15,57 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.schema;
package org.msgpack.object;
import java.io.IOException;
import org.msgpack.*;
public class BooleanSchema extends Schema {
public BooleanSchema() { }
public class BooleanType extends MessagePackObject {
private boolean value;
@Override
public String getClassName() {
return "Boolean";
BooleanType(boolean value) {
this.value = value;
}
public static BooleanType create(boolean value) {
return new BooleanType(value);
}
@Override
public String getExpression() {
return "boolean";
public boolean isBooleanType() {
return true;
}
@Override
public void pack(Packer pk, Object obj) throws IOException {
if(obj instanceof Boolean) {
pk.packBoolean((Boolean)obj);
} else if(obj == null) {
pk.packNil();
public boolean asBoolean() {
return value;
}
@Override
public void messagePack(Packer pk) throws IOException {
pk.packBoolean(value);
}
@Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()) {
return false;
}
return ((BooleanType)obj).value == value;
}
@Override
public int hashCode() {
if(value) {
return 1231;
} else {
throw MessageTypeException.invalidConvert(obj, this);
return 1237;
}
}
public static final boolean convertBoolean(Object obj) throws MessageTypeException {
if(obj instanceof Boolean) {
return (Boolean)obj;
}
throw new MessageTypeException();
}
@Override
public Object convert(Object obj) throws MessageTypeException {
return convertBoolean(obj);
}
@Override
public Object createFromBoolean(boolean v) {
return v;
public Object clone() {
return new BooleanType(value);
}
}

View File

@@ -0,0 +1,101 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.object;
import java.math.BigInteger;
import java.io.IOException;
import org.msgpack.*;
class DoubleTypeIMPL extends FloatType {
private double value;
public DoubleTypeIMPL(double value) {
this.value = value;
}
@Override
public float asFloat() {
// FIXME check overflow, underflow?
return (float)value;
}
@Override
public double asDouble() {
return value;
}
@Override
public byte byteValue() {
return (byte)value;
}
@Override
public short shortValue() {
return (short)value;
}
@Override
public int intValue() {
return (int)value;
}
@Override
public long longValue() {
return (long)value;
}
@Override
public BigInteger bigIntegerValue() {
return BigInteger.valueOf((long)value);
}
@Override
public float floatValue() {
return (float)value;
}
@Override
public double doubleValue() {
return (double)value;
}
@Override
public void messagePack(Packer pk) throws IOException {
pk.packDouble(value);
}
@Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()) {
return false;
}
return ((DoubleTypeIMPL)obj).value == value;
}
@Override
public int hashCode() {
long v = Double.doubleToLongBits(value);
return (int)(v^(v>>>32));
}
@Override
public Object clone() {
return new DoubleTypeIMPL(value);
}
}

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