# HG changeset patch # User sugi # Date 1413612375 -32400 # Node ID cb825acd883af678aa6085ffdba06d2fac4f6796 first commit diff -r 000000000000 -r cb825acd883a .DS_Store Binary file .DS_Store has changed diff -r 000000000000 -r cb825acd883a .classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r cb825acd883a .project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,24 @@ + + + msgpack + MessagePack for Java is a binary-based efficient object + serialization library in Java. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff -r 000000000000 -r cb825acd883a .settings/org.eclipse.core.resources.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.core.resources.prefs Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff -r 000000000000 -r cb825acd883a .settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.core.prefs Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff -r 000000000000 -r cb825acd883a .settings/org.eclipse.m2e.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.m2e.core.prefs Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff -r 000000000000 -r cb825acd883a .travis.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.travis.yml Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,15 @@ +language: java +jdk: + - openjdk6 + - openjdk7 + - oraclejdk7 +branches: + only: + - master + - develop + - v07 +notifications: + email: + - muga.nishizawa@gmail.com + - ozawa.tsuyoshi@gmail.com + - leo@xerial.org diff -r 000000000000 -r cb825acd883a AUTHORS --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AUTHORS Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,2 @@ +FURUHASHI Sadayuki +Muga Nishizawa diff -r 000000000000 -r cb825acd883a CHANGES.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CHANGES.txt Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,200 @@ +Release 0.6.8 - 2013/08/17 + BUG FIXES + Replaces method calls of LinkedList#peek{First,Last}() into get{First,Last}() within LinkedBufferInput class (pull request #18) + Makes encoding byte[][] work correctly (pull request #24) + Ports SimpleImmutableEntry for Android2.2 or below (pull request #27) + Fixes to check upper bound and lower bound of IntAccept#acceptInteger(long) correctly (pull request #43) + + IMPROVEMENTS + MSGPACK-83 Gracefully handling new enum value with OrdinalEnum (pull request #26) + Refactors some jar dependencies for Android + Adds MessagePack#read(byte[] bytes, int off, int len, Class c) + Changes README format to Markdown + Supports maven-findbugs-plugin + +Release 0.6.7 - 2012/12/09 + NEW FEATURES + Adds MessagePack for Android + + BUG FIXES + MSGPACK-78 Generated template causes SecurityException when used from Java web start applications + MSGPACK-76 Tries to generate a template of an abstract class + MSGPACK-75 ClassCastException occurs during generating a class that has fields of TypeVariable types + MSGPACK-74 Writing message with java.util.Set field causes StackOverflowError + MSGPACK-74 Reading message with java.util.Set field causes IllegalArgumentException + +Release 0.6.6 - 2012/05/09 + BUG FIXES + Fixes bug: cannot generate templates of user-classes that have fields of + generic WildcardType types + + IMPROVEMENTS + Changes version of dependency json-simple: 1.1 to 1.1.1 + Changes version of dependency Javassist: 3.15.0-GA to 3.16.1-GA + Implements a template generation for GenericArrayType + Increases limition of element sizes of unpacked array and map objects + +Release 0.6.5 - 2012/01/12 + IMPROVEMENTS + MSGPACK-59: includes OSGi headers in manifest + +Release 0.6.4 - 2012/01/05 + NEW FEATURES + Adds getBufferSize in BufferUnpacker interface. + + BUG FIXES + Fixes bug:validation error occurs when loading templates of array classes with + Javassist-based template builder. + MSGPACK-58 Changes logging library from SLF4J to java.util.logging.Logger. + PULL REQUEST-10 Fix compilation error caused by package name mistake. + +Release 0.6.3 - 2011/11/08 + NEW FEATURES + Adds getReadByteCount and resetReadByteCount methods to Unpacker interface. + Adds setRawSizeLimit, setArraySizeLimit and setMapSizeLimit methods to + Unpacker interface. + + BUG FIXES + Fixes Perf. loss: generated templates reflectively accessed via variables of + public fields in the objects. + + IMPROVEMENTS + Changes source and target release, which are Javac options, to 1.6. + Registers Date and BigDecimal templates as builtin. + +Release 0.6.2 - 2011/10/24 + NEW FEATURES + Enables serializing private fields in objects by Javassist generated templates. + + BUG FIXES + MSGPACK-42 VerifyError occurs when generating templates for classes that have + @Optional primitive fields + MSGPACK-43 Mutually referencing MessagePack objects causes StackOverflowError + MSGPACK-49 Fail to serialize org.msgpack.type.Value objects + MSGPACK-50 Fail to serialize object representing classes have fields of + nested non-generic List, Map and Collection types + + IMPROVEMENTS + Modifies TemplateRegistry class for msgpack-scala + Adds deleteTemplateClass method to TemplatePrecompiler. + +Release 0.6.1 - 2011/10/07 + IMPROVEMENTS + Deleted unused methods in Packer and Unpacker classes. + +Release 0.6.0 - 2011/10/03 + NEW FEATURES + Adds some new APIs (Packer, Unpacker, Value, and so on). See + "Quick Start" (http://wiki.msgpack.org/display/MSGPACK/QuickStart+for+Java). + Adds JSON data serialization. See org.msgpack.util.json package. It allows + serializing JSON data to MessagePack binary. + MessagePack jar file was deployed to Maven's central repository. + License of Javassist was changed into triple license of the MPL, the LGPL, + and the Apache License. MessagePack uses Javassist under Apache License. + + IMPROVEMENTS + Refactors and optimizes core library for serialization/deserialization. + Refactors template classes and those builder classes. + +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, 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 MessagePackObject.unpack(Class) 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. + + BUG FIXES + Zero-length Array and Map is deserialized as List and Map, instead of the + array of the Object. + + fixed the bug around Packer.packByte(). diff -r 000000000000 -r cb825acd883a LICENSE.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.txt Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff -r 000000000000 -r cb825acd883a Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,24 @@ + +.PHONY: compile test eclipse clean package + +all: + compile + +package: + mvn package + +install: + mvn install + +compile: + mvn compile + +test: + mvn test + +# generate .project and .classpath file for Eclipse +eclipse: + mvn eclipse:eclipse + +clean: + mvn clean diff -r 000000000000 -r cb825acd883a NOTICE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NOTICE Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,52 @@ +This project uses code from the ASF Apache Harmony project. The following are the relevant notices +from that project, included in order to comply with its license requirements. +------------------- +Apache Harmony +Copyright 2006, 2010 The Apache Software Foundation. + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +Portions of Apache Harmony were originally developed by +Intel Corporation and are licensed to the Apache Software +Foundation under the "Software Grant and Corporate Contribution +License Agreement" and for which the following copyright notices +apply + (C) Copyright 2005 Intel Corporation + (C) Copyright 2005-2006 Intel Corporation + (C) Copyright 2006 Intel Corporation + +Portions of Apache Harmony's Class Library TEXT module contain JavaDoc +derived from the ICU project. +Copyright (c) 1995-2008 International Business Machines Corporation and others + + +The Apache Harmony Development Kit (HDK) contains a jar file from the +Apache Derby Project for which the following notice applies: + +Apache Derby +Copyright 2004-2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +Portions of Derby were originally developed by +International Business Machines Corporation and are +licensed to the Apache Software Foundation under the +"Software Grant and Corporate Contribution License Agreement", +informally known as the "Derby CLA". +The following copyright notice(s) were affixed to portions of the code +with which this file is now or was at one time distributed +and are placed here unaltered. + +(C) Copyright 1997,2004 International Business Machines Corporation. +All rights reserved. + +(C) Copyright IBM Corp. 2003. + +The portion of the functionTests under 'nist' was originally +developed by the National Institute of Standards and Technology (NIST), +an agency of the United States Department of Commerce, and adapted by +International Business Machines Corporation in accordance with the NIST +Software Acknowledgment and Redistribution document at +http://www.itl.nist.gov/div897/ctg/sql_form.htm \ No newline at end of file diff -r 000000000000 -r cb825acd883a README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,53 @@ +# MessagePack for Java + +[MessagePack](http://msgpack.org/) is an efficient binary serialization format. +It lets you exchange data among multiple languages like JSON but it's faster and smaller. +For example, small integers (like flags or error code) are encoded into a single byte, +and typical short strings only require an extra byte in addition to the strings themselves. + +You may be interested in how msgpack-java is faster than the other libraries. +To know this, please see [jvm-serializers](https://github.com/eishay/jvm-serializers/wiki), which is one of well-known benchmarks for comparing Java libraries of data serialization. + +[![Build Status](https://travis-ci.org/msgpack/msgpack-java.png?branch=master)](https://travis-ci.org/msgpack/msgpack-java) + +## Quick start + +Quick start for msgpack-java is available at [Wiki](https://github.com/msgpack/msgpack-java/wiki/QuickStart). + + +## Build + +To build the JAR file of MessagePack, you need to install Maven (http://maven.apache.org), then type the following command: + + $ mvn package + +To locally install the project, type + + $ mvn install + +To generate project files (.project, .classpath) for Eclipse, do + + $ mvn eclipse:eclipse + +then import the folder from your Eclipse. + +Next, open the preference page in Eclipse and add the CLASSPATH variable: + + M2_REPO = $HOME/.m2/repository + +where $HOME is your home directory. In Windows XP, $HOME is: + + C:/Documents and Settings/(user name)/.m2/repository + + +## How to release + +To relese the project (compile, test, tagging, deploy), please use the commands as follows: + + $ mvn release:prepare + $ mvn release:perform + +## License + +This software is distributed under [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). + diff -r 000000000000 -r cb825acd883a build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.xml Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,303 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tests Failed! + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + Javadoc warnings! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 000000000000 -r cb825acd883a ivy.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ivy.xml Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,23 @@ + + + + + MessagePack + + + + + + + + + + + + + + + + diff -r 000000000000 -r cb825acd883a msgpack.org.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/msgpack.org.md Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,46 @@ +# MessagePack for Java + +QuickStart for msgpack-java is available [here](https://github.com/msgpack/msgpack-java/wiki/QuickStart). + +## How to install + +You can install msgpack via maven: + + + ... + + org.msgpack + msgpack + ${msgpack.version} + + ... + + +## Simple Serialization/Deserialization/Duck Typing using Value + + // Create serialize objects. + List src = new ArrayList(); + src.add("msgpack"); + src.add("kumofs"); + src.add("viver"); + + MessagePack msgpack = new MessagePack(); + // Serialize + byte[] raw = msgpack.write(src); + + // Deserialize directly using a template + List dst1 = msgpack.read(raw, Templates.tList(Templates.TString)); + System.out.println(dst1.get(0)); + System.out.println(dst1.get(1)); + System.out.println(dst1.get(2)); + + // Or, Deserialze to Value then convert type. + Value dynamic = msgpack.read(raw); + List dst2 = new Converter(dynamic) + .read(Templates.tList(Templates.TString)); + System.out.println(dst2.get(0)); + System.out.println(dst2.get(1)); + System.out.println(dst2.get(2)); + + + diff -r 000000000000 -r cb825acd883a pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,193 @@ + + + 4.0.0 + org.msgpack + msgpack + MessagePack for Java + MessagePack for Java is a binary-based efficient object + serialization library in Java. + 0.6.12-SNAPSHOT + bundle + http://msgpack.org/ + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + scm:git:git://github.com/msgpack/msgpack-java.git + scm:git:git@github.com:msgpack/msgpack-java.git + scm:git:git://github.com/msgpack/msgpack-java.git + + + + GitHub + https://github.com/msgpack/msgpack-java/issues + + + + + frsyuki + Sadayuki Furuhashi + frsyuki@users.sourceforge.jp + + + muga + Muga Nishizawa + muga.nishizawa@gmail.com + + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + junit + junit + + + + + org.javassist + javassist + 3.18.1-GA + compile + + + junit + junit + 4.8.2 + test + + + + + org.sonatype.oss + oss-parent + 7 + + + + + + src/main/resources + + + + + src/test/resources + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + UTF-8 + + + + org.apache.felix + maven-bundle-plugin + 2.3.6 + true + + + maven-eclipse-plugin + 2.5.1 + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-scm-plugin + 1.6 + + false + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8.1 + + ${project.name} ${project.version} API + true + en_US + UTF-8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.8.1 + + -Xmx512M + + + + org.codehaus.mojo + findbugs-maven-plugin + + true + true + Max + + + + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.2 + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.11 + + + + + diff -r 000000000000 -r cb825acd883a src/main/java/org/apache/harmony/beans/Argument.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/apache/harmony/beans/Argument.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,62 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.apache.harmony.beans; + +public class Argument { + + private Class type; + + private Object value; + + private Class[] interfaces; + + public Argument(Object value) { + this.value = value; + if (this.value != null) { + this.type = value.getClass(); + this.interfaces = this.type.getInterfaces(); + } + } + + public Argument(Class type, Object value) { + this.type = type; + this.value = value; + this.interfaces = type.getInterfaces(); + } + + public Class getType() { + return type; + } + + public Object getValue() { + return value; + } + + public Class[] getInterfaces() { + return interfaces; + } + + public void setType(Class type) { + this.type = type; + this.interfaces = type.getInterfaces(); + } + + public void setInterfaces(Class[] interfaces) { + this.interfaces = interfaces; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/apache/harmony/beans/BeansUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/apache/harmony/beans/BeansUtils.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,122 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.apache.harmony.beans; + +import java.lang.reflect.Method; +import java.util.Arrays; + +public class BeansUtils { + + public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + + public static final String NEW = "new"; //$NON-NLS-1$ + + public static final String NEWINSTANCE = "newInstance"; //$NON-NLS-1$ + + public static final String NEWARRAY = "newArray"; //$NON-NLS-1$ + + public static final String FORNAME = "forName"; //$NON-NLS-1$ + + public static final String GET = "get"; //$NON-NLS-1$ + + public static final String IS = "is"; //$NON-NLS-1$ + + public static final String SET = "set"; //$NON-NLS-1$ + + public static final String ADD = "add"; //$NON-NLS-1$ + + public static final String PUT = "put"; //$NON-NLS-1$ + + public static final String NULL = "null"; //$NON-NLS-1$ + + public static final String QUOTE = "\"\""; //$NON-NLS-1$ + + public static final int getHashCode(Object obj) { + return obj != null ? obj.hashCode() : 0; + } + + public static final int getHashCode(boolean bool) { + return bool ? 1 : 0; + } + + public static String toASCIILowerCase(String string) { + char[] charArray = string.toCharArray(); + StringBuilder sb = new StringBuilder(charArray.length); + for (int index = 0; index < charArray.length; index++) { + if ('A' <= charArray[index] && charArray[index] <= 'Z') { + sb.append((char) (charArray[index] + ('a' - 'A'))); + } else { + sb.append(charArray[index]); + } + } + return sb.toString(); + } + + public static String toASCIIUpperCase(String string) { + char[] charArray = string.toCharArray(); + StringBuilder sb = new StringBuilder(charArray.length); + for (int index = 0; index < charArray.length; index++) { + if ('a' <= charArray[index] && charArray[index] <= 'z') { + sb.append((char) (charArray[index] - ('a' - 'A'))); + } else { + sb.append(charArray[index]); + } + } + return sb.toString(); + } + + public static boolean isPrimitiveWrapper(Class wrapper, Class base) { + return (base == boolean.class) && (wrapper == Boolean.class) + || (base == byte.class) && (wrapper == Byte.class) + || (base == char.class) && (wrapper == Character.class) + || (base == short.class) && (wrapper == Short.class) + || (base == int.class) && (wrapper == Integer.class) + || (base == long.class) && (wrapper == Long.class) + || (base == float.class) && (wrapper == Float.class) + || (base == double.class) && (wrapper == Double.class); + } + + private static final String EQUALS_METHOD = "equals"; + + private static final Class[] EQUALS_PARAMETERS = new Class[] { Object.class }; + + public static boolean declaredEquals(Class clazz) { + for (Method declaredMethod : clazz.getDeclaredMethods()) { + if (EQUALS_METHOD.equals(declaredMethod.getName()) + && Arrays.equals(declaredMethod.getParameterTypes(), + EQUALS_PARAMETERS)) { + return true; + } + } + return false; + } + + public static String idOfClass(Class clazz) { + Class theClass = clazz; + StringBuilder sb = new StringBuilder(); + if (theClass.isArray()) { + do { + sb.append("Array"); //$NON-NLS-1$ + theClass = theClass.getComponentType(); + } while (theClass.isArray()); + } + String clazzName = theClass.getName(); + clazzName = clazzName.substring(clazzName.lastIndexOf('.') + 1); + return clazzName + sb.toString(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/apache/harmony/beans/internal/nls/Messages.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/apache/harmony/beans/internal/nls/Messages.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,240 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// + +// +// THE FILE HAS BEEN AUTOGENERATED BY MSGTOOL TOOL. +// All changes made to this file manually will be overwritten +// if this tool runs again. Better make changes in the template file. +// + +package org.apache.harmony.beans.internal.nls; + + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +//import org.apache.harmony.kernel.vm.VM; + +/** + * This class retrieves strings from a resource bundle and returns them, + * formatting them with MessageFormat when required. + *

+ * It is used by the system classes to provide national language support, by + * looking up messages in the + * org.apache.harmony.beans.internal.nls.messages + * + * resource bundle. Note that if this file is not available, or an invalid key + * is looked up, or resource bundle support is not available, the key itself + * will be returned as the associated message. This means that the KEY + * should a reasonable human-readable (english) string. + * + */ +public class Messages { + + // ResourceBundle holding the system messages. + static private ResourceBundle bundle = null; + + /** + * Retrieves a message which has no arguments. + * + * @param msg + * String the key to look up. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg) { + if (bundle == null) + return msg; + try { + return bundle.getString(msg); + } catch (MissingResourceException e) { + return "Missing message: " + msg; //$NON-NLS-1$ + } + } + + /** + * Retrieves a message which takes 1 argument. + * + * @param msg + * String the key to look up. + * @param arg + * Object the object to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object arg) { + return getString(msg, new Object[] { arg }); + } + + /** + * Retrieves a message which takes 1 integer argument. + * + * @param msg + * String the key to look up. + * @param arg + * int the integer to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, int arg) { + return getString(msg, new Object[] { Integer.toString(arg) }); + } + + /** + * Retrieves a message which takes 1 character argument. + * + * @param msg + * String the key to look up. + * @param arg + * char the character to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, char arg) { + return getString(msg, new Object[] { String.valueOf(arg) }); + } + + /** + * Retrieves a message which takes 2 arguments. + * + * @param msg + * String the key to look up. + * @param arg1 + * Object an object to insert in the formatted output. + * @param arg2 + * Object another object to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object arg1, Object arg2) { + return getString(msg, new Object[] { arg1, arg2 }); + } + + /** + * Retrieves a message which takes several arguments. + * + * @param msg + * String the key to look up. + * @param args + * Object[] the objects to insert in the formatted output. + * @return String the message for that key in the system message bundle. + */ + static public String getString(String msg, Object[] args) { + String format = msg; + + if (bundle != null) { + try { + format = bundle.getString(msg); + } catch (MissingResourceException e) { + } + } + + return format(format, args); + } + + /** + * Generates a formatted text string given a source string containing + * "argument markers" of the form "{argNum}" where each argNum must be in + * the range 0..9. The result is generated by inserting the toString of each + * argument into the position indicated in the string. + *

+ * To insert the "{" character into the output, use a single backslash + * character to escape it (i.e. "\{"). The "}" character does not need to be + * escaped. + * + * @param format + * String the format to use when printing. + * @param args + * Object[] the arguments to use. + * @return String the formatted message. + */ + public static String format(String format, Object[] args) { + StringBuilder answer = new StringBuilder(format.length() + + (args.length * 20)); + String[] argStrings = new String[args.length]; + for (int i = 0; i < args.length; ++i) { + if (args[i] == null) + argStrings[i] = ""; //$NON-NLS-1$ + else + argStrings[i] = args[i].toString(); + } + int lastI = 0; + for (int i = format.indexOf('{', 0); i >= 0; i = format.indexOf('{', + lastI)) { + if (i != 0 && format.charAt(i - 1) == '\\') { + // It's escaped, just print and loop. + if (i != 1) + answer.append(format.substring(lastI, i - 1)); + answer.append('{'); + lastI = i + 1; + } else { + // It's a format character. + if (i > format.length() - 3) { + // Bad format, just print and loop. + answer.append(format.substring(lastI, format.length())); + lastI = format.length(); + } else { + int argnum = (byte) Character.digit(format.charAt(i + 1), + 10); + if (argnum < 0 || format.charAt(i + 2) != '}') { + // Bad format, just print and loop. + answer.append(format.substring(lastI, i + 1)); + lastI = i + 1; + } else { + // Got a good one! + answer.append(format.substring(lastI, i)); + if (argnum >= argStrings.length) + answer.append(""); //$NON-NLS-1$ + else + answer.append(argStrings[argnum]); + lastI = i + 3; + } + } + } + } + if (lastI < format.length()) + answer.append(format.substring(lastI, format.length())); + return answer.toString(); + } +// +// /** +// * Changes the locale of the messages. +// * +// * @param locale +// * Locale the locale to change to. +// */ +// static public ResourceBundle setLocale(final Locale locale, +// final String resource) { +// try { +// final ClassLoader loader = VM.bootCallerClassLoader(); +// return (ResourceBundle) AccessController +// .doPrivileged(new PrivilegedAction() { +// public Object run() { +// return ResourceBundle.getBundle(resource, locale, +// loader != null ? loader : ClassLoader.getSystemClassLoader()); +// } +// }); +// } catch (MissingResourceException e) { +// } +// return null; +// } +// +// static { +// // Attempt to load the messages. +// try { +// bundle = setLocale(Locale.getDefault(), +// "org.apache.harmony.beans.internal.nls.messages"); //$NON-NLS-1$ +// } catch (Throwable e) { +// e.printStackTrace(); +// } +// } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/apache/harmony/beans/internal/nls/messages.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,134 @@ +# MODIFIED FOR THE MSGPACK PROJECT +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# messages for EN locale +beans.00=no getter for {0} property +beans.01=no property for name {0} is found +beans.02=in DefaultPersistenceDelegate.mutatesTo() {0} : {1} +beans.03=Target Bean class is null +beans.04=bad property name +beans.05=Modifier for setter method should be public. +beans.06=Number of parameters in setter method is not equal to 1. +beans.07=Parameter type in setter method does not corresponds to predefined. +beans.08=Number of parameters in getter method is not equal to 0. +beans.09=Parameter type in getter method does not corresponds to predefined. +beans.0A=Modifier for getter method should be public. +beans.0B=Exception in command execution +beans.0C=source is null +beans.0D=Error in expression: {0} +beans.0E=Changes are null +beans.0F=The new BeanContext can not be set +beans.10=no node is found for statement with target = {0} +beans.11=no getter for property {0} found +beans.12=cannot access property {0} getter +beans.13=no setter for property {0} found +beans.14=Exception while finding property descriptor +beans.15=The listener is null +beans.16=The provider is null +beans.17=The child is null +beans.18=The requestor is null +beans.19=The service class is null +beans.1A=The service selector is null +beans.1B=The service is null +beans.1C=The event is null +beans.1D=bean is null +beans.1E=Illegal class name: {0} +beans.1F=Method not found: get{0} +beans.20=Method not found: set{0} +beans.21=Modifier for indexed getter method should be public. +beans.22=Number of parameters in getter method is not equal to 1. +beans.23=Parameter in indexed getter method is not of integer type. +beans.24=Parameter type in indexed getter method does not correspond to predefined. +beans.25=Modifier for indexed setter method should be public. +beans.26=Number of parameters in indexed setter method is not equal to 2. +beans.27=First parameter type in indexed setter method should be int. +beans.28=Second parameter type in indexed setter method does not corresponds to predefined. +beans.29=Membership listener is null +beans.2A=Target child can not be null +beans.2B=Resource name can not be null +beans.2C=The child can not be null +beans.2D=Invalid resource +beans.2E=PropertyVetoException was thrown while removing a child: {0}; Original error message:{1} +beans.2F=Target child is null +beans.30=PropertyVetoException was thrown while adding a child: {0}; Original error message:{1} +beans.31=No valid method {0} for {1} found. +beans.32=Cannot acquire event type from {0} listener. +beans.33={0} does not return +beans.34={0} should have a single input parameter +beans.35=Single parameter does not match to {0} class +beans.36=No input params are allowed for getListenerMethod +beans.37=Return type of getListenerMethod is not an array of listeners +beans.38=Add and remove methods are not available +beans.39=Cannot generate event set descriptor for name {0}. +beans.3A=Event type with name {0} is not found. +beans.3B=skipping expression {0}... +beans.3C=Unknown method name for array +beans.3D=First parameter in array getter(setter) is not of Integer type +beans.3E=Illegal number of arguments in array getter +beans.3F=Illegal number of arguments in array setter +beans.40=No constructor for class {0} found +beans.41=No method with name {0} is found +beans.42=target is not generated: classname {0} is not found +beans.43=Cannot convert {0} to char +beans.44=for property {0} no getter(setter) is found +beans.45=method name is not generated: error in getMethodName() +beans.46=Not a valid child +beans.47=Unable to instantiate property editor +beans.48=Property editor is not assignable from the PropertyEditor interface +beans.49=Child cannot implement both BeanContextChild and BeanContextProxy +beans.4A=newInstance is null +beans.4B=type is null +beans.4C=encoder is null +beans.4D=Invalid method call +beans.4E=stopClass is not ancestor of beanClass +beans.4F=search path is null +beans.50=not an indexed property +beans.51=Listener method {0} should have parameter of type {1} +beans.52=listenerMethodName(s) is null +beans.53=eventSetName is null +beans.54=listenerType is null +beans.55=Method is null +beans.56=Provider does not match +beans.57=Property type is incompatible with the indexed property type +beans.58=No such indexed read method +beans.59=Security violation accessing indexed read method +beans.5A=Indexed read method is not compatible with indexed write method +beans.5B=Indexed read method must take a single int argument +beans.5C=Security violation accessing indexed write method +beans.5D=No such indexed write method +beans.5E=Indexed method is not compatible with non indexed method +beans.5F=Indexed write method must take a two arguments +beans.60=Indexed write method must take an int as its first argument +beans.61=Indexed write method is not compatible with indexed read method +beans.62=Cannot decide which method to call to match {0} +beans.63=The type of element is mismatch with the type of array +beans.64=Method not found: {0} +beans.65=not a child of this context +beans.66=not the service provider registered with this context +beans.67=null child +beans.68=cannot update children during serialization +beans.69=Validation failed to add the child +beans.6A=null BeanContextChild proxy +beans.6B=failed to update child's beanContext property +beans.6C=Illegal to impl both BeanContextChild and BeanContextProxy +beans.6D=Not a child of this context +beans.6E=Validation failed to remove the child +beans.6F=children changed during serialization! +beans.70=no more objects to read +beans.71=Unknown tag of basic type: {0} +beans.72=Unknown root element: {0} +beans.73=Unknown basic object: {0} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/MessagePack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/MessagePack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,837 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.packer.Packer; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.MessagePackPacker; +import org.msgpack.packer.MessagePackBufferPacker; +import org.msgpack.packer.Unconverter; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.MessagePackUnpacker; +import org.msgpack.unpacker.MessagePackBufferUnpacker; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; + +/** + *

+ * This is basic class to use MessagePack for Java. It creates serializers and + * deserializers for objects of classes. + *

+ * + *

+ * See Quick + * Start for Java on MessagePack wiki. + *

+ * + */ +public class MessagePack { + private TemplateRegistry registry; + + /** + * + * @since 0.6.0 + */ + public MessagePack() { + registry = new TemplateRegistry(null); + } + + /** + * + * @since 0.6.0 + * @param msgpack + */ + public MessagePack(MessagePack msgpack) { + registry = new TemplateRegistry(msgpack.registry); + } + + protected MessagePack(TemplateRegistry registry) { + this.registry = registry; + } + + /** + * + * @since 0.6.0 + * @param cl + */ + public void setClassLoader(final ClassLoader cl) { + registry.setClassLoader(cl); + } + + /** + * Returns serializer that enables serializing objects into + * {@link java.io.OutputStream} object. + * + * @since 0.6.0 + * @param out + * output stream + * @return stream-based serializer + */ + public Packer createPacker(OutputStream out) { + return new MessagePackPacker(this, out); + } + + /** + * Returns serializer that enables serializing objects into buffer. + * + * @since 0.6.0 + * @return buffer-based serializer + */ + public BufferPacker createBufferPacker() { + return new MessagePackBufferPacker(this); + } + + /** + * Returns serializer that enables serializing objects into buffer. + * + * @since 0.6.0 + * @param bufferSize + * initial size of buffer + * @return buffer-based serializer + */ + public BufferPacker createBufferPacker(int bufferSize) { + return new MessagePackBufferPacker(this, bufferSize); + } + + /** + * Returns deserializer that enables deserializing + * {@link java.io.InputStream} object. + * + * @since 0.6.0 + * @param in + * input stream + * @return stream-based deserializer + */ + public Unpacker createUnpacker(InputStream in) { + return new MessagePackUnpacker(this, in); + } + + /** + * Returns empty deserializer that enables deserializing buffer. + * + * @since 0.6.0 + * @return buffer-based deserializer + */ + public BufferUnpacker createBufferUnpacker() { + return new MessagePackBufferUnpacker(this); + } + + /** + * Returns deserializer that enables deserializing buffer. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @return buffer-based deserializer + */ + public BufferUnpacker createBufferUnpacker(byte[] bytes) { + return createBufferUnpacker().wrap(bytes); + } + + /** + * Returns deserializer that enables deserializing buffer. + * + * @since 0.6.0 + * @param bytes + * @param off + * @param len + * @return buffer-based deserializer + */ + public BufferUnpacker createBufferUnpacker(byte[] bytes, int off, int len) { + return createBufferUnpacker().wrap(bytes, off, len); + } + + /** + * Returns deserializer that enables deserializing buffer. + * + * @since 0.6.0 + * @param buffer + * input {@link java.nio.ByteBuffer} object + * @return buffer-based deserializer + */ + public BufferUnpacker createBufferUnpacker(ByteBuffer buffer) { + return createBufferUnpacker().wrap(buffer); + } + + /** + * Serializes specified object. + * + * @since 0.6.0 + * @param v + * serialized object + * @return output byte array + * @throws IOException + */ + public byte[] write(T v) throws IOException { + BufferPacker pk = createBufferPacker(); + if (v == null) { + pk.writeNil(); + } else { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + tmpl.write(pk, v); + } + return pk.toByteArray(); + } + + /** + * Serializes specified object. It allows serializing object by specified + * template. + * + * @since 0.6.0 + * @param v + * @param template + * @return + * @throws IOException + */ + public byte[] write(T v, Template template) throws IOException { + BufferPacker pk = createBufferPacker(); + template.write(pk, v); + return pk.toByteArray(); + } + + /** + * Serializes specified object to output stream. + * + * @since 0.6.0 + * @param out + * output stream + * @param v + * serialized object + * @throws IOException + */ + public void write(OutputStream out, T v) throws IOException { + Packer pk = createPacker(out); + if (v == null) { + pk.writeNil(); + } else { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + tmpl.write(pk, v); + } + } + + /** + * Serializes object to output stream by specified template. + * + * @since 0.6.0 + * @param out + * output stream + * @param v + * serialized object + * @param template + * serializer/deserializer for the object + * @throws IOException + */ + public void write(OutputStream out, T v, Template template) + throws IOException { + Packer pk = createPacker(out); + template.write(pk, v); + } + + /** + * Serializes {@link org.msgpack.type.Value} object to byte array. + * + * @since 0.6.0 + * @param v + * serialized {@link org.msgpack.type.Value} object + * @return output byte array + * @throws IOException + */ + public byte[] write(Value v) throws IOException { + // FIXME ValueTemplate should do this + BufferPacker pk = createBufferPacker(); + pk.write(v); + return pk.toByteArray(); + } + + /** + * Deserializes specified byte array to {@link org.msgpack.type.Value} + * object. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @return + * @throws IOException + */ + public Value read(byte[] bytes) throws IOException { + return read(bytes, 0, bytes.length); + } + + /** + * Deserializes byte array to {@link org.msgpack.type.Value} object. + * + * @since 0.6.0 + * @param bytes + * @param off + * @param len + * @return + * @throws IOException + */ + public Value read(byte[] bytes, int off, int len) throws IOException { + return createBufferUnpacker(bytes, off, len).readValue(); + } + + /** + * Deserializes {@link java.nio.ByteBuffer} object to + * {@link org.msgpack.type.Value} object. + * + * @since 0.6.0 + * @param buffer + * input buffer + * @return + * @throws IOException + */ + public Value read(ByteBuffer buffer) throws IOException { + return createBufferUnpacker(buffer).readValue(); + } + + /** + * Deserializes input stream to {@link org.msgpack.type.Value} object. + * + * @since 0.6.0 + * @param in + * input stream + * @return deserialized {@link org.msgpack.type.Value} object + * @throws IOException + */ + public Value read(InputStream in) throws IOException { + return createUnpacker(in).readValue(); + } + + /** + * Deserializes byte array to object. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @param v + * @return + * @throws IOException + */ + public T read(byte[] bytes, T v) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + return read(bytes, v, tmpl); + } + + /** + * Deserializes byte array to object according to template. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @param tmpl + * template + * @return + * @throws IOException + */ + public T read(byte[] bytes, Template tmpl) throws IOException { + return read(bytes, null, tmpl); + } + + /** + * Deserializes byte array to object of specified class. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @param c + * @return + * @throws IOException + */ + public T read(byte[] bytes, Class c) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(c); + return read(bytes, null, tmpl); + } + + /** + * Deserializes byte array to object according to specified template. + * + * @since 0.6.0 + * @param bytes + * input byte array + * @param v + * @param tmpl + * template + * @return + * @throws IOException + */ + public T read(byte[] bytes, T v, Template tmpl) throws IOException { + BufferUnpacker u = createBufferUnpacker(bytes); + return (T) tmpl.read(u, v); + } + + /** + * Deserializes byte array to object. + * + * @since 0.6.8 + * @param bytes + * input byte array + * @param v + * @return + * @throws IOException + */ + public T read(byte[] bytes, int off, int len, Class c) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(c); + BufferUnpacker u = createBufferUnpacker(bytes, off, len); + return (T) tmpl.read(u, null); + } + + /** + * Deserializes buffer to object. + * + * @since 0.6.0 + * @param b + * input {@link java.nio.ByteBuffer} object + * @param v + * @return + * @throws IOException + */ + public T read(ByteBuffer b, T v) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + return read(b, v, tmpl); + } + + /** + * Deserializes buffer to object according to template. + * + * @since 0.6.0 + * @param b + * input buffer object + * @param tmpl + * @return + * @throws IOException + */ + public T read(ByteBuffer b, Template tmpl) throws IOException { + return read(b, null, tmpl); + } + + /** + * Deserializes buffer to object of specified class. + * + * @since 0.6.0 + * @param b + * @param c + * @return + * @throws IOException + */ + public T read(ByteBuffer b, Class c) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(c); + return read(b, null, tmpl); + } + + /** + * Deserializes buffer to object according to template. + * + * @since 0.6.0 + * @param b + * input buffer object + * @param v + * @param tmpl + * @return + * @throws IOException + */ + public T read(ByteBuffer b, T v, Template tmpl) throws IOException { + BufferUnpacker u = createBufferUnpacker(b); + return tmpl.read(u, v); + } + + /** + * Deserializes input stream to object. + * + * @since 0.6.0 + * @param in + * input stream + * @param v + * @return + * @throws IOException + */ + public T read(InputStream in, T v) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + return read(in, v, tmpl); + } + + /** + * Deserializes input stream to object according to template. + * + * @since 0.6.0 + * @param in + * input stream + * @param tmpl + * @return + * @throws IOException + */ + public T read(InputStream in, Template tmpl) throws IOException { + return read(in, null, tmpl); + } + + /** + * Deserializes input stream to object of specified class. + * + * @since 0.6.0 + * @param in + * @param c + * @return + * @throws IOException + */ + public T read(InputStream in, Class c) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(c); + return read(in, null, tmpl); + } + + /** + * Deserializes input stream to object according to template + * + * @since 0.6.0 + * @param in + * input stream + * @param v + * @param tmpl + * @return + * @throws IOException + */ + public T read(InputStream in, T v, Template tmpl) throws IOException { + Unpacker u = createUnpacker(in); + return tmpl.read(u, v); + } + + /** + * Converts specified {@link org.msgpack.type.Value} object to object. + * + * @since 0.6.0 + * @param v + * @param to + * @return + * @throws IOException + */ + public T convert(Value v, T to) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(to.getClass()); + return tmpl.read(new Converter(this, v), to); + } + + /** + * Converts {@link org.msgpack.type.Value} object to object specified class. + * + * @since 0.6.0 + * @param v + * @param c + * @return + * @throws IOException + */ + public T convert(Value v, Class c) throws IOException { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(c); + return tmpl.read(new Converter(this, v), null); + } + + /** + * Converts {@link org.msgpack.type.Value} object to object according to template + * + * @since 0.6.8 + * @param v + * @param tmpl + * @return + * @throws IOException + */ + public T convert(Value v, Template tmpl) throws IOException { + return tmpl.read(new Converter(this, v), null); + } + + /** + * Unconverts specified object to {@link org.msgpack.type.Value} object. + * + * @since 0.6.0 + * @param v + * @return + * @throws IOException + */ + public Value unconvert(T v) throws IOException { + Unconverter pk = new Unconverter(this); + if (v == null) { + pk.writeNil(); + } else { + @SuppressWarnings("unchecked") + Template tmpl = registry.lookup(v.getClass()); + tmpl.write(pk, v); + } + return pk.getResult(); + } + + /** + * Registers {@link org.msgpack.template.Template} object for objects of + * specified class. Template object is a pair of serializer and + * deserializer for object serialization. It is generated automatically. + * + * @since 0.6.0 + * @param type + */ + public void register(Class type) { + registry.register(type); + } + + /** + * Registers specified {@link org.msgpack.template.Template} object + * associated by class. + * + * @see #register(Class) + * @since 0.6.0 + * @param type + * @param template + */ + public void register(Class type, Template template) { + registry.register(type, template); + } + + /** + * Unregisters {@link org.msgpack.template.Template} object for objects of + * specified class. + * + * @since 0.6.0 + * @param type + * @return + */ + public boolean unregister(Class type) { + return registry.unregister(type); + } + + /** + * Unregisters all {@link org.msgpack.template.Template} objects that have + * been registered in advance. + * + * @since 0.6.0 + */ + public void unregister() { + registry.unregister(); + } + + /** + * Looks up a {@link org.msgpack.template.Template} object, which is + * serializer/deserializer associated by specified class. + * + * @since 0.6.0 + * @param type + * @return + */ + @SuppressWarnings("unchecked") + public Template lookup(Class type) { + return registry.lookup(type); + } + + public Template lookup(Type type) { + return registry.lookup(type); + } + + private static final MessagePack globalMessagePack = new MessagePack(); + + /** + * Serializes specified object and returns the byte array. + * + * @deprecated {@link MessagePack#write(Object)} + * @param v + * @return + * @throws IOException + */ + @Deprecated + public static byte[] pack(Object v) throws IOException { + return globalMessagePack.write(v); + } + + /** + * Serializes specified object to output stream. + * + * @deprecated {@link MessagePack#write(OutputStream, Object)} + * @param out + * @param v + * @throws IOException + */ + @Deprecated + public static void pack(OutputStream out, Object v) throws IOException { + globalMessagePack.write(out, v); + } + + /** + * Serializes object by specified template and return the byte array. + * + * @deprecated {@link MessagePack#write(Object, Template)} + * @param v + * @param template + * @return + * @throws IOException + */ + @Deprecated + public static byte[] pack(T v, Template template) throws IOException { + return globalMessagePack.write(v, template); + } + + /** + * Serializes object to output stream. The object is serialized by specified + * template. + * + * @deprecated {@link MessagePack#write(OutputStream, Object, Template)} + * @param out + * @param v + * @param template + * @throws IOException + */ + @Deprecated + public static void pack(OutputStream out, T v, Template template) + throws IOException { + globalMessagePack.write(out, v, template); + } + + /** + * Converts byte array to {@link org.msgpack.type.Value} object. + * + * @deprecated {@link MessagePack#read(byte[])} + * @param bytes + * @return + * @throws IOException + */ + @Deprecated + public static Value unpack(byte[] bytes) throws IOException { + return globalMessagePack.read(bytes); + } + + @Deprecated + public static T unpack(byte[] bytes, Template template) throws IOException { + BufferUnpacker u = new MessagePackBufferUnpacker(globalMessagePack).wrap(bytes); + return template.read(u, null); + } + + @Deprecated + public static T unpack(byte[] bytes, Template template, T to) throws IOException { + BufferUnpacker u = new MessagePackBufferUnpacker(globalMessagePack).wrap(bytes); + return template.read(u, to); + } + + /** + * Deserializes byte array to object of specified class. + * + * @deprecated {@link MessagePack#read(byte[], Class)} + * @param bytes + * @param klass + * @return + * @throws IOException + */ + @Deprecated + public static T unpack(byte[] bytes, Class klass) throws IOException { + return globalMessagePack.read(bytes, klass); + } + + /** + * Deserializes byte array to object. + * + * @param bytes + * @param to + * @return + * @throws IOException + */ + @Deprecated + public static T unpack(byte[] bytes, T to) throws IOException { + return globalMessagePack.read(bytes, to); + } + + /** + * Converts input stream to {@link org.msgpack.type.Value} object. + * + * @deprecated {@link MessagePack#read(InputStream)} + * @param in + * @return + * @throws IOException + */ + @Deprecated + public static Value unpack(InputStream in) throws IOException { + return globalMessagePack.read(in); + } + + /** + * @deprecated + * @param in + * @param tmpl + * @return + * @throws IOException + * @throws MessageTypeException + */ + @Deprecated + public static T unpack(InputStream in, Template tmpl) + throws IOException, MessageTypeException { + return tmpl.read(new MessagePackUnpacker(globalMessagePack, in), null); + } + + /** + * @deprecated + * @param in + * @param tmpl + * @param to + * @return + * @throws IOException + * @throws MessageTypeException + */ + @Deprecated + public static T unpack(InputStream in, Template tmpl, T to) + throws IOException, MessageTypeException { + return (T) tmpl.read(new MessagePackUnpacker(globalMessagePack, in), to); + } + + /** + * Deserializes input stream to object of specified class. + * + * @deprecated {@link MessagePack#read(InputStream, Class)} + * @param in + * @param klass + * @return + * @throws IOException + */ + @Deprecated + public static T unpack(InputStream in, Class klass) + throws IOException { + return globalMessagePack.read(in, klass); + } + + /** + * Deserializes input stream to object. + * + * @deprecated {@link MessagePack#read(InputStream, Object)} + * @param in + * @param to + * @return + * @throws IOException + */ + @Deprecated + public static T unpack(InputStream in, T to) throws IOException { + return globalMessagePack.read(in, to); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/MessagePackable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/MessagePackable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public interface MessagePackable { + public void writeTo(Packer pk) throws IOException; + + public void readFrom(Unpacker u) throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/MessageTypeException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/MessageTypeException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,37 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +@SuppressWarnings("serial") +public class MessageTypeException extends RuntimeException { + public MessageTypeException() { + super(); + } + + public MessageTypeException(String message) { + super(message); + } + + public MessageTypeException(String message, Throwable cause) { + super(message, cause); + } + + public MessageTypeException(Throwable cause) { + super(cause); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Beans.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Beans.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 Beans { + FieldOption value() default FieldOption.DEFAULT; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Delegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Delegate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,29 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 Delegate { + String value(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Ignore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Ignore.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 { +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Index.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Index.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,29 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Message.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Message.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 Message { + FieldOption value() default FieldOption.DEFAULT; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/MessagePackBeans.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/MessagePackBeans.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,37 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/MessagePackDelegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/MessagePackDelegate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,29 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/MessagePackMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/MessagePackMessage.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/MessagePackOrdinalEnum.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/MessagePackOrdinalEnum.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 { +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/NotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/NotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,29 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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, ElementType.FIELD, ElementType.PARAMETER, + ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface NotNullable { +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/Optional.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/Optional.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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 { +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/annotation/OrdinalEnum.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/annotation/OrdinalEnum.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,45 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +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.MessageTypeException; +import org.msgpack.template.OrdinalEnumTemplate; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface OrdinalEnum { + + /** + * Specify whether the ordinal index lookup should be handled strictly or + * not when mapping ordinal value to an enum value. By specifying true, + * {@link MessageTypeException} will be thrown if the enum specified by the + * ordinal value does not exist in this implementation. If false, then the + * missing ordinal value treated as null, gracefully handling the lookup. + * Default is true. + * + * @since 0.6.8 + * @see OrdinalEnumTemplate + */ + boolean strict() default true; + +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/AbstractInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/AbstractInput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,39 @@ +// +// MessagePack for Java +// +// Copyright (C) 2011 Muga Nishizawa +// +// 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.io; + +abstract class AbstractInput implements Input { + + private int readByteCount = 0; + + public int getReadByteCount() { + return readByteCount; + } + + public void resetReadByteCount() { + readByteCount = 0; + } + + protected final void incrReadByteCount(int size) { + readByteCount += size; + } + + protected final void incrReadOneByteCount() { + readByteCount += 1; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/BufferReferer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/BufferReferer.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,25 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public interface BufferReferer { + public void refer(ByteBuffer bb, boolean gift) throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/BufferedOutput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/BufferedOutput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,219 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.nio.ByteBuffer; + +abstract class BufferedOutput implements Output { + protected byte[] buffer; + protected int filled; + protected final int bufferSize; + protected ByteBuffer castByteBuffer; + + public BufferedOutput(int bufferSize) { + if (bufferSize < 9) { + bufferSize = 9; + } + this.bufferSize = bufferSize; + } + + private void allocateNewBuffer() { + buffer = new byte[bufferSize]; + castByteBuffer = ByteBuffer.wrap(buffer); + } + + private void reserve(int len) throws IOException { + if (buffer == null) { + allocateNewBuffer(); + return; + } + if (bufferSize - filled < len) { + if (!flushBuffer(buffer, 0, filled)) { + buffer = new byte[bufferSize]; + castByteBuffer = ByteBuffer.wrap(buffer); + } + filled = 0; + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (buffer == null) { + if (bufferSize < len) { + flushBuffer(b, off, len); + return; + } + allocateNewBuffer(); + } + if (len <= bufferSize - filled) { + System.arraycopy(b, off, buffer, filled, len); + filled += len; + } else if (len <= bufferSize) { + if (!flushBuffer(buffer, 0, filled)) { + allocateNewBuffer(); + } + filled = 0; + System.arraycopy(b, off, buffer, 0, len); + filled = len; + } else { + flush(); + flushBuffer(b, off, len); + } + } + + @Override + public void write(ByteBuffer bb) throws IOException { + int len = bb.remaining(); + if (buffer == null) { + if (bufferSize < len) { + flushByteBuffer(bb); + return; + } + allocateNewBuffer(); + } + if (len <= bufferSize - filled) { + bb.get(buffer, filled, len); + filled += len; + } else if (len <= bufferSize) { + if (!flushBuffer(buffer, 0, filled)) { + allocateNewBuffer(); + } + filled = 0; + bb.get(buffer, 0, len); + filled = len; + } else { + flush(); + flushByteBuffer(bb); + } + } + + @Override + public void writeByte(byte v) throws IOException { + reserve(1); + buffer[filled++] = v; + } + + @Override + public void writeShort(short v) throws IOException { + reserve(2); + castByteBuffer.putShort(filled, v); + filled += 2; + } + + @Override + public void writeInt(int v) throws IOException { + reserve(4); + castByteBuffer.putInt(filled, v); + filled += 4; + } + + @Override + public void writeLong(long v) throws IOException { + reserve(8); + castByteBuffer.putLong(filled, v); + filled += 8; + } + + @Override + public void writeFloat(float v) throws IOException { + reserve(4); + castByteBuffer.putFloat(filled, v); + filled += 4; + } + + @Override + public void writeDouble(double v) throws IOException { + reserve(8); + castByteBuffer.putDouble(filled, v); + filled += 8; + } + + @Override + public void writeByteAndByte(byte b, byte v) throws IOException { + reserve(2); + buffer[filled++] = b; + buffer[filled++] = v; + } + + @Override + public void writeByteAndShort(byte b, short v) throws IOException { + reserve(3); + buffer[filled++] = b; + castByteBuffer.putShort(filled, v); + filled += 2; + } + + @Override + public void writeByteAndInt(byte b, int v) throws IOException { + reserve(5); + buffer[filled++] = b; + castByteBuffer.putInt(filled, v); + filled += 4; + } + + @Override + public void writeByteAndLong(byte b, long v) throws IOException { + reserve(9); + buffer[filled++] = b; + castByteBuffer.putLong(filled, v); + filled += 8; + } + + @Override + public void writeByteAndFloat(byte b, float v) throws IOException { + reserve(5); + buffer[filled++] = b; + castByteBuffer.putFloat(filled, v); + filled += 4; + } + + @Override + public void writeByteAndDouble(byte b, double v) throws IOException { + reserve(9); + buffer[filled++] = b; + castByteBuffer.putDouble(filled, v); + filled += 8; + } + + @Override + public void flush() throws IOException { + if (filled > 0) { + if (!flushBuffer(buffer, 0, filled)) { + buffer = null; + } + filled = 0; + } + } + + protected void flushByteBuffer(ByteBuffer bb) throws IOException { + if (bb.hasArray()) { + byte[] array = bb.array(); + int offset = bb.arrayOffset(); + flushBuffer(array, offset + bb.position(), bb.remaining()); + bb.position(bb.limit()); + } else { + byte[] buf = new byte[bb.remaining()]; + bb.get(buf); + flushBuffer(buf, 0, buf.length); + } + } + + protected abstract boolean flushBuffer(byte[] buffer, int off, int len) + throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/ByteBufferOutput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/ByteBufferOutput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,148 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.BufferOverflowException; + +public class ByteBufferOutput implements Output { + public static interface ExpandBufferCallback { + ByteBuffer call(ByteBuffer buffer, int len) throws IOException; + } + + private ByteBuffer buffer; + private ExpandBufferCallback callback; + + public ByteBufferOutput(ByteBuffer buffer) { + this(buffer, null); + } + + public ByteBufferOutput(ByteBuffer buffer, ExpandBufferCallback callback) { + this.buffer = buffer; + this.callback = callback; + } + + private void reserve(int len) throws IOException { + if (len <= buffer.remaining()) { + return; + } + if (callback == null) { + throw new BufferOverflowException(); + } + buffer = callback.call(buffer, len); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + reserve(len); + buffer.put(b, off, len); + } + + @Override + public void write(ByteBuffer bb) throws IOException { + reserve(bb.remaining()); + buffer.put(bb); + } + + @Override + public void writeByte(byte v) throws IOException { + reserve(1); + buffer.put(v); + } + + @Override + public void writeShort(short v) throws IOException { + reserve(2); + buffer.putShort(v); + } + + @Override + public void writeInt(int v) throws IOException { + reserve(4); + buffer.putInt(v); + } + + @Override + public void writeLong(long v) throws IOException { + reserve(8); + buffer.putLong(v); + } + + @Override + public void writeFloat(float v) throws IOException { + reserve(4); + buffer.putFloat(v); + } + + @Override + public void writeDouble(double v) throws IOException { + reserve(8); + buffer.putDouble(v); + } + + @Override + public void writeByteAndByte(byte b, byte v) throws IOException { + reserve(2); + buffer.put(b); + buffer.put(v); + } + + @Override + public void writeByteAndShort(byte b, short v) throws IOException { + reserve(3); + buffer.put(b); + buffer.putShort(v); + } + + @Override + public void writeByteAndInt(byte b, int v) throws IOException { + reserve(5); + buffer.put(b); + buffer.putInt(v); + } + + @Override + public void writeByteAndLong(byte b, long v) throws IOException { + reserve(9); + buffer.put(b); + buffer.putLong(v); + } + + @Override + public void writeByteAndFloat(byte b, float v) throws IOException { + reserve(5); + buffer.put(b); + buffer.putFloat(v); + } + + @Override + public void writeByteAndDouble(byte b, double v) throws IOException { + reserve(9); + buffer.put(b); + buffer.putDouble(v); + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/EndOfBufferException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/EndOfBufferException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.EOFException; + +@SuppressWarnings("serial") +public class EndOfBufferException extends EOFException { + public EndOfBufferException() { + super(); + } + + public EndOfBufferException(String s) { + super(s); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/Input.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/Input.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,47 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.io.Closeable; + +public interface Input extends Closeable { + public int read(byte[] b, int off, int len) throws IOException; + + public boolean tryRefer(BufferReferer ref, int len) throws IOException; + + public byte readByte() throws IOException; + + public void advance(); + + public byte getByte() throws IOException; + + public short getShort() throws IOException; + + public int getInt() throws IOException; + + public long getLong() throws IOException; + + public float getFloat() throws IOException; + + public double getDouble() throws IOException; + + public int getReadByteCount(); + + public void resetReadByteCount(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/LinkedBufferInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/LinkedBufferInput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,399 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.io.EOFException; +import java.util.LinkedList; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.nio.ByteBuffer; + +public class LinkedBufferInput extends AbstractInput { + LinkedList link; + + int writable; + + private int nextAdvance; + + private byte[] tmpBuffer; + + private ByteBuffer tmpByteBuffer; + + private final int bufferSize; + + public LinkedBufferInput(int bufferSize) { + this.link = new LinkedList(); + this.writable = -1; + this.tmpBuffer = new byte[8]; + this.tmpByteBuffer = ByteBuffer.wrap(tmpBuffer); + this.bufferSize = bufferSize; + } + + public int read(byte[] b, int off, int len) throws EOFException { + if (link.isEmpty()) { + return 0; + } + int olen = len; + while (true) { + ByteBuffer bb = link.getFirst(); + if (len < bb.remaining()) { + bb.get(b, off, len); + incrReadByteCount(len); + return olen; + } + int rem = bb.remaining(); + bb.get(b, off, rem); + incrReadByteCount(rem); + len -= rem; + off += rem; + if (!removeFirstLink(bb)) { + break; + } + } + return olen - len; + } + + public boolean tryRefer(BufferReferer ref, int len) throws IOException { + ByteBuffer bb = null; + try { + bb = link.getFirst(); + } catch(NoSuchElementException e) {} + if (bb == null) { + throw new EndOfBufferException(); + } else if (bb.remaining() < len) { + return false; + } + boolean success = false; + int pos = bb.position(); + int lim = bb.limit(); + try { + bb.limit(pos + len); + ref.refer(bb, true); + incrReadByteCount(len); + success = true; + } finally { + bb.limit(lim); + if (success) { + bb.position(pos + len); + } else { + bb.position(pos); + } + if (bb.remaining() == 0) { + removeFirstLink(bb); + } + } + return true; + } + + public byte readByte() throws EOFException { + ByteBuffer bb = null; + try { + bb = link.getFirst(); + } catch(NoSuchElementException e) {} + if (bb == null || bb.remaining() == 0) { + throw new EndOfBufferException(); + } + byte result = bb.get(); + incrReadOneByteCount(); + if (bb.remaining() == 0) { + removeFirstLink(bb); + } + return result; + } + + public void advance() { + if (link.isEmpty()) { + return; + } + int len = nextAdvance; + ByteBuffer bb; + while (true) { + bb = link.getFirst(); + if (len < bb.remaining()) { + bb.position(bb.position() + len); + break; + } + len -= bb.remaining(); + bb.position(bb.position() + bb.remaining()); + if (!removeFirstLink(bb)) { + break; + } + } + incrReadByteCount(nextAdvance); + nextAdvance = 0; + } + + private boolean removeFirstLink(ByteBuffer first) { + if (link.size() == 1) { + if (writable >= 0) { + first.position(0); + first.limit(0); + writable = first.capacity(); + return false; + } else { + link.removeFirst(); + return false; + } + } else { + link.removeFirst(); + return true; + } + } + + private void requireMore(int n) throws EOFException { + int off = 0; + for (ByteBuffer bb : link) { + if (n <= bb.remaining()) { + int pos = bb.position(); + bb.get(tmpBuffer, off, n); + bb.position(pos); + return; + } + int rem = bb.remaining(); + int pos = bb.position(); + bb.get(tmpBuffer, off, rem); + bb.position(pos); + n -= rem; + off += rem; + } + throw new EndOfBufferException(); + } + + private ByteBuffer require(int n) throws EOFException { + ByteBuffer bb = null; + try { + bb = link.getFirst(); + } catch(NoSuchElementException e) {} + if (bb == null) { + throw new EndOfBufferException(); + } + if (n <= bb.remaining()) { + nextAdvance = n; + return bb; + } else { + requireMore(n); + nextAdvance = n; + return tmpByteBuffer; + } + } + + public byte getByte() throws EOFException { + ByteBuffer bb = require(1); + return bb.get(bb.position()); + } + + public short getShort() throws EOFException { + ByteBuffer bb = require(2); + return bb.getShort(bb.position()); + } + + public int getInt() throws EOFException { + ByteBuffer bb = require(4); + return bb.getInt(bb.position()); + } + + public long getLong() throws EOFException { + ByteBuffer bb = require(8); + return bb.getLong(bb.position()); + } + + public float getFloat() throws EOFException { + ByteBuffer bb = require(4); + return bb.getFloat(bb.position()); + } + + public double getDouble() throws EOFException { + ByteBuffer bb = require(8); + return bb.getDouble(bb.position()); + } + + public void feed(byte[] b) { + feed(b, 0, b.length, false); + } + + public void feed(byte[] b, boolean reference) { + feed(b, 0, b.length, reference); + } + + public void feed(byte[] b, int off, int len) { + feed(b, off, len, false); + } + + public void feed(byte[] b, int off, int len, boolean reference) { + if (reference) { + if (writable > 0 && link.getLast().remaining() == 0) { + link.add(link.size()-1, ByteBuffer.wrap(b, off, len)); + return; + } + link.addLast(ByteBuffer.wrap(b, off, len)); + writable = -1; + return; + } + + ByteBuffer bb = null; + try { + bb = link.getLast(); + } catch(NoSuchElementException e) {} + if (len <= writable) { + int pos = bb.position(); + bb.position(bb.limit()); + bb.limit(bb.limit() + len); + bb.put(b, off, len); + bb.position(pos); + writable = bb.capacity() - bb.limit(); + return; + } + + if (writable > 0) { + int pos = bb.position(); + bb.position(bb.limit()); + bb.limit(bb.limit() + writable); + bb.put(b, off, writable); + bb.position(pos); + off += writable; + len -= writable; + writable = 0; + } + + int sz = Math.max(len, bufferSize); + ByteBuffer nb = ByteBuffer.allocate(sz); + nb.put(b, off, len); + nb.limit(len); + nb.position(0); + link.addLast(nb); + writable = sz - len; + } + + public void feed(ByteBuffer b) { + feed(b, false); + } + + public void feed(ByteBuffer buf, boolean reference) { + if (reference) { + if (writable > 0 && link.getLast().remaining() == 0) { + link.add(link.size()-1, buf); + return; + } + link.addLast(buf); + writable = -1; + return; + } + + int rem = buf.remaining(); + + ByteBuffer bb = null; + try { + bb = link.getLast(); + } catch(NoSuchElementException e) {} + if (rem <= writable) { + int pos = bb.position(); + bb.position(bb.limit()); + bb.limit(bb.limit() + rem); + bb.put(buf); + bb.position(pos); + writable = bb.capacity() - bb.limit(); + return; + } + + if (writable > 0) { + int pos = bb.position(); + bb.position(bb.limit()); + bb.limit(bb.limit() + writable); + buf.limit(writable); + bb.put(buf); + bb.position(pos); + rem -= writable; + buf.limit(buf.limit() + rem); + writable = 0; + } + + int sz = Math.max(rem, bufferSize); + ByteBuffer nb = ByteBuffer.allocate(sz); + nb.put(buf); + nb.limit(rem); + nb.position(0); + link.addLast(nb); + writable = sz - rem; + } + + public void clear() { + if (writable >= 0) { + ByteBuffer bb = link.getLast(); + link.clear(); + bb.position(0); + bb.limit(0); + link.addLast(bb); + writable = bb.capacity(); + } else { + link.clear(); + writable = -1; + } + } + + public void copyReferencedBuffer() { + if (link.isEmpty()) { + return; + } + + int size = 0; + for(ByteBuffer bb : link) { + size += bb.remaining(); + } + if (size == 0) { + return; + } + + if (writable >= 0) { + ByteBuffer last = link.removeLast(); + byte[] copy = new byte[size - last.remaining()]; + int off = 0; + for(ByteBuffer bb : link) { + int len = bb.remaining(); + bb.get(copy, off, len); + off += len; + } + link.clear(); + link.add(ByteBuffer.wrap(copy)); + link.add(last); + + } else { + byte[] copy = new byte[size]; + int off = 0; + for(ByteBuffer bb : link) { + int len = bb.remaining(); + bb.get(copy, off, len); + off += len; + } + link.clear(); + link.add(ByteBuffer.wrap(copy)); + writable = 0; + } + } + + public int getSize() { + int size = 0; + for(ByteBuffer bb : link) { + size += bb.remaining(); + } + return size; + } + + public void close() { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/LinkedBufferOutput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/LinkedBufferOutput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,76 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.util.LinkedList; + +public final class LinkedBufferOutput extends BufferedOutput { + private static final class Link { + final byte[] buffer; + final int offset; + final int size; + + Link(byte[] buffer, int offset, int size) { + this.buffer = buffer; + this.offset = offset; + this.size = size; + } + } + + private LinkedList link; + private int size; + + public LinkedBufferOutput(int bufferSize) { + super(bufferSize); + link = new LinkedList(); + } + + public byte[] toByteArray() { + byte[] bytes = new byte[size + filled]; + int off = 0; + for (Link l : link) { + System.arraycopy(l.buffer, l.offset, bytes, off, l.size); + off += l.size; + } + if (filled > 0) { + System.arraycopy(buffer, 0, bytes, off, filled); + } + return bytes; + } + + public int getSize() { + return size + filled; + } + + @Override + protected boolean flushBuffer(byte[] b, int off, int len) { + link.add(new Link(b, off, len)); + size += len; + return false; + } + + public void clear() { + link.clear(); + size = 0; + filled = 0; + } + + @Override + public void close() { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/Output.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/Output.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,53 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.io.Closeable; +import java.io.Flushable; +import java.nio.ByteBuffer; + +public interface Output extends Closeable, Flushable { + public void write(byte[] b, int off, int len) throws IOException; + + public void write(ByteBuffer bb) throws IOException; + + public void writeByte(byte v) throws IOException; + + public void writeShort(short v) throws IOException; + + public void writeInt(int v) throws IOException; + + public void writeLong(long v) throws IOException; + + public void writeFloat(float v) throws IOException; + + public void writeDouble(double v) throws IOException; + + public void writeByteAndByte(byte b, byte v) throws IOException; + + public void writeByteAndShort(byte b, short v) throws IOException; + + public void writeByteAndInt(byte b, int v) throws IOException; + + public void writeByteAndLong(byte b, long v) throws IOException; + + public void writeByteAndFloat(byte b, float v) throws IOException; + + public void writeByteAndDouble(byte b, double v) throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/StreamInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/StreamInput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,114 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.io.IOException; +import java.io.EOFException; + +public class StreamInput extends AbstractInput { + private final InputStream in; + + private byte[] castBuffer; + private ByteBuffer castByteBuffer; + private int filled; + + public StreamInput(InputStream in) { + this.in = in; + this.castBuffer = new byte[8]; + this.castByteBuffer = ByteBuffer.wrap(castBuffer); + this.filled = 0; + } + + public int read(byte[] b, int off, int len) throws IOException { + int remain = len; + while (remain > 0) { + int n = in.read(b, off, remain); + if (n <= 0) { + throw new EOFException(); + } + incrReadByteCount(n); + remain -= n; + off += n; + } + return len; + } + + public boolean tryRefer(BufferReferer ref, int size) throws IOException { + return false; + } + + public byte readByte() throws IOException { + int n = in.read(); + if (n < 0) { + throw new EOFException(); + } + incrReadOneByteCount(); + return (byte) n; + } + + public void advance() { + incrReadByteCount(filled); + filled = 0; + } + + private void require(int len) throws IOException { + while (filled < len) { + int n = in.read(castBuffer, filled, len - filled); + if (n < 0) { + throw new EOFException(); + } + filled += n; + } + } + + public byte getByte() throws IOException { + require(1); + return castBuffer[0]; + } + + public short getShort() throws IOException { + require(2); + return castByteBuffer.getShort(0); + } + + public int getInt() throws IOException { + require(4); + return castByteBuffer.getInt(0); + } + + public long getLong() throws IOException { + require(8); + return castByteBuffer.getLong(0); + } + + public float getFloat() throws IOException { + require(4); + return castByteBuffer.getFloat(0); + } + + public double getDouble() throws IOException { + require(8); + return castByteBuffer.getDouble(0); + } + + public void close() throws IOException { + in.close(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/io/StreamOutput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/io/StreamOutput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,126 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.io; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.DataOutputStream; +import java.nio.ByteBuffer; + +public class StreamOutput implements Output { + private DataOutputStream out; + + public StreamOutput(OutputStream out) { + this.out = new DataOutputStream(out); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + out.write(b, off, len); + } + + @Override + public void write(ByteBuffer bb) throws IOException { + if (bb.hasArray()) { + byte[] array = bb.array(); + int offset = bb.arrayOffset(); + out.write(array, offset, bb.remaining()); + bb.position(bb.limit()); + } else { + // int pos = bb.position(); + byte[] buf = new byte[bb.remaining()]; + bb.get(buf); + out.write(buf); + } + } + + @Override + public void writeByte(byte v) throws IOException { + out.write(v); + } + + @Override + public void writeShort(short v) throws IOException { + out.writeShort(v); + } + + @Override + public void writeInt(int v) throws IOException { + out.writeInt(v); + } + + @Override + public void writeLong(long v) throws IOException { + out.writeLong(v); + } + + @Override + public void writeFloat(float v) throws IOException { + out.writeFloat(v); + } + + @Override + public void writeDouble(double v) throws IOException { + out.writeDouble(v); + } + + @Override + public void writeByteAndByte(byte b, byte v) throws IOException { + out.write(b); + out.write(v); + } + + @Override + public void writeByteAndShort(byte b, short v) throws IOException { + out.write(b); + out.writeShort(v); + } + + @Override + public void writeByteAndInt(byte b, int v) throws IOException { + out.write(b); + out.writeInt(v); + } + + @Override + public void writeByteAndLong(byte b, long v) throws IOException { + out.write(b); + out.writeLong(v); + } + + @Override + public void writeByteAndFloat(byte b, float v) throws IOException { + out.write(b); + out.writeFloat(v); + } + + @Override + public void writeByteAndDouble(byte b, double v) throws IOException { + out.write(b); + out.writeDouble(v); + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() throws IOException { + out.close(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/AbstractPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/AbstractPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,259 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.io.IOException; +import org.msgpack.type.Value; +import org.msgpack.MessagePack; +import org.msgpack.template.Template; + +public abstract class AbstractPacker implements Packer { + protected MessagePack msgpack; + + protected AbstractPacker(MessagePack msgpack) { + this.msgpack = msgpack; + } + + @Override + public Packer write(boolean o) throws IOException { + writeBoolean(o); + return this; + } + + @Override + public Packer write(byte o) throws IOException { + writeByte(o); + return this; + } + + @Override + public Packer write(short o) throws IOException { + writeShort(o); + return this; + } + + @Override + public Packer write(int o) throws IOException { + writeInt(o); + return this; + } + + @Override + public Packer write(long o) throws IOException { + writeLong(o); + return this; + } + + @Override + public Packer write(float o) throws IOException { + writeFloat(o); + return this; + } + + @Override + public Packer write(double o) throws IOException { + writeDouble(o); + return this; + } + + @Override + public Packer write(Boolean o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeBoolean(o); + } + return this; + } + + @Override + public Packer write(Byte o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeByte(o); + } + return this; + } + + @Override + public Packer write(Short o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeShort(o); + } + return this; + } + + @Override + public Packer write(Integer o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeInt(o); + } + return this; + } + + @Override + public Packer write(Long o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeLong(o); + } + return this; + } + + @Override + public Packer write(BigInteger o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeBigInteger(o); + } + return this; + } + + @Override + public Packer write(Float o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeFloat(o); + } + return this; + } + + @Override + public Packer write(Double o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeDouble(o); + } + return this; + } + + @Override + public Packer write(byte[] o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeByteArray(o); + } + return this; + } + + @Override + public Packer write(byte[] o, int off, int len) throws IOException { + if (o == null) { + writeNil(); + } else { + writeByteArray(o, off, len); + } + return this; + } + + @Override + public Packer write(ByteBuffer o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeByteBuffer(o); + } + return this; + } + + @Override + public Packer write(String o) throws IOException { + if (o == null) { + writeNil(); + } else { + writeString(o); + } + return this; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public Packer write(Object o) throws IOException { + if (o == null) { + writeNil(); + } else { + Template tmpl = msgpack.lookup(o.getClass()); + tmpl.write(this, o); + } + return this; + } + + @Override + public Packer write(Value v) throws IOException { + if (v == null) { + writeNil(); + } else { + v.writeTo(this); + } + return this; + } + + @Override + public Packer writeArrayEnd() throws IOException { + writeArrayEnd(true); + return this; + } + + @Override + public Packer writeMapEnd() throws IOException { + writeMapEnd(true); + return this; + } + + @Override + public void close() throws IOException { + } + + abstract protected void writeBoolean(boolean v) throws IOException; + + abstract protected void writeByte(byte v) throws IOException; + + abstract protected void writeShort(short v) throws IOException; + + abstract protected void writeInt(int v) throws IOException; + + abstract protected void writeLong(long v) throws IOException; + + abstract protected void writeBigInteger(BigInteger v) throws IOException; + + abstract protected void writeFloat(float v) throws IOException; + + abstract protected void writeDouble(double v) throws IOException; + + protected void writeByteArray(byte[] b) throws IOException { + writeByteArray(b, 0, b.length); + } + + abstract protected void writeByteArray(byte[] b, int off, int len) throws IOException; + + abstract protected void writeByteBuffer(ByteBuffer bb) throws IOException; + + abstract protected void writeString(String s) throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/BufferPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/BufferPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,32 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +/** + * This class is buffer-specific serializer. + * + * @version 0.6.0 + * @see {@link org.msgpack.packer.Packer} + */ +public interface BufferPacker extends Packer { + public int getBufferSize(); + + public byte[] toByteArray(); + + public void clear(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/MessagePackBufferPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/MessagePackBufferPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,46 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import org.msgpack.MessagePack; +import org.msgpack.io.LinkedBufferOutput; + +public class MessagePackBufferPacker extends MessagePackPacker implements BufferPacker { + private static final int DEFAULT_BUFFER_SIZE = 512; + + public MessagePackBufferPacker(MessagePack msgpack) { + this(msgpack, DEFAULT_BUFFER_SIZE); + } + + public MessagePackBufferPacker(MessagePack msgpack, int bufferSize) { + super(msgpack, new LinkedBufferOutput(bufferSize)); + } + + public int getBufferSize() { + return ((LinkedBufferOutput) out).getSize(); + } + + public byte[] toByteArray() { + return ((LinkedBufferOutput) out).toByteArray(); + } + + public void clear() { + reset(); + ((LinkedBufferOutput) out).clear(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/MessagePackPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/MessagePackPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,334 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.math.BigInteger; +import org.msgpack.io.Output; +import org.msgpack.io.StreamOutput; +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; + +public class MessagePackPacker extends AbstractPacker { + protected final Output out; + + private PackerStack stack = new PackerStack(); + + public MessagePackPacker(MessagePack msgpack, OutputStream stream) { + this(msgpack, new StreamOutput(stream)); + } + + protected MessagePackPacker(MessagePack msgpack, Output out) { + super(msgpack); + this.out = out; + } + + @Override + protected void writeByte(byte d) throws IOException { + if (d < -(1 << 5)) { + out.writeByteAndByte((byte) 0xd0, d); + } else { + out.writeByte(d); + } + stack.reduceCount(); + } + + @Override + protected void writeShort(short d) throws IOException { + if (d < -(1 << 5)) { + if (d < -(1 << 7)) { + // signed 16 + out.writeByteAndShort((byte) 0xd1, d); + } else { + // signed 8 + out.writeByteAndByte((byte) 0xd0, (byte) d); + } + } else if (d < (1 << 7)) { + // fixnum + out.writeByte((byte) d); + } else { + if (d < (1 << 8)) { + // unsigned 8 + out.writeByteAndByte((byte) 0xcc, (byte) d); + } else { + // unsigned 16 + out.writeByteAndShort((byte) 0xcd, d); + } + } + stack.reduceCount(); + } + + @Override + protected void writeInt(int d) throws IOException { + if (d < -(1 << 5)) { + if (d < -(1 << 15)) { + // signed 32 + out.writeByteAndInt((byte) 0xd2, d); + } else if (d < -(1 << 7)) { + // signed 16 + out.writeByteAndShort((byte) 0xd1, (short) d); + } else { + // signed 8 + out.writeByteAndByte((byte) 0xd0, (byte) d); + } + } else if (d < (1 << 7)) { + // fixnum + out.writeByte((byte) d); + } else { + if (d < (1 << 8)) { + // unsigned 8 + out.writeByteAndByte((byte) 0xcc, (byte) d); + } else if (d < (1 << 16)) { + // unsigned 16 + out.writeByteAndShort((byte) 0xcd, (short) d); + } else { + // unsigned 32 + out.writeByteAndInt((byte) 0xce, d); + } + } + stack.reduceCount(); + } + + @Override + protected void writeLong(long d) throws IOException { + if (d < -(1L << 5)) { + if (d < -(1L << 15)) { + if (d < -(1L << 31)) { + // signed 64 + out.writeByteAndLong((byte) 0xd3, d); + } else { + // signed 32 + out.writeByteAndInt((byte) 0xd2, (int) d); + } + } else { + if (d < -(1 << 7)) { + // signed 16 + out.writeByteAndShort((byte) 0xd1, (short) d); + } else { + // signed 8 + out.writeByteAndByte((byte) 0xd0, (byte) d); + } + } + } else if (d < (1 << 7)) { + // fixnum + out.writeByte((byte) d); + } else { + if (d < (1L << 16)) { + if (d < (1 << 8)) { + // unsigned 8 + out.writeByteAndByte((byte) 0xcc, (byte) d); + } else { + // unsigned 16 + out.writeByteAndShort((byte) 0xcd, (short) d); + } + } else { + if (d < (1L << 32)) { + // unsigned 32 + out.writeByteAndInt((byte) 0xce, (int) d); + } else { + // unsigned 64 + out.writeByteAndLong((byte) 0xcf, d); + } + } + } + stack.reduceCount(); + } + + @Override + protected void writeBigInteger(BigInteger d) throws IOException { + if (d.bitLength() <= 63) { + writeLong(d.longValue()); + stack.reduceCount(); + } else if (d.bitLength() == 64 && d.signum() == 1) { + // unsigned 64 + out.writeByteAndLong((byte) 0xcf, d.longValue()); + stack.reduceCount(); + } else { + throw new MessageTypeException( + "MessagePack can't serialize BigInteger larger than (2^64)-1"); + } + } + + @Override + protected void writeFloat(float d) throws IOException { + out.writeByteAndFloat((byte) 0xca, d); + stack.reduceCount(); + } + + @Override + protected void writeDouble(double d) throws IOException { + out.writeByteAndDouble((byte) 0xcb, d); + stack.reduceCount(); + } + + @Override + protected void writeBoolean(boolean d) throws IOException { + if (d) { + // true + out.writeByte((byte) 0xc3); + } else { + // false + out.writeByte((byte) 0xc2); + } + stack.reduceCount(); + } + + @Override + protected void writeByteArray(byte[] b, int off, int len) + throws IOException { + if (len < 32) { + out.writeByte((byte) (0xa0 | len)); + } else if (len < 65536) { + out.writeByteAndShort((byte) 0xda, (short) len); + } else { + out.writeByteAndInt((byte) 0xdb, len); + } + out.write(b, off, len); + stack.reduceCount(); + } + + @Override + protected void writeByteBuffer(ByteBuffer bb) throws IOException { + int len = bb.remaining(); + if (len < 32) { + out.writeByte((byte) (0xa0 | len)); + } else if (len < 65536) { + out.writeByteAndShort((byte) 0xda, (short) len); + } else { + out.writeByteAndInt((byte) 0xdb, len); + } + int pos = bb.position(); + try { + out.write(bb); + } finally { + bb.position(pos); + } + stack.reduceCount(); + } + + @Override + protected void writeString(String s) throws IOException { + byte[] b; + try { + // TODO encoding error? + b = s.getBytes("UTF-8"); + } catch (UnsupportedEncodingException ex) { + throw new MessageTypeException(ex); + } + writeByteArray(b, 0, b.length); + stack.reduceCount(); + } + + @Override + public Packer writeNil() throws IOException { + out.writeByte((byte) 0xc0); + stack.reduceCount(); + return this; + } + + @Override + public Packer writeArrayBegin(int size) throws IOException { + // TODO check size < 0? + if (size < 16) { + // FixArray + out.writeByte((byte) (0x90 | size)); + } else if (size < 65536) { + out.writeByteAndShort((byte) 0xdc, (short) size); + } else { + out.writeByteAndInt((byte) 0xdd, size); + } + stack.reduceCount(); + stack.pushArray(size); + return this; + } + + @Override + public Packer writeArrayEnd(boolean check) throws IOException { + if (!stack.topIsArray()) { + throw new MessageTypeException( + "writeArrayEnd() is called but writeArrayBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeArrayEnd(check=true) is called but the array is not end: " + remain); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + return this; + } + + @Override + public Packer writeMapBegin(int size) throws IOException { + // TODO check size < 0? + if (size < 16) { + // FixMap + out.writeByte((byte) (0x80 | size)); + } else if (size < 65536) { + out.writeByteAndShort((byte) 0xde, (short) size); + } else { + out.writeByteAndInt((byte) 0xdf, size); + } + stack.reduceCount(); + stack.pushMap(size); + return this; + } + + @Override + public Packer writeMapEnd(boolean check) throws IOException { + if (!stack.topIsMap()) { + throw new MessageTypeException( + "writeMapEnd() is called but writeMapBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeMapEnd(check=true) is called but the map is not end: " + remain); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + return this; + } + + public void reset() { + stack.clear(); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + out.close(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/Packer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/Packer.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,90 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import java.math.BigInteger; +import java.io.IOException; +import java.io.Closeable; +import java.io.Flushable; +import java.nio.ByteBuffer; +import org.msgpack.type.Value; + +/** + * Standard serializer in MessagePack for Java. It allows users to serialize + * objects like String, List, Map, byte[], + * primitive types and so on. + * + * @version 0.6.0 + */ +public interface Packer extends Closeable, Flushable { + public Packer write(boolean o) throws IOException; + + public Packer write(byte o) throws IOException; + + public Packer write(short o) throws IOException; + + public Packer write(int o) throws IOException; + + public Packer write(long o) throws IOException; + + public Packer write(float o) throws IOException; + + public Packer write(double o) throws IOException; + + public Packer write(Boolean o) throws IOException; + + public Packer write(Byte o) throws IOException; + + public Packer write(Short o) throws IOException; + + public Packer write(Integer o) throws IOException; + + public Packer write(Long o) throws IOException; + + public Packer write(Float o) throws IOException; + + public Packer write(Double o) throws IOException; + + public Packer write(BigInteger o) throws IOException; + + public Packer write(byte[] o) throws IOException; + + public Packer write(byte[] o, int off, int len) throws IOException; + + public Packer write(ByteBuffer o) throws IOException; + + public Packer write(String o) throws IOException; + + public Packer write(Value v) throws IOException; + + public Packer write(Object o) throws IOException; + + public Packer writeNil() throws IOException; + + public Packer writeArrayBegin(int size) throws IOException; + + public Packer writeArrayEnd(boolean check) throws IOException; + + public Packer writeArrayEnd() throws IOException; + + public Packer writeMapBegin(int size) throws IOException; + + public Packer writeMapEnd(boolean check) throws IOException; + + public Packer writeMapEnd() throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/PackerStack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/PackerStack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,98 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import org.msgpack.MessageTypeException; + +public final class PackerStack { + private int top; + private byte[] types; + private int[] counts; + + public static final int MAX_STACK_SIZE = 128; + + private static final byte TYPE_INVALID = 0; + private static final byte TYPE_ARRAY = 1; + private static final byte TYPE_MAP = 2; + + public PackerStack() { + this.top = 0; + this.types = new byte[MAX_STACK_SIZE]; + this.counts = new int[MAX_STACK_SIZE]; + this.types[0] = TYPE_INVALID; + } + + public void pushArray(int size) { + top++; + types[top] = TYPE_ARRAY; + counts[top] = size; + } + + public void pushMap(int size) { + top++; + types[top] = TYPE_MAP; + counts[top] = size * 2; + } + + public void checkCount() { + if (counts[top] > 0) { + return; + } + + if (types[top] == TYPE_ARRAY) { + throw new MessageTypeException( + "Array is end but writeArrayEnd() is not called"); + + } else if (types[top] == TYPE_MAP) { + throw new MessageTypeException( + "Map is end but writeMapEnd() is not called"); + + } else { + // empty + return; + } + } + + public void reduceCount() { + counts[top]--; + } + + public void pop() { + top--; + } + + public int getDepth() { + return top; + } + + public int getTopCount() { + return counts[top]; + } + + public boolean topIsArray() { + return types[top] == TYPE_ARRAY; + } + + public boolean topIsMap() { + return types[top] == TYPE_MAP; + } + + public void clear() { + top = 0; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/packer/Unconverter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/packer/Unconverter.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,230 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.packer; + +import java.io.IOException; +import java.math.BigInteger; +import java.nio.ByteBuffer; + +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + +public class Unconverter extends AbstractPacker { + private PackerStack stack; + private Object[] values; + private Value result; + + // private Value topContainer; + + public Unconverter() { + this(new MessagePack()); + } + + public Unconverter(MessagePack msgpack) { + super(msgpack); + this.stack = new PackerStack(); + this.values = new Object[PackerStack.MAX_STACK_SIZE]; + } + + public Value getResult() { + return result; + } + + public void resetResult() { + this.result = null; + } + + @Override + public void writeBoolean(boolean v) throws IOException { + put(ValueFactory.createBooleanValue(v)); + } + + @Override + public void writeByte(byte v) throws IOException { + put(ValueFactory.createIntegerValue(v)); + } + + @Override + public void writeShort(short v) throws IOException { + put(ValueFactory.createIntegerValue(v)); + } + + @Override + public void writeInt(int v) throws IOException { + put(ValueFactory.createIntegerValue(v)); + } + + @Override + public void writeBigInteger(BigInteger v) throws IOException { + put(ValueFactory.createIntegerValue(v)); + } + + @Override + public void writeLong(long v) throws IOException { + put(ValueFactory.createIntegerValue(v)); + } + + @Override + public void writeFloat(float v) throws IOException { + put(ValueFactory.createFloatValue(v)); + } + + @Override + public void writeDouble(double v) throws IOException { + put(ValueFactory.createFloatValue(v)); + } + + @Override + public void writeByteArray(byte[] b, int off, int len) throws IOException { + put(ValueFactory.createRawValue(b, off, len)); + } + + @Override + public void writeByteBuffer(ByteBuffer bb) throws IOException { + put(ValueFactory.createRawValue(bb)); + } + + @Override + public void writeString(String s) throws IOException { + put(ValueFactory.createRawValue(s)); + } + + @Override + public Packer writeNil() throws IOException { + put(ValueFactory.createNilValue()); + return this; + } + + @Override + public Packer writeArrayBegin(int size) throws IOException { + if (size == 0) { + // Value[] array = new Value[size]; + putContainer(ValueFactory.createArrayValue()); + stack.pushArray(0); + values[stack.getDepth()] = null; + } else { + Value[] array = new Value[size]; + putContainer(ValueFactory.createArrayValue(array, true)); + stack.pushArray(size); + values[stack.getDepth()] = array; + } + return this; + } + + @Override + public Packer writeArrayEnd(boolean check) throws IOException { + if (!stack.topIsArray()) { + throw new MessageTypeException( + "writeArrayEnd() is called but writeArrayBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeArrayEnd(check=true) is called but the array is not end"); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + if (stack.getDepth() <= 0) { + this.result = (Value) values[0]; + } + return this; + } + + @Override + public Packer writeMapBegin(int size) throws IOException { + stack.checkCount(); + if (size == 0) { + putContainer(ValueFactory.createMapValue()); + stack.pushMap(0); + values[stack.getDepth()] = null; + } else { + Value[] array = new Value[size * 2]; + putContainer(ValueFactory.createMapValue(array, true)); + stack.pushMap(size); + values[stack.getDepth()] = array; + } + return this; + } + + @Override + public Packer writeMapEnd(boolean check) throws IOException { + if (!stack.topIsMap()) { + throw new MessageTypeException( + "writeMapEnd() is called but writeMapBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeMapEnd(check=true) is called but the map is not end"); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + if (stack.getDepth() <= 0) { + this.result = (Value) values[0]; + } + return this; + } + + @Override + public Packer write(Value v) throws IOException { + put(v); + return this; + } + + private void put(Value v) { + if (stack.getDepth() <= 0) { + this.result = v; + } else { + stack.checkCount(); + Value[] array = (Value[]) values[stack.getDepth()]; + array[array.length - stack.getTopCount()] = v; + stack.reduceCount(); + } + } + + private void putContainer(Value v) { + if (stack.getDepth() <= 0) { + values[0] = (Object) v; + } else { + stack.checkCount(); + Value[] array = (Value[]) values[stack.getDepth()]; + array[array.length - stack.getTopCount()] = v; + stack.reduceCount(); + } + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() throws IOException { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/AbstractTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/AbstractTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,33 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public abstract class AbstractTemplate implements Template { + + public void write(Packer pk, T v) throws IOException { + write(pk, v, false); + } + + public T read(Unpacker u, T to) throws IOException { + return read(u, to, false); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/AnyTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/AnyTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,60 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; + +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public class AnyTemplate extends AbstractTemplate { + + private TemplateRegistry registry; + + public AnyTemplate(TemplateRegistry registry) { + this.registry = registry; + } + + @SuppressWarnings("unchecked") + public void write(Packer pk, T target, boolean required) throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + } else { + registry.lookup(target.getClass()).write(pk, target); + } + } + + public T read(Unpacker u, T to, boolean required) throws IOException, + MessageTypeException { + if (!required && u.trySkipNil()) { + return null; + } + if (to == null) { + throw new MessageTypeException("convert into unknown type is invalid"); + } + T o = u.read(to); + if (required && o == null) { + throw new MessageTypeException("Unexpected nil value"); + } + return o; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/BigDecimalTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/BigDecimalTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,56 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.math.BigDecimal; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class BigDecimalTemplate extends AbstractTemplate { + private BigDecimalTemplate() { + } + + public void write(Packer pk, BigDecimal target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write(target.toString()); + } + + public BigDecimal read(Unpacker u, BigDecimal to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + String temp = u.readString(); + return new BigDecimal(temp); + } + + static public BigDecimalTemplate getInstance() { + return instance; + } + + static final BigDecimalTemplate instance = new BigDecimalTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/BigIntegerTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/BigIntegerTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,55 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.math.BigInteger; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class BigIntegerTemplate extends AbstractTemplate { + private BigIntegerTemplate() { + } + + public void write(Packer pk, BigInteger target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((BigInteger) target); + } + + public BigInteger read(Unpacker u, BigInteger to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readBigInteger(); + } + + static public BigIntegerTemplate getInstance() { + return instance; + } + + static final BigIntegerTemplate instance = new BigIntegerTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/BooleanArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/BooleanArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class BooleanArrayTemplate extends AbstractTemplate { + private BooleanArrayTemplate() { + } + + public void write(Packer pk, boolean[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (boolean a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public boolean[] read(Unpacker u, boolean[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null || to.length != n) { + to = new boolean[n]; + } + for (int i = 0; i < n; i++) { + to[i] = u.readBoolean(); + } + u.readArrayEnd(); + return to; + } + + static public BooleanArrayTemplate getInstance() { + return instance; + } + + static final BooleanArrayTemplate instance = new BooleanArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/BooleanTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/BooleanTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class BooleanTemplate extends AbstractTemplate { + private BooleanTemplate() { + } + + public void write(Packer pk, Boolean target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((boolean) target); + } + + public Boolean read(Unpacker u, Boolean to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readBoolean(); + } + + static public BooleanTemplate getInstance() { + return instance; + } + + static final BooleanTemplate instance = new BooleanTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ByteArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ByteArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ByteArrayTemplate extends AbstractTemplate { + private ByteArrayTemplate() { + } + + public void write(Packer pk, byte[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write(target); + } + + public byte[] read(Unpacker u, byte[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readByteArray(); // TODO read to 'to' obj + } + + static public ByteArrayTemplate getInstance() { + return instance; + } + + static final ByteArrayTemplate instance = new ByteArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ByteBufferTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ByteBufferTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,56 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ByteBufferTemplate extends AbstractTemplate { + private ByteBufferTemplate() { + } + + public void write(Packer pk, ByteBuffer target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write(target); + } + + public ByteBuffer read(Unpacker u, ByteBuffer to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readByteBuffer(); // TODO read to 'to' obj? + } + + static public ByteBufferTemplate getInstance() { + return instance; + } + + static final ByteBufferTemplate instance = new ByteBufferTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ByteTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ByteTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,53 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ByteTemplate extends AbstractTemplate { + private ByteTemplate() { + } + + public void write(Packer pk, Byte target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((byte) target); + } + + public Byte read(Unpacker u, Byte to, boolean required) throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readByte(); + } + + static public ByteTemplate getInstance() { + return instance; + } + + static final ByteTemplate instance = new ByteTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/CharacterTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/CharacterTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,62 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +/** + * CharacterTemplate
+ * + * @author watabiki + */ +public class CharacterTemplate extends AbstractTemplate { + + private CharacterTemplate() { + } + + @Override + public void write(Packer pk, Character target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((int) (char) target); + } + + @Override + public Character read(Unpacker u, Character to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return (char) u.readInt(); + } + + static public CharacterTemplate getInstance() { + return instance; + } + + static final CharacterTemplate instance = new CharacterTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/CollectionTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/CollectionTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,69 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class CollectionTemplate extends AbstractTemplate> { + private Template elementTemplate; + + public CollectionTemplate(Template elementTemplate) { + this.elementTemplate = elementTemplate; + } + + public void write(Packer pk, Collection target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + Collection col = target; + pk.writeArrayBegin(col.size()); + for (E e : col) { + elementTemplate.write(pk, e); + } + pk.writeArrayEnd(); + } + + public Collection read(Unpacker u, Collection to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null) { + to = new LinkedList(); + } else { + to.clear(); + } + for (int i = 0; i < n; i++) { + E e = elementTemplate.read(u, null); + to.add(e); + } + u.readArrayEnd(); + return to; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/DateTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/DateTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,56 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.Date; + +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class DateTemplate extends AbstractTemplate { + private DateTemplate() { + } + + public void write(Packer pk, Date target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((long) target.getTime()); + } + + public Date read(Unpacker u, Date to, boolean required) throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + long temp = u.readLong(); + return new Date(temp); + } + + static public DateTemplate getInstance() { + return instance; + } + + static final DateTemplate instance = new DateTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/DoubleArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/DoubleArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class DoubleArrayTemplate extends AbstractTemplate { + private DoubleArrayTemplate() { + } + + public void write(Packer pk, double[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (double a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public double[] read(Unpacker u, double[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null || to.length != n) { + to = new double[n]; + } + for (int i = 0; i < n; i++) { + to[i] = u.readDouble(); + } + u.readArrayEnd(); + return to; + } + + static public DoubleArrayTemplate getInstance() { + return instance; + } + + static final DoubleArrayTemplate instance = new DoubleArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/DoubleTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/DoubleTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class DoubleTemplate extends AbstractTemplate { + private DoubleTemplate() { + } + + public void write(Packer pk, Double target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((double) target); + } + + public Double read(Unpacker u, Double to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readDouble(); + } + + static public DoubleTemplate getInstance() { + return instance; + } + + static final DoubleTemplate instance = new DoubleTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/FieldList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/FieldList.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,83 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.util.List; +import java.util.ArrayList; + +public class FieldList { + public static class Entry { + private String name; + + private FieldOption option; + + public Entry() { + this(null, FieldOption.IGNORE); + } + + public Entry(final String name, final FieldOption option) { + this.name = name; + this.option = option; + } + + public String getName() { + return name; + } + + public FieldOption getOption() { + return option; + } + + public boolean isAvailable() { + return option != FieldOption.IGNORE; + } + } + + private ArrayList list; + + public FieldList() { + list = new ArrayList(); + } + + public void add(final String name) { + add(name, FieldOption.DEFAULT); + } + + public void add(final String name, final FieldOption option) { + list.add(new Entry(name, option)); + } + + public void put(final int index, final String name) { + put(index, name, FieldOption.DEFAULT); + } + + public void put(final int index, final String name, final FieldOption option) { + if (list.size() < index) { + do { + list.add(new Entry()); + } while (list.size() < index); + list.add(new Entry(name, option)); + } else { + list.set(index, new Entry(name, option)); + } + } + + public List getList() { + return list; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/FieldOption.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/FieldOption.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,22 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +public enum FieldOption { + IGNORE, OPTIONAL, NOTNULLABLE, DEFAULT; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/FloatArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/FloatArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class FloatArrayTemplate extends AbstractTemplate { + private FloatArrayTemplate() { + } + + public void write(Packer pk, float[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (float a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public float[] read(Unpacker u, float[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null || to.length != n) { + to = new float[n]; + } + for (int i = 0; i < n; i++) { + to[i] = u.readFloat(); + } + u.readArrayEnd(); + return to; + } + + static public FloatArrayTemplate getInstance() { + return instance; + } + + static final FloatArrayTemplate instance = new FloatArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/FloatTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/FloatTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class FloatTemplate extends AbstractTemplate { + private FloatTemplate() { + } + + public void write(Packer pk, Float target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((float) target); + } + + public Float read(Unpacker u, Float to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readFloat(); + } + + static public FloatTemplate getInstance() { + return instance; + } + + static final FloatTemplate instance = new FloatTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/GenericCollectionTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/GenericCollectionTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,55 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public class GenericCollectionTemplate implements GenericTemplate { + @SuppressWarnings("rawtypes") + Constructor constructor; + + @SuppressWarnings("rawtypes") + public GenericCollectionTemplate(TemplateRegistry registry, Class tmpl) { + try { + constructor = tmpl.getConstructor(new Class[] { Template.class }); + constructor.newInstance(new Object[] { new AnyTemplate(registry) }); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(e); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } + } + + @SuppressWarnings("rawtypes") + public Template build(Template[] params) { + try { + return constructor.newInstance((Object[]) params); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/GenericMapTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/GenericMapTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,57 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public class GenericMapTemplate implements GenericTemplate { + @SuppressWarnings("rawtypes") + Constructor constructor; + + @SuppressWarnings("rawtypes") + public GenericMapTemplate(TemplateRegistry registry, Class tmpl) { + try { + constructor = tmpl.getConstructor(new Class[] { Template.class, Template.class }); + constructor.newInstance(new Object[] { new AnyTemplate(registry), new AnyTemplate(registry) }); + // AnyTemplate.getInstance(registry), + // AnyTemplate.getInstance(registry)}); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(e); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } + } + + @SuppressWarnings("rawtypes") + public Template build(Template[] params) { + try { + return constructor.newInstance((Object[]) params); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/GenericTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/GenericTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,23 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +public interface GenericTemplate { + @SuppressWarnings("rawtypes") + public Template build(Template[] params); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/IntegerArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/IntegerArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,69 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class IntegerArrayTemplate extends AbstractTemplate { + private IntegerArrayTemplate() { + } + + public void write(Packer pk, int[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (int a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public int[] read(Unpacker u, int[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + int[] array; + if (to != null && to.length == n) { + array = to; + } else { + array = new int[n]; + } + for (int i = 0; i < n; i++) { + array[i] = u.readInt(); + } + u.readArrayEnd(); + return array; + } + + static public IntegerArrayTemplate getInstance() { + return instance; + } + + static final IntegerArrayTemplate instance = new IntegerArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/IntegerTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/IntegerTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class IntegerTemplate extends AbstractTemplate { + private IntegerTemplate() { + } + + public void write(Packer pk, Integer target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((int) target); + } + + public Integer read(Unpacker u, Integer to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readInt(); + } + + static public IntegerTemplate getInstance() { + return instance; + } + + static final IntegerTemplate instance = new IntegerTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ListTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ListTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,72 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ListTemplate extends AbstractTemplate> { + private Template elementTemplate; + + public ListTemplate(Template elementTemplate) { + this.elementTemplate = elementTemplate; + } + + public void write(Packer pk, List target, boolean required) + throws IOException { + if (!(target instanceof List)) { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + throw new MessageTypeException("Target is not a List but " + + target.getClass()); + } + pk.writeArrayBegin(target.size()); + for (E e : target) { + elementTemplate.write(pk, e); + } + pk.writeArrayEnd(); + } + + public List read(Unpacker u, List to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null) { + to = new ArrayList(n); + } else { + to.clear(); + } + for (int i = 0; i < n; i++) { + E e = elementTemplate.read(u, null); + to.add(e); + } + u.readArrayEnd(); + return to; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/LongArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/LongArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class LongArrayTemplate extends AbstractTemplate { + private LongArrayTemplate() { + } + + public void write(Packer pk, long[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (long a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public long[] read(Unpacker u, long[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null || to.length != n) { + to = new long[n]; + } + for (int i = 0; i < n; i++) { + to[i] = u.readLong(); + } + u.readArrayEnd(); + return to; + } + + static public LongArrayTemplate getInstance() { + return instance; + } + + static final LongArrayTemplate instance = new LongArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/LongTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/LongTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,53 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class LongTemplate extends AbstractTemplate { + private LongTemplate() { + } + + public void write(Packer pk, Long target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write((long) target); + } + + public Long read(Unpacker u, Long to, boolean required) throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readLong(); + } + + static public LongTemplate getInstance() { + return instance; + } + + static final LongTemplate instance = new LongTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/MapTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/MapTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,78 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class MapTemplate extends AbstractTemplate> { + private Template keyTemplate; + private Template valueTemplate; + + public MapTemplate(Template keyTemplate, Template valueTemplate) { + this.keyTemplate = keyTemplate; + this.valueTemplate = valueTemplate; + } + + public void write(Packer pk, Map target, boolean required) + throws IOException { + if (!(target instanceof Map)) { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + throw new MessageTypeException("Target is not a Map but " + target.getClass()); + } + Map map = (Map) target; + pk.writeMapBegin(map.size()); + for (Map.Entry pair : map.entrySet()) { + keyTemplate.write(pk, pair.getKey()); + valueTemplate.write(pk, pair.getValue()); + } + pk.writeMapEnd(); + } + + public Map read(Unpacker u, Map to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readMapBegin(); + Map map; + if (to != null) { + map = (Map) to; + map.clear(); + } else { + map = new HashMap(n); + } + for (int i = 0; i < n; i++) { + K key = keyTemplate.read(u, null); + V value = valueTemplate.read(u, null); + map.put(key, value); + } + u.readMapEnd(); + return map; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/MessagePackableTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/MessagePackableTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,62 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessagePackable; +import org.msgpack.MessageTypeException; + +public class MessagePackableTemplate extends AbstractTemplate { + private Class targetClass; + + MessagePackableTemplate(Class targetClass) { + this.targetClass = targetClass; + } + + public void write(Packer pk, MessagePackable target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + target.writeTo(pk); + } + + public MessagePackable read(Unpacker u, MessagePackable to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + if (to == null) { + try { + to = (MessagePackable) targetClass.newInstance(); + } catch (InstantiationException e) { + throw new MessageTypeException(e); + } catch (IllegalAccessException e) { + throw new MessageTypeException(e); + } + } + to.readFrom(u); + return to; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/NotNullableTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/NotNullableTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,35 @@ +package org.msgpack.template; + +import java.io.IOException; + +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public class NotNullableTemplate extends AbstractTemplate { + + private Template tmpl; + + public NotNullableTemplate(Template elementTemplate) { + tmpl = elementTemplate; + } + + @Override + public void write(Packer pk, T v, boolean required) throws IOException { + tmpl.write(pk, v, required); + } + + @Override + public void write(Packer pk, T v) throws IOException { + write(pk, v, true); + } + + @Override + public T read(Unpacker u, T to, boolean required) throws IOException { + return tmpl.read(u, to, required); + } + + @Override + public T read(Unpacker u, T to) throws IOException { + return read(u, to, true); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ObjectArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ObjectArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,60 @@ +package org.msgpack.template; + +import java.io.IOException; +import java.lang.reflect.Array; + +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class ObjectArrayTemplate extends AbstractTemplate { + protected Class componentClass; + + protected Template componentTemplate; + + public ObjectArrayTemplate(Class componentClass, Template componentTemplate) { + this.componentClass = componentClass; + this.componentTemplate = componentTemplate; + } + + @Override + public void write(Packer packer, Object v, boolean required) + throws IOException { + if (v == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + packer.writeNil(); + return; + } + if (!(v instanceof Object[]) || + !componentClass.isAssignableFrom(v.getClass().getComponentType())) { + throw new MessageTypeException(); + } + + Object[] array = (Object[]) v; + int length = array.length; + packer.writeArrayBegin(length); + for (int i = 0; i < length; i++) { + componentTemplate.write(packer, array[i], required); + } + packer.writeArrayEnd(); + } + + @Override + public Object read(Unpacker unpacker, Object to, boolean required) + throws IOException { + if (!required && unpacker.trySkipNil()) { + return null; + } + + int length = unpacker.readArrayBegin(); + Object[] array = (Object[]) Array.newInstance(componentClass, length); + for (int i = 0; i < length; i++) { + array[i] = componentTemplate.read(unpacker, null, required); + } + unpacker.readArrayEnd(); + return array; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/OrdinalEnumTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/OrdinalEnumTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,81 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.HashMap; + +import org.msgpack.MessageTypeException; +import org.msgpack.annotation.OrdinalEnum; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public class OrdinalEnumTemplate extends AbstractTemplate { + protected T[] entries; + protected HashMap reverse; + protected boolean strict; + + public OrdinalEnumTemplate(Class targetClass) { + entries = targetClass.getEnumConstants(); + reverse = new HashMap(); + for (int i = 0; i < entries.length; i++) { + reverse.put(entries[i], i); + } + strict = !targetClass.isAnnotationPresent(OrdinalEnum.class) + || targetClass.getAnnotation(OrdinalEnum.class).strict(); + } + + @Override + public void write(Packer pk, T target, boolean required) throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + Integer ordinal = reverse.get(target); + if (ordinal == null) { + throw new MessageTypeException( + new IllegalArgumentException("ordinal: " + ordinal)); + } + pk.write((int) ordinal); + } + + @Override + public T read(Unpacker pac, T to, boolean required) throws IOException, + MessageTypeException { + if (!required && pac.trySkipNil()) { + return null; + } + + int ordinal = pac.readInt(); + + if (ordinal < entries.length) { + return entries[ordinal]; + } + + if (!strict) { + return null; + } + + throw new MessageTypeException(new IllegalArgumentException("ordinal: " + + ordinal)); + + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/SetTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/SetTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,73 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class SetTemplate extends AbstractTemplate> { + private Template elementTemplate; + + public SetTemplate(Template elementTemplate) { + this.elementTemplate = elementTemplate; + } + + public void write(Packer pk, Set target, boolean required) + throws IOException { + if (!(target instanceof Set)) { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + throw new MessageTypeException("Target is not a List but " + + target.getClass()); + } + pk.writeArrayBegin(target.size()); + for (E e : target) { + elementTemplate.write(pk, e); + } + pk.writeArrayEnd(); + } + + public Set read(Unpacker u, Set to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null) { + to = new HashSet(n); + } else { + to.clear(); + } + for (int i = 0; i < n; i++) { + E e = elementTemplate.read(u, null); + to.add(e); + } + u.readArrayEnd(); + return to; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ShortArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ShortArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ShortArrayTemplate extends AbstractTemplate { + private ShortArrayTemplate() { + } + + public void write(Packer pk, short[] target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.writeArrayBegin(target.length); + for (short a : target) { + pk.write(a); + } + pk.writeArrayEnd(); + } + + public short[] read(Unpacker u, short[] to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + int n = u.readArrayBegin(); + if (to == null || to.length != n) { + to = new short[n]; + } + for (int i = 0; i < n; i++) { + to[i] = u.readShort(); + } + u.readArrayEnd(); + return to; + } + + static public ShortArrayTemplate getInstance() { + return instance; + } + + static final ShortArrayTemplate instance = new ShortArrayTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ShortTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ShortTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class ShortTemplate extends AbstractTemplate { + private ShortTemplate() { + } + + public void write(Packer pk, Short target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write(target); + } + + public Short read(Unpacker u, Short to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readShort(); + } + + static public ShortTemplate getInstance() { + return instance; + } + + static final ShortTemplate instance = new ShortTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/StringTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/StringTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; + +public class StringTemplate extends AbstractTemplate { + private StringTemplate() { + } + + public void write(Packer pk, String target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + pk.write(target); + } + + public String read(Unpacker u, String to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readString(); + } + + static public StringTemplate getInstance() { + return instance; + } + + static final StringTemplate instance = new StringTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/Template.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/Template.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,32 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public interface Template { + public void write(Packer pk, T v) throws IOException; + + public void write(Packer pk, T v, boolean required) throws IOException; + + public T read(Unpacker u, T to) throws IOException; + + public T read(Unpacker u, T to, boolean required) throws IOException; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/TemplateReference.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/TemplateReference.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,74 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import java.lang.reflect.Type; + +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + +public class TemplateReference extends AbstractTemplate { + + private TemplateRegistry registry; + + private Type targetType; + + private Template actualTemplate; + + public TemplateReference(TemplateRegistry registry, Type targetType) { + this.registry = registry; + this.targetType = targetType; + } + + @SuppressWarnings("unchecked") + private void validateActualTemplate() { + if (actualTemplate == null) { + actualTemplate = (Template) registry.cache.get(targetType); + if (actualTemplate == null) { + throw new MessageTypeException( + "Actual template have not been created"); + } + } + } + + @Override + public void write(Packer pk, T v, boolean required) throws IOException { + validateActualTemplate(); + actualTemplate.write(pk, v, required); + } + + @Override + public void write(Packer pk, T v) throws IOException { + validateActualTemplate(); + actualTemplate.write(pk, v, false); + } + + @Override + public T read(Unpacker u, T to, boolean required) throws IOException { + validateActualTemplate(); + return actualTemplate.read(u, to, required); + } + + @Override + public T read(Unpacker u, T to) throws IOException { + validateActualTemplate(); + return actualTemplate.read(u, to, false); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/TemplateRegistry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/TemplateRegistry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,623 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; + +import org.msgpack.MessagePackable; +import org.msgpack.MessageTypeException; +import org.msgpack.template.BigIntegerTemplate; +import org.msgpack.template.BooleanTemplate; +import org.msgpack.template.ByteArrayTemplate; +import org.msgpack.template.ByteTemplate; +import org.msgpack.template.DoubleArrayTemplate; +import org.msgpack.template.DoubleTemplate; +import org.msgpack.template.FieldList; +import org.msgpack.template.FloatArrayTemplate; +import org.msgpack.template.FloatTemplate; +import org.msgpack.template.GenericTemplate; +import org.msgpack.template.IntegerArrayTemplate; +import org.msgpack.template.IntegerTemplate; +import org.msgpack.template.LongArrayTemplate; +import org.msgpack.template.LongTemplate; +import org.msgpack.template.ShortArrayTemplate; +import org.msgpack.template.ShortTemplate; +import org.msgpack.template.StringTemplate; +import org.msgpack.template.Template; +import org.msgpack.template.ValueTemplate; +import org.msgpack.template.builder.ArrayTemplateBuilder; +import org.msgpack.template.builder.TemplateBuilder; +import org.msgpack.template.builder.TemplateBuilderChain; +import org.msgpack.type.Value; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class TemplateRegistry { + + private TemplateRegistry parent = null; + + private TemplateBuilderChain chain; + + Map> cache; + + private Map genericCache; + + /** + * create TemplateRegistry object of root. + */ + private TemplateRegistry() { + parent = null; + chain = createTemplateBuilderChain(); + genericCache = new HashMap(); + cache = new HashMap>(); + registerTemplates(); + cache = Collections.unmodifiableMap(cache); + } + + /** + * + * @param registry + */ + public TemplateRegistry(TemplateRegistry registry) { + if (registry != null) { + parent = registry; + } else { + parent = new TemplateRegistry(); + } + chain = createTemplateBuilderChain(); + cache = new HashMap>(); + genericCache = new HashMap(); + registerTemplatesWhichRefersRegistry(); + } + + protected TemplateBuilderChain createTemplateBuilderChain() { + return new TemplateBuilderChain(this); + } + + public void setClassLoader(final ClassLoader cl) { + chain = new TemplateBuilderChain(this, cl); + } + + private void registerTemplates() { + register(boolean.class, BooleanTemplate.getInstance()); + register(Boolean.class, BooleanTemplate.getInstance()); + register(byte.class, ByteTemplate.getInstance()); + register(Byte.class, ByteTemplate.getInstance()); + register(short.class, ShortTemplate.getInstance()); + register(Short.class, ShortTemplate.getInstance()); + register(int.class, IntegerTemplate.getInstance()); + register(Integer.class, IntegerTemplate.getInstance()); + register(long.class, LongTemplate.getInstance()); + register(Long.class, LongTemplate.getInstance()); + register(float.class, FloatTemplate.getInstance()); + register(Float.class, FloatTemplate.getInstance()); + register(double.class, DoubleTemplate.getInstance()); + register(Double.class, DoubleTemplate.getInstance()); + register(BigInteger.class, BigIntegerTemplate.getInstance()); + register(char.class, CharacterTemplate.getInstance()); + register(Character.class, CharacterTemplate.getInstance()); + register(boolean[].class, BooleanArrayTemplate.getInstance()); + register(short[].class, ShortArrayTemplate.getInstance()); + register(int[].class, IntegerArrayTemplate.getInstance()); + register(long[].class, LongArrayTemplate.getInstance()); + register(float[].class, FloatArrayTemplate.getInstance()); + register(double[].class, DoubleArrayTemplate.getInstance()); + register(String.class, StringTemplate.getInstance()); + register(byte[].class, ByteArrayTemplate.getInstance()); + register(ByteBuffer.class, ByteBufferTemplate.getInstance()); + register(Value.class, ValueTemplate.getInstance()); + register(BigDecimal.class, BigDecimalTemplate.getInstance()); + register(Date.class, DateTemplate.getInstance()); + + registerTemplatesWhichRefersRegistry(); + + } + + protected void registerTemplatesWhichRefersRegistry() { + AnyTemplate anyTemplate = new AnyTemplate(this); + + register(List.class, new ListTemplate(anyTemplate)); + register(Set.class, new SetTemplate(anyTemplate)); + register(Collection.class, new CollectionTemplate(anyTemplate)); + register(Map.class, new MapTemplate(anyTemplate, anyTemplate)); + registerGeneric(List.class, new GenericCollectionTemplate(this, ListTemplate.class)); + registerGeneric(Set.class, new GenericCollectionTemplate(this, SetTemplate.class)); + registerGeneric(Collection.class, new GenericCollectionTemplate(this, CollectionTemplate.class)); + registerGeneric(Map.class, new GenericMapTemplate(this, MapTemplate.class)); + } + + public void register(final Class targetClass) { + buildAndRegister(null, targetClass, false, null); + } + + public void register(final Class targetClass, final FieldList flist) { + if (flist == null) { + throw new NullPointerException("FieldList object is null"); + } + + buildAndRegister(null, targetClass, false, flist); + } + + public synchronized void register(final Type targetType, final Template tmpl) { + if (tmpl == null) { + throw new NullPointerException("Template object is null"); + } + + if (targetType instanceof ParameterizedType) { + cache.put(((ParameterizedType) targetType).getRawType(), tmpl); + } else { + cache.put(targetType, tmpl); + } + } + + public synchronized void registerGeneric(final Type targetType, final GenericTemplate tmpl) { + if (targetType instanceof ParameterizedType) { + genericCache.put(((ParameterizedType) targetType).getRawType(), + tmpl); + } else { + genericCache.put(targetType, tmpl); + } + } + + public synchronized boolean unregister(final Type targetType) { + Template tmpl = cache.remove(targetType); + return tmpl != null; + } + + public synchronized void unregister() { + cache.clear(); + } + + public synchronized Template lookup(Type targetType) { + Template tmpl; + + if (targetType instanceof ParameterizedType) { + // ParameterizedType is not a Class + ParameterizedType paramedType = (ParameterizedType) targetType; + tmpl = lookupGenericType(paramedType); + if (tmpl != null) { + return tmpl; + } + targetType = paramedType.getRawType(); + } + + tmpl = lookupGenericArrayType(targetType); + if (tmpl != null) { + return tmpl; + } + + tmpl = lookupCache(targetType); + if (tmpl != null) { + return tmpl; + } + + if (targetType instanceof WildcardType || + targetType instanceof TypeVariable) { + // WildcardType is not a Class + tmpl = new AnyTemplate(this); + register(targetType, tmpl); + return tmpl; + } + + Class targetClass = (Class) targetType; + + // MessagePackable interface is implemented + if (MessagePackable.class.isAssignableFrom(targetClass)) { + // FIXME #MN + // following processing should be merged into lookAfterBuilding + // or lookupInterfaceTypes method in next version + tmpl = new MessagePackableTemplate(targetClass); + register(targetClass, tmpl); + return tmpl; + } + + if (targetClass.isInterface()) { + // writing interfaces will succeed + // reading into interfaces will fail + tmpl = new AnyTemplate(this); + register(targetType, tmpl); + return tmpl; + } + + // find matched template builder and build template + tmpl = lookupAfterBuilding(targetClass); + if (tmpl != null) { + return tmpl; + } + + // lookup template of interface type + tmpl = lookupInterfaceTypes(targetClass); + if (tmpl != null) { + return tmpl; + } + + // lookup template of superclass type + tmpl = lookupSuperclasses(targetClass); + if (tmpl != null) { + return tmpl; + } + + // lookup template of interface type of superclasss + tmpl = lookupSuperclassInterfaceTypes(targetClass); + if (tmpl != null) { + return tmpl; + } + + throw new MessageTypeException( + "Cannot find template for " + targetClass + " class. " + + "Try to add @Message annotation to the class or call MessagePack.register(Type)."); + } + + private Template lookupGenericType(ParameterizedType paramedType) { + Template tmpl = lookupGenericTypeImpl(paramedType); + if (tmpl != null) { + return tmpl; + } + + try { + tmpl = parent.lookupGenericTypeImpl(paramedType); + if (tmpl != null) { + return tmpl; + } + } catch (NullPointerException e) { // ignore + } + + tmpl = lookupGenericInterfaceTypes(paramedType); + if (tmpl != null) { + return tmpl; + } + + tmpl = lookupGenericSuperclasses(paramedType); + if (tmpl != null) { + return tmpl; + } + + return null; + } + + private Template lookupGenericTypeImpl(ParameterizedType targetType) { + Type rawType = targetType.getRawType(); + return lookupGenericTypeImpl0(targetType, rawType); + } + + private Template lookupGenericTypeImpl0(ParameterizedType targetType, Type rawType) { + GenericTemplate gtmpl = genericCache.get(rawType); + if (gtmpl == null) { + return null; + } + + Type[] types = targetType.getActualTypeArguments(); + Template[] tmpls = new Template[types.length]; + for (int i = 0; i < types.length; ++i) { + tmpls[i] = lookup(types[i]); + } + + return gtmpl.build(tmpls); + } + + private Template lookupGenericInterfaceTypes(ParameterizedType targetType) { + Type rawType = targetType.getRawType(); + Template tmpl = null; + + try { + Class[] infTypes = ((Class) rawType).getInterfaces(); + for (Class infType : infTypes) { + tmpl = lookupGenericTypeImpl0(targetType, infType); + if (tmpl != null) { + return tmpl; + } + } + } catch (ClassCastException e) { // ignore + } + + return tmpl; + } + + private Template lookupGenericSuperclasses(ParameterizedType targetType) { + Type rawType = targetType.getRawType(); + Template tmpl = null; + + try { + Class superClass = ((Class) rawType).getSuperclass(); + if (superClass == null) { + return null; + } + + for (; superClass != Object.class; superClass = superClass.getSuperclass()) { + tmpl = lookupGenericTypeImpl0(targetType, superClass); + if (tmpl != null) { + register(targetType, tmpl); + return tmpl; + } + } + } catch (ClassCastException e) { // ignore + } + + return tmpl; + } + + private Template lookupGenericArrayType(Type targetType) { + // TODO GenericArrayType is not a Class => buildArrayTemplate + if (! (targetType instanceof GenericArrayType)) { + return null; + } + + GenericArrayType genericArrayType = (GenericArrayType) targetType; + Template tmpl = lookupGenericArrayTypeImpl(genericArrayType); + if (tmpl != null) { + return tmpl; + } + + try { + tmpl = parent.lookupGenericArrayTypeImpl(genericArrayType); + if (tmpl != null) { + return tmpl; + } + } catch (NullPointerException e) { // ignore + } + + return null; + } + + private Template lookupGenericArrayTypeImpl(GenericArrayType genericArrayType) { + String genericArrayTypeName = "" + genericArrayType; + int dim = genericArrayTypeName.split("\\[").length - 1; + if (dim <= 0) { + throw new MessageTypeException( + String.format("fatal error: type=", genericArrayTypeName)); + } else if (dim > 1) { + throw new UnsupportedOperationException(String.format( + "Not implemented template generation of %s", genericArrayTypeName)); + } + + String genericCompTypeName = "" + genericArrayType.getGenericComponentType(); + boolean isPrimitiveType = isPrimitiveType(genericCompTypeName); + StringBuffer sbuf = new StringBuffer(); + for (int i = 0; i < dim; i++) { + sbuf.append('['); + } + if (!isPrimitiveType) { + sbuf.append('L'); + sbuf.append(toJvmReferenceTypeName(genericCompTypeName)); + sbuf.append(';'); + } else { + sbuf.append(toJvmPrimitiveTypeName(genericCompTypeName)); + } + + String jvmArrayClassName = sbuf.toString(); + Class jvmArrayClass = null; + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + if (cl != null) { + jvmArrayClass = cl.loadClass(jvmArrayClassName); + if (jvmArrayClass != null) { + return lookupAfterBuilding(jvmArrayClass); + } + } + } catch (ClassNotFoundException e) {} // ignore + + try { + cl = getClass().getClassLoader(); + if (cl != null) { + jvmArrayClass = cl.loadClass(jvmArrayClassName); + if (jvmArrayClass != null) { + return lookupAfterBuilding(jvmArrayClass); + } + } + } catch (ClassNotFoundException e) {} // ignore + + try { + jvmArrayClass = Class.forName(jvmArrayClassName); + if (jvmArrayClass != null) { + return lookupAfterBuilding(jvmArrayClass); + } + } catch (ClassNotFoundException e) {} // ignore + + throw new MessageTypeException(String.format( + "cannot find template of %s", jvmArrayClassName)); + } + + private Template lookupCache(Type targetType) { + Template tmpl = cache.get(targetType); + if (tmpl != null) { + return tmpl; + } + + try { + tmpl = parent.lookupCache(targetType); + } catch (NullPointerException e) { // ignore + } + return tmpl; + } + + private Template lookupAfterBuilding(Class targetClass) { + TemplateBuilder builder = chain.select(targetClass, true); + Template tmpl = null; + if (builder != null) { + // TODO #MN for Android, we should modify here + tmpl = chain.getForceBuilder().loadTemplate(targetClass); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } + tmpl = buildAndRegister(builder, targetClass, true, null); + } + return tmpl; + } + + private Template lookupInterfaceTypes(Class targetClass) { + Class[] infTypes = targetClass.getInterfaces(); + Template tmpl = null; + for (Class infType : infTypes) { + tmpl = (Template) cache.get(infType); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } else { + try { + tmpl = (Template) parent.lookupCache(infType); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } + } catch (NullPointerException e) { // ignore + } + } + } + return tmpl; + } + + private Template lookupSuperclasses(Class targetClass) { + Class superClass = targetClass.getSuperclass(); + Template tmpl = null; + if (superClass != null) { + for (; superClass != Object.class; superClass = superClass + .getSuperclass()) { + tmpl = (Template) cache.get(superClass); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } else { + try { + tmpl = (Template) parent.lookupCache(superClass); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } + } catch (NullPointerException e) { // ignore + } + } + } + } + return tmpl; + } + + private Template lookupSuperclassInterfaceTypes(Class targetClass) { + Class superClass = targetClass.getSuperclass(); + Template tmpl = null; + if (superClass != null) { + for (; superClass != Object.class; superClass = superClass.getSuperclass()) { + tmpl = (Template) lookupInterfaceTypes(superClass); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } else { + try { + tmpl = (Template) parent.lookupCache(superClass); + if (tmpl != null) { + register(targetClass, tmpl); + return tmpl; + } + } catch (NullPointerException e) { // ignore + } + } + } + } + return tmpl; + } + + private synchronized Template buildAndRegister(TemplateBuilder builder, + final Class targetClass, final boolean hasAnnotation, + final FieldList flist) { + Template newTmpl = null; + Template oldTmpl = null; + try { + if (cache.containsKey(targetClass)) { + oldTmpl = cache.get(targetClass); + } + newTmpl = new TemplateReference(this, targetClass); + cache.put(targetClass, newTmpl); + if (builder == null) { + builder = chain.select(targetClass, hasAnnotation); + } + newTmpl = flist != null ? + builder.buildTemplate(targetClass, flist) : builder.buildTemplate(targetClass); + return newTmpl; + } catch (Exception e) { + if (oldTmpl != null) { + cache.put(targetClass, oldTmpl); + } else { + cache.remove(targetClass); + } + newTmpl = null; + if (e instanceof MessageTypeException) { + throw (MessageTypeException) e; + } else { + throw new MessageTypeException(e); + } + } finally { + if (newTmpl != null) { + cache.put(targetClass, newTmpl); + } + } + } + + private static boolean isPrimitiveType(String genericCompTypeName) { + return (genericCompTypeName.equals("byte") + || genericCompTypeName.equals("short") + || genericCompTypeName.equals("int") + || genericCompTypeName.equals("long") + || genericCompTypeName.equals("float") + || genericCompTypeName.equals("double") + || genericCompTypeName.equals("boolean") + || genericCompTypeName.equals("char")); + } + + private static String toJvmReferenceTypeName(String typeName) { + // delete "class " from class name + // e.g. "class Foo" to "Foo" by this method + return typeName.substring(6); + } + + private static String toJvmPrimitiveTypeName(String typeName) { + if (typeName.equals("byte")) { + return "B"; + } else if (typeName.equals("short")) { + return "S"; + } else if (typeName.equals("int")) { + return "I"; + } else if (typeName.equals("long")) { + return "J"; + } else if (typeName.equals("float")) { + return "F"; + } else if (typeName.equals("double")) { + return "D"; + } else if (typeName.equals("boolean")) { + return "Z"; + } else if (typeName.equals("char")) { + return "C"; + } else { + throw new MessageTypeException(String.format( + "fatal error: type=%s", typeName)); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/Templates.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/Templates.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,154 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; +import java.util.Collection; +import java.util.Date; +import java.math.BigInteger; +import java.math.BigDecimal; +import org.msgpack.type.Value; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public final class Templates { + public static final Template TValue = ValueTemplate.getInstance(); + + public static final Template TByte = ByteTemplate.getInstance(); + + public static final Template TShort = ShortTemplate.getInstance(); + + public static final Template TInteger = IntegerTemplate.getInstance(); + + public static final Template TLong = LongTemplate.getInstance(); + + public static final Template TCharacter = CharacterTemplate.getInstance(); + + public static final Template TBigInteger = BigIntegerTemplate.getInstance(); + + public static final Template TBigDecimal = BigDecimalTemplate.getInstance(); + + public static final Template TFloat = FloatTemplate.getInstance(); + + public static final Template TDouble = DoubleTemplate.getInstance(); + + public static final Template TBoolean = BooleanTemplate.getInstance(); + + public static final Template TString = StringTemplate.getInstance(); + + public static final Template TByteArray = ByteArrayTemplate.getInstance(); + + public static final Template TByteBuffer = ByteBufferTemplate.getInstance(); + + public static final Template TDate = DateTemplate.getInstance(); + + public static Template tNotNullable(Template innerTemplate) { + return new NotNullableTemplate(innerTemplate); + } + + 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 tOrdinalEnum(Class enumClass) { + return new OrdinalEnumTemplate(enumClass); + } + + // public static Template tClass(Class target) { + // // TODO + // } + + @Deprecated + public static Template tByte() { + return TByte; + } + + @Deprecated + public static Template tShort() { + return TShort; + } + + @Deprecated + public static Template tInteger() { + return TInteger; + } + + @Deprecated + public static Template tLong() { + return TLong; + } + + @Deprecated + public static Template tCharacter() { + return TCharacter; + } + + @Deprecated + public static Template tBigInteger() { + return TBigInteger; + } + + @Deprecated + public static Template tBigDecimal() { + return TBigDecimal; + } + + @Deprecated + public static Template tFloat() { + return TFloat; + } + + @Deprecated + public static Template tDouble() { + return TDouble; + } + + @Deprecated + public static Template tBoolean() { + return TBoolean; + } + + @Deprecated + public static Template tString() { + return TString; + } + + @Deprecated + public static Template tByteArray() { + return TByteArray; + } + + @Deprecated + public static Template tByteBuffer() { + return TByteBuffer; + } + + @Deprecated + public static Template tDate() { + return TDate; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/ValueTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/ValueTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,55 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.MessageTypeException; +import org.msgpack.type.Value; + +public class ValueTemplate extends AbstractTemplate { + private ValueTemplate() { + } + + public void write(Packer pk, Value target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + pk.writeNil(); + return; + } + target.writeTo(pk); + } + + public Value read(Unpacker u, Value to, boolean required) + throws IOException { + if (!required && u.trySkipNil()) { + return null; + } + return u.readValue(); + } + + static public ValueTemplate getInstance() { + return instance; + } + + static final ValueTemplate instance = new ValueTemplate(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/AbstractTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/AbstractTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,293 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Ignore; +import org.msgpack.annotation.Index; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.MessagePackBeans; +import org.msgpack.annotation.MessagePackMessage; +import org.msgpack.annotation.MessagePackOrdinalEnum; +import org.msgpack.annotation.NotNullable; +import org.msgpack.annotation.Optional; +import org.msgpack.annotation.OrdinalEnum; +import org.msgpack.template.FieldList; +import org.msgpack.template.FieldOption; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.TemplateBuildException; + +public abstract class AbstractTemplateBuilder implements TemplateBuilder { + + protected TemplateRegistry registry; + + protected AbstractTemplateBuilder(TemplateRegistry registry) { + this.registry = registry; + } + + @Override + public Template buildTemplate(final Type targetType) + throws TemplateBuildException { + @SuppressWarnings("unchecked") + Class targetClass = (Class) targetType; + checkClassValidation(targetClass); + FieldOption fieldOption = getFieldOption(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, fieldOption); + return buildTemplate(targetClass, entries); + } + + @Override + public Template buildTemplate(final Class targetClass, final FieldList fieldList) + throws TemplateBuildException { + checkClassValidation(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, fieldList); + return buildTemplate(targetClass, entries); + } + + protected abstract Template buildTemplate(Class targetClass, FieldEntry[] entries); + + protected void checkClassValidation(final Class targetClass) { + if (targetClass.isInterface()) { + throw new TemplateBuildException( + "Cannot build template for interface: " + targetClass.getName()); + } + if (Modifier.isAbstract(targetClass.getModifiers())) { + throw new TemplateBuildException( + "Cannot build template for abstract class: " + targetClass.getName()); + } + if (targetClass.isArray()) { + throw new TemplateBuildException( + "Cannot build template for array class: " + targetClass.getName()); + } + if (targetClass.isPrimitive()) { + throw new TemplateBuildException( + "Cannot build template of primitive type: " + targetClass.getName()); + } + } + + protected FieldOption getFieldOption(Class targetClass) { + Message m = targetClass.getAnnotation(Message.class); + if (m == null) { + return FieldOption.DEFAULT; + } + MessagePackMessage mpm = targetClass + .getAnnotation(MessagePackMessage.class); + if (mpm == null) { + return FieldOption.DEFAULT; + } + // TODO #MN + return m.value(); + } + + private FieldEntry[] toFieldEntries(final Class targetClass, final FieldList flist) { + List src = flist.getList(); + FieldEntry[] entries = new FieldEntry[src.size()]; + for (int i = 0; i < src.size(); i++) { + FieldList.Entry s = src.get(i); + if (s.isAvailable()) { + try { + entries[i] = new DefaultFieldEntry(targetClass.getDeclaredField(s.getName()), s.getOption()); + } catch (SecurityException e) { + throw new TemplateBuildException(e); + } catch (NoSuchFieldException e) { + throw new TemplateBuildException(e); + } + } else { + entries[i] = new DefaultFieldEntry(); + } + } + return entries; + } + + protected FieldEntry[] toFieldEntries(final Class targetClass, final FieldOption from) { + Field[] fields = getFields(targetClass); + + /* + * index: + * + * @Index(0) + * int field_a; // 0 + * int field_b; // 1 + * @Index(3) + * int field_c; // 3 + * int field_d; // 4 + * @Index(2) + * int field_e; // 2 + * int field_f; // 5 + */ + List indexed = new ArrayList(); + int maxIndex = -1; + for (Field f : fields) { + FieldOption opt = getFieldOption(f, from); + if (opt == FieldOption.IGNORE) { + // skip + continue; + } + + int index = getFieldIndex(f, maxIndex); + if (indexed.size() > index && indexed.get(index) != null) { + throw new TemplateBuildException("duplicated index: " + index); + } + if (index < 0) { + throw new TemplateBuildException("invalid index: " + index); + } + + while (indexed.size() <= index) { + indexed.add(null); + } + indexed.set(index, new DefaultFieldEntry(f, opt)); + + if (maxIndex < index) { + maxIndex = index; + } + } + + FieldEntry[] entries = new FieldEntry[maxIndex + 1]; + for (int i = 0; i < indexed.size(); i++) { + FieldEntry e = indexed.get(i); + if (e == null) { + entries[i] = new DefaultFieldEntry(); + } else { + entries[i] = e; + } + } + return entries; + } + + private Field[] getFields(Class targetClass) { + // order: [fields of super class, ..., fields of this class] + List succ = new ArrayList(); + int total = 0; + for (Class c = targetClass; c != Object.class; c = c.getSuperclass()) { + Field[] fields = c.getDeclaredFields(); + total += fields.length; + succ.add(fields); + } + Field[] result = new Field[total]; + int off = 0; + for (int i = succ.size() - 1; i >= 0; i--) { + Field[] fields = succ.get(i); + System.arraycopy(fields, 0, result, off, fields.length); + off += fields.length; + } + return result; + } + + private FieldOption getFieldOption(Field field, FieldOption from) { + int mod = field.getModifiers(); + // default mode: + // transient, static, final : Ignore + // primitive type : NotNullable + // reference type : Ignore + if (Modifier.isStatic(mod) || Modifier.isFinal(mod) + || Modifier.isTransient(mod)) { + return FieldOption.IGNORE; + } + + if (isAnnotated(field, Ignore.class)) { + return FieldOption.IGNORE; + } else if (isAnnotated(field, Optional.class)) { + return FieldOption.OPTIONAL; + } else if (isAnnotated(field, NotNullable.class)) { + return FieldOption.NOTNULLABLE; + } + + if (from != FieldOption.DEFAULT) { + return from; + } + + if (field.getType().isPrimitive()) { + return FieldOption.NOTNULLABLE; + } else { + return FieldOption.OPTIONAL; + } + } + + private int getFieldIndex(final Field field, int maxIndex) { + Index a = field.getAnnotation(Index.class); + if (a == null) { + return maxIndex + 1; + } else { + return a.value(); + } + } + + @Override + public void writeTemplate(Type targetType, String directoryName) { + throw new UnsupportedOperationException(targetType.toString()); + } + + @Override + public Template loadTemplate(Type targetType) { + return null; + } + + public static boolean isAnnotated(Class targetClass, + Class with) { + return targetClass.getAnnotation(with) != null; + } + + public static boolean isAnnotated(AccessibleObject accessibleObject, Class with) { + return accessibleObject.getAnnotation(with) != null; + } + + public static boolean matchAtClassTemplateBuilder(Class targetClass, boolean hasAnnotation) { + if (hasAnnotation) { + return AbstractTemplateBuilder.isAnnotated(targetClass, Message.class) + || AbstractTemplateBuilder.isAnnotated(targetClass, MessagePackMessage.class); + } else { + return !targetClass.isEnum() && !targetClass.isInterface(); + } + } + + public static boolean matchAtBeansClassTemplateBuilder(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + if (hasAnnotation) { + return AbstractTemplateBuilder.isAnnotated((Class) targetType, Beans.class) + || AbstractTemplateBuilder.isAnnotated((Class) targetType, MessagePackBeans.class); + } else { + return !targetClass.isEnum() || !targetClass.isInterface(); + } + } + + public static boolean matchAtArrayTemplateBuilder(Class targetClass, boolean hasAnnotation) { + if (((Type) targetClass) instanceof GenericArrayType) { + return true; + } + return targetClass.isArray(); + } + + public static boolean matchAtOrdinalEnumTemplateBuilder(Class targetClass, boolean hasAnnotation) { + if (hasAnnotation) { + return AbstractTemplateBuilder.isAnnotated(targetClass, OrdinalEnum.class) + || AbstractTemplateBuilder.isAnnotated(targetClass, MessagePackOrdinalEnum.class); + } else { + return targetClass.isEnum(); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/ArrayTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/ArrayTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,199 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.template.AbstractTemplate; +import org.msgpack.template.BooleanArrayTemplate; +import org.msgpack.template.ByteArrayTemplate; +import org.msgpack.template.DoubleArrayTemplate; +import org.msgpack.template.FieldList; +import org.msgpack.template.FloatArrayTemplate; +import org.msgpack.template.IntegerArrayTemplate; +import org.msgpack.template.LongArrayTemplate; +import org.msgpack.template.ObjectArrayTemplate; +import org.msgpack.template.ShortArrayTemplate; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.unpacker.Unpacker; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class ArrayTemplateBuilder extends AbstractTemplateBuilder { + + private static final Logger LOG = Logger.getLogger(ArrayTemplateBuilder.class.getName()); + + static class ReflectionMultidimentionalArrayTemplate extends AbstractTemplate { + + private Class componentClass; + + private Template componentTemplate; + + public ReflectionMultidimentionalArrayTemplate(Class componentClass, Template componentTemplate) { + this.componentClass = componentClass; + this.componentTemplate = componentTemplate; + } + + Class getComponentClass() { + return componentClass; + } + + @Override + public void write(Packer packer, Object v, boolean required) throws IOException { + if (v == null) { + if (required) { + throw new MessageTypeException("Attempted to write null"); + } + packer.writeNil(); + return; + } + if (!(v instanceof Object[]) + || !componentClass.isAssignableFrom(v.getClass().getComponentType())) { + throw new MessageTypeException(); + } + + Object[] array = (Object[]) v; + int length = array.length; + packer.writeArrayBegin(length); + for (int i = 0; i < length; i++) { + componentTemplate.write(packer, array[i], required); + } + packer.writeArrayEnd(); + } + + @Override + public Object read(Unpacker unpacker, Object to, boolean required) throws IOException { + if (!required && unpacker.trySkipNil()) { + return null; + } + + int length = unpacker.readArrayBegin(); + Object[] array = (Object[]) Array.newInstance(componentClass, length); + for (int i = 0; i < length; i++) { + array[i] = componentTemplate.read(unpacker, null, required); + } + unpacker.readArrayEnd(); + return array; + } + } + + public ArrayTemplateBuilder(TemplateRegistry registry) { + super(registry); + } + + @Override + public boolean matchType(Type targetType, boolean forceBuild) { + Class targetClass = (Class) targetType; + boolean matched = AbstractTemplateBuilder.matchAtArrayTemplateBuilder(targetClass, false); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + @Override + public Template buildTemplate(Type arrayType) { + Type baseType; + Class baseClass; + int dim = 1; + if (arrayType instanceof GenericArrayType) { + GenericArrayType type = (GenericArrayType) arrayType; + baseType = type.getGenericComponentType(); + while (baseType instanceof GenericArrayType) { + baseType = ((GenericArrayType) baseType).getGenericComponentType(); + dim += 1; + } + if (baseType instanceof ParameterizedType) { + baseClass = (Class) ((ParameterizedType) baseType).getRawType(); + } else { + baseClass = (Class) baseType; + } + } else { + Class type = (Class) arrayType; + baseClass = type.getComponentType(); + while (baseClass.isArray()) { + baseClass = baseClass.getComponentType(); + dim += 1; + } + baseType = baseClass; + } + return toTemplate(arrayType, baseType, baseClass, dim); + } + + private Template toTemplate(Type arrayType, Type genericBaseType, Class baseClass, int dim) { + if (dim == 1) { + if (baseClass == boolean.class) { + return BooleanArrayTemplate.getInstance(); + } else if (baseClass == short.class) { + return ShortArrayTemplate.getInstance(); + } else if (baseClass == int.class) { + return IntegerArrayTemplate.getInstance(); + } else if (baseClass == long.class) { + return LongArrayTemplate.getInstance(); + } else if (baseClass == float.class) { + return FloatArrayTemplate.getInstance(); + } else if (baseClass == double.class) { + return DoubleArrayTemplate.getInstance(); + } else if (baseClass == byte.class) { + return ByteArrayTemplate.getInstance(); + } else { + Template baseTemplate = registry.lookup(genericBaseType); + return new ObjectArrayTemplate(baseClass, baseTemplate); + } + } else if (dim == 2) { + Class componentClass = Array.newInstance(baseClass, 0).getClass(); + Template componentTemplate = toTemplate(arrayType, genericBaseType, baseClass, dim - 1); + return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate); + } else { + ReflectionMultidimentionalArrayTemplate componentTemplate = + (ReflectionMultidimentionalArrayTemplate) toTemplate(arrayType, genericBaseType, baseClass, dim - 1); + Class componentClass = Array.newInstance(componentTemplate.getComponentClass(), 0).getClass(); + return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate); + } + } + + @Override + public Template buildTemplate(Class targetClass, FieldList flist) + throws TemplateBuildException { + throw new UnsupportedOperationException(targetClass.getName()); + } + + @Override + protected Template buildTemplate(Class targetClass, FieldEntry[] entries) { + throw new UnsupportedOperationException(targetClass.getName()); + } + + @Override + public void writeTemplate(Type targetType, String directoryName) { + throw new UnsupportedOperationException(targetType.toString()); + } + + @Override + public Template loadTemplate(Type targetType) { + return null; + } + +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/BeansBuildContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/BeansBuildContext.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,189 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import org.msgpack.*; +import org.msgpack.template.*; + +import javassist.CannotCompileException; +import javassist.CtClass; +import javassist.CtConstructor; +import javassist.CtNewConstructor; +import javassist.NotFoundException; + +@SuppressWarnings("rawtypes") +public class BeansBuildContext extends BuildContext { + protected BeansFieldEntry[] entries; + + protected Class origClass; + + protected String origName; + + protected Template[] templates; + + public BeansBuildContext(JavassistTemplateBuilder director) { + super(director); + } + + public Template buildTemplate(Class targetClass, + BeansFieldEntry[] entries, Template[] templates) { + this.entries = entries; + this.templates = templates; + this.origClass = targetClass; + this.origName = origClass.getName(); + return build(origName); + } + + protected void setSuperClass() throws CannotCompileException, NotFoundException { + tmplCtClass.setSuperclass(director.getCtClass( + JavassistTemplateBuilder.JavassistTemplate.class.getName())); + } + + protected void buildConstructor() throws CannotCompileException, + NotFoundException { + // Constructor(Class targetClass, Template[] templates) + CtConstructor newCtCons = CtNewConstructor.make( + new CtClass[] { + director.getCtClass(Class.class.getName()), + director.getCtClass(Template.class.getName() + "[]") + }, new CtClass[0], tmplCtClass); + tmplCtClass.addConstructor(newCtCons); + } + + protected Template buildInstance(Class c) throws NoSuchMethodException, + InstantiationException, IllegalAccessException, InvocationTargetException { + Constructor cons = c.getConstructor(new Class[] { Class.class, Template[].class }); + Object tmpl = cons.newInstance(new Object[] { origClass, templates }); + return (Template) tmpl; + } + + protected void buildMethodInit() { + } + + @Override + protected String buildWriteMethodBody() { + resetStringBuilder(); + buildString("{"); + + buildString("if($2 == null) {"); + buildString(" if($3) {"); + buildString(" throw new %s(\"Attempted to write null\");", MessageTypeException.class.getName()); + buildString(" }"); + buildString(" $1.writeNil();"); + buildString(" return;"); + buildString("}"); + + buildString("%s _$$_t = (%s)$2;", origName, origName); + buildString("$1.writeArrayBegin(%d);", entries.length); + + for (int i = 0; i < entries.length; i++) { + BeansFieldEntry e = entries[i]; + if (!e.isAvailable()) { + buildString("$1.writeNil();"); + continue; + } + Class type = e.getType(); + if (type.isPrimitive()) { + buildString("$1.%s(_$$_t.%s());", primitiveWriteName(type), e.getGetterName()); + } else { + buildString("if(_$$_t.%s() == null) {", e.getGetterName()); + if (e.isNotNullable()) { + buildString("throw new %s();", MessageTypeException.class.getName()); + } else { + buildString("$1.writeNil();"); + } + buildString("} else {"); + buildString(" this.templates[%d].write($1, _$$_t.%s());", i, e.getGetterName()); + buildString("}"); + } + } + + buildString("$1.writeArrayEnd();"); + buildString("}"); + return getBuiltString(); + } + + @Override + protected String buildReadMethodBody() { + resetStringBuilder(); + buildString("{ "); + + buildString("if(!$3 && $1.trySkipNil()) {"); + buildString(" return null;"); + buildString("}"); + + buildString("%s _$$_t;", origName); + buildString("if($2 == null) {"); + buildString(" _$$_t = new %s();", origName); + buildString("} else {"); + buildString(" _$$_t = (%s)$2;", origName); + buildString("}"); + + buildString("$1.readArrayBegin();"); + + for (int i = 0; i < entries.length; i++) { + BeansFieldEntry e = entries[i]; + + if (!e.isAvailable()) { + buildString("$1.skip();"); // TODO #MN + continue; + } + + if (e.isOptional()) { + buildString("if($1.trySkipNil()) {"); + buildString("_$$_t.%s(null);", e.getSetterName()); + buildString("} else {"); + } + + Class type = e.getType(); + if (type.isPrimitive()) { + buildString("_$$_t.%s( $1.%s() );", e.getSetterName(), primitiveReadName(type)); + } else { + buildString( + "_$$_t.%s( (%s)this.templates[%d].read($1, _$$_t.%s()) );", + e.getSetterName(), e.getJavaTypeName(), i, e.getGetterName()); + } + + if (e.isOptional()) { + buildString("}"); + } + } + + buildString("$1.readArrayEnd();"); + buildString("return _$$_t;"); + + buildString("}"); + + return getBuiltString(); + } + + @Override + public void writeTemplate(Class targetClass, BeansFieldEntry[] entries, + Template[] templates, String directoryName) { + throw new UnsupportedOperationException(targetClass.getName()); + } + + @Override + public Template loadTemplate(Class targetClass, + BeansFieldEntry[] entries, Template[] templates) { + return null; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/BeansFieldEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/BeansFieldEntry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,84 @@ +package org.msgpack.template.builder; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Type; + +import org.msgpack.MessageTypeException; +import org.msgpack.template.FieldOption; +import org.msgpack.template.builder.beans.PropertyDescriptor; + +public class BeansFieldEntry extends FieldEntry { + + protected PropertyDescriptor desc; + + public BeansFieldEntry() { + super(); + } + + public BeansFieldEntry(final BeansFieldEntry e) { + super(e.option); + this.desc = e.getPropertyDescriptor(); + } + + public BeansFieldEntry(final PropertyDescriptor desc) { + this(desc, FieldOption.DEFAULT); + } + + public BeansFieldEntry(final PropertyDescriptor desc, final FieldOption option) { + super(option); + this.desc = desc; + } + + public String getGetterName() { + return getPropertyDescriptor().getReadMethod().getName(); + } + + public String getSetterName() { + return getPropertyDescriptor().getWriteMethod().getName(); + } + + public PropertyDescriptor getPropertyDescriptor() { + return desc; + } + + @Override + public String getName() { + return getPropertyDescriptor().getDisplayName(); + } + + @Override + public Class getType() { + return getPropertyDescriptor().getPropertyType(); + } + + @Override + public Type getGenericType() { + return getPropertyDescriptor().getReadMethod().getGenericReturnType(); + } + + @Override + public Object get(Object target) { + try { + return getPropertyDescriptor().getReadMethod().invoke(target); + } catch (IllegalArgumentException e) { + throw new MessageTypeException(e); + } catch (IllegalAccessException e) { + throw new MessageTypeException(e); + } catch (InvocationTargetException e) { + throw new MessageTypeException(e); + } + } + + @Override + public void set(Object target, Object value) { + try { + getPropertyDescriptor().getWriteMethod().invoke(target, value); + } catch (IllegalArgumentException e) { + throw new MessageTypeException(e); + } catch (IllegalAccessException e) { + throw new MessageTypeException(e); + } catch (InvocationTargetException e) { + throw new MessageTypeException(e); + } + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/BuildContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/BuildContext.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,249 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; + +import org.msgpack.*; +import org.msgpack.packer.Packer; +import org.msgpack.template.*; +import org.msgpack.unpacker.Unpacker; + +import javassist.CannotCompileException; +import javassist.CtClass; +import javassist.CtMethod; +import javassist.CtNewMethod; +import javassist.NotFoundException; + +@SuppressWarnings({ "rawtypes" }) +public abstract class BuildContext { + + private static Logger LOG = Logger.getLogger(BuildContext.class.getName()); + + protected JavassistTemplateBuilder director; + + protected String tmplName; + + protected CtClass tmplCtClass; + + protected abstract Template buildTemplate(Class targetClass, T[] entries, Template[] templates); + + protected abstract void setSuperClass() throws CannotCompileException, NotFoundException; + + protected abstract void buildConstructor() throws CannotCompileException, NotFoundException; + + public BuildContext(JavassistTemplateBuilder director) { + this.director = director; + } + + protected Template build(final String className) { + try { + reset(className, false); + LOG.fine(String.format("started generating template class %s for original class %s", + new Object[] { tmplCtClass.getName(), className })); + buildClass(); + buildConstructor(); + buildMethodInit(); + buildWriteMethod(); + buildReadMethod(); + LOG.fine(String.format("finished generating template class %s for original class %s", + new Object[] { tmplCtClass.getName(), className })); + return buildInstance(createClass()); + } catch (Exception e) { + String code = getBuiltString(); + if (code != null) { + LOG.severe("builder: " + code); + throw new TemplateBuildException("Cannot compile: " + code, e); + } else { + throw new TemplateBuildException(e); + } + } + } + + protected void reset(String className, boolean isWritten) { + String tmplName = null; + if (!isWritten) { + tmplName = className + "_$$_Template" + "_" + director.hashCode() + + "_" + director.nextSeqId(); + } else { + tmplName = className + "_$$_Template"; + } + tmplCtClass = director.makeCtClass(tmplName); + } + + protected void buildClass() throws CannotCompileException, NotFoundException { + setSuperClass(); + tmplCtClass.addInterface(director.getCtClass(Template.class.getName())); + } + + protected void buildMethodInit() { + } + + protected abstract Template buildInstance(Class c) + throws NoSuchMethodException, InstantiationException, + IllegalAccessException, InvocationTargetException; + + protected void buildWriteMethod() throws CannotCompileException, NotFoundException { + LOG.fine(String.format("started generating write method in template class %s", + new Object[] { tmplCtClass.getName() })); + String mbody = buildWriteMethodBody(); + int mod = javassist.Modifier.PUBLIC; + CtClass returnType = CtClass.voidType; + String mname = "write"; + CtClass[] paramTypes = new CtClass[] { + director.getCtClass(Packer.class.getName()), + director.getCtClass(Object.class.getName()), + CtClass.booleanType + }; + CtClass[] exceptTypes = new CtClass[] { + director.getCtClass(IOException.class.getName()) + }; + LOG.fine(String.format("compiling write method body: %s", new Object[] { mbody })); + CtMethod newCtMethod = CtNewMethod.make( + mod, returnType, mname, paramTypes, exceptTypes, mbody, tmplCtClass); + tmplCtClass.addMethod(newCtMethod); + LOG.fine(String.format("finished generating write method in template class %s", + new Object[] { tmplCtClass.getName() })); + } + + protected abstract String buildWriteMethodBody(); + + protected void buildReadMethod() throws CannotCompileException, NotFoundException { + LOG.fine(String.format("started generating read method in template class %s", + new Object[] { tmplCtClass.getName() })); + String mbody = buildReadMethodBody(); + int mod = javassist.Modifier.PUBLIC; + CtClass returnType = director.getCtClass(Object.class.getName()); + String mname = "read"; + CtClass[] paramTypes = new CtClass[] { + director.getCtClass(Unpacker.class.getName()), + director.getCtClass(Object.class.getName()), + CtClass.booleanType + }; + CtClass[] exceptTypes = new CtClass[] { + director.getCtClass(MessageTypeException.class.getName()) + }; + LOG.fine(String.format("compiling read method body: %s", new Object[] { mbody })); + CtMethod newCtMethod = CtNewMethod.make( + mod, returnType, mname, paramTypes, exceptTypes, mbody, tmplCtClass); + tmplCtClass.addMethod(newCtMethod); + LOG.fine(String.format("finished generating read method in template class %s", + new Object[] { tmplCtClass.getName() })); + } + + protected abstract String buildReadMethodBody(); + + protected Class createClass() throws CannotCompileException { + return (Class) tmplCtClass.toClass(director.getClassLoader(), getClass().getProtectionDomain()); + } + + protected void saveClass(final String directoryName) throws CannotCompileException, IOException { + tmplCtClass.writeFile(directoryName); + } + + protected StringBuilder stringBuilder = null; + + protected void resetStringBuilder() { + stringBuilder = new StringBuilder(); + } + + protected void buildString(String str) { + stringBuilder.append(str); + } + + protected void buildString(String format, Object... args) { + stringBuilder.append(String.format(format, args)); + } + + protected String getBuiltString() { + if (stringBuilder == null) { + return null; + } + return stringBuilder.toString(); + } + + protected String primitiveWriteName(Class type) { + return "write"; + } + + protected String primitiveReadName(Class type) { + if (type == boolean.class) { + return "readBoolean"; + } else if (type == byte.class) { + return "readByte"; + } else if (type == short.class) { + return "readShort"; + } else if (type == int.class) { + return "readInt"; + } else if (type == long.class) { + return "readLong"; + } else if (type == float.class) { + return "readFloat"; + } else if (type == double.class) { + return "readDouble"; + } else if (type == char.class) { + return "readInt"; + } + return null; + } + + protected abstract void writeTemplate(Class targetClass, T[] entries, + Template[] templates, String directoryName); + + protected void write(final String className, final String directoryName) { + try { + reset(className, true); + buildClass(); + buildConstructor(); + buildMethodInit(); + buildWriteMethod(); + buildReadMethod(); + saveClass(directoryName); + } catch (Exception e) { + String code = getBuiltString(); + if (code != null) { + LOG.severe("builder: " + code); + throw new TemplateBuildException("Cannot compile: " + code, e); + } else { + throw new TemplateBuildException(e); + } + } + } + + protected abstract Template loadTemplate(Class targetClass, T[] entries, Template[] templates); + + protected Template load(final String className) { + String tmplName = className + "_$$_Template"; + try { + Class tmplClass = getClass().getClassLoader().loadClass(tmplName); + return buildInstance(tmplClass); + } catch (ClassNotFoundException e) { + return null; + } catch (Exception e) { + String code = getBuiltString(); + if (code != null) { + LOG.severe("builder: " + code); + throw new TemplateBuildException("Cannot compile: " + code, e); + } else { + throw new TemplateBuildException(e); + } + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/DefaultBuildContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/DefaultBuildContext.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,286 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; + +import org.msgpack.*; +import org.msgpack.packer.Packer; +import org.msgpack.template.*; +import org.msgpack.unpacker.Unpacker; + +import javassist.CannotCompileException; +import javassist.CtClass; +import javassist.CtConstructor; +import javassist.CtNewConstructor; +import javassist.NotFoundException; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class DefaultBuildContext extends BuildContext { + protected FieldEntry[] entries; + + protected Class origClass; + + protected String origName; + + protected Template[] templates; + + public DefaultBuildContext(JavassistTemplateBuilder director) { + super(director); + } + + public Template buildTemplate(Class targetClass, FieldEntry[] entries, + Template[] templates) { + this.entries = entries; + this.templates = templates; + this.origClass = targetClass; + this.origName = origClass.getName(); + return build(origName); + } + + protected void setSuperClass() throws CannotCompileException, NotFoundException { + tmplCtClass.setSuperclass(director.getCtClass( + JavassistTemplateBuilder.JavassistTemplate.class.getName())); + } + + protected void buildConstructor() throws CannotCompileException, + NotFoundException { + // Constructor(Class targetClass, Template[] templates) + CtConstructor newCtCons = CtNewConstructor.make( + new CtClass[] { + director.getCtClass(Class.class.getName()), + director.getCtClass(Template.class.getName() + "[]") + }, new CtClass[0], tmplCtClass); + tmplCtClass.addConstructor(newCtCons); + } + + protected Template buildInstance(Class c) throws NoSuchMethodException, + InstantiationException, IllegalAccessException, + InvocationTargetException { + Constructor cons = c.getConstructor(new Class[] { Class.class, Template[].class }); + Object tmpl = cons.newInstance(new Object[] { origClass, templates }); + return (Template) tmpl; + } + + protected void buildMethodInit() { + } + + protected String buildWriteMethodBody() { + resetStringBuilder(); + buildString("\n{\n"); + + buildString(" if ($2 == null) {\n"); + buildString(" if ($3) {\n"); + buildString(" throw new %s(\"Attempted to write null\");\n", MessageTypeException.class.getName()); + buildString(" }\n"); + buildString(" $1.writeNil();\n"); + buildString(" return;\n"); + buildString(" }\n"); + + buildString(" %s _$$_t = (%s) $2;\n", origName, origName); + buildString(" $1.writeArrayBegin(%d);\n", entries.length); + + for (int i = 0; i < entries.length; i++) { + FieldEntry e = entries[i]; + if (!e.isAvailable()) { + buildString(" $1.writeNil();\n"); + continue; + } + DefaultFieldEntry de = (DefaultFieldEntry) e; + boolean isPrivate = Modifier.isPrivate(de.getField().getModifiers()); + Class type = de.getType(); + if (type.isPrimitive()) { // primitive types + if (!isPrivate) { + buildString(" $1.%s(_$$_t.%s);\n", primitiveWriteName(type), de.getName()); + } else { + buildString( + " %s.writePrivateField($1, _$$_t, %s.class, \"%s\", templates[%d]);\n", + DefaultBuildContext.class.getName(), de.getField().getDeclaringClass().getName(), de.getName(), i); + } + } else { // reference types + if (!isPrivate) { + buildString(" if (_$$_t.%s == null) {\n", de.getName()); + } else { + buildString( + " if (%s.readPrivateField(_$$_t, %s.class, \"%s\") == null) {\n", + DefaultBuildContext.class.getName(), de.getField().getDeclaringClass().getName(), de.getName()); + } + if (de.isNotNullable()) { + buildString( + " throw new %s(\"%s cannot be null by @NotNullable\");\n", + MessageTypeException.class.getName(), de.getName()); + } else { + buildString(" $1.writeNil();\n"); + } + buildString(" } else {\n"); + if (!isPrivate) { + buildString(" templates[%d].write($1, _$$_t.%s);\n", i, de.getName()); + } else { + buildString( + " %s.writePrivateField($1, _$$_t, %s.class, \"%s\", templates[%d]);\n", + DefaultBuildContext.class.getName(), de.getField().getDeclaringClass().getName(), de.getName(), i); + } + buildString(" }\n"); + } + } + + buildString(" $1.writeArrayEnd();\n"); + buildString("}\n"); + return getBuiltString(); + } + + public static Object readPrivateField(Object target, Class targetClass, String fieldName) { + Field field = null; + try { + field = targetClass.getDeclaredField(fieldName); + field.setAccessible(true); + Object valueReference = field.get(target); + return valueReference; + } catch (Exception e) { + throw new MessageTypeException(e); + } finally { + if (field != null) { + field.setAccessible(false); + } + } + } + + public static void writePrivateField(Packer packer, Object target, + Class targetClass, String fieldName, Template tmpl) { + Field field = null; + try { + field = targetClass.getDeclaredField(fieldName); + field.setAccessible(true); + Object valueReference = field.get(target); + tmpl.write(packer, valueReference); + } catch (Exception e) { + throw new MessageTypeException(e); + } finally { + if (field != null) { + field.setAccessible(false); + } + } + } + + protected String buildReadMethodBody() { + resetStringBuilder(); + buildString("\n{\n"); + + buildString(" if (!$3 && $1.trySkipNil()) {\n"); + buildString(" return null;\n"); + buildString(" }\n"); + + buildString(" %s _$$_t;\n", origName); + buildString(" if ($2 == null) {\n"); + buildString(" _$$_t = new %s();\n", origName); + buildString(" } else {\n"); + buildString(" _$$_t = (%s) $2;\n", origName); + buildString(" }\n"); + buildString(" $1.readArrayBegin();\n"); + + int i; + for (i = 0; i < entries.length; i++) { + FieldEntry e = entries[i]; + if (!e.isAvailable()) { + buildString(" $1.skip();\n"); + continue; + } + + if (e.isOptional()) { + buildString(" if ($1.trySkipNil()) {"); + // if Optional and nil, then keep default value + buildString(" } else {\n"); + } + + DefaultFieldEntry de = (DefaultFieldEntry) e; + boolean isPrivate = Modifier.isPrivate(de.getField().getModifiers()); + Class type = de.getType(); + if (type.isPrimitive()) { + if (!isPrivate) { + buildString(" _$$_t.%s = $1.%s();\n", de.getName(), primitiveReadName(type)); + } else { + buildString( + " %s.readPrivateField($1, _$$_t, %s.class, \"%s\", templates[%d]);\n", + DefaultBuildContext.class.getName(), de.getField().getDeclaringClass().getName(), de.getName(), i); + } + } else { + if (!isPrivate) { + buildString( + " _$$_t.%s = (%s) this.templates[%d].read($1, _$$_t.%s);\n", + de.getName(), de.getJavaTypeName(), i, de.getName()); + } else { + buildString( + " %s.readPrivateField($1, _$$_t, %s.class, \"%s\", templates[%d]);\n", + DefaultBuildContext.class.getName(), de.getField().getDeclaringClass().getName(), de.getName(), i); + } + } + + if (de.isOptional()) { + buildString(" }\n"); + } + } + + buildString(" $1.readArrayEnd();\n"); + buildString(" return _$$_t;\n"); + + buildString("}\n"); + return getBuiltString(); + } + + public static void readPrivateField(Unpacker unpacker, Object target, + Class targetClass, String fieldName, Template tmpl) { + Field field = null; + try { + field = targetClass.getDeclaredField(fieldName); + field.setAccessible(true); + Object fieldReference = field.get(target); + Object valueReference = tmpl.read(unpacker, fieldReference); + if (valueReference != fieldReference) { + field.set(target, valueReference); + } + } catch (Exception e) { + throw new MessageTypeException(e); + } finally { + if (field != null) { + field.setAccessible(false); + } + } + } + + @Override + public void writeTemplate(Class targetClass, FieldEntry[] entries, + Template[] templates, String directoryName) { + this.entries = entries; + this.templates = templates; + this.origClass = targetClass; + this.origName = origClass.getName(); + write(origName, directoryName); + } + + @Override + public Template loadTemplate(Class targetClass, FieldEntry[] entries, Template[] templates) { + this.entries = entries; + this.templates = templates; + this.origClass = targetClass; + this.origName = origClass.getName(); + return load(origName); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/DefaultFieldEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/DefaultFieldEntry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,86 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; + +import org.msgpack.MessageTypeException; +import org.msgpack.template.FieldOption; + +public class DefaultFieldEntry extends FieldEntry { + protected Field field; + + public DefaultFieldEntry() { + this(null, FieldOption.IGNORE); + } + + public DefaultFieldEntry(final DefaultFieldEntry e) { + this(e.field, e.option); + } + + public DefaultFieldEntry(final Field field, final FieldOption option) { + super(option); + this.field = field; + } + + public Field getField() { + return field; + } + + public void setField(final Field field) { + this.field = field; + } + + @Override + public String getName() { + return field.getName(); + } + + @Override + public Class getType() { + return field.getType(); + } + + @Override + public Type getGenericType() { + return field.getGenericType(); + } + + @Override + public Object get(Object target) { + try { + return getField().get(target); + } catch (IllegalArgumentException e) { + throw new MessageTypeException(e); + } catch (IllegalAccessException e) { + throw new MessageTypeException(e); + } + } + + @Override + public void set(Object target, Object value) { + try { + field.set(target, value); + } catch (IllegalArgumentException e) { + throw new MessageTypeException(e); + } catch (IllegalAccessException e) { + throw new MessageTypeException(e); + } + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/FieldEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/FieldEntry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,90 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Type; + +import org.msgpack.template.FieldOption; + +public abstract class FieldEntry { + + protected FieldOption option; + + public FieldEntry() { + this(FieldOption.IGNORE); + } + + public FieldEntry(FieldOption option) { + this.option = option; + } + + public FieldOption getOption() { + return option; + } + + public void setOption(FieldOption option) { + this.option = option; + } + + public boolean isAvailable() { + return option != FieldOption.IGNORE; + } + + public boolean isOptional() { + return option == FieldOption.OPTIONAL; + } + + public boolean isNotNullable() { + return option == FieldOption.NOTNULLABLE; + } + + public abstract String getName(); + + public abstract Class getType(); + + public abstract Type getGenericType(); + + public abstract Object get(Object target); + + public abstract void set(Object target, Object value); + + public String getJavaTypeName() { + Class type = getType(); + if (type.isArray()) { + return arrayTypeToString(type); + } else { + return type.getName(); + } + } + + public String arrayTypeToString(Class type) { + int dim = 1; + Class baseType = type.getComponentType(); + while (baseType.isArray()) { + baseType = baseType.getComponentType(); + dim += 1; + } + StringBuilder sb = new StringBuilder(); + sb.append(baseType.getName()); + for (int i = 0; i < dim; ++i) { + sb.append("[]"); + } + return sb.toString(); + } + +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/JavassistBeansTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/JavassistBeansTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +package org.msgpack.template.builder; + +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.msgpack.template.TemplateRegistry; + +@SuppressWarnings({ "rawtypes" }) +public class JavassistBeansTemplateBuilder extends JavassistTemplateBuilder { + private static final Logger LOG = Logger.getLogger(JavassistBeansTemplateBuilder.class.getName()); + + public JavassistBeansTemplateBuilder(TemplateRegistry registry) { + super(registry); + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtClassTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + @Override + protected BuildContext createBuildContext() { + return new BeansBuildContext(this); + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/JavassistTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/JavassistTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,178 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javassist.ClassClassPath; +import javassist.ClassPool; +import javassist.CtClass; +import javassist.LoaderClassPath; +import javassist.NotFoundException; + +import org.msgpack.template.FieldOption; +import org.msgpack.template.Template; +import org.msgpack.template.AbstractTemplate; +import org.msgpack.template.TemplateRegistry; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class JavassistTemplateBuilder extends AbstractTemplateBuilder { + + private static Logger LOG = Logger.getLogger(JavassistTemplateBuilder.class.getName()); + + public static abstract class JavassistTemplate extends AbstractTemplate { + public Class targetClass; + public Template[] templates; + + public JavassistTemplate(Class targetClass, Template[] templates) { + this.targetClass = targetClass; + this.templates = templates; + } + } + + protected ClassPool pool; + + protected int seqId = 0; + + protected ClassLoader loader; + + public JavassistTemplateBuilder(TemplateRegistry registry) { + this(registry, null); + } + + public JavassistTemplateBuilder(TemplateRegistry registry, ClassLoader cl) { + super(registry); + pool = new ClassPool(); + pool.appendClassPath(new ClassClassPath(getClass())); + boolean appended = false; + loader = cl; + if (loader == null) { + loader = pool.getClassLoader(); + } + + try { + if (loader != null) { + pool.appendClassPath(new LoaderClassPath(loader)); + appended = true; + } + } catch (SecurityException e) { + LOG.fine("Cannot append a search path of classloader"); + e.printStackTrace(); + } + if (!appended) { + pool.appendSystemPath(); + } + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtClassTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + public void addClassLoader(ClassLoader cl) { + pool.appendClassPath(new LoaderClassPath(cl)); + } + + protected CtClass makeCtClass(String className) { + return pool.makeClass(className); + } + + protected CtClass getCtClass(String className) throws NotFoundException { + return pool.get(className); + } + + protected int nextSeqId() { + return seqId++; + } + + protected BuildContext createBuildContext() { + return new DefaultBuildContext(this); + } + + @Override + public Template buildTemplate(Class targetClass, FieldEntry[] entries) { + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + return bc.buildTemplate(targetClass, entries, tmpls); + } + + private Template[] toTemplate(FieldEntry[] from) { + Template[] tmpls = new Template[from.length]; + for (int i = 0; i < from.length; ++i) { + FieldEntry e = from[i]; + if (!e.isAvailable()) { + tmpls[i] = null; + } else { + Template tmpl = registry.lookup(e.getGenericType()); + tmpls[i] = tmpl; + } + } + return tmpls; + } + + @Override + public void writeTemplate(Type targetType, String directoryName) { + Class targetClass = (Class) targetType; + checkClassValidation(targetClass); + FieldOption implicitOption = getFieldOption(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, implicitOption); + writeTemplate(targetClass, entries, directoryName); + } + + private void writeTemplate(Class targetClass, FieldEntry[] entries, String directoryName) { + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + bc.writeTemplate(targetClass, entries, tmpls, directoryName); + } + + @Override + public Template loadTemplate(Type targetType) { + // FIXME #MN must consider how to load "reference cycle class" in next + // version + Class targetClass = (Class) targetType; + //checkClassValidation(targetClass); + try { + // check loadable + String tmplName = targetClass.getName() + "_$$_Template"; + ClassLoader cl = targetClass.getClassLoader(); + if (cl != null) { + cl.loadClass(tmplName); + } else { + return null; + } + } catch (ClassNotFoundException e) { + return null; + } + FieldOption implicitOption = getFieldOption(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, implicitOption); + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + return bc.loadTemplate(targetClass, entries, tmpls); + } + + protected ClassLoader getClassLoader() { + return loader; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/JavassistTemplateBuilder.java.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/JavassistTemplateBuilder.java.orig Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,174 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.Thread; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javassist.ClassPool; +import javassist.CtClass; +import javassist.LoaderClassPath; +import javassist.NotFoundException; + +import org.msgpack.template.FieldOption; +import org.msgpack.template.Template; +import org.msgpack.template.AbstractTemplate; +import org.msgpack.template.TemplateRegistry; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class JavassistTemplateBuilder extends AbstractTemplateBuilder { + + private static Logger LOG = Logger.getLogger(JavassistTemplateBuilder.class.getName()); + + public static abstract class JavassistTemplate extends AbstractTemplate { + public Class targetClass; + public Template[] templates; + + public JavassistTemplate(Class targetClass, Template[] templates) { + this.targetClass = targetClass; + this.templates = templates; + } + } + + protected ClassPool pool; + + protected int seqId = 0; + + public JavassistTemplateBuilder(TemplateRegistry registry) { + super(registry); + pool = new ClassPool(); + boolean appended = false; + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + if (cl != null) { + pool.appendClassPath(new LoaderClassPath(cl)); + appended = true; + } + } catch (SecurityException e) { + LOG.fine("Cannot append a search path of context classloader"); + e.printStackTrace(); + } + try { + ClassLoader cl2 = getClass().getClassLoader(); + if (cl2 != null && cl2 != cl) { + pool.appendClassPath(new LoaderClassPath(cl2)); + appended = true; + } + } catch (SecurityException e) { + LOG.fine("Cannot append a search path of classloader"); + e.printStackTrace(); + } + if (!appended) { + pool.appendSystemPath(); + } + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtClassTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + public void addClassLoader(ClassLoader cl) { + pool.appendClassPath(new LoaderClassPath(cl)); + } + + protected CtClass makeCtClass(String className) { + return pool.makeClass(className); + } + + protected CtClass getCtClass(String className) throws NotFoundException { + return pool.get(className); + } + + protected int nextSeqId() { + return seqId++; + } + + protected BuildContext createBuildContext() { + return new DefaultBuildContext(this); + } + + @Override + public Template buildTemplate(Class targetClass, FieldEntry[] entries) { + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + return bc.buildTemplate(targetClass, entries, tmpls); + } + + private Template[] toTemplate(FieldEntry[] from) { + Template[] tmpls = new Template[from.length]; + for (int i = 0; i < from.length; ++i) { + FieldEntry e = from[i]; + if (!e.isAvailable()) { + tmpls[i] = null; + } else { + Template tmpl = registry.lookup(e.getGenericType()); + tmpls[i] = tmpl; + } + } + return tmpls; + } + + @Override + public void writeTemplate(Type targetType, String directoryName) { + Class targetClass = (Class) targetType; + checkClassValidation(targetClass); + FieldOption implicitOption = getFieldOption(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, implicitOption); + writeTemplate(targetClass, entries, directoryName); + } + + private void writeTemplate(Class targetClass, FieldEntry[] entries, String directoryName) { + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + bc.writeTemplate(targetClass, entries, tmpls, directoryName); + } + + @Override + public Template loadTemplate(Type targetType) { + // FIXME #MN must consider how to load "reference cycle class" in next + // version + Class targetClass = (Class) targetType; + //checkClassValidation(targetClass); + try { + // check loadable + String tmplName = targetClass.getName() + "_$$_Template"; + ClassLoader cl = targetClass.getClassLoader(); + if (cl != null) { + cl.loadClass(tmplName); + } else { + return null; + } + } catch (ClassNotFoundException e) { + return null; + } + FieldOption implicitOption = getFieldOption(targetClass); + FieldEntry[] entries = toFieldEntries(targetClass, implicitOption); + Template[] tmpls = toTemplate(entries); + BuildContext bc = createBuildContext(); + return bc.loadTemplate(targetClass, entries, tmpls); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/OrdinalEnumTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/OrdinalEnumTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.msgpack.template.OrdinalEnumTemplate; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.TemplateBuildException; + +public class OrdinalEnumTemplateBuilder extends AbstractTemplateBuilder { + + private static final Logger LOG = Logger.getLogger(OrdinalEnumTemplateBuilder.class.getName()); + + public OrdinalEnumTemplateBuilder(TemplateRegistry registry) { + super(registry); + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtOrdinalEnumTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + @Override + public Template buildTemplate(Class targetClass, FieldEntry[] entries) { + throw new UnsupportedOperationException("fatal error: " + targetClass.getName()); + } + + @Override + public Template buildTemplate(Type targetType) throws TemplateBuildException { + @SuppressWarnings("unchecked") + Class targetClass = (Class) targetType; + checkOrdinalEnumValidation(targetClass); + return new OrdinalEnumTemplate(targetClass); + } + + protected void checkOrdinalEnumValidation(Class targetClass) { + if (!targetClass.isEnum()) { + throw new TemplateBuildException( + "tried to build ordinal enum template of non-enum class: " + targetClass.getName()); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/ReflectionBeansTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/ReflectionBeansTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,210 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.msgpack.annotation.Ignore; +import org.msgpack.annotation.Index; +import org.msgpack.annotation.NotNullable; +import org.msgpack.annotation.Optional; +import org.msgpack.packer.Packer; +import org.msgpack.template.FieldOption; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.beans.BeanInfo; +import org.msgpack.template.builder.beans.IntrospectionException; +import org.msgpack.template.builder.beans.Introspector; +import org.msgpack.template.builder.beans.PropertyDescriptor; +import org.msgpack.unpacker.Unpacker; + +/** + * Class for building java reflection template builder for java beans class. + * + * @author takeshita + * + */ +@SuppressWarnings({ "rawtypes" }) +public class ReflectionBeansTemplateBuilder extends ReflectionTemplateBuilder { + + private static Logger LOG = Logger.getLogger(ReflectionBeansTemplateBuilder.class.getName()); + + static class ReflectionBeansFieldTemplate extends ReflectionFieldTemplate { + ReflectionBeansFieldTemplate(final FieldEntry entry) { + super(entry); + } + + @Override + public void write(Packer packer, Object v, boolean required) throws IOException { + packer.write(v); + } + + @Override + public Object read(Unpacker unpacker, Object to, boolean required) throws IOException { + Object o = unpacker.read(entry.getType()); + entry.set(to, o); + return o; + } + } + + public ReflectionBeansTemplateBuilder(TemplateRegistry registry) { + super(registry, null); + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtBeansClassTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + @Override + protected ReflectionFieldTemplate[] toTemplates(FieldEntry[] entries) { + ReflectionFieldTemplate[] tmpls = new ReflectionFieldTemplate[entries.length]; + for (int i = 0; i < entries.length; i++) { + FieldEntry e = entries[i]; + Class type = e.getType(); + if (type.isPrimitive()) { + tmpls[i] = new ReflectionBeansFieldTemplate(e); + } else { + Template tmpl = registry.lookup(e.getGenericType()); + tmpls[i] = new FieldTemplateImpl(e, tmpl); + } + } + return tmpls; + } + + @Override + public FieldEntry[] toFieldEntries(Class targetClass, FieldOption implicitOption) { + BeanInfo desc; + try { + desc = Introspector.getBeanInfo(targetClass); + } catch (IntrospectionException e1) { + throw new TemplateBuildException( + "Class must be java beans class:" + targetClass.getName()); + } + + PropertyDescriptor[] props = desc.getPropertyDescriptors(); + ArrayList list = new ArrayList(); + for (int i = 0; i < props.length; i++) { + PropertyDescriptor pd = props[i]; + if (!isIgnoreProperty(pd)) { + list.add(pd); + } + } + props = new PropertyDescriptor[list.size()]; + list.toArray(props); + + BeansFieldEntry[] entries = new BeansFieldEntry[props.length]; + for (int i = 0; i < props.length; i++) { + PropertyDescriptor p = props[i]; + int index = getPropertyIndex(p); + if (index >= 0) { + if (entries[index] != null) { + throw new TemplateBuildException("duplicated index: " + index); + } + if (index >= entries.length) { + throw new TemplateBuildException("invalid index: " + index); + } + entries[index] = new BeansFieldEntry(p); + props[i] = null; + } + } + int insertIndex = 0; + for (int i = 0; i < props.length; i++) { + PropertyDescriptor p = props[i]; + if (p != null) { + while (entries[insertIndex] != null) { + insertIndex++; + } + entries[insertIndex] = new BeansFieldEntry(p); + } + + } + for (int i = 0; i < entries.length; i++) { + BeansFieldEntry e = entries[i]; + FieldOption op = getPropertyOption(e, implicitOption); + e.setOption(op); + } + return entries; + } + + private FieldOption getPropertyOption(BeansFieldEntry e, FieldOption implicitOption) { + FieldOption forGetter = getMethodOption(e.getPropertyDescriptor().getReadMethod()); + if (forGetter != FieldOption.DEFAULT) { + return forGetter; + } + FieldOption forSetter = getMethodOption(e.getPropertyDescriptor().getWriteMethod()); + if (forSetter != FieldOption.DEFAULT) { + return forSetter; + } else { + return implicitOption; + } + } + + private FieldOption getMethodOption(Method method) { + if (isAnnotated(method, Ignore.class)) { + return FieldOption.IGNORE; + } else if (isAnnotated(method, Optional.class)) { + return FieldOption.OPTIONAL; + } else if (isAnnotated(method, NotNullable.class)) { + return FieldOption.NOTNULLABLE; + } + return FieldOption.DEFAULT; + } + + private int getPropertyIndex(PropertyDescriptor desc) { + int getterIndex = getMethodIndex(desc.getReadMethod()); + if (getterIndex >= 0) { + return getterIndex; + } + int setterIndex = getMethodIndex(desc.getWriteMethod()); + return setterIndex; + } + + private int getMethodIndex(Method method) { + Index a = method.getAnnotation(Index.class); + if (a == null) { + return -1; + } else { + return a.value(); + } + } + + private boolean isIgnoreProperty(PropertyDescriptor desc) { + if (desc == null) { + return true; + } + Method getter = desc.getReadMethod(); + Method setter = desc.getWriteMethod(); + return getter == null || setter == null + || !Modifier.isPublic(getter.getModifiers()) + || !Modifier.isPublic(setter.getModifiers()) + || isAnnotated(getter, Ignore.class) + || isAnnotated(setter, Ignore.class); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/ReflectionTemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/ReflectionTemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,204 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.template.Template; +import org.msgpack.template.AbstractTemplate; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.unpacker.Unpacker; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class ReflectionTemplateBuilder extends AbstractTemplateBuilder { + + private static Logger LOG = Logger.getLogger(ReflectionBeansTemplateBuilder.class.getName()); + + protected static abstract class ReflectionFieldTemplate extends AbstractTemplate { + protected FieldEntry entry; + + ReflectionFieldTemplate(final FieldEntry entry) { + this.entry = entry; + } + + void setNil(Object v) { + entry.set(v, null); + } + } + + static final class FieldTemplateImpl extends ReflectionFieldTemplate { + private Template template; + + public FieldTemplateImpl(final FieldEntry entry, final Template template) { + super(entry); + this.template = template; + } + + @Override + public void write(Packer packer, Object v, boolean required) + throws IOException { + template.write(packer, v, required); + } + + @Override + public Object read(Unpacker unpacker, Object to, boolean required) + throws IOException { + // Class type = (Class) entry.getType(); + Object f = entry.get(to); + Object o = template.read(unpacker, f, required); + if (o != f) { + entry.set(to, o); + } + return o; + } + } + + protected static class ReflectionClassTemplate extends AbstractTemplate { + protected Class targetClass; + + protected ReflectionFieldTemplate[] templates; + + protected ReflectionClassTemplate(Class targetClass, ReflectionFieldTemplate[] templates) { + this.targetClass = targetClass; + this.templates = templates; + } + + @Override + public void write(Packer packer, T target, boolean required) + throws IOException { + if (target == null) { + if (required) { + throw new MessageTypeException("attempted to write null"); + } + packer.writeNil(); + return; + } + try { + packer.writeArrayBegin(templates.length); + for (ReflectionFieldTemplate tmpl : templates) { + if (!tmpl.entry.isAvailable()) { + packer.writeNil(); + continue; + } + Object obj = tmpl.entry.get(target); + if (obj == null) { + if (tmpl.entry.isNotNullable()) { + throw new MessageTypeException(tmpl.entry.getName() + + " cannot be null by @NotNullable"); + } + packer.writeNil(); + } else { + tmpl.write(packer, obj, true); + } + } + packer.writeArrayEnd(); + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new MessageTypeException(e); + } + } + + @Override + public T read(Unpacker unpacker, T to, boolean required) + throws IOException { + if (!required && unpacker.trySkipNil()) { + return null; + } + try { + if (to == null) { + to = targetClass.newInstance(); + } + + unpacker.readArrayBegin(); + for (int i = 0; i < templates.length; i++) { + ReflectionFieldTemplate tmpl = templates[i]; + if (!tmpl.entry.isAvailable()) { + unpacker.skip(); + } else if (tmpl.entry.isOptional() && unpacker.trySkipNil()) { + // if Optional + nil, than keep default value + } else { + tmpl.read(unpacker, to, false); + } + } + + unpacker.readArrayEnd(); + return to; + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new MessageTypeException(e); + } + } + } + + public ReflectionTemplateBuilder(TemplateRegistry registry) { + this(registry, null); + } + + public ReflectionTemplateBuilder(TemplateRegistry registry, ClassLoader cl) { + super(registry); + } + + @Override + public boolean matchType(Type targetType, boolean hasAnnotation) { + Class targetClass = (Class) targetType; + boolean matched = matchAtClassTemplateBuilder(targetClass, hasAnnotation); + if (matched && LOG.isLoggable(Level.FINE)) { + LOG.fine("matched type: " + targetClass.getName()); + } + return matched; + } + + @Override + public Template buildTemplate(Class targetClass, FieldEntry[] entries) { + if (entries == null) { + throw new NullPointerException("entries is null: " + targetClass); + } + + ReflectionFieldTemplate[] tmpls = toTemplates(entries); + return new ReflectionClassTemplate(targetClass, tmpls); + } + + protected ReflectionFieldTemplate[] toTemplates(FieldEntry[] entries) { + // TODO Now it is simply cast. #SF + for (FieldEntry entry : entries) { + Field field = ((DefaultFieldEntry) entry).getField(); + int mod = field.getModifiers(); + if (!Modifier.isPublic(mod)) { + field.setAccessible(true); + } + } + + ReflectionFieldTemplate[] templates = new ReflectionFieldTemplate[entries.length]; + for (int i = 0; i < entries.length; i++) { + FieldEntry entry = entries[i]; + // Class t = entry.getType(); + Template template = registry.lookup(entry.getGenericType()); + templates[i] = new FieldTemplateImpl(entry, template); + } + return templates; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/TemplateBuildException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/TemplateBuildException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,34 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +@SuppressWarnings("serial") +public class TemplateBuildException extends RuntimeException { + + public TemplateBuildException(String reason) { + super(reason); + } + + public TemplateBuildException(String reason, Throwable t) { + super(reason, t); + } + + public TemplateBuildException(Throwable t) { + super(t); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/TemplateBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/TemplateBuilder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,38 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Type; + +import org.msgpack.template.FieldList; +import org.msgpack.template.Template; + +public interface TemplateBuilder { + + boolean matchType(Type targetType, boolean forceBuild); + + Template buildTemplate(Type targetType) + throws TemplateBuildException; + + Template buildTemplate(Class targetClass, FieldList flist) + throws TemplateBuildException; + + void writeTemplate(Type targetType, String directoryName); + + Template loadTemplate(Type targetType); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/TemplateBuilderChain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/TemplateBuilderChain.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,102 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.template.builder; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import org.msgpack.template.TemplateRegistry; +import org.msgpack.util.android.DalvikVmChecker; + +public class TemplateBuilderChain { + private static final String JAVASSIST_TEMPLATE_BUILDER_CLASS_NAME = + "org.msgpack.template.builder.JavassistTemplateBuilder"; + private static final String REFLECTION_TEMPLATE_BUILDER_CLASS_NAME = + "org.msgpack.template.builder.ReflectionTemplateBuilder"; + + private static boolean enableDynamicCodeGeneration() { + return !DalvikVmChecker.isDalvikVm() && + Boolean.parseBoolean(System.getProperties().getProperty("msgpack.dynamic-codegen.enabled", "true")); + } + + protected List templateBuilders; + + protected TemplateBuilder forceBuilder; + + public TemplateBuilderChain(final TemplateRegistry registry) { + this(registry, null); + } + + public TemplateBuilderChain(final TemplateRegistry registry, final ClassLoader cl) { + templateBuilders = new ArrayList(); + reset(registry, cl); + } + + protected void reset(final TemplateRegistry registry, final ClassLoader cl) { + if (registry == null) { + throw new NullPointerException("registry is null"); + } + + // FIXME + // Javassist{,Beans}TemplateBuilder should be created with reflection for android. + + String forceBuilderClassName = null; + if (enableDynamicCodeGeneration()) { // use dynamic code generation + forceBuilderClassName = JAVASSIST_TEMPLATE_BUILDER_CLASS_NAME; + } else { + forceBuilderClassName = REFLECTION_TEMPLATE_BUILDER_CLASS_NAME; + } + + // create builder chain + forceBuilder = createForceTemplateBuilder(forceBuilderClassName, registry, cl); + TemplateBuilder builder = forceBuilder; + templateBuilders.add(new ArrayTemplateBuilder(registry)); + templateBuilders.add(new OrdinalEnumTemplateBuilder(registry)); + templateBuilders.add(builder); + templateBuilders.add(new ReflectionBeansTemplateBuilder(registry)); + } + + private static TemplateBuilder createForceTemplateBuilder(String className, + TemplateRegistry registry, ClassLoader cl) { + try { + Class c = (Class) Class.forName(className); + Constructor cons = c.getConstructor(TemplateRegistry.class, + ClassLoader.class); + return (TemplateBuilder) cons.newInstance(registry, cl); + } catch (Exception e) { + e.printStackTrace(); + } + return new ReflectionTemplateBuilder(registry, cl); + } + + public TemplateBuilder getForceBuilder() { + return forceBuilder; + } + + public TemplateBuilder select(final Type targetType, final boolean hasAnnotation) { + for (TemplateBuilder tb : templateBuilders) { + if (tb.matchType(targetType, hasAnnotation)) { + return tb; + } + } + return null; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/BeanDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/BeanDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,105 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + + +/** + * Describes a bean's global information. + */ +public class BeanDescriptor extends FeatureDescriptor { + + private Class beanClass; + + private Class customizerClass; + + /** + *

+ * Constructs an instance with the bean's {@link Class} and a customizer + * {@link Class}. The descriptor's {@link #getName()} is set as the + * unqualified name of the beanClass. + *

+ * + * @param beanClass + * The bean's Class. + * @param customizerClass + * The bean's customizer Class. + */ + public BeanDescriptor(Class beanClass, Class customizerClass) { + if (beanClass == null) { + throw new NullPointerException(); + } + setName(getShortClassName(beanClass)); + this.beanClass = beanClass; + this.customizerClass = customizerClass; + } + + /** + *

+ * Constructs an instance with the bean's {@link Class}. The descriptor's + * {@link #getName()} is set as the unqualified name of the + * beanClass. + *

+ * + * @param beanClass + * The bean's Class. + */ + public BeanDescriptor(Class beanClass) { + this(beanClass, null); + } + + /** + *

+ * Gets the bean's customizer {@link Class}/ + *

+ * + * @return A {@link Class} instance or null. + */ + public Class getCustomizerClass() { + return customizerClass; + } + + /** + *

+ * Gets the bean's {@link Class}. + *

+ * + * @return A {@link Class} instance. + */ + public Class getBeanClass() { + return beanClass; + } + + /** + *

+ * Utility method for getting the unqualified name of a {@link Class}. + *

+ * + * @param leguminaClass + * The Class to get the name from. + * @return A String instance or null. + */ + private String getShortClassName(Class leguminaClass) { + if(leguminaClass == null) { + return null; + } + String beanClassName = leguminaClass.getName(); + int lastIndex = beanClassName.lastIndexOf("."); //$NON-NLS-1$ + return (lastIndex == -1) ? beanClassName : beanClassName.substring(lastIndex + 1); + } + +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/BeanInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/BeanInfo.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,36 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + + +public interface BeanInfo { + + public PropertyDescriptor[] getPropertyDescriptors(); + + public MethodDescriptor[] getMethodDescriptors(); + + public EventSetDescriptor[] getEventSetDescriptors(); + + public BeanInfo[] getAdditionalBeanInfo(); + + public BeanDescriptor getBeanDescriptor(); + + public int getDefaultPropertyIndex(); + + public int getDefaultEventIndex(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/EventSetDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/EventSetDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,432 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.TooManyListenersException; +import org.apache.harmony.beans.internal.nls.Messages; + +public class EventSetDescriptor extends FeatureDescriptor { + private Class listenerType; + + private ArrayList listenerMethodDescriptors; + + private Method[] listenerMethods; + + private Method getListenerMethod; + + private Method addListenerMethod; + + private Method removeListenerMethod; + + private boolean unicast; + + private boolean inDefaultEventSet = true; + + public EventSetDescriptor(Class sourceClass, String eventSetName, + Class listenerType, String listenerMethodName) + throws IntrospectionException { + checkNotNull(sourceClass, eventSetName, listenerType, + listenerMethodName); + setName(eventSetName); + this.listenerType = listenerType; + + Method method = findListenerMethodByName(listenerMethodName); + checkEventType(eventSetName, method); + listenerMethodDescriptors = new ArrayList(); + listenerMethodDescriptors.add(new MethodDescriptor(method)); + addListenerMethod = findMethodByPrefix(sourceClass, "add", ""); //$NON-NLS-1$ //$NON-NLS-2$ + removeListenerMethod = findMethodByPrefix(sourceClass, "remove", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + if (addListenerMethod == null || removeListenerMethod == null) { + throw new IntrospectionException(Messages.getString("custom.beans.38")); //$NON-NLS-1$ + } + + getListenerMethod = findMethodByPrefix(sourceClass, "get", "s"); //$NON-NLS-1$ //$NON-NLS-2$ + unicast = isUnicastByDefault(addListenerMethod); + } + + public EventSetDescriptor(Class sourceClass, String eventSetName, + Class listenerType, String[] listenerMethodNames, + String addListenerMethodName, String removeListenerMethodName) + throws IntrospectionException { + this(sourceClass, eventSetName, listenerType, listenerMethodNames, + addListenerMethodName, removeListenerMethodName, null); + + } + + public EventSetDescriptor(Class sourceClass, String eventSetName, + Class listenerType, String[] listenerMethodNames, + String addListenerMethodName, String removeListenerMethodName, + String getListenerMethodName) throws IntrospectionException { + + checkNotNull(sourceClass, eventSetName, listenerType, + listenerMethodNames); + + setName(eventSetName); + this.listenerType = listenerType; + + listenerMethodDescriptors = new ArrayList(); + for (String element : listenerMethodNames) { + Method m = findListenerMethodByName(element); + + // checkEventType(eventSetName, m); + listenerMethodDescriptors.add(new MethodDescriptor(m)); + } + + if (addListenerMethodName != null) { + this.addListenerMethod = findAddRemoveListenerMethod(sourceClass, + addListenerMethodName); + } + if (removeListenerMethodName != null) { + this.removeListenerMethod = findAddRemoveListenerMethod( + sourceClass, removeListenerMethodName); + } + if (getListenerMethodName != null) { + this.getListenerMethod = findGetListenerMethod(sourceClass, + getListenerMethodName); + } + this.unicast = isUnicastByDefault(addListenerMethod); + } + + private Method findListenerMethodByName(String listenerMethodName) + throws IntrospectionException { + Method result = null; + Method[] methods = listenerType.getMethods(); + for (Method method : methods) { + if (listenerMethodName.equals(method.getName())) { + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length == 1 + && paramTypes[0].getName().endsWith("Event")) { //$NON-NLS-1$ + result = method; + break; + } + + } + } + if (null == result) { + throw new IntrospectionException(Messages.getString("custom.beans.31", //$NON-NLS-1$ + listenerMethodName, listenerType.getName())); + } + return result; + } + + public EventSetDescriptor(String eventSetName, Class listenerType, + Method[] listenerMethods, Method addListenerMethod, + Method removeListenerMethod) throws IntrospectionException { + + this(eventSetName, listenerType, listenerMethods, addListenerMethod, + removeListenerMethod, null); + } + + public EventSetDescriptor(String eventSetName, Class listenerType, + Method[] listenerMethods, Method addListenerMethod, + Method removeListenerMethod, Method getListenerMethod) + throws IntrospectionException { + + setName(eventSetName); + this.listenerType = listenerType; + + this.listenerMethods = listenerMethods; + if (listenerMethods != null) { + listenerMethodDescriptors = new ArrayList(); + + for (Method element : listenerMethods) { + // XXX do we need this check? + // checkEventType(eventSetName, element); + // if (checkMethod(listenerType, element)) { + this.listenerMethodDescriptors + .add(new MethodDescriptor(element)); + // } + } + } + + this.addListenerMethod = addListenerMethod; + this.removeListenerMethod = removeListenerMethod; + this.getListenerMethod = getListenerMethod; + this.unicast = isUnicastByDefault(addListenerMethod); + } + + public EventSetDescriptor(String eventSetName, Class listenerType, + MethodDescriptor[] listenerMethodDescriptors, + Method addListenerMethod, Method removeListenerMethod) + throws IntrospectionException { + + this(eventSetName, listenerType, null, addListenerMethod, + removeListenerMethod, null); + + if (listenerMethodDescriptors != null) { + this.listenerMethodDescriptors = new ArrayList(); + + for (MethodDescriptor element : listenerMethodDescriptors) { + this.listenerMethodDescriptors.add(element); + } + } + } + + // ensures that there is no nulls + @SuppressWarnings("nls") + private void checkNotNull(Object sourceClass, Object eventSetName, + Object alistenerType, Object listenerMethodName) { + if (sourceClass == null) { + throw new NullPointerException(Messages.getString("custom.beans.0C")); + } + if (eventSetName == null) { + throw new NullPointerException(Messages.getString("custom.beans.53")); + } + if (alistenerType == null) { + throw new NullPointerException(Messages.getString("custom.beans.54")); + } + if (listenerMethodName == null) { + throw new NullPointerException(Messages.getString("custom.beans.52")); + } + } + + /** + * Checks that given listener method has an argument of the valid type. + * + * @param eventSetName + * event set name + * @param listenerMethod + * listener method + * @throws IntrospectionException + * if check fails + */ + private static void checkEventType(String eventSetName, + Method listenerMethod) throws IntrospectionException { + Class[] params = listenerMethod.getParameterTypes(); + String firstParamTypeName = null; + String eventTypeName = prepareEventTypeName(eventSetName); + + if (params.length > 0) { + firstParamTypeName = extractShortClassName(params[0] + .getName()); + } + + if (firstParamTypeName == null + || !firstParamTypeName.equals(eventTypeName)) { + throw new IntrospectionException(Messages.getString("custom.beans.51", //$NON-NLS-1$ + listenerMethod.getName(), eventTypeName)); + } + } + + /** + * @param fullClassName full name of the class + * @return name with package and encapsulating class info omitted + */ + private static String extractShortClassName(String fullClassName) { + int k = fullClassName.lastIndexOf('$'); + k = (k == -1 ? fullClassName.lastIndexOf('.') : k); + return fullClassName.substring(k + 1); + } + + private static String prepareEventTypeName(String eventSetName) { + StringBuilder sb = new StringBuilder(); + + if (eventSetName != null && eventSetName.length() > 0) { + sb.append(Character.toUpperCase(eventSetName.charAt(0))); + + if (eventSetName.length() > 1) { + sb.append(eventSetName.substring(1)); + } + } + + sb.append("Event"); //$NON-NLS-1$ + return sb.toString(); + } + + public Method[] getListenerMethods() { + if (listenerMethods != null) { + return listenerMethods; + } + + if (listenerMethodDescriptors != null) { + listenerMethods = new Method[listenerMethodDescriptors.size()]; + int index = 0; + for (MethodDescriptor md : listenerMethodDescriptors) { + listenerMethods[index++] = md.getMethod(); + } + return listenerMethods; + } + return null; + } + + public MethodDescriptor[] getListenerMethodDescriptors() { + return listenerMethodDescriptors == null ? null + : listenerMethodDescriptors.toArray(new MethodDescriptor[0]); + } + + public Method getRemoveListenerMethod() { + return removeListenerMethod; + } + + public Method getGetListenerMethod() { + return getListenerMethod; + } + + public Method getAddListenerMethod() { + return addListenerMethod; + } + + public Class getListenerType() { + return listenerType; + } + + public void setUnicast(boolean unicast) { + this.unicast = unicast; + } + + public void setInDefaultEventSet(boolean inDefaultEventSet) { + this.inDefaultEventSet = inDefaultEventSet; + } + + public boolean isUnicast() { + return unicast; + } + + public boolean isInDefaultEventSet() { + return inDefaultEventSet; + } + + /** + * Searches for {add|remove}Listener methods in the event source. Parameter + * check is also performed. + * + * @param sourceClass + * event source class + * @param methodName + * method name to search + * @return found method + * @throws IntrospectionException + * if no valid method found + */ + private Method findAddRemoveListenerMethod(Class sourceClass, + String methodName) throws IntrospectionException { + try { + return sourceClass.getMethod(methodName, listenerType); + } catch (NoSuchMethodException e) { + return findAddRemoveListnerMethodWithLessCheck(sourceClass, + methodName); + } catch (Exception e) { + throw new IntrospectionException(Messages.getString("custom.beans.31", //$NON-NLS-1$ + methodName, listenerType.getName())); + } + } + + private Method findAddRemoveListnerMethodWithLessCheck( + Class sourceClass, String methodName) + throws IntrospectionException { + Method[] methods = sourceClass.getMethods(); + Method result = null; + for (Method method : methods) { + if (method.getName().equals(methodName)) { + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length == 1) { + result = method; + break; + } + } + } + if (null == result) { + throw new IntrospectionException(Messages.getString("custom.beans.31", //$NON-NLS-1$ + methodName, listenerType.getName())); + } + return result; + } + + /** + * @param sourceClass + * class of event source + * @param methodName + * name of the custom getListeners() method + * @return found Method object for custom getListener or null if nothing is + * found + */ + private Method findGetListenerMethod(Class sourceClass, String methodName) { + try { + return sourceClass.getMethod(methodName); + } catch (Exception e) { + // RI keeps silence here and just returns null + return null; + } + } + + private Method findMethodByPrefix(Class sourceClass, String prefix, + String postfix) { + String shortName = listenerType.getName(); + if (listenerType.getPackage() != null) { + shortName = shortName.substring(listenerType.getPackage().getName() + .length() + 1); + } + String methodName = prefix + shortName + postfix; + try { + if ("get".equals(prefix)) { //$NON-NLS-1$ + return sourceClass.getMethod(methodName); + } + } catch (NoSuchMethodException nsme) { + return null; + } + Method[] methods = sourceClass.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(methodName)) { + Class[] paramTypes = methods[i].getParameterTypes(); + if (paramTypes.length == 1) { + return methods[i]; + } + } + } + return null; + } + + private static boolean isUnicastByDefault(Method addMethod) { + if (addMethod != null) { + Class[] exceptionTypes = addMethod.getExceptionTypes(); + for (Class element : exceptionTypes) { + if (element.equals(TooManyListenersException.class)) { + return true; + } + } + } + return false; + } + + void merge(EventSetDescriptor event) { + super.merge(event); + if (addListenerMethod == null) { + addListenerMethod = event.addListenerMethod; + } + if (getListenerMethod == null) { + getListenerMethod = event.getListenerMethod; + } + if (listenerMethodDescriptors == null) { + listenerMethodDescriptors = event.listenerMethodDescriptors; + } + if (listenerMethods == null) { + listenerMethods = event.listenerMethods; + } + if (listenerType == null) { + listenerType = event.listenerType; + } + + if (removeListenerMethod == null) { + removeListenerMethod = event.removeListenerMethod; + } + inDefaultEventSet &= event.inDefaultEventSet; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/ExceptionListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/ExceptionListener.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,23 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +public interface ExceptionListener { + + public void exceptionThrown(Exception e); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/Expression.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/Expression.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,72 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import org.apache.harmony.beans.BeansUtils; + +public class Expression extends Statement { + + boolean valueIsDefined = false; + + Object value; + + public Expression(Object value, Object target, String methodName, + Object[] arguments) { + super(target, methodName, arguments); + this.value = value; + this.valueIsDefined = true; + } + + public Expression(Object target, String methodName, Object[] arguments) { + super(target, methodName, arguments); + this.value = null; + this.valueIsDefined = false; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (!valueIsDefined) { + sb.append(""); //$NON-NLS-1$ + } else { + if (value == null) { + sb.append(BeansUtils.NULL); + } else { + Class clazz = value.getClass(); + sb.append(clazz == String.class ? BeansUtils.QUOTE : BeansUtils + .idOfClass(clazz)); + } + } + sb.append('='); + sb.append(super.toString()); + return sb.toString(); + } + + public void setValue(Object value) { + this.value = value; + this.valueIsDefined = true; + } + + public Object getValue() throws Exception { + if (!valueIsDefined) { + value = invokeMethod(); + valueIsDefined = true; + } + return value; + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/FeatureDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/FeatureDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,249 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +/** + * Common base class for Descriptors. + */ +public class FeatureDescriptor { + + private Map values; + + boolean preferred, hidden, expert; + + String shortDescription; + + String name; + + String displayName; + + /** + *

+ * Constructs an instance. + *

+ */ + public FeatureDescriptor() { + this.values = new HashMap(); + } + + /** + *

+ * Sets the value for the named attribute. + *

+ * + * @param attributeName + * The name of the attribute to set a value with. + * @param value + * The value to set. + */ + public void setValue(String attributeName, Object value) { + if (attributeName == null || value == null) { + throw new NullPointerException(); + } + values.put(attributeName, value); + } + + /** + *

+ * Gets the value associated with the named attribute. + *

+ * + * @param attributeName + * The name of the attribute to get a value for. + * @return The attribute's value. + */ + public Object getValue(String attributeName) { + if (attributeName != null) { + return values.get(attributeName); + } + return null; + } + + /** + *

+ * Enumerates the attribute names. + *

+ * + * @return An instance of {@link Enumeration}. + */ + public Enumeration attributeNames() { + // Create a new list, so that the references are copied + return Collections.enumeration(new LinkedList(values.keySet())); + } + + /** + *

+ * Sets the short description. + *

+ * + * @param text + * The description to set. + */ + public void setShortDescription(String text) { + this.shortDescription = text; + } + + /** + *

+ * Sets the name. + *

+ * + * @param name + * The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + *

+ * Sets the display name. + *

+ * + * @param displayName + * The display name to set. + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + *

+ * Gets the short description or {@link #getDisplayName()} if not set. + *

+ * + * @return The description. + */ + public String getShortDescription() { + return shortDescription == null ? getDisplayName() : shortDescription; + } + + /** + *

+ * Gets the name. + *

+ * + * @return The name. + */ + public String getName() { + return name; + } + + /** + *

+ * Gets the display name or {@link #getName()} if not set. + *

+ * + * @return The display name. + */ + public String getDisplayName() { + return displayName == null ? getName() : displayName; + } + + /** + *

+ * Sets the preferred indicator. + *

+ * + * @param preferred + * true if preferred, false + * otherwise. + */ + public void setPreferred(boolean preferred) { + this.preferred = preferred; + } + + /** + *

+ * Sets the hidden indicator. + *

+ * + * @param hidden + * true if hidden, false otherwise. + */ + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + /** + *

+ * Sets the expert indicator. + *

+ * + * @param expert + * true if expert, false otherwise. + */ + public void setExpert(boolean expert) { + this.expert = expert; + } + + /** + *

+ * Indicates if this feature is preferred. + *

+ * + * @return true if preferred, false otherwise. + */ + public boolean isPreferred() { + return preferred; + } + + /** + *

+ * Indicates if this feature is hidden. + *

+ * + * @return true if hidden, false otherwise. + */ + public boolean isHidden() { + return hidden; + } + + /** + *

+ * Indicates if this feature is an expert feature. + *

+ * + * @return true if hidden, false otherwise. + */ + public boolean isExpert() { + return expert; + } + + void merge(FeatureDescriptor feature){ + assert(name.equals(feature.name)); + expert |= feature.expert; + hidden |= feature.hidden; + preferred |= feature.preferred; + if(shortDescription == null){ + shortDescription = feature.shortDescription; + } + if(name == null){ + name = feature.name; + } + if(displayName == null){ + displayName = feature.displayName; + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/IndexedPropertyDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/IndexedPropertyDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,383 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.lang.reflect.Method; + +import org.apache.harmony.beans.BeansUtils; +import org.apache.harmony.beans.internal.nls.Messages; + +public class IndexedPropertyDescriptor extends PropertyDescriptor { + + private Class indexedPropertyType; + + private Method indexedGetter; + + private Method indexedSetter; + + /** + * Constructs a new instance of IndexedPropertyDescriptor. + * + * @param propertyName + * the specified indexed property's name. + * @param beanClass + * the bean class + * @param getterName + * the name of the array getter + * @param setterName + * the name of the array setter + * @param indexedGetterName + * the name of the indexed getter. + * @param indexedSetterName + * the name of the indexed setter. + * @throws IntrospectionException + */ + public IndexedPropertyDescriptor(String propertyName, Class beanClass, + String getterName, String setterName, String indexedGetterName, + String indexedSetterName) throws IntrospectionException { + super(propertyName, beanClass, getterName, setterName); + setIndexedByName(beanClass, indexedGetterName, indexedSetterName); + } + + private void setIndexedByName(Class beanClass, String indexedGetterName, + String indexedSetterName) throws IntrospectionException { + + String theIndexedGetterName = indexedGetterName; + if (theIndexedGetterName == null) { + if (indexedSetterName != null) { + setIndexedWriteMethod(beanClass, indexedSetterName); + } + } else { + if (theIndexedGetterName.length() == 0) { + theIndexedGetterName = "get" + name; //$NON-NLS-1$ + } + setIndexedReadMethod(beanClass, theIndexedGetterName); + if (indexedSetterName != null) { + setIndexedWriteMethod(beanClass, indexedSetterName, + indexedPropertyType); + } + } + + if (!isCompatible()) { + // custom.beans.57=Property type is incompatible with the indexed property type + throw new IntrospectionException(Messages.getString("custom.beans.57")); //$NON-NLS-1$ + } + } + + private boolean isCompatible() { + Class propertyType = getPropertyType(); + + if (propertyType == null) { + return true; + } + Class componentTypeOfProperty = propertyType.getComponentType(); + if (componentTypeOfProperty == null) { + return false; + } + if (indexedPropertyType == null) { + return false; + } + + return componentTypeOfProperty.getName().equals( + indexedPropertyType.getName()); + } + + /** + * Constructs a new instance of IndexedPropertyDescriptor. + * + * @param propertyName + * the specified indexed property's name. + * @param getter + * the array getter + * @param setter + * the array setter + * @param indexedGetter + * the indexed getter + * @param indexedSetter + * the indexed setter + * @throws IntrospectionException + */ + public IndexedPropertyDescriptor(String propertyName, Method getter, + Method setter, Method indexedGetter, Method indexedSetter) + throws IntrospectionException { + super(propertyName, getter, setter); + if (indexedGetter != null) { + internalSetIndexedReadMethod(indexedGetter); + internalSetIndexedWriteMethod(indexedSetter, true); + } else { + internalSetIndexedWriteMethod(indexedSetter, true); + internalSetIndexedReadMethod(indexedGetter); + } + + if (!isCompatible()) { + // custom.beans.57=Property type is incompatible with the indexed property type + throw new IntrospectionException(Messages.getString("custom.beans.57")); //$NON-NLS-1$ + } + } + + /** + * Constructs a new instance of IndexedPropertyDescriptor. + * + * @param propertyName + * the specified indexed property's name. + * @param beanClass + * the bean class. + * @throws IntrospectionException + */ + public IndexedPropertyDescriptor(String propertyName, Class beanClass) + throws IntrospectionException { + super(propertyName, beanClass); + setIndexedByName(beanClass, "get" //$NON-NLS-1$ + .concat(initialUpperCase(propertyName)), "set" //$NON-NLS-1$ + .concat(initialUpperCase(propertyName))); + } + + /** + * Sets the indexed getter as the specified method. + * + * @param indexedGetter + * the specified indexed getter. + * @throws IntrospectionException + */ + public void setIndexedReadMethod(Method indexedGetter) + throws IntrospectionException { + this.internalSetIndexedReadMethod(indexedGetter); + } + + /** + * Sets the indexed setter as the specified method. + * + * @param indexedSetter + * the specified indexed setter. + * @throws IntrospectionException + */ + public void setIndexedWriteMethod(Method indexedSetter) + throws IntrospectionException { + this.internalSetIndexedWriteMethod(indexedSetter, false); + } + + /** + * Obtains the indexed setter. + * + * @return the indexed setter. + */ + public Method getIndexedWriteMethod() { + return indexedSetter; + } + + /** + * Obtains the indexed getter. + * + * @return the indexed getter. + */ + public Method getIndexedReadMethod() { + return indexedGetter; + } + + /** + * Determines if this IndexedPropertyDescriptor is equal to + * the specified object. Two IndexedPropertyDescriptor s are + * equal if the reader, indexed reader, writer, indexed writer, property + * types, indexed property type, property editor and flags are equal. + * + * @param obj + * @return true if this indexed property descriptor is equal to the + * specified object. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof IndexedPropertyDescriptor)) { + return false; + } + + IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj; + + return (super.equals(other) + && (indexedPropertyType == null ? other.indexedPropertyType == null + : indexedPropertyType.equals(other.indexedPropertyType)) + && (indexedGetter == null ? other.indexedGetter == null + : indexedGetter.equals(other.indexedGetter)) && (indexedSetter == null ? other.indexedSetter == null + : indexedSetter.equals(other.indexedSetter))); + } + + /** + * HashCode of the IndexedPropertyDescriptor + */ + @Override + public int hashCode() { + return super.hashCode() + BeansUtils.getHashCode(indexedPropertyType) + + BeansUtils.getHashCode(indexedGetter) + + BeansUtils.getHashCode(indexedSetter); + } + + /** + * Obtains the Class object of the indexed property type. + * + * @return the Class object of the indexed property type. + */ + public Class getIndexedPropertyType() { + return indexedPropertyType; + } + + private void setIndexedReadMethod(Class beanClass, String indexedGetterName) + throws IntrospectionException { + Method getter; + try { + getter = beanClass.getMethod(indexedGetterName, + new Class[] { Integer.TYPE }); + } catch (NoSuchMethodException exception) { + // custom.beans.58=No such indexed read method + throw new IntrospectionException(Messages.getString("custom.beans.58")); //$NON-NLS-1$ + } catch (SecurityException exception) { + // custom.beans.59=Security violation accessing indexed read method + throw new IntrospectionException(Messages.getString("custom.beans.59")); //$NON-NLS-1$ + } + internalSetIndexedReadMethod(getter); + } + + private void internalSetIndexedReadMethod(Method indexGetter) + throws IntrospectionException { + // Clearing the indexed read method. + if (indexGetter == null) { + if (indexedSetter == null) { + if (getPropertyType() != null) { + // custom.beans.5A=Indexed method is not compatible with non indexed method + throw new IntrospectionException(Messages + .getString("custom.beans.5A")); //$NON-NLS-1$ + } + indexedPropertyType = null; + } + this.indexedGetter = null; + return; + } + // Validate the indexed getter. + if ((indexGetter.getParameterTypes().length != 1) + || (indexGetter.getParameterTypes()[0] != Integer.TYPE)) { + // custom.beans.5B=Indexed read method must take a single int argument + throw new IntrospectionException(Messages.getString("custom.beans.5B")); //$NON-NLS-1$ + } + Class indexedReadType = indexGetter.getReturnType(); + if (indexedReadType == Void.TYPE) { + // custom.beans.5B=Indexed read method must take a single int argument + throw new IntrospectionException(Messages.getString("custom.beans.5B")); //$NON-NLS-1$ + } else if (indexedSetter != null + && indexGetter.getReturnType() != indexedSetter + .getParameterTypes()[1]) { + // custom.beans.5A=Indexed read method is not compatible with indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5A")); //$NON-NLS-1$ + } + + // Set the indexed property type if not already set, confirm validity if + // it is. + if (this.indexedGetter == null) { + indexedPropertyType = indexedReadType; + } else { + if (indexedPropertyType != indexedReadType) { + // custom.beans.5A=Indexed read method is not compatible with indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5A")); //$NON-NLS-1$ + } + } + + // Set the indexed getter + this.indexedGetter = indexGetter; + } + + private void setIndexedWriteMethod(Class beanClass, String indexedSetterName) + throws IntrospectionException { + Method setter = null; + try { + setter = beanClass.getMethod(indexedSetterName, new Class[] { + Integer.TYPE, getPropertyType().getComponentType() }); + } catch (SecurityException e) { + // custom.beans.5C=Security violation accessing indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5C")); //$NON-NLS-1$ + } catch (NoSuchMethodException e) { + // custom.beans.5D=No such indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5D")); //$NON-NLS-1$ + } + internalSetIndexedWriteMethod(setter, true); + } + + private void setIndexedWriteMethod(Class beanClass, + String indexedSetterName, Class argType) + throws IntrospectionException { + try { + Method setter = beanClass.getMethod(indexedSetterName, new Class[] { + Integer.TYPE, argType }); + internalSetIndexedWriteMethod(setter, true); + } catch (NoSuchMethodException exception) { + // custom.beans.5D=No such indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5D")); //$NON-NLS-1$ + } catch (SecurityException exception) { + // custom.beans.5C=Security violation accessing indexed write method + throw new IntrospectionException(Messages.getString("custom.beans.5C")); //$NON-NLS-1$ + } + } + + private void internalSetIndexedWriteMethod(Method indexSetter, + boolean initialize) throws IntrospectionException { + // Clearing the indexed write method. + if (indexSetter == null) { + if (indexedGetter == null) { + if (getPropertyType() != null) { + // custom.beans.5E=Indexed method is not compatible with non indexed method + throw new IntrospectionException(Messages + .getString("custom.beans.5E")); //$NON-NLS-1$ + } + indexedPropertyType = null; + } + this.indexedSetter = null; + return; + } + + // Validate the indexed write method. + Class[] indexedSetterArgs = indexSetter.getParameterTypes(); + if (indexedSetterArgs.length != 2) { + // custom.beans.5F=Indexed write method must take two arguments + throw new IntrospectionException(Messages.getString("custom.beans.5F")); //$NON-NLS-1$ + } + if (indexedSetterArgs[0] != Integer.TYPE) { + // custom.beans.60=Indexed write method must take an int as its first argument + throw new IntrospectionException(Messages.getString("custom.beans.60")); //$NON-NLS-1$ + } + + // Set the indexed property type if not already set, confirm validity if + // it is. + Class indexedWriteType = indexedSetterArgs[1]; + if (initialize && indexedGetter == null) { + indexedPropertyType = indexedWriteType; + } else { + if (indexedPropertyType != indexedWriteType) { + // custom.beans.61=Indexed write method is not compatible with indexed read method + throw new IntrospectionException(Messages.getString("custom.beans.61")); //$NON-NLS-1$ + } + } + + // Set the indexed write method. + this.indexedSetter = indexSetter; + } + + private static String initialUpperCase(String string) { + if (Character.isUpperCase(string.charAt(0))) { + return string; + } + + String initial = string.substring(0, 1).toUpperCase(); + return initial.concat(string.substring(1)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/IntrospectionException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/IntrospectionException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,27 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +public class IntrospectionException extends Exception { + + private static final long serialVersionUID = -3728150539969542619L; + + public IntrospectionException(String message) { + super(message); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/Introspector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/Introspector.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,368 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.util.Collections; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * The Introspector is a utility for developers to figure out + * which properties, events, and methods a JavaBean supports. + *

+ * The Introspector class walks over the class/superclass chain + * of the target bean class. At each level it checks if there is a matching + * BeanInfo class which provides explicit information about the + * bean, and if so uses that explicit information. Otherwise it uses the low + * level reflection APIs to study the target class and uses design patterns to + * analyze its behaviour and then proceeds to continue the introspection with + * its baseclass. + *

+ *

+ * To look for the explicit information of a bean: + *

+ *
    + *
  1. The Introspector appends "BeanInfo" to the qualified name + * of the bean class, try to use the new class as the "BeanInfo" class. If the + * "BeanInfo" class exsits and returns non-null value when queried for explicit + * information, use the explicit information
  2. + *
  3. If the first step fails, the Introspector will extract a + * simple class name of the bean class by removing the package name from the + * qualified name of the bean class, append "BeanInfo" to it. And look for the + * simple class name in the packages defined in the "BeanInfo" search path (The + * default "BeanInfo" search path is sun.beans.infos). If it + * finds a "BeanInfo" class and the "BeanInfo" class returns non-null value when + * queried for explicit information, use the explicit information
  4. + *
+ * + */ +//ScrollPane cannot be introspected correctly +public class Introspector extends java.lang.Object { + + // Public fields + /** + * Constant values to indicate that the Introspector will + * ignore all BeanInfo class. + */ + public static final int IGNORE_ALL_BEANINFO = 3; + + /** + * Constant values to indicate that the Introspector will + * ignore the BeanInfo class of the current bean class. + */ + public static final int IGNORE_IMMEDIATE_BEANINFO = 2; + + /** + * Constant values to indicate that the Introspector will use + * all BeanInfo class which have been found. This is the default one. + */ + public static final int USE_ALL_BEANINFO = 1; + + // Default search path for BeanInfo classes + private static final String DEFAULT_BEANINFO_SEARCHPATH = "sun.beans.infos"; //$NON-NLS-1$ + + // The search path to use to find BeanInfo classes + // - an array of package names that are used in turn + private static String[] searchPath = { DEFAULT_BEANINFO_SEARCHPATH }; + + // The cache to store Bean Info objects that have been found or created + private static final int DEFAULT_CAPACITY = 128; + + private static Map, StandardBeanInfo> theCache = Collections.synchronizedMap(new WeakHashMap, StandardBeanInfo>(DEFAULT_CAPACITY)); + + private Introspector() { + super(); + } + + /** + * Decapitalizes a given string according to the rule: + *
    + *
  • If the first or only character is Upper Case, it is made Lower Case + *
  • UNLESS the second character is also Upper Case, when the String is + * returned unchanged + * + * @param name - + * the String to decapitalize + * @return the decapitalized version of the String + */ + public static String decapitalize(String name) { + + if (name == null) + return null; + // The rule for decapitalize is that: + // If the first letter of the string is Upper Case, make it lower case + // UNLESS the second letter of the string is also Upper Case, in which case no + // changes are made. + if (name.length() == 0 || (name.length() > 1 && Character.isUpperCase(name.charAt(1)))) { + return name; + } + + char[] chars = name.toCharArray(); + chars[0] = Character.toLowerCase(chars[0]); + return new String(chars); + } + + /** + * Flushes all BeanInfo caches. + * + */ + public static void flushCaches() { + // Flush the cache by throwing away the cache HashMap and creating a + // new empty one + theCache.clear(); + } + + /** + * Flushes the BeanInfo caches of the specified bean class + * + * @param clazz + * the specified bean class + */ + public static void flushFromCaches(Class clazz) { + if(clazz == null){ + throw new NullPointerException(); + } + theCache.remove(clazz); + } + + /** + * Gets the BeanInfo object which contains the information of + * the properties, events and methods of the specified bean class. + * + *

    + * The Introspector will cache the BeanInfo + * object. Subsequent calls to this method will be answered with the cached + * data. + *

    + * + * @param beanClass + * the specified bean class. + * @return the BeanInfo of the bean class. + * @throws IntrospectionException + */ + public static BeanInfo getBeanInfo(Class beanClass) + throws IntrospectionException { + StandardBeanInfo beanInfo = theCache.get(beanClass); + if (beanInfo == null) { + beanInfo = getBeanInfoImplAndInit(beanClass, null, USE_ALL_BEANINFO); + theCache.put(beanClass, beanInfo); + } + return beanInfo; + } + + /** + * Gets the BeanInfo object which contains the information of + * the properties, events and methods of the specified bean class. It will + * not introspect the "stopclass" and its super class. + * + *

    + * The Introspector will cache the BeanInfo + * object. Subsequent calls to this method will be answered with the cached + * data. + *

    + * + * @param beanClass + * the specified beanClass. + * @param stopClass + * the sopt class which should be super class of the bean class. + * May be null. + * @return the BeanInfo of the bean class. + * @throws IntrospectionException + */ + public static BeanInfo getBeanInfo(Class beanClass, Class stopClass) + throws IntrospectionException { + if(stopClass == null){ + //try to use cache + return getBeanInfo(beanClass); + } + return getBeanInfoImplAndInit(beanClass, stopClass, USE_ALL_BEANINFO); + } + + /** + * Gets the BeanInfo object which contains the information of + * the properties, events and methods of the specified bean class. + *
      + *
    1. If flag==IGNORE_ALL_BEANINFO, the + * Introspector will ignore all BeanInfo + * class.
    2. + *
    3. If flag==IGNORE_IMMEDIATE_BEANINFO, the + * Introspector will ignore the BeanInfo class + * of the current bean class.
    4. + *
    5. If flag==USE_ALL_BEANINFO, the + * Introspector will use all BeanInfo class + * which have been found.
    6. + *
    + *

    + * The Introspector will cache the BeanInfo + * object. Subsequent calls to this method will be answered with the cached + * data. + *

    + * + * @param beanClass + * the specified bean class. + * @param flags + * the flag to control the usage of the explicit + * BeanInfo class. + * @return the BeanInfo of the bean class. + * @throws IntrospectionException + */ + public static BeanInfo getBeanInfo(Class beanClass, int flags) + throws IntrospectionException { + if(flags == USE_ALL_BEANINFO){ + //try to use cache + return getBeanInfo(beanClass); + } + return getBeanInfoImplAndInit(beanClass, null, flags); + } + + /** + * Gets an array of search packages. + * + * @return an array of search packages. + */ + public static String[] getBeanInfoSearchPath() { + String[] path = new String[searchPath.length]; + System.arraycopy(searchPath, 0, path, 0, searchPath.length); + return path; + } + + /** + * Sets the search packages. + * + * @param path the new search packages to be set. + */ + public static void setBeanInfoSearchPath(String[] path) { + if (System.getSecurityManager() != null) { + System.getSecurityManager().checkPropertiesAccess(); + } + searchPath = path; + } + + private static StandardBeanInfo getBeanInfoImpl(Class beanClass, Class stopClass, + int flags) throws IntrospectionException { + BeanInfo explicitInfo = null; + if (flags == USE_ALL_BEANINFO) { + explicitInfo = getExplicitBeanInfo(beanClass); + } + StandardBeanInfo beanInfo = new StandardBeanInfo(beanClass, explicitInfo, stopClass); + + if (beanInfo.additionalBeanInfo != null) { + for (int i = beanInfo.additionalBeanInfo.length-1; i >=0; i--) { + BeanInfo info = beanInfo.additionalBeanInfo[i]; + beanInfo.mergeBeanInfo(info, true); + } + } + + // recursive get beaninfo for super classes + Class beanSuperClass = beanClass.getSuperclass(); + if (beanSuperClass != stopClass) { + if (beanSuperClass == null) + throw new IntrospectionException( + "Stop class is not super class of bean class"); //$NON-NLS-1$ + int superflags = flags == IGNORE_IMMEDIATE_BEANINFO ? USE_ALL_BEANINFO + : flags; + BeanInfo superBeanInfo = getBeanInfoImpl(beanSuperClass, stopClass, + superflags); + if (superBeanInfo != null) { + beanInfo.mergeBeanInfo(superBeanInfo, false); + } + } + return beanInfo; + } + + private static BeanInfo getExplicitBeanInfo(Class beanClass) { + String beanInfoClassName = beanClass.getName() + "BeanInfo"; //$NON-NLS-1$ + try { + return loadBeanInfo(beanInfoClassName, beanClass); + } catch (Exception e) { + // fall through + } + + int index = beanInfoClassName.lastIndexOf('.'); + String beanInfoName = index >= 0 ? beanInfoClassName + .substring(index + 1) : beanInfoClassName; + BeanInfo theBeanInfo = null; + BeanDescriptor beanDescriptor = null; + for (int i = 0; i < searchPath.length; i++) { + beanInfoClassName = searchPath[i] + "." + beanInfoName; //$NON-NLS-1$ + try { + theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass); + } catch (Exception e) { + // ignore, try next one + continue; + } + beanDescriptor = theBeanInfo.getBeanDescriptor(); + if (beanDescriptor != null + && beanClass == beanDescriptor.getBeanClass()) { + return theBeanInfo; + } + } + if (BeanInfo.class.isAssignableFrom(beanClass)) { + try { + return loadBeanInfo(beanClass.getName(), beanClass); + } catch (Exception e) { + // fall through + } + } + return null; + } + + /* MODIFIED FOR THE MSGPACK PROJECT + * Method which attempts to instantiate a BeanInfo object of the supplied + * classname + * + * @param theBeanInfoClassName - + * the Class Name of the class of which the BeanInfo is an + * instance + * @param classLoader + * @return A BeanInfo object which is an instance of the Class named + * theBeanInfoClassName null if the Class does not exist or if there + * are problems instantiating the instance + */ + private static BeanInfo loadBeanInfo(String beanInfoClassName, + Class beanClass) throws Exception{ + try { + ClassLoader cl = beanClass.getClassLoader(); + if(cl != null){ + return (BeanInfo) Class.forName(beanInfoClassName, true, + beanClass.getClassLoader()).newInstance(); + } + } catch (Exception e) { + // fall through + } + try { + return (BeanInfo) Class.forName(beanInfoClassName, true, + ClassLoader.getSystemClassLoader()).newInstance(); + } catch (Exception e) { + // fall through + } + return (BeanInfo) Class.forName(beanInfoClassName, true, + Thread.currentThread().getContextClassLoader()).newInstance(); + } + + private static StandardBeanInfo getBeanInfoImplAndInit(Class beanClass, + Class stopClass, int flag) throws IntrospectionException { + StandardBeanInfo standardBeanInfo = getBeanInfoImpl(beanClass, + stopClass, flag); + standardBeanInfo.init(); + return standardBeanInfo; + } +} + + + diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/MethodDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/MethodDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,109 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.lang.reflect.Method; + +/** + * Describes a bean's method. + */ +public class MethodDescriptor extends FeatureDescriptor { + + private Method method; + + private ParameterDescriptor[] parameterDescriptors; + + /** + *

    + * Constructs an instance with the given {@link Method} and + * {@link ParameterDescriptor}s. The {@link #getName()} is set as the name + * of the method passed. + *

    + * + * @param method + * The Method to set. + * @param parameterDescriptors + * An array of parameter descriptors. + */ + public MethodDescriptor(Method method, + ParameterDescriptor[] parameterDescriptors) { + super(); + + if (method == null) { + throw new NullPointerException(); + } + this.method = method; + this.parameterDescriptors = parameterDescriptors; + + setName(method.getName()); + } + + /** + *

    + * Constructs an instance with the given {@link Method}. The + * {@link #getName()} is set as the name of the method + * passed. + *

    + * + * @param method + * The Method to set. + */ + public MethodDescriptor(Method method) { + super(); + + if (method == null) { + throw new NullPointerException(); + } + this.method = method; + + setName(method.getName()); + } + + /** + *

    + * Gets the method. + *

    + * + * @return A {@link Method} instance. + */ + public Method getMethod() { + return method; + } + + /** + *

    + * Gets the parameter descriptors. + *

    + * + * @return An array of {@link ParameterDescriptor} instance or + * null. + */ + public ParameterDescriptor[] getParameterDescriptors() { + return parameterDescriptors; + } + + void merge(MethodDescriptor anotherMethod){ + super.merge(anotherMethod); + if(method == null){ + method = anotherMethod.method; + } + if(parameterDescriptors == null){ + parameterDescriptors = anotherMethod.parameterDescriptors; + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/ParameterDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/ParameterDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,25 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +public class ParameterDescriptor extends FeatureDescriptor { + + public ParameterDescriptor() { + // do nothing + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/PropertyChangeEvent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/PropertyChangeEvent.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,62 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.util.EventObject; + +public class PropertyChangeEvent extends EventObject { + + private static final long serialVersionUID = 7042693688939648123L; + + String propertyName; + + Object oldValue; + + Object newValue; + + Object propagationId; + + public PropertyChangeEvent(Object source, String propertyName, + Object oldValue, Object newValue) { + super(source); + + this.propertyName = propertyName; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropagationId(Object propagationId) { + this.propagationId = propagationId; + } + + public Object getPropagationId() { + return propagationId; + } + + public Object getOldValue() { + return oldValue; + } + + public Object getNewValue() { + return newValue; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/PropertyChangeListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/PropertyChangeListener.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,25 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.util.EventListener; + +public interface PropertyChangeListener extends EventListener { + + public void propertyChange(PropertyChangeEvent event); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/PropertyDescriptor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/PropertyDescriptor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,300 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.apache.harmony.beans.BeansUtils; +import org.apache.harmony.beans.internal.nls.Messages; + +public class PropertyDescriptor extends FeatureDescriptor { + private Method getter; + + private Method setter; + + private Class propertyEditorClass; + + boolean constrained; + + boolean bound; + + public PropertyDescriptor(String propertyName, Class beanClass, + String getterName, String setterName) throws IntrospectionException { + super(); + if (beanClass == null) { + throw new IntrospectionException(Messages.getString("custom.beans.03")); //$NON-NLS-1$ + } + if (propertyName == null || propertyName.length() == 0) { + throw new IntrospectionException(Messages.getString("custom.beans.04")); //$NON-NLS-1$ + } + this.setName(propertyName); + if (getterName != null) { + if (getterName.length() == 0) { + throw new IntrospectionException( + "read or write method cannot be empty."); //$NON-NLS-1$ + } + try { + setReadMethod(beanClass, getterName); + } catch (IntrospectionException e) { + setReadMethod(beanClass, createDefaultMethodName(propertyName, + "get")); //$NON-NLS-1$ + } + } + if (setterName != null) { + if (setterName.length() == 0) { + throw new IntrospectionException( + "read or write method cannot be empty."); //$NON-NLS-1$ + } + setWriteMethod(beanClass, setterName); + } + } + + public PropertyDescriptor(String propertyName, Method getter, Method setter) + throws IntrospectionException { + super(); + if (propertyName == null || propertyName.length() == 0) { + throw new IntrospectionException(Messages.getString("custom.beans.04")); //$NON-NLS-1$ + } + this.setName(propertyName); + setReadMethod(getter); + setWriteMethod(setter); + } + + public PropertyDescriptor(String propertyName, Class beanClass) + throws IntrospectionException { + if (beanClass == null) { + throw new IntrospectionException(Messages.getString("custom.beans.03")); //$NON-NLS-1$ + } + if (propertyName == null || propertyName.length() == 0) { + throw new IntrospectionException(Messages.getString("custom.beans.04")); //$NON-NLS-1$ + } + this.setName(propertyName); + try { + setReadMethod(beanClass, + createDefaultMethodName(propertyName, "is")); //$NON-NLS-1$ + } catch (Exception e) { + setReadMethod(beanClass, createDefaultMethodName(propertyName, + "get")); //$NON-NLS-1$ + } + + setWriteMethod(beanClass, createDefaultMethodName(propertyName, "set")); //$NON-NLS-1$ + } + + public void setWriteMethod(Method setter) throws IntrospectionException { + if (setter != null) { + int modifiers = setter.getModifiers(); + if (!Modifier.isPublic(modifiers)) { + throw new IntrospectionException(Messages.getString("custom.beans.05")); //$NON-NLS-1$ + } + Class[] parameterTypes = setter.getParameterTypes(); + if (parameterTypes.length != 1) { + throw new IntrospectionException(Messages.getString("custom.beans.06")); //$NON-NLS-1$ + } + Class parameterType = parameterTypes[0]; + Class propertyType = getPropertyType(); + if (propertyType != null && !propertyType.equals(parameterType)) { + throw new IntrospectionException(Messages.getString("custom.beans.07")); //$NON-NLS-1$ + } + } + this.setter = setter; + } + + public void setReadMethod(Method getter) throws IntrospectionException { + if (getter != null) { + int modifiers = getter.getModifiers(); + if (!Modifier.isPublic(modifiers)) { + throw new IntrospectionException(Messages.getString("custom.beans.0A")); //$NON-NLS-1$ + } + Class[] parameterTypes = getter.getParameterTypes(); + if (parameterTypes.length != 0) { + throw new IntrospectionException(Messages.getString("custom.beans.08")); //$NON-NLS-1$ + } + Class returnType = getter.getReturnType(); + if (returnType.equals(Void.TYPE)) { + throw new IntrospectionException(Messages.getString("custom.beans.33")); //$NON-NLS-1$ + } + Class propertyType = getPropertyType(); + if ((propertyType != null) && !returnType.equals(propertyType)) { + throw new IntrospectionException(Messages.getString("custom.beans.09")); //$NON-NLS-1$ + } + } + this.getter = getter; + } + + public Method getWriteMethod() { + return setter; + } + + public Method getReadMethod() { + return getter; + } + + @Override + public boolean equals(Object object) { + boolean result = object instanceof PropertyDescriptor; + if (result) { + PropertyDescriptor pd = (PropertyDescriptor) object; + boolean gettersAreEqual = (this.getter == null) + && (pd.getReadMethod() == null) || (this.getter != null) + && (this.getter.equals(pd.getReadMethod())); + boolean settersAreEqual = (this.setter == null) + && (pd.getWriteMethod() == null) || (this.setter != null) + && (this.setter.equals(pd.getWriteMethod())); + boolean propertyTypesAreEqual = this.getPropertyType() == pd + .getPropertyType(); + boolean propertyEditorClassesAreEqual = this + .getPropertyEditorClass() == pd.getPropertyEditorClass(); + boolean boundPropertyAreEqual = this.isBound() == pd.isBound(); + boolean constrainedPropertyAreEqual = this.isConstrained() == pd + .isConstrained(); + result = gettersAreEqual && settersAreEqual + && propertyTypesAreEqual && propertyEditorClassesAreEqual + && boundPropertyAreEqual && constrainedPropertyAreEqual; + } + return result; + } + + @Override + public int hashCode() { + return BeansUtils.getHashCode(getter) + BeansUtils.getHashCode(setter) + + BeansUtils.getHashCode(getPropertyType()) + + BeansUtils.getHashCode(getPropertyEditorClass()) + + BeansUtils.getHashCode(isBound()) + + BeansUtils.getHashCode(isConstrained()); + } + + public void setPropertyEditorClass(Class propertyEditorClass) { + this.propertyEditorClass = propertyEditorClass; + } + + public Class getPropertyType() { + Class result = null; + if (getter != null) { + result = getter.getReturnType(); + } else if (setter != null) { + Class[] parameterTypes = setter.getParameterTypes(); + result = parameterTypes[0]; + } + return result; + } + + public Class getPropertyEditorClass() { + return propertyEditorClass; + } + + public void setConstrained(boolean constrained) { + this.constrained = constrained; + } + + public void setBound(boolean bound) { + this.bound = bound; + } + + public boolean isConstrained() { + return constrained; + } + + public boolean isBound() { + return bound; + } + + String createDefaultMethodName(String propertyName, String prefix) { + String result = null; + if (propertyName != null) { + String bos = BeansUtils.toASCIIUpperCase(propertyName.substring(0, 1)); + String eos = propertyName.substring(1, propertyName.length()); + result = prefix + bos + eos; + } + return result; + } + + void setReadMethod(Class beanClass, String getterName) + throws IntrospectionException { + try { + Method readMethod = beanClass.getMethod(getterName, new Class[] {}); + setReadMethod(readMethod); + } catch (Exception e) { + throw new IntrospectionException(e.getLocalizedMessage()); + } + } + + void setWriteMethod(Class beanClass, String setterName) + throws IntrospectionException { + Method writeMethod = null; + try { + if (getter != null) { + writeMethod = beanClass.getMethod(setterName, + new Class[] { getter.getReturnType() }); + } else { + Class clazz = beanClass; + Method[] methods = null; + while (clazz != null && writeMethod == null) { + methods = clazz.getDeclaredMethods(); + for (Method method : methods) { + if (setterName.equals(method.getName())) { + if (method.getParameterTypes().length == 1) { + writeMethod = method; + break; + } + } + } + clazz = clazz.getSuperclass(); + } + } + } catch (Exception e) { + throw new IntrospectionException(e.getLocalizedMessage()); + } + if (writeMethod == null) { + throw new IntrospectionException(Messages.getString( + "custom.beans.64", setterName)); //$NON-NLS-1$ + } + setWriteMethod(writeMethod); + } + + public PropertyEditor createPropertyEditor(Object bean) { + PropertyEditor editor; + if (propertyEditorClass == null) { + return null; + } + if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) { + // custom.beans.48=Property editor is not assignable from the + // PropertyEditor interface + throw new ClassCastException(Messages.getString("custom.beans.48")); //$NON-NLS-1$ + } + try { + Constructor constr; + try { + // try to look for the constructor with single Object argument + constr = propertyEditorClass.getConstructor(Object.class); + editor = (PropertyEditor) constr.newInstance(bean); + } catch (NoSuchMethodException e) { + // try no-argument constructor + constr = propertyEditorClass.getConstructor(); + editor = (PropertyEditor) constr.newInstance(); + } + } catch (Exception e) { + // custom.beans.47=Unable to instantiate property editor + RuntimeException re = new RuntimeException(Messages + .getString("custom.beans.47"), e); //$NON-NLS-1$ + throw re; + } + return editor; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/PropertyEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/PropertyEditor.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,43 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import org.msgpack.template.builder.beans.PropertyChangeListener; + +public interface PropertyEditor { + + public void setAsText(String text) throws IllegalArgumentException; + + public String[] getTags(); + + public String getJavaInitializationString(); + + public String getAsText(); + + public void setValue(Object value); + + public Object getValue(); + + public void removePropertyChangeListener(PropertyChangeListener listener); + + public void addPropertyChangeListener(PropertyChangeListener listener); + + public boolean supportsCustomEditor(); + + public boolean isPaintable(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/PropertyVetoException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/PropertyVetoException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,55 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + + +/** + * Indicates that a proposed property change is unacceptable. + */ +public class PropertyVetoException extends Exception { + + private static final long serialVersionUID = 129596057694162164L; + + private final PropertyChangeEvent evt; + + /** + *

    + * Constructs an instance with a message and the change event. + *

    + * + * @param message + * A description of the veto. + * @param event + * The event that was vetoed. + */ + public PropertyVetoException(String message, PropertyChangeEvent event) { + super(message); + this.evt = event; + } + + /** + *

    + * Gets the property change event. + *

    + * + * @return An instance of {@link PropertyChangeEvent} + */ + public PropertyChangeEvent getPropertyChangeEvent() { + return evt; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/SimpleBeanInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/SimpleBeanInfo.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + + +public class SimpleBeanInfo implements BeanInfo { + + public SimpleBeanInfo() { + // expected + } + + public PropertyDescriptor[] getPropertyDescriptors() { + return null; + } + + public MethodDescriptor[] getMethodDescriptors() { + return null; + } + + public EventSetDescriptor[] getEventSetDescriptors() { + return null; + } + + public BeanInfo[] getAdditionalBeanInfo() { + return null; + } + + public BeanDescriptor getBeanDescriptor() { + return null; + } + + public int getDefaultPropertyIndex() { + return -1; + } + + public int getDefaultEventIndex() { + return -1; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/StandardBeanInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/StandardBeanInfo.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,1505 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import static org.msgpack.template.builder.beans.Introspector.decapitalize; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.EventListener; +import java.util.EventObject; +import java.util.HashMap; +import java.util.Map; +import java.util.TooManyListenersException; + +class StandardBeanInfo extends SimpleBeanInfo { + + // Prefixes for methods that set or get a Property + private static final String PREFIX_IS = "is"; //$NON-NLS-1$ + + private static final String PREFIX_GET = "get"; //$NON-NLS-1$ + + private static final String PREFIX_SET = "set"; //$NON-NLS-1$ + + // Prefix and suffix for Event related methods + private static final String PREFIX_ADD = "add"; //$NON-NLS-1$ + + private static final String PREFIX_REMOVE = "remove"; //$NON-NLS-1$ + + private static final String SUFFIX_LISTEN = "Listener"; //$NON-NLS-1$ + + private static final String STR_NORMAL = "normal"; //$NON-NLS-1$ + + private static final String STR_INDEXED = "indexed"; //$NON-NLS-1$ + + private static final String STR_VALID = "valid"; //$NON-NLS-1$ + + private static final String STR_INVALID = "invalid"; //$NON-NLS-1$ + + private static final String STR_PROPERTY_TYPE = "PropertyType"; //$NON-NLS-1$ + + private static final String STR_IS_CONSTRAINED = "isConstrained"; //$NON-NLS-1$ + + private static final String STR_SETTERS = "setters"; //$NON-NLS-1$ + + private static final String STR_GETTERS = "getters"; //$NON-NLS-1$ + + private boolean explicitMethods = false; + + private boolean explicitProperties = false; + + private boolean explicitEvents = false; + + private BeanInfo explicitBeanInfo = null; + + private EventSetDescriptor[] events = null; + + private MethodDescriptor[] methods = null; + + private PropertyDescriptor[] properties = null; + + private BeanDescriptor beanDescriptor = null; + + BeanInfo[] additionalBeanInfo = null; + + private Class beanClass; + + private int defaultEventIndex = -1; + + private int defaultPropertyIndex = -1; + + private static PropertyComparator comparator = new PropertyComparator(); + + private boolean canAddPropertyChangeListener; + + private boolean canRemovePropertyChangeListener; + + StandardBeanInfo(Class beanClass, BeanInfo explicitBeanInfo, Class stopClass) + throws IntrospectionException { + this.beanClass = beanClass; + /*-------------------------------------------------------------------------------------- + * There are 3 aspects of BeanInfo that must be supplied: + * a) PropertyDescriptors + * b) MethodDescriptors + * c) EventSetDescriptors + * Each of these may be optionally provided in the explicitBeanInfo object relating to + * this bean. Where the explicitBeanInfo provides one of these aspects, it is used + * without question and no introspection of the beanClass is performed for that aspect. + * There are also 3 optional items of BeanInfo that may be provided by the + * explicitBeanInfo object: + * 1) BeanDescriptor + * 2) DefaultEventIndex + * 3) DefaultPropertyIndex + * These aspects of the beanClass cannot be derived through introspection of the class. + * If they are not provided by the explicitBeanInfo, then they must be left null in the + * returned BeanInfo, otherwise they will be copied from the explicitBeanInfo + --------------------------------------------------------------------------------------*/ + if (explicitBeanInfo != null) { + this.explicitBeanInfo = explicitBeanInfo; + events = explicitBeanInfo.getEventSetDescriptors(); + methods = explicitBeanInfo.getMethodDescriptors(); + properties = explicitBeanInfo.getPropertyDescriptors(); + defaultEventIndex = explicitBeanInfo.getDefaultEventIndex(); + if (defaultEventIndex < 0 || defaultEventIndex >= events.length) { + defaultEventIndex = -1; + } + defaultPropertyIndex = explicitBeanInfo.getDefaultPropertyIndex(); + if (defaultPropertyIndex < 0 + || defaultPropertyIndex >= properties.length) { + defaultPropertyIndex = -1; + } + additionalBeanInfo = explicitBeanInfo.getAdditionalBeanInfo(); + + if (events != null) + explicitEvents = true; + if (methods != null) + explicitMethods = true; + if (properties != null) + explicitProperties = true; + } + + if (methods == null) { + methods = introspectMethods(); + } + + if (properties == null) { + properties = introspectProperties(stopClass); + } + + if (events == null) { + events = introspectEvents(); + } + } + + @Override + public BeanInfo[] getAdditionalBeanInfo() { + return null; + } + + @Override + public EventSetDescriptor[] getEventSetDescriptors() { + return events; + } + + @Override + public MethodDescriptor[] getMethodDescriptors() { + return methods; + } + + @Override + public PropertyDescriptor[] getPropertyDescriptors() { + return properties; + } + + @Override + public BeanDescriptor getBeanDescriptor() { + if (beanDescriptor == null) { + if (explicitBeanInfo != null) { + beanDescriptor = explicitBeanInfo.getBeanDescriptor(); + } + if (beanDescriptor == null) { + beanDescriptor = new BeanDescriptor(beanClass); + } + } + return beanDescriptor; + } + + @Override + public int getDefaultEventIndex() { + return this.defaultEventIndex; + } + + @Override + public int getDefaultPropertyIndex() { + return this.defaultPropertyIndex; + } + + void mergeBeanInfo(BeanInfo beanInfo, boolean force) + throws IntrospectionException { + if (force || !explicitProperties) { + PropertyDescriptor[] superDescs = beanInfo.getPropertyDescriptors(); + if (superDescs != null) { + if (getPropertyDescriptors() != null) { + properties = mergeProps(superDescs, beanInfo + .getDefaultPropertyIndex()); + } else { + properties = superDescs; + defaultPropertyIndex = beanInfo.getDefaultPropertyIndex(); + } + } + } + + if (force || !explicitMethods) { + MethodDescriptor[] superMethods = beanInfo.getMethodDescriptors(); + if (superMethods != null) { + if (methods != null) { + methods = mergeMethods(superMethods); + } else { + methods = superMethods; + } + } + } + + if (force || !explicitEvents) { + EventSetDescriptor[] superEvents = beanInfo + .getEventSetDescriptors(); + if (superEvents != null) { + if (events != null) { + events = mergeEvents(superEvents, beanInfo + .getDefaultEventIndex()); + } else { + events = superEvents; + defaultEventIndex = beanInfo.getDefaultEventIndex(); + } + } + } + } + + /* MODIFIED FOR THE MSGPACK PROJECT + * merge the PropertyDescriptor with superclass + */ + private PropertyDescriptor[] mergeProps(PropertyDescriptor[] superDescs, + int superDefaultIndex) throws IntrospectionException { + // FIXME:change to OO way as EventSetD and MethodD + HashMap subMap = internalAsMap(properties); + String defaultPropertyName = null; + if (defaultPropertyIndex >= 0 + && defaultPropertyIndex < properties.length) { + defaultPropertyName = properties[defaultPropertyIndex].getName(); + } else if (superDefaultIndex >= 0 + && superDefaultIndex < superDescs.length) { + defaultPropertyName = superDescs[superDefaultIndex].getName(); + } + + for (int i = 0; i < superDescs.length; i++) { + PropertyDescriptor superDesc = superDescs[i]; + String propertyName = superDesc.getName(); + if (!subMap.containsKey(propertyName)) { + subMap.put(propertyName, superDesc); + continue; + } + + Object value = subMap.get(propertyName); + // if sub and super are both PropertyDescriptor + Method subGet = ((PropertyDescriptor) value).getReadMethod(); + Method subSet = ((PropertyDescriptor) value).getWriteMethod(); + Method superGet = superDesc.getReadMethod(); + Method superSet = superDesc.getWriteMethod(); + + Class superType = superDesc.getPropertyType(); + Class superIndexedType = null; + Class subType = ((PropertyDescriptor) value).getPropertyType(); + Class subIndexedType = null; + + if (value instanceof IndexedPropertyDescriptor) { + subIndexedType = ((IndexedPropertyDescriptor) value) + .getIndexedPropertyType(); + } + if (superDesc instanceof IndexedPropertyDescriptor) { + superIndexedType = ((IndexedPropertyDescriptor) superDesc) + .getIndexedPropertyType(); + } + + // if superDesc is PropertyDescriptor + if (superIndexedType == null) { + PropertyDescriptor subDesc = (PropertyDescriptor) value; + // Sub is PropertyDescriptor + if (subIndexedType == null) { + // Same property type + if (subType != null && superType != null + && subType.getName() != null + && subType.getName().equals(superType.getName())) { + if (superGet != null + && (subGet == null || superGet.equals(subGet))) { + subDesc.setReadMethod(superGet); + } + if (superSet != null + && (subSet == null || superSet.equals(subSet))) { + subDesc.setWriteMethod(superSet); + } + if (subType == boolean.class && subGet != null + && superGet != null) { + if (superGet.getName().startsWith(PREFIX_IS)) { + subDesc.setReadMethod(superGet); + } + } + } else { // Different type + if ((subGet == null || subSet == null) + && (superGet != null)) { + subDesc = new PropertyDescriptor(propertyName, + superGet, superSet); + if (subGet != null) { + String subGetName = subGet.getName(); + Method method = null; + MethodDescriptor[] introspectMethods = introspectMethods(); + for (MethodDescriptor methodDesc : introspectMethods) { + method = methodDesc.getMethod(); + if (method != subGet + && subGetName.equals(method + .getName()) + && method.getParameterTypes().length == 0 + && method.getReturnType() == superType) { + subDesc.setReadMethod(method); + break; + } + } + } + } + } + } else { // Sub is IndexedPropertyDescriptor and super is PropertyDescriptor + if (superType != null + && (superType.isArray()) + && (superType.getComponentType().getName() + .equals(subIndexedType.getName()))) { + if ((subGet == null) && (superGet != null)) { + subDesc.setReadMethod(superGet); + } + if ((subSet == null) && (superSet != null)) { + subDesc.setWriteMethod(superSet); + } + } // different type do nothing + // sub is indexed pd and super is normal pd + if (subIndexedType == boolean.class + && superType == boolean.class) { + Method subIndexedSet = ((IndexedPropertyDescriptor) subDesc) + .getIndexedWriteMethod(); + if (subGet == null && subSet == null + && subIndexedSet != null && superGet != null) { + try { + subSet = beanClass.getDeclaredMethod( + subIndexedSet.getName(), boolean.class); + } catch (Exception e) { + // ignored + } + if (subSet != null) { + // Cast sub into PropertyDescriptor + subDesc = new PropertyDescriptor(propertyName, + superGet, subSet); + } + } + } + } + subMap.put(propertyName, subDesc); + } else { // Super is IndexedPropertyDescriptor + if (subIndexedType == null) { // Sub is PropertyDescriptor + if (subType != null + && subType.isArray() + && (subType.getComponentType().getName() + .equals(superIndexedType.getName()))) { + // Same type + if (subGet != null) { + superDesc.setReadMethod(subGet); + } + if (subSet != null) { + superDesc.setWriteMethod(subSet); + } + subMap.put(propertyName, superDesc); + } else { + // subDesc is PropertyDescriptor + // superDesc is IndexedPropertyDescriptor + + // fill null subGet or subSet method with superClass's + if (subGet == null || subSet == null) { + Class beanSuperClass = beanClass.getSuperclass(); + String methodSuffix = capitalize(propertyName); + Method method = null; + if (subGet == null) { + // subGet is null + if (subType == boolean.class) { + try { + method = beanSuperClass + .getDeclaredMethod(PREFIX_IS + + methodSuffix); + } catch (Exception e) { + // ignored + } + } else { + try { + method = beanSuperClass + .getDeclaredMethod(PREFIX_GET + + methodSuffix); + } catch (Exception e) { + // ignored + } + } + if (method != null + && !Modifier.isStatic(method + .getModifiers()) + && method.getReturnType() == subType) { + ((PropertyDescriptor) value) + .setReadMethod(method); + } + } else { + // subSet is null + try { + method = beanSuperClass.getDeclaredMethod( + PREFIX_SET + methodSuffix, subType); + } catch (Exception e) { + // ignored + } + if (method != null + && !Modifier.isStatic(method + .getModifiers()) + && method.getReturnType() == void.class) { + ((PropertyDescriptor) value) + .setWriteMethod(method); + } + } + } + subMap.put(propertyName, (PropertyDescriptor) value); + } + } else if (subIndexedType.getName().equals( + superIndexedType.getName())) { + // Sub is IndexedPropertyDescriptor and Same type + IndexedPropertyDescriptor subDesc = (IndexedPropertyDescriptor) value; + if ((subGet == null) && (superGet != null)) { + subDesc.setReadMethod(superGet); + } + if ((subSet == null) && (superSet != null)) { + subDesc.setWriteMethod(superSet); + } + IndexedPropertyDescriptor superIndexedDesc = (IndexedPropertyDescriptor) superDesc; + + if ((subDesc.getIndexedReadMethod() == null) + && (superIndexedDesc.getIndexedReadMethod() != null)) { + subDesc.setIndexedReadMethod(superIndexedDesc + .getIndexedReadMethod()); + } + + if ((subDesc.getIndexedWriteMethod() == null) + && (superIndexedDesc.getIndexedWriteMethod() != null)) { + subDesc.setIndexedWriteMethod(superIndexedDesc + .getIndexedWriteMethod()); + } + + subMap.put(propertyName, subDesc); + } // Different indexed type, do nothing + } + mergeAttributes((PropertyDescriptor) value, superDesc); + } + + PropertyDescriptor[] theDescs = new PropertyDescriptor[subMap.size()]; + subMap.values().toArray(theDescs); + + if (defaultPropertyName != null && !explicitProperties) { + for (int i = 0; i < theDescs.length; i++) { + if (defaultPropertyName.equals(theDescs[i].getName())) { + defaultPropertyIndex = i; + break; + } + } + } + return theDescs; + } + + private String capitalize(String name) { + if (name == null) { + return null; + } + // The rule for decapitalize is that: + // If the first letter of the string is Upper Case, make it lower case + // UNLESS the second letter of the string is also Upper Case, in which case no + // changes are made. + if (name.length() == 0 || (name.length() > 1 && Character.isUpperCase(name.charAt(1)))) { + return name; + } + + char[] chars = name.toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + return new String(chars); + } + + private static void mergeAttributes(PropertyDescriptor subDesc, + PropertyDescriptor superDesc) { + // FIXME: this is just temp workaround, need more elegant solution to + // handle this + subDesc.hidden |= superDesc.hidden; + subDesc.expert |= superDesc.expert; + subDesc.preferred |= superDesc.preferred; + subDesc.bound |= superDesc.bound; + subDesc.constrained |= superDesc.constrained; + subDesc.name = superDesc.name; + if (subDesc.shortDescription == null + && superDesc.shortDescription != null) { + subDesc.shortDescription = superDesc.shortDescription; + } + if (subDesc.displayName == null && superDesc.displayName != null) { + subDesc.displayName = superDesc.displayName; + } + } + + /* MODIFIED FOR THE MSGPACK PROJECT + * merge the MethodDescriptor + */ + private MethodDescriptor[] mergeMethods(MethodDescriptor[] superDescs) { + HashMap subMap = internalAsMap(methods); + + for (MethodDescriptor superMethod : superDescs) { + String methodName = getQualifiedName(superMethod.getMethod()); + MethodDescriptor method = subMap.get(methodName); + if (method == null) { + subMap.put(methodName, superMethod); + } else { + method.merge(superMethod); + } + } + MethodDescriptor[] theMethods = new MethodDescriptor[subMap.size()]; + subMap.values().toArray(theMethods); + return theMethods; + } + + private EventSetDescriptor[] mergeEvents(EventSetDescriptor[] otherEvents, + int otherDefaultIndex) { + HashMap subMap = internalAsMap(events); + String defaultEventName = null; + if (defaultEventIndex >= 0 && defaultEventIndex < events.length) { + defaultEventName = events[defaultEventIndex].getName(); + } else if (otherDefaultIndex >= 0 + && otherDefaultIndex < otherEvents.length) { + defaultEventName = otherEvents[otherDefaultIndex].getName(); + } + + for (EventSetDescriptor event : otherEvents) { + String eventName = event.getName(); + EventSetDescriptor subEvent = subMap.get(eventName); + if (subEvent == null) { + subMap.put(eventName, event); + } else { + subEvent.merge(event); + } + } + + EventSetDescriptor[] theEvents = new EventSetDescriptor[subMap.size()]; + subMap.values().toArray(theEvents); + + if (defaultEventName != null && !explicitEvents) { + for (int i = 0; i < theEvents.length; i++) { + if (defaultEventName.equals(theEvents[i].getName())) { + defaultEventIndex = i; + break; + } + } + } + return theEvents; + } + + private static HashMap internalAsMap( + PropertyDescriptor[] propertyDescs) { + HashMap map = new HashMap(); + for (int i = 0; i < propertyDescs.length; i++) { + map.put(propertyDescs[i].getName(), propertyDescs[i]); + } + return map; + } + + private static HashMap internalAsMap( + MethodDescriptor[] theDescs) { + HashMap map = new HashMap(); + for (int i = 0; i < theDescs.length; i++) { + String qualifiedName = getQualifiedName(theDescs[i].getMethod()); + map.put(qualifiedName, theDescs[i]); + } + return map; + } + + private static HashMap internalAsMap( + EventSetDescriptor[] theDescs) { + HashMap map = new HashMap(); + for (int i = 0; i < theDescs.length; i++) { + map.put(theDescs[i].getName(), theDescs[i]); + } + return map; + } + + private static String getQualifiedName(Method method) { + String qualifiedName = method.getName(); + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes != null) { + for (int i = 0; i < paramTypes.length; i++) { + qualifiedName += "_" + paramTypes[i].getName(); //$NON-NLS-1$ + } + } + return qualifiedName; + } + + /** + * Introspects the supplied class and returns a list of the public methods + * of the class + * + * @return An array of MethodDescriptors with the public methods. null if + * there are no public methods + */ + private MethodDescriptor[] introspectMethods() { + return introspectMethods(false, beanClass); + } + + private MethodDescriptor[] introspectMethods(boolean includeSuper) { + return introspectMethods(includeSuper, beanClass); + } + + private MethodDescriptor[] introspectMethods(boolean includeSuper, + Class introspectorClass) { + + // Get the list of methods belonging to this class + Method[] basicMethods = includeSuper ? introspectorClass.getMethods() + : introspectorClass.getDeclaredMethods(); + + if (basicMethods == null || basicMethods.length == 0) + return null; + + ArrayList methodList = new ArrayList( + basicMethods.length); + + // Loop over the methods found, looking for public non-static methods + for (int i = 0; i < basicMethods.length; i++) { + int modifiers = basicMethods[i].getModifiers(); + if (Modifier.isPublic(modifiers)) { + // Allocate a MethodDescriptor for this method + MethodDescriptor theDescriptor = new MethodDescriptor( + basicMethods[i]); + methodList.add(theDescriptor); + } + } + + // Get the list of public methods into the returned array + int methodCount = methodList.size(); + MethodDescriptor[] theMethods = null; + if (methodCount > 0) { + theMethods = new MethodDescriptor[methodCount]; + theMethods = methodList.toArray(theMethods); + } + + return theMethods; + } + + /** + * Introspects the supplied class and returns a list of the Properties of + * the class + * + * @param stopClass - + * the to introspecting at + * @return The list of Properties as an array of PropertyDescriptors + * @throws IntrospectionException + */ + @SuppressWarnings("rawtypes") + private PropertyDescriptor[] introspectProperties(Class stopClass) + throws IntrospectionException { + + // Get descriptors for the public methods + MethodDescriptor[] methodDescriptors = introspectMethods(); + + if (methodDescriptors == null) { + return null; + } + + ArrayList methodList = new ArrayList(); + // Loop over the methods found, looking for public non-static methods + for (int index = 0; index < methodDescriptors.length; index++) { + int modifiers = methodDescriptors[index].getMethod().getModifiers(); + if (!Modifier.isStatic(modifiers)) { + methodList.add(methodDescriptors[index]); + } + } + + // Get the list of public non-static methods into an array + int methodCount = methodList.size(); + MethodDescriptor[] theMethods = null; + if (methodCount > 0) { + theMethods = new MethodDescriptor[methodCount]; + theMethods = methodList.toArray(theMethods); + } + + if (theMethods == null) { + return null; + } + + HashMap propertyTable = new HashMap( + theMethods.length); + + // Search for methods that either get or set a Property + for (int i = 0; i < theMethods.length; i++) { + introspectGet(theMethods[i].getMethod(), propertyTable); + introspectSet(theMethods[i].getMethod(), propertyTable); + } + + // fix possible getter & setter collisions + fixGetSet(propertyTable); + + // If there are listener methods, should be bound. + MethodDescriptor[] allMethods = introspectMethods(true); + if (stopClass != null) { + MethodDescriptor[] excludeMethods = introspectMethods(true, + stopClass); + if (excludeMethods != null) { + ArrayList tempMethods = new ArrayList(); + for (MethodDescriptor method : allMethods) { + if (!isInSuper(method, excludeMethods)) { + tempMethods.add(method); + } + } + allMethods = tempMethods + .toArray(new MethodDescriptor[0]); + } + } + for (int i = 0; i < allMethods.length; i++) { + introspectPropertyListener(allMethods[i].getMethod()); + } + // Put the properties found into the PropertyDescriptor array + ArrayList propertyList = new ArrayList(); + + for (Map.Entry entry : propertyTable.entrySet()) { + String propertyName = entry.getKey(); + HashMap table = entry.getValue(); + if (table == null) { + continue; + } + String normalTag = (String) table.get(STR_NORMAL); + String indexedTag = (String) table.get(STR_INDEXED); + + if ((normalTag == null) && (indexedTag == null)) { + continue; + } + + Method get = (Method) table.get(STR_NORMAL + PREFIX_GET); + Method set = (Method) table.get(STR_NORMAL + PREFIX_SET); + Method indexedGet = (Method) table.get(STR_INDEXED + PREFIX_GET); + Method indexedSet = (Method) table.get(STR_INDEXED + PREFIX_SET); + + PropertyDescriptor propertyDesc = null; + if (indexedTag == null) { + propertyDesc = new PropertyDescriptor(propertyName, get, set); + } else { + try { + propertyDesc = new IndexedPropertyDescriptor(propertyName, + get, set, indexedGet, indexedSet); + } catch (IntrospectionException e) { + // If the getter and the indexGetter is not compatible, try + // getter/setter is null; + propertyDesc = new IndexedPropertyDescriptor(propertyName, + null, null, indexedGet, indexedSet); + } + } + // RI set propretyDescriptor as bound. FIXME + // propertyDesc.setBound(true); + if (canAddPropertyChangeListener && canRemovePropertyChangeListener) { + propertyDesc.setBound(true); + } else { + propertyDesc.setBound(false); + } + if (table.get(STR_IS_CONSTRAINED) == Boolean.TRUE) { //$NON-NLS-1$ + propertyDesc.setConstrained(true); + } + propertyList.add(propertyDesc); + } + + PropertyDescriptor[] theProperties = new PropertyDescriptor[propertyList + .size()]; + propertyList.toArray(theProperties); + return theProperties; + } + + private boolean isInSuper(MethodDescriptor method, + MethodDescriptor[] excludeMethods) { + for (MethodDescriptor m : excludeMethods) { + if (method.getMethod().equals(m.getMethod())) { + return true; + } + } + return false; + } + + @SuppressWarnings("nls") + private void introspectPropertyListener(Method theMethod) { + String methodName = theMethod.getName(); + Class[] param = theMethod.getParameterTypes(); + if (param.length != 1) { + return; + } + if (methodName.equals("addPropertyChangeListener") + && param[0].equals(PropertyChangeListener.class)) + canAddPropertyChangeListener = true; + if (methodName.equals("removePropertyChangeListener") + && param[0].equals(PropertyChangeListener.class)) + canRemovePropertyChangeListener = true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void introspectGet(Method theMethod, + HashMap propertyTable) { + + String methodName = theMethod.getName(); + int prefixLength = 0; + String propertyName; + Class propertyType; + Class[] paramTypes; + HashMap table; + ArrayList getters; + + if (methodName == null) { + return; + } + + if (methodName.startsWith(PREFIX_GET)) { + prefixLength = PREFIX_GET.length(); + } + + if (methodName.startsWith(PREFIX_IS)) { + prefixLength = PREFIX_IS.length(); + } + + if (prefixLength == 0) { + return; + } + + propertyName = decapitalize(methodName.substring(prefixLength)); + + // validate property name + if (!isValidProperty(propertyName)) { + return; + } + + // validate return type + propertyType = theMethod.getReturnType(); + + if (propertyType == null || propertyType == void.class) { + return; + } + + // isXXX return boolean + if (prefixLength == 2) { + if (!(propertyType == boolean.class)) { + return; + } + } + + // validate parameter types + paramTypes = theMethod.getParameterTypes(); + if (paramTypes.length > 1 + || (paramTypes.length == 1 && paramTypes[0] != int.class)) { + return; + } + + table = propertyTable.get(propertyName); + if (table == null) { + table = new HashMap(); + propertyTable.put(propertyName, table); + } + + getters = (ArrayList) table.get(STR_GETTERS); + if (getters == null) { + getters = new ArrayList(); + table.put(STR_GETTERS, getters); + } + + // add current method as a valid getter + getters.add(theMethod); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void introspectSet(Method theMethod, + HashMap propertyTable) { + + String methodName = theMethod.getName(); + if (methodName == null) { + return; + } + String propertyName; + Class returnType; + Class[] paramTypes; + + // setter method should never return type other than void + returnType = theMethod.getReturnType(); + if (returnType != void.class) { + return; + } + + if (methodName == null || !methodName.startsWith(PREFIX_SET)) { + return; + } + + propertyName = decapitalize(methodName.substring(PREFIX_SET.length())); + + // validate property name + if (!isValidProperty(propertyName)) { + return; + } + + // It seems we do not need to validate return type + + // validate param types + paramTypes = theMethod.getParameterTypes(); + + if (paramTypes.length == 0 || paramTypes.length > 2 + || (paramTypes.length == 2 && paramTypes[0] != int.class)) { + return; + } + + HashMap table = propertyTable.get(propertyName); + if (table == null) { + table = new HashMap(); + propertyTable.put(propertyName, table); + } + + ArrayList setters = (ArrayList) table.get(STR_SETTERS); + if (setters == null) { + setters = new ArrayList(); + table.put(STR_SETTERS, setters); + } + + // handle constrained + Class[] exceptions = theMethod.getExceptionTypes(); + for (Class e : exceptions) { + if (e.equals(PropertyVetoException.class)) { + table.put(STR_IS_CONSTRAINED, Boolean.TRUE); //$NON-NLS-1$ + } + } + + // add new setter + setters.add(theMethod); + } + + /** + * Checks and fixs all cases when several incompatible checkers / getters + * were specified for single property. + * + * @param propertyTable + * @throws IntrospectionException + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private void fixGetSet(HashMap propertyTable) + throws IntrospectionException { + + if (propertyTable == null) { + return; + } + + for (Map.Entry entry : propertyTable.entrySet()) { + HashMap table = entry.getValue(); + ArrayList getters = (ArrayList) table + .get(STR_GETTERS); + ArrayList setters = (ArrayList) table + .get(STR_SETTERS); + + Method normalGetter = null; + Method indexedGetter = null; + Method normalSetter = null; + Method indexedSetter = null; + + Class normalPropType = null; + Class indexedPropType = null; + + if (getters == null) { + getters = new ArrayList(); + } + + if (setters == null) { + setters = new ArrayList(); + } + + // retrieve getters + Class[] paramTypes = null; + String methodName = null; + for (Method getter : getters) { + paramTypes = getter.getParameterTypes(); + methodName = getter.getName(); + // checks if it's a normal getter + if (paramTypes == null || paramTypes.length == 0) { + // normal getter found + if (normalGetter == null + || methodName.startsWith(PREFIX_IS)) { + normalGetter = getter; + } + } + + // checks if it's an indexed getter + if (paramTypes != null && paramTypes.length == 1 + && paramTypes[0] == int.class) { + // indexed getter found + if (indexedGetter == null + || methodName.startsWith(PREFIX_GET) + || (methodName.startsWith(PREFIX_IS) && !indexedGetter + .getName().startsWith(PREFIX_GET))) { + indexedGetter = getter; + } + } + } + + // retrieve normal setter + if (normalGetter != null) { + // Now we will try to look for normal setter of the same type. + Class propertyType = normalGetter.getReturnType(); + + for (Method setter : setters) { + if (setter.getParameterTypes().length == 1 + && propertyType + .equals(setter.getParameterTypes()[0])) { + normalSetter = setter; + break; + } + } + } else { + // Normal getter wasn't defined. Let's look for the last + // defined setter + + for (Method setter : setters) { + if (setter.getParameterTypes().length == 1) { + normalSetter = setter; + } + } + } + + // retrieve indexed setter + if (indexedGetter != null) { + // Now we will try to look for indexed setter of the same type. + Class propertyType = indexedGetter.getReturnType(); + + for (Method setter : setters) { + if (setter.getParameterTypes().length == 2 + && setter.getParameterTypes()[0] == int.class + && propertyType + .equals(setter.getParameterTypes()[1])) { + indexedSetter = setter; + break; + } + } + } else { + // Indexed getter wasn't defined. Let's look for the last + // defined indexed setter + + for (Method setter : setters) { + if (setter.getParameterTypes().length == 2 + && setter.getParameterTypes()[0] == int.class) { + indexedSetter = setter; + } + } + } + + // determine property type + if (normalGetter != null) { + normalPropType = normalGetter.getReturnType(); + } else if (normalSetter != null) { + normalPropType = normalSetter.getParameterTypes()[0]; + } + + // determine indexed getter/setter type + if (indexedGetter != null) { + indexedPropType = indexedGetter.getReturnType(); + } else if (indexedSetter != null) { + indexedPropType = indexedSetter.getParameterTypes()[1]; + } + + // convert array-typed normal getters to indexed getters + if (normalGetter != null && normalGetter.getReturnType().isArray()) { + + } + + // RULES + // These rules were created after performing extensive black-box + // testing of RI + + // RULE1 + // Both normal getter and setter of the same type were defined; + // no indexed getter/setter *PAIR* of the other type defined + if (normalGetter != null && normalSetter != null + && (indexedGetter == null || indexedSetter == null)) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, normalPropType); + continue; + } + + // RULE2 + // normal getter and/or setter was defined; no indexed + // getters & setters defined + if ((normalGetter != null || normalSetter != null) + && indexedGetter == null && indexedSetter == null) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, normalPropType); + continue; + } + + // RULE3 + // mix of normal / indexed getters and setters are defined. Types + // are compatible + if ((normalGetter != null || normalSetter != null) + && (indexedGetter != null || indexedSetter != null)) { + // (1)!A!B!C!D + if (normalGetter != null && normalSetter != null + && indexedGetter != null && indexedSetter != null) { + if (indexedGetter.getName().startsWith(PREFIX_GET)) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, + indexedPropType); + } else { + if (normalPropType != boolean.class + && normalGetter.getName().startsWith(PREFIX_IS)) { + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, + indexedPropType); + } else { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + } + } + continue; + } + + // (2)!AB!C!D + if (normalGetter != null && normalSetter == null + && indexedGetter != null && indexedSetter != null) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, normalPropType); + + table.put(STR_INDEXED, STR_VALID); + if (indexedGetter.getName().startsWith(PREFIX_GET)) { + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + } + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + + // (3)A!B!C!D + if (normalGetter == null && normalSetter != null + && indexedGetter != null && indexedSetter != null) { + table.put(STR_INDEXED, STR_VALID); + if (indexedGetter.getName().startsWith(PREFIX_GET)) { + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + } + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + + // (4)!AB!CD + if (normalGetter != null && normalSetter == null + && indexedGetter != null && indexedSetter == null) { + if (indexedGetter.getName().startsWith(PREFIX_GET)) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, + indexedPropType); + } else { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + } + continue; + } + + // (5)A!B!CD + if (normalGetter == null && normalSetter != null + && indexedGetter != null && indexedSetter == null) { + if (indexedGetter.getName().startsWith(PREFIX_GET)) { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, + indexedPropType); + } else { + table.put(STR_NORMAL, STR_VALID); + table.put(STR_NORMAL + PREFIX_GET, normalGetter); + table.put(STR_NORMAL + PREFIX_SET, normalSetter); + table.put(STR_NORMAL + STR_PROPERTY_TYPE, + normalPropType); + } + continue; + } + + // (6)!ABC!D + if (normalGetter != null && normalSetter == null + && indexedGetter == null && indexedSetter != null) { + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + + // (7)A!BC!D + if (normalGetter == null && normalSetter != null + && indexedGetter == null && indexedSetter != null) { + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + } + + // RULE4 + // no normal normal getter / setter. + // Only indexed getter and/or setter is given + // no normal setters / getters defined + if (normalSetter == null && normalGetter == null + && (indexedGetter != null || indexedSetter != null)) { + if (indexedGetter != null + && indexedGetter.getName().startsWith(PREFIX_IS)) { + if (indexedSetter != null) { + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, + indexedPropType); + } + continue; + } + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + + // RULE5 + // Both indexed getter and setter methods are defined + // no normal getter/setter *PAIR* of the other type defined + if ((normalSetter != null || normalGetter != null) + && indexedGetter != null && indexedSetter != null) { + table.put(STR_INDEXED, STR_VALID); + table.put(STR_INDEXED + PREFIX_GET, indexedGetter); + table.put(STR_INDEXED + PREFIX_SET, indexedSetter); + table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType); + continue; + } + + // default rule - invalid property + table.put(STR_NORMAL, STR_INVALID); + table.put(STR_INDEXED, STR_INVALID); + } + + } + + /** + * Introspects the supplied Bean class and returns a list of the Events of + * the class + * + * @return the events + * @throws IntrospectionException + */ + @SuppressWarnings({ "rawtypes" }) + private EventSetDescriptor[] introspectEvents() throws IntrospectionException { + // Get descriptors for the public methods + // FIXME: performance + MethodDescriptor[] theMethods = introspectMethods(); + + if (theMethods == null) + return null; + + HashMap eventTable = new HashMap( + theMethods.length); + + // Search for methods that add an Event Listener + for (int i = 0; i < theMethods.length; i++) { + introspectListenerMethods(PREFIX_ADD, theMethods[i].getMethod(), + eventTable); + introspectListenerMethods(PREFIX_REMOVE, theMethods[i].getMethod(), + eventTable); + introspectGetListenerMethods(theMethods[i].getMethod(), eventTable); + } + + ArrayList eventList = new ArrayList(); + for (Map.Entry entry : eventTable.entrySet()) { + HashMap table = entry.getValue(); + Method add = (Method) table.get(PREFIX_ADD); + Method remove = (Method) table.get(PREFIX_REMOVE); + + if ((add == null) || (remove == null)) { + continue; + } + + Method get = (Method) table.get(PREFIX_GET); + Class listenerType = (Class) table.get("listenerType"); //$NON-NLS-1$ + Method[] listenerMethods = (Method[]) table.get("listenerMethods"); //$NON-NLS-1$ + EventSetDescriptor eventSetDescriptor = new EventSetDescriptor( + decapitalize(entry.getKey()), listenerType, listenerMethods, add, + remove, get); + + eventSetDescriptor.setUnicast(table.get("isUnicast") != null); //$NON-NLS-1$ + eventList.add(eventSetDescriptor); + } + + EventSetDescriptor[] theEvents = new EventSetDescriptor[eventList + .size()]; + eventList.toArray(theEvents); + + return theEvents; + } + + /* MODIFIED FOR THE MSGPACK PROJECT + * find the add, remove listener method + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void introspectListenerMethods(String type, + Method theMethod, HashMap methodsTable) { + String methodName = theMethod.getName(); + if (methodName == null) { + return; + } + + if (!((methodName.startsWith(type)) && (methodName + .endsWith(SUFFIX_LISTEN)))) { + return; + } + + String listenerName = methodName.substring(type.length()); + String eventName = listenerName.substring(0, listenerName + .lastIndexOf(SUFFIX_LISTEN)); + if ((eventName == null) || (eventName.length() == 0)) { + return; + } + + Class[] paramTypes = theMethod.getParameterTypes(); + if ((paramTypes == null) || (paramTypes.length != 1)) { + return; + } + + Class listenerType = paramTypes[0]; + + if (!EventListener.class.isAssignableFrom(listenerType)) { + return; + } + + if (!listenerType.getName().endsWith(listenerName)) { + return; + } + + HashMap table = methodsTable.get(eventName); + if (table == null) { + table = new HashMap(); + } + // put listener type + if (table.get("listenerType") == null) { //$NON-NLS-1$ + table.put("listenerType", listenerType); //$NON-NLS-1$ + table.put("listenerMethods", //$NON-NLS-1$ + introspectListenerMethods(listenerType)); + } + // put add / remove + table.put(type, theMethod); + + // determine isUnicast() + if (type.equals(PREFIX_ADD)) { + Class[] exceptionTypes = theMethod.getExceptionTypes(); + if (exceptionTypes != null) { + for (int i = 0; i < exceptionTypes.length; i++) { + if (exceptionTypes[i].getName().equals( + TooManyListenersException.class.getName())) { + table.put("isUnicast", "true"); //$NON-NLS-1$//$NON-NLS-2$ + break; + } + } + } + } + + methodsTable.put(eventName, table); + } + + private static Method[] introspectListenerMethods(Class listenerType) { + Method[] methods = listenerType.getDeclaredMethods(); + ArrayList list = new ArrayList(); + for (int i = 0; i < methods.length; i++) { + Class[] paramTypes = methods[i].getParameterTypes(); + if (paramTypes.length != 1) { + continue; + } + + if (EventObject.class.isAssignableFrom(paramTypes[0])) { + list.add(methods[i]); + } + } + Method[] matchedMethods = new Method[list.size()]; + list.toArray(matchedMethods); + return matchedMethods; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void introspectGetListenerMethods(Method theMethod, + HashMap methodsTable) { + String type = PREFIX_GET; + + String methodName = theMethod.getName(); + if (methodName == null) { + return; + } + + if (!((methodName.startsWith(type)) && (methodName + .endsWith(SUFFIX_LISTEN + "s")))) { //$NON-NLS-1$ + return; + } + + String listenerName = methodName.substring(type.length(), methodName + .length() - 1); + String eventName = listenerName.substring(0, listenerName + .lastIndexOf(SUFFIX_LISTEN)); + if ((eventName == null) || (eventName.length() == 0)) { + return; + } + + Class[] paramTypes = theMethod.getParameterTypes(); + if ((paramTypes == null) || (paramTypes.length != 0)) { + return; + } + + Class returnType = theMethod.getReturnType(); + if ((returnType.getComponentType() == null) + || (!returnType.getComponentType().getName().endsWith( + listenerName))) { + return; + } + + HashMap table = methodsTable.get(eventName); + if (table == null) { + table = new HashMap(); + } + // put add / remove + table.put(type, theMethod); + methodsTable.put(eventName, table); + } + + private static boolean isValidProperty(String propertyName) { + return (propertyName != null) && (propertyName.length() != 0); + } + + private static class PropertyComparator implements + Comparator { + public int compare(PropertyDescriptor object1, + PropertyDescriptor object2) { + return object1.getName().compareTo(object2.getName()); + } + + } + + // TODO + void init() { + if (this.events == null) { + events = new EventSetDescriptor[0]; + } + if (this.properties == null) { + this.properties = new PropertyDescriptor[0]; + } + + if (properties != null) { + String defaultPropertyName = (defaultPropertyIndex != -1 ? properties[defaultPropertyIndex] + .getName() + : null); + Arrays.sort(properties, comparator); + if (null != defaultPropertyName) { + for (int i = 0; i < properties.length; i++) { + if (defaultPropertyName.equals(properties[i].getName())) { + defaultPropertyIndex = i; + break; + } + } + } + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/Statement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/Statement.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,610 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.harmony.beans.BeansUtils; +import org.apache.harmony.beans.internal.nls.Messages; + +public class Statement { + + private Object target; + + private String methodName; + + private Object[] arguments; + + // cache used methods of specified target class to accelerate method search + private static WeakHashMap, Method[]> classMethodsCache = new WeakHashMap, Method[]>(); + + public Statement(Object target, String methodName, Object[] arguments) { + this.target = target; + this.methodName = methodName; + this.arguments = arguments == null ? BeansUtils.EMPTY_OBJECT_ARRAY + : arguments; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (target == null) { + sb.append(BeansUtils.NULL); + } else { + Class clazz = target.getClass(); + sb.append(clazz == String.class ? BeansUtils.QUOTE : BeansUtils + .idOfClass(clazz)); + } + sb.append('.' + methodName + '('); + if (arguments != null) { + Class clazz; + for (int index = 0; index < arguments.length; index++) { + if (index > 0) { + sb.append(", "); //$NON-NLS-1$ + } + if (arguments[index] == null) { + sb.append(BeansUtils.NULL); + } else { + clazz = arguments[index].getClass(); + sb.append(clazz == String.class ? '"' + (String) arguments[index] + '"' + : BeansUtils.idOfClass(clazz)); + } + } + } + sb.append(')'); + sb.append(';'); + return sb.toString(); + } + + public String getMethodName() { + return methodName; + } + + public Object[] getArguments() { + return arguments; + } + + public Object getTarget() { + return target; + } + + public void execute() throws Exception { + invokeMethod(); + } + + Object invokeMethod() throws Exception { + Object result = null; + try { + Object target = getTarget(); + String methodName = getMethodName(); + Object[] arguments = getArguments(); + Class targetClass = target.getClass(); + if (targetClass.isArray()) { + Method method = findArrayMethod(methodName, arguments); + Object[] copy = new Object[arguments.length + 1]; + copy[0] = target; + System.arraycopy(arguments, 0, copy, 1, arguments.length); + result = method.invoke(null, copy); + } else if (BeansUtils.NEWINSTANCE.equals(methodName) + && target == Array.class) { + result = Array.newInstance((Class) arguments[0], + ((Integer) arguments[1]).intValue()); + } else if (BeansUtils.NEW.equals(methodName) + || BeansUtils.NEWINSTANCE.equals(methodName)) { + if (target instanceof Class) { + Constructor constructor = findConstructor( + (Class) target, arguments); + result = constructor.newInstance(arguments); + } else { + if (BeansUtils.NEW.equals(methodName)) { + throw new NoSuchMethodException(this.toString()); + } + // target class declares a public named "newInstance" method + Method method = findMethod(targetClass, methodName, + arguments, false); + result = method.invoke(target, arguments); + } + } else if (methodName.equals(BeansUtils.NEWARRAY)) { + // create a new array instance without length attribute + Class clazz = (Class) target, argClass; + + // check the element types of array + for (int index = 0; index < arguments.length; index++) { + argClass = arguments[index] == null ? null + : arguments[index].getClass(); + if (argClass != null && !clazz.isAssignableFrom(argClass) + && !BeansUtils.isPrimitiveWrapper(argClass, clazz)) { + throw new IllegalArgumentException( + Messages.getString("custom.beans.63")); //$NON-NLS-1$ + } + } + result = Array.newInstance(clazz, arguments.length); + if (clazz.isPrimitive()) { + // Copy element according to primitive types + arrayCopy(clazz, arguments, result, arguments.length); + } else { + // Copy element of Objects + System.arraycopy(arguments, 0, result, 0, arguments.length); + } + return result; + } else if (target instanceof Class) { + Method method = null; + try { + /* MODIFIED FOR THE MSGPACK PROJECT + * Try to look for a static method of class described by the + * given Class object at first process only if the class + * differs from Class itself + */ + if (target != Class.class) { + method = findMethod((Class) target, methodName, + arguments, true); + result = method.invoke(null, arguments); + } + } catch (NoSuchMethodException e) { + // expected + } + if (method == null) { + // static method was not found + // try to invoke method of Class object + if (BeansUtils.FORNAME.equals(methodName) + && arguments.length == 1 + && arguments[0] instanceof String) { + // special handling of Class.forName(String) + try { + result = Class.forName((String) arguments[0]); + } catch (ClassNotFoundException e2) { + result = Class.forName((String) arguments[0], true, + Thread.currentThread() + .getContextClassLoader()); + } + } else { + method = findMethod(targetClass, methodName, arguments, + false); + result = method.invoke(target, arguments); + } + } + } else if (target instanceof Iterator) { + final Iterator iterator = (Iterator) target; + final Method method = findMethod(targetClass, methodName, + arguments, false); + if (iterator.hasNext()) { + result = new PrivilegedAction() { + public Object run() { + try { + method.setAccessible(true); + return (method.invoke(iterator, new Object[0])); + } catch (Exception e) { + // ignore + } + return null; + } + + }.run(); + } + } else { + Method method = findMethod(targetClass, methodName, arguments, + false); + method.setAccessible(true); + result = method.invoke(target, arguments); + } + } catch (InvocationTargetException ite) { + Throwable t = ite.getCause(); + throw (t != null) && (t instanceof Exception) ? (Exception) t : ite; + } + return result; + } + + private void arrayCopy(Class type, Object[] src, Object dest, int length) { + if (type == boolean.class) { + boolean[] destination = (boolean[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Boolean) src[index]).booleanValue(); + } + } else if (type == short.class) { + short[] destination = (short[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Short) src[index]).shortValue(); + } + } else if (type == byte.class) { + byte[] destination = (byte[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Byte) src[index]).byteValue(); + } + } else if (type == char.class) { + char[] destination = (char[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Character) src[index]).charValue(); + } + } else if (type == int.class) { + int[] destination = (int[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Integer) src[index]).intValue(); + } + } else if (type == long.class) { + long[] destination = (long[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Long) src[index]).longValue(); + } + } else if (type == float.class) { + float[] destination = (float[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Float) src[index]).floatValue(); + } + } else if (type == double.class) { + double[] destination = (double[]) dest; + for (int index = 0; index < length; index++) { + destination[index] = ((Double) src[index]).doubleValue(); + } + } + } + + private Method findArrayMethod(String methodName, Object[] args) + throws NoSuchMethodException { + // the code below reproduces exact RI exception throwing behavior + boolean isGet = BeansUtils.GET.equals(methodName); //$NON-NLS-1$ + boolean isSet = BeansUtils.SET.equals(methodName); //$NON-NLS-1$ + if (!isGet && !isSet) { + throw new NoSuchMethodException(Messages.getString("custom.beans.3C")); //$NON-NLS-1$ + } else if (args.length > 0 && args[0].getClass() != Integer.class) { + throw new ClassCastException(Messages.getString("custom.beans.3D")); //$NON-NLS-1$ + } else if (isGet && args.length != 1) { + throw new ArrayIndexOutOfBoundsException( + Messages.getString("custom.beans.3E")); //$NON-NLS-1$ + } else if (isSet && args.length != 2) { + throw new ArrayIndexOutOfBoundsException( + Messages.getString("custom.beans.3F")); //$NON-NLS-1$ + } + + Class[] paraTypes = isGet ? new Class[] { Object.class, int.class } + : new Class[] { Object.class, int.class, Object.class }; + return Array.class.getMethod(methodName, paraTypes); + } + + private Constructor findConstructor(Class clazz, Object[] args) + throws NoSuchMethodException { + Class[] argTypes = getTypes(args), paraTypes, resultParaTypes; + Constructor result = null; + boolean isAssignable; + for (Constructor constructor : clazz.getConstructors()) { + paraTypes = constructor.getParameterTypes(); + if (match(argTypes, paraTypes)) { + if (result == null) { + // first time, set constructor + result = constructor; + continue; + } + // find out more suitable constructor + resultParaTypes = result.getParameterTypes(); + isAssignable = true; + for (int index = 0; index < paraTypes.length; index++) { + if (argTypes[index] != null + && !(isAssignable &= resultParaTypes[index] + .isAssignableFrom(paraTypes[index]))) { + break; + } + if (argTypes[index] == null + && !(isAssignable &= paraTypes[index] + .isAssignableFrom(resultParaTypes[index]))) { + break; + } + } + if (isAssignable) { + result = constructor; + } + } + } + if (result == null) { + throw new NoSuchMethodException(Messages.getString( + "custom.beans.40", clazz.getName())); //$NON-NLS-1$ + } + return result; + } + + /** + * Searches for best matching method for given name and argument types. + */ + static Method findMethod(Class clazz, String methodName, Object[] args, + boolean isStatic) throws NoSuchMethodException { + Class[] argTypes = getTypes(args); + + Method[] methods = null; + if (classMethodsCache.containsKey(clazz)) { + methods = classMethodsCache.get(clazz); + } else { + methods = clazz.getMethods(); + classMethodsCache.put(clazz, methods); + } + + ArrayList fitMethods = new ArrayList(); + for (Method method : methods) { + if (methodName.equals(method.getName())) { + if (!isStatic || Modifier.isStatic(method.getModifiers())) { + if (match(argTypes, method.getParameterTypes())) { + fitMethods.add(method); + } + } + } + } + int fitSize = fitMethods.size(); + if (fitSize == 0) { + throw new NoSuchMethodException(Messages.getString( + "custom.beans.41", methodName)); //$NON-NLS-1$ + } + if (fitSize == 1) { + return fitMethods.get(0); + } + // find the most relevant one + MethodComparator comparator = new MethodComparator(methodName, argTypes); + Method[] fitMethodArray = fitMethods.toArray(new Method[fitSize]); + Method onlyMethod = fitMethodArray[0]; + Class onlyReturnType, fitReturnType; + int difference; + for (int i = 1; i < fitMethodArray.length; i++) { + // if 2 methods have same relevance, check their return type + if ((difference = comparator.compare(onlyMethod, fitMethodArray[i])) == 0) { + // if 2 methods have the same signature, check their return type + onlyReturnType = onlyMethod.getReturnType(); + fitReturnType = fitMethodArray[i].getReturnType(); + if (onlyReturnType == fitReturnType) { + // if 2 methods have the same relevance and return type + throw new NoSuchMethodException(Messages.getString( + "custom.beans.62", methodName)); //$NON-NLS-1$ + } + + if (onlyReturnType.isAssignableFrom(fitReturnType)) { + // if onlyReturnType is super class or interface of + // fitReturnType, set onlyMethod to fitMethodArray[i] + onlyMethod = fitMethodArray[i]; + } + } + if (difference > 0) { + onlyMethod = fitMethodArray[i]; + } + } + return onlyMethod; + } + + private static boolean match(Class[] argTypes, Class[] paraTypes) { + if (paraTypes.length != argTypes.length) { + return false; + } + for (int index = 0; index < paraTypes.length; index++) { + if (argTypes[index] != null + && !paraTypes[index].isAssignableFrom(argTypes[index]) + && !BeansUtils.isPrimitiveWrapper(argTypes[index], + paraTypes[index])) { + return false; + } + } + return true; + } + + static boolean isStaticMethodCall(Statement stmt) { + Object target = stmt.getTarget(); + String methodName = stmt.getMethodName(); + if (!(target instanceof Class)) { + return false; + } + try { + Statement.findMethod((Class) target, methodName, + stmt.getArguments(), true); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + + /* MODIFIED FOR THE MSGPACK PROJECT + * The list of "method signatures" used by persistence delegates to create + * objects. Not necessary reflects to real methods. + */ + private static final String[][] pdConstructorSignatures = { + { "java.lang.Class", "new", "java.lang.Boolean", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Byte", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Character", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Double", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Float", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Integer", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Long", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.Short", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "new", "java.lang.String", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "forName", "java.lang.String", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "newInstance", "java.lang.Class", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "java.lang.Integer", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + { "java.lang.reflect.Field", "get", "null", "", "", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + { "java.lang.Class", "forName", "java.lang.String", "", "", "" } //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + }; + + static boolean isPDConstructor(Statement stmt) { + Object target = stmt.getTarget(); + String methodName = stmt.getMethodName(); + Object[] args = stmt.getArguments(); + String[] sig = new String[pdConstructorSignatures[0].length]; + if (target == null || methodName == null || args == null + || args.length == 0) { + // not a constructor for sure + return false; + } + sig[0] = target.getClass().getName(); + sig[1] = methodName; + for (int i = 2; i < sig.length; i++) { + if (args.length > i - 2) { + sig[i] = args[i - 2] != null ? args[i - 2].getClass().getName() + : "null"; //$NON-NLS-1$ + } else { + sig[i] = ""; //$NON-NLS-1$ + } + } + for (String[] element : pdConstructorSignatures) { + if (Arrays.equals(sig, element)) { + return true; + } + } + return false; + } + + private static Class getPrimitiveWrapper(Class base) { + Class res = null; + if (base == boolean.class) { + res = Boolean.class; + } else if (base == byte.class) { + res = Byte.class; + } else if (base == char.class) { + res = Character.class; + } else if (base == short.class) { + res = Short.class; + } else if (base == int.class) { + res = Integer.class; + } else if (base == long.class) { + res = Long.class; + } else if (base == float.class) { + res = Float.class; + } else if (base == double.class) { + res = Double.class; + } + return res; + } + + private static Class[] getTypes(Object[] arguments) { + Class[] types = new Class[arguments.length]; + for (int index = 0; index < arguments.length; ++index) { + types[index] = (arguments[index] == null) ? null : arguments[index] + .getClass(); + } + return types; + } + + /** + * Comparator to determine which of two methods is "closer" to the reference + * method. + */ + static class MethodComparator implements Comparator { + static int INFINITY = Integer.MAX_VALUE; + + private String referenceMethodName; + + private Class[] referenceMethodArgumentTypes; + + private final Map cache; + + public MethodComparator(String refMethodName, + Class[] refArgumentTypes) { + this.referenceMethodName = refMethodName; + this.referenceMethodArgumentTypes = refArgumentTypes; + cache = new HashMap(); + } + + public int compare(Method m1, Method m2) { + Integer norm1 = cache.get(m1); + Integer norm2 = cache.get(m2); + if (norm1 == null) { + norm1 = Integer.valueOf(getNorm(m1)); + cache.put(m1, norm1); + } + if (norm2 == null) { + norm2 = Integer.valueOf(getNorm(m2)); + cache.put(m2, norm2); + } + return (norm1.intValue() - norm2.intValue()); + } + + /** + * Returns the norm for given method. The norm is the "distance" from + * the reference method to the given method. + * + * @param m + * the method to calculate the norm for + * @return norm of given method + */ + private int getNorm(Method m) { + String methodName = m.getName(); + Class[] argumentTypes = m.getParameterTypes(); + int totalNorm = 0; + if (!referenceMethodName.equals(methodName) + || referenceMethodArgumentTypes.length != argumentTypes.length) { + return INFINITY; + } + for (int i = 0; i < referenceMethodArgumentTypes.length; i++) { + if (referenceMethodArgumentTypes[i] == null) { + // doesn't affect the norm calculation if null + continue; + } + if (referenceMethodArgumentTypes[i].isPrimitive()) { + referenceMethodArgumentTypes[i] = getPrimitiveWrapper(referenceMethodArgumentTypes[i]); + } + if (argumentTypes[i].isPrimitive()) { + argumentTypes[i] = getPrimitiveWrapper(argumentTypes[i]); + } + totalNorm += getDistance(referenceMethodArgumentTypes[i], + argumentTypes[i]); + } + return totalNorm; + } + + /** + * Returns a "hierarchy distance" between two classes. + * + * @param clz1 + * @param clz2 + * should be superclass or superinterface of clz1 + * @return hierarchy distance from clz1 to clz2, Integer.MAX_VALUE if + * clz2 is not assignable from clz1. + */ + private static int getDistance(Class clz1, Class clz2) { + Class superClz; + int superDist = INFINITY; + if (!clz2.isAssignableFrom(clz1)) { + return INFINITY; + } + if (clz1.getName().equals(clz2.getName())) { + return 0; + } + superClz = clz1.getSuperclass(); + if (superClz != null) { + superDist = getDistance(superClz, clz2); + } + if (clz2.isInterface()) { + Class[] interfaces = clz1.getInterfaces(); + int bestDist = INFINITY; + for (Class element : interfaces) { + int curDist = getDistance(element, clz2); + if (curDist < bestDist) { + bestDist = curDist; + } + } + if (superDist < bestDist) { + bestDist = superDist; + } + return (bestDist != INFINITY ? bestDist + 1 : INFINITY); + } + return (superDist != INFINITY ? superDist + 2 : INFINITY); + } + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/template/builder/beans/XMLDecoder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/template/builder/beans/XMLDecoder.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,705 @@ +// MODIFIED FOR THE MSGPACK PROJECT +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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.template.builder.beans; + +import java.io.InputStream; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Stack; + +import javax.xml.parsers.SAXParserFactory; + +import org.apache.harmony.beans.internal.nls.Messages; +import org.msgpack.template.builder.beans.Statement.MethodComparator; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + + +/** + * XMLDecoder reads objects from xml created by + * XMLEncoder. + *

    + * The API is similar to ObjectInputStream. + *

    + */ +public class XMLDecoder { + + private ClassLoader defaultClassLoader = null; + + private static class DefaultExceptionListener implements ExceptionListener { + + public void exceptionThrown(Exception e) { + System.err.println(e.getMessage()); + System.err.println("Continue..."); //$NON-NLS-1$ + } + } + + private class SAXHandler extends DefaultHandler { + + boolean inJavaElem = false; + + HashMap idObjMap = new HashMap(); + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + if (!inJavaElem) { + return; + } + if (readObjs.size() > 0) { + Elem elem = readObjs.peek(); + if (elem.isBasicType) { + String str = new String(ch, start, length); + elem.methodName = elem.methodName == null ? str + : elem.methodName + str; + } + } + } + + @SuppressWarnings("nls") + @Override + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + if (!inJavaElem) { + if ("java".equals(qName)) { + inJavaElem = true; + } else { + listener.exceptionThrown(new Exception( + Messages.getString("custom.beans.72", qName))); + } + return; + } + + if ("object".equals(qName)) { + startObjectElem(attributes); + } else if ("array".equals(qName)) { + startArrayElem(attributes); + } else if ("void".equals(qName)) { + startVoidElem(attributes); + } else if ("boolean".equals(qName) || "byte".equals(qName) + || "char".equals(qName) || "class".equals(qName) + || "double".equals(qName) || "float".equals(qName) + || "int".equals(qName) || "long".equals(qName) + || "short".equals(qName) || "string".equals(qName) + || "null".equals(qName)) { + startBasicElem(qName, attributes); + } + } + + @SuppressWarnings("nls") + private void startObjectElem(Attributes attributes) { + Elem elem = new Elem(); + elem.isExpression = true; + elem.id = attributes.getValue("id"); + elem.idref = attributes.getValue("idref"); + elem.attributes = attributes; + if (elem.idref == null) { + obtainTarget(elem, attributes); + obtainMethod(elem, attributes); + } + + readObjs.push(elem); + } + + private void obtainTarget(Elem elem, Attributes attributes) { + String className = attributes.getValue("class"); //$NON-NLS-1$ + if (className != null) { + try { + elem.target = classForName(className); + } catch (ClassNotFoundException e) { + listener.exceptionThrown(e); + } + } else { + Elem parent = latestUnclosedElem(); + if (parent == null) { + elem.target = owner; + return; + } + elem.target = execute(parent); + } + } + + @SuppressWarnings("nls") + private void obtainMethod(Elem elem, Attributes attributes) { + elem.methodName = attributes.getValue("method"); + if (elem.methodName != null) { + return; + } + + elem.methodName = attributes.getValue("property"); + if (elem.methodName != null) { + elem.fromProperty = true; + return; + } + + elem.methodName = attributes.getValue("index"); + if (elem.methodName != null) { + elem.fromIndex = true; + return; + } + + elem.methodName = attributes.getValue("field"); + if (elem.methodName != null) { + elem.fromField = true; + return; + } + + elem.methodName = attributes.getValue("owner"); + if (elem.methodName != null) { + elem.fromOwner = true; + return; + } + + elem.methodName = "new"; // default method name + } + + @SuppressWarnings("nls") + private Class classForName(String className) + throws ClassNotFoundException { + if ("boolean".equals(className)) { + return Boolean.TYPE; + } else if ("byte".equals(className)) { + return Byte.TYPE; + } else if ("char".equals(className)) { + return Character.TYPE; + } else if ("double".equals(className)) { + return Double.TYPE; + } else if ("float".equals(className)) { + return Float.TYPE; + } else if ("int".equals(className)) { + return Integer.TYPE; + } else if ("long".equals(className)) { + return Long.TYPE; + } else if ("short".equals(className)) { + return Short.TYPE; + } else { + return Class.forName(className, true, + defaultClassLoader == null ? Thread.currentThread() + .getContextClassLoader() : defaultClassLoader); + } + } + + private void startArrayElem(Attributes attributes) { + Elem elem = new Elem(); + elem.isExpression = true; + elem.id = attributes.getValue("id"); //$NON-NLS-1$ + elem.attributes = attributes; + try { + // find component class + Class compClass = classForName(attributes.getValue("class")); //$NON-NLS-1$ + String lengthValue = attributes.getValue("length"); //$NON-NLS-1$ + if (lengthValue != null) { + // find length + int length = Integer + .parseInt(attributes.getValue("length")); //$NON-NLS-1$ + // execute, new array instance + elem.result = Array.newInstance(compClass, length); + elem.isExecuted = true; + } else { + // create array without length attribute, + // delay the excution to the end, + // get array length from sub element + elem.target = compClass; + elem.methodName = "newArray"; //$NON-NLS-1$ + elem.isExecuted = false; + } + } catch (Exception e) { + listener.exceptionThrown(e); + } + readObjs.push(elem); + } + + @SuppressWarnings("nls") + private void startVoidElem(Attributes attributes) { + Elem elem = new Elem(); + elem.id = attributes.getValue("id"); + elem.attributes = attributes; + obtainTarget(elem, attributes); + obtainMethod(elem, attributes); + readObjs.push(elem); + } + + @SuppressWarnings("nls") + private void startBasicElem(String tagName, Attributes attributes) { + Elem elem = new Elem(); + elem.isBasicType = true; + elem.isExpression = true; + elem.id = attributes.getValue("id"); + elem.idref = attributes.getValue("idref"); + elem.attributes = attributes; + elem.target = tagName; + readObjs.push(elem); + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + if (!inJavaElem) { + return; + } + if ("java".equals(qName)) { //$NON-NLS-1$ + inJavaElem = false; + return; + } + // find the elem to close + Elem toClose = latestUnclosedElem(); + if ("string".equals(toClose.target)) { + StringBuilder sb = new StringBuilder(); + for (int index = readObjs.size() - 1; index >= 0; index--) { + Elem elem = (Elem) readObjs.get(index); + if (toClose == elem) { + break; + } + if ("char".equals(elem.target)) { + sb.insert(0, elem.methodName); + } + } + toClose.methodName = toClose.methodName != null ? toClose.methodName + + sb.toString() + : sb.toString(); + } + // make sure it is executed + execute(toClose); + // set to closed + toClose.isClosed = true; + // pop it and its children + while (readObjs.pop() != toClose) { + // + } + + if (toClose.isExpression) { + // push back expression + readObjs.push(toClose); + } + } + + private Elem latestUnclosedElem() { + for (int i = readObjs.size() - 1; i >= 0; i--) { + Elem elem = readObjs.get(i); + if (!elem.isClosed) { + return elem; + } + } + return null; + } + + private Object execute(Elem elem) { + if (elem.isExecuted) { + return elem.result; + } + + // execute to obtain result + try { + if (elem.idref != null) { + elem.result = idObjMap.get(elem.idref); + } else if (elem.isBasicType) { + elem.result = executeBasic(elem); + } else { + elem.result = executeCommon(elem); + } + } catch (Exception e) { + listener.exceptionThrown(e); + } + + // track id + if (elem.id != null) { + idObjMap.put(elem.id, elem.result); + } + + elem.isExecuted = true; + return elem.result; + } + + @SuppressWarnings("nls") + private Object executeCommon(Elem elem) throws Exception { + // pop args + ArrayList args = new ArrayList(5); + while (readObjs.peek() != elem) { + Elem argElem = readObjs.pop(); + args.add(0, argElem.result); + } + // decide method name + String method = elem.methodName; + if (elem.fromProperty) { + method = (args.size() == 0 ? "get" : "set") + + capitalize(method); + } + if (elem.fromIndex) { + Integer index = Integer.valueOf(method); + args.add(0, index); + method = args.size() == 1 ? "get" : "set"; + } + if (elem.fromField) { + Field f = ((Class) elem.target).getField(method); + return (new Expression(f, "get", new Object[] { null })) + .getValue(); + } + if (elem.fromOwner) { + return owner; + } + + if (elem.target == owner) { + if ("getOwner".equals(method)) { + return owner; + } + Class[] c = new Class[args.size()]; + for (int i = 0; i < args.size(); i++) { + Object arg = args.get(i); + c[i] = (arg == null ? null: arg.getClass()); + } + + // Try actual match method + try { + Method m = owner.getClass().getMethod(method, c); + return m.invoke(owner, args.toArray()); + } catch (NoSuchMethodException e) { + // Do nothing + } + + // Find the specific method matching the parameter + Method mostSpecificMethod = findMethod( + owner instanceof Class ? (Class) owner : owner + .getClass(), method, c); + + return mostSpecificMethod.invoke(owner, args.toArray()); + } + + // execute + Expression exp = new Expression(elem.target, method, args.toArray()); + return exp.getValue(); + } + + private Method findMethod(Class clazz, String methodName, + Class[] clazzes) throws Exception { + Method[] methods = clazz.getMethods(); + ArrayList matchMethods = new ArrayList(); + + // Add all matching methods into a ArrayList + for (Method method : methods) { + if (!methodName.equals(method.getName())) { + continue; + } + Class[] parameterTypes = method.getParameterTypes(); + if (parameterTypes.length != clazzes.length) { + continue; + } + boolean match = true; + for (int i = 0; i < parameterTypes.length; i++) { + boolean isNull = (clazzes[i] == null); + boolean isPrimitive = isPrimitiveWrapper(clazzes[i], parameterTypes[i]); + boolean isAssignable = isNull? false : parameterTypes[i].isAssignableFrom(clazzes[i]); + if ( isNull || isPrimitive || isAssignable ) { + continue; + } + match = false; + } + if (match) { + matchMethods.add(method); + } + } + + int size = matchMethods.size(); + if (size == 1) { + // Only one method matches, just invoke it + return matchMethods.get(0); + } else if (size == 0) { + // Does not find any matching one, throw exception + throw new NoSuchMethodException(Messages.getString( + "custom.beans.41", methodName)); //$NON-NLS-1$ + } + + // There are more than one method matching the signature + // Find the most specific one to invoke + MethodComparator comparator = new MethodComparator(methodName, + clazzes); + Method chosenOne = matchMethods.get(0); + matchMethods.remove(0); + int methodCounter = 1; + for (Method method : matchMethods) { + int difference = comparator.compare(chosenOne, method); + if (difference > 0) { + chosenOne = method; + methodCounter = 1; + } else if (difference == 0) { + methodCounter++; + } + } + if (methodCounter > 1) { + // if 2 methods have same relevance, throw exception + throw new NoSuchMethodException(Messages.getString( + "custom.beans.62", methodName)); //$NON-NLS-1$ + } + return chosenOne; + } + + private boolean isPrimitiveWrapper(Class wrapper, Class base) { + return (base == boolean.class) && (wrapper == Boolean.class) + || (base == byte.class) && (wrapper == Byte.class) + || (base == char.class) && (wrapper == Character.class) + || (base == short.class) && (wrapper == Short.class) + || (base == int.class) && (wrapper == Integer.class) + || (base == long.class) && (wrapper == Long.class) + || (base == float.class) && (wrapper == Float.class) + || (base == double.class) && (wrapper == Double.class); + } + + private String capitalize(String str) { + StringBuilder buf = new StringBuilder(str); + buf.setCharAt(0, Character.toUpperCase(buf.charAt(0))); + return buf.toString(); + } + + @SuppressWarnings("nls") + private Object executeBasic(Elem elem) throws Exception { + String tag = (String) elem.target; + String value = elem.methodName; + + if ("null".equals(tag)) { + return null; + } else if ("string".equals(tag)) { + return value == null ? "" : value; + } else if ("class".equals(tag)) { + return classForName(value); + } else if ("boolean".equals(tag)) { + return Boolean.valueOf(value); + } else if ("byte".equals(tag)) { + return Byte.valueOf(value); + } else if ("char".equals(tag)) { + if (value == null && elem.attributes != null) { + String codeAttr = elem.attributes.getValue("code"); + if (codeAttr != null) { + Character character = new Character((char) Integer + .valueOf(codeAttr.substring(1), 16).intValue()); + elem.methodName = character.toString(); + return character; + } + } + return Character.valueOf(value.charAt(0)); + } else if ("double".equals(tag)) { + return Double.valueOf(value); + } else if ("float".equals(tag)) { + return Float.valueOf(value); + } else if ("int".equals(tag)) { + return Integer.valueOf(value); + } else if ("long".equals(tag)) { + return Long.valueOf(value); + } else if ("short".equals(tag)) { + return Short.valueOf(value); + } else { + throw new Exception(Messages.getString("custom.beans.71", tag)); + } + } + + @Override + public void error(SAXParseException e) throws SAXException { + listener.exceptionThrown(e); + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + listener.exceptionThrown(e); + } + + @Override + public void warning(SAXParseException e) throws SAXException { + listener.exceptionThrown(e); + } + } + + private static class Elem { + String id; + + String idref; + + boolean isExecuted; + + boolean isExpression; + + boolean isBasicType; + + boolean isClosed; + + Object target; + + String methodName; + + boolean fromProperty; + + boolean fromIndex; + + boolean fromField; + + boolean fromOwner; + + Attributes attributes; + + Object result; + + } + + private InputStream inputStream; + + private ExceptionListener listener; + + private Object owner; + + private Stack readObjs = new Stack(); + + private int readObjIndex = 0; + + private SAXHandler saxHandler = null; + + /** + * Create a decoder to read from specified input stream. + * + * @param inputStream + * an input stream of xml + */ + public XMLDecoder(InputStream inputStream) { + this(inputStream, null, null, null); + } + + /** + * Create a decoder to read from specified input stream. + * + * @param inputStream + * an input stream of xml + * @param owner + * the owner of this decoder + */ + public XMLDecoder(InputStream inputStream, Object owner) { + this(inputStream, owner, null, null); + } + + /** + * Create a decoder to read from specified input stream. + * + * @param inputStream + * an input stream of xml + * @param owner + * the owner of this decoder + * @param listener + * listen to the exceptions thrown by the decoder + */ + public XMLDecoder(InputStream inputStream, Object owner, + ExceptionListener listener) { + this(inputStream, owner, listener, null); + } + + public XMLDecoder(InputStream inputStream, Object owner, + ExceptionListener listener, ClassLoader cl) { + this.inputStream = inputStream; + this.owner = owner; + this.listener = (listener == null) ? new DefaultExceptionListener() + : listener; + defaultClassLoader = cl; + } + + /** + * Close the input stream of xml data. + */ + public void close() { + if (inputStream == null) { + return; + } + try { + inputStream.close(); + } catch (Exception e) { + listener.exceptionThrown(e); + } + } + + /** + * Returns the exception listener. + * + * @return the exception listener + */ + public ExceptionListener getExceptionListener() { + return listener; + } + + /** + * Returns the owner of this decoder. + * + * @return the owner of this decoder + */ + public Object getOwner() { + return owner; + } + + /** + * Reads the next object. + * + * @return the next object + * @exception ArrayIndexOutOfBoundsException + * if no more objects to read + */ + @SuppressWarnings("nls") + public Object readObject() { + if (inputStream == null) { + return null; + } + if (saxHandler == null) { + saxHandler = new SAXHandler(); + try { + SAXParserFactory.newInstance().newSAXParser().parse( + inputStream, saxHandler); + } catch (Exception e) { + this.listener.exceptionThrown(e); + } + } + + if (readObjIndex >= readObjs.size()) { + throw new ArrayIndexOutOfBoundsException(Messages.getString("custom.beans.70")); + } + Elem elem = readObjs.get(readObjIndex); + if (!elem.isClosed) { + // bad element, error occurred while parsing + throw new ArrayIndexOutOfBoundsException(Messages.getString("custom.beans.70")); + } + readObjIndex++; + return elem.result; + } + + /** + * Sets the exception listener. + * + * @param listener + * an exception listener + */ + public void setExceptionListener(ExceptionListener listener) { + if (listener != null) { + this.listener = listener; + } + } + + /** + * Sets the owner of this decoder. + * + * @param owner + * the owner of this decoder + */ + public void setOwner(Object owner) { + this.owner = owner; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/AbstractArrayValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/AbstractArrayValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,98 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.AbstractList; +import org.msgpack.MessageTypeException; + +abstract class AbstractArrayValue extends AbstractList implements ArrayValue { + @Override + public ValueType getType() { + return ValueType.ARRAY; + } + + @Override + public boolean isArrayValue() { + return true; + } + + @Override + public ArrayValue asArrayValue() { + return this; + } + + @Override + public boolean isNilValue() { + return false; + } + + @Override + public boolean isBooleanValue() { + return false; + } + + @Override + public boolean isIntegerValue() { + return false; + } + + @Override + public boolean isFloatValue() { + return false; + } + + @Override + public boolean isMapValue() { + return false; + } + + @Override + public boolean isRawValue() { + return false; + } + + @Override + public NilValue asNilValue() { + throw new MessageTypeException(); + } + + @Override + public BooleanValue asBooleanValue() { + throw new MessageTypeException(); + } + + @Override + public IntegerValue asIntegerValue() { + throw new MessageTypeException(); + } + + @Override + public FloatValue asFloatValue() { + throw new MessageTypeException(); + } + + @Override + public MapValue asMapValue() { + throw new MessageTypeException(); + } + + @Override + public RawValue asRawValue() { + throw new MessageTypeException(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/AbstractBooleanValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/AbstractBooleanValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,43 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +abstract class AbstractBooleanValue extends AbstractValue implements BooleanValue { + @Override + public ValueType getType() { + return ValueType.BOOLEAN; + } + + @Override + public boolean isBooleanValue() { + return true; + } + + public boolean isTrue() { + return getBoolean(); + } + + public boolean isFalse() { + return !getBoolean(); + } + + @Override + public BooleanValue asBooleanValue() { + return this; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/AbstractMapValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/AbstractMapValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,98 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.AbstractMap; +import org.msgpack.MessageTypeException; + +abstract class AbstractMapValue extends AbstractMap implements MapValue { + @Override + public ValueType getType() { + return ValueType.MAP; + } + + @Override + public boolean isMapValue() { + return true; + } + + @Override + public MapValue asMapValue() { + return this; + } + + @Override + public boolean isNilValue() { + return false; + } + + @Override + public boolean isBooleanValue() { + return false; + } + + @Override + public boolean isIntegerValue() { + return false; + } + + @Override + public boolean isFloatValue() { + return false; + } + + @Override + public boolean isArrayValue() { + return false; + } + + @Override + public boolean isRawValue() { + return false; + } + + @Override + public NilValue asNilValue() { + throw new MessageTypeException(); + } + + @Override + public BooleanValue asBooleanValue() { + throw new MessageTypeException(); + } + + @Override + public IntegerValue asIntegerValue() { + throw new MessageTypeException(); + } + + @Override + public FloatValue asFloatValue() { + throw new MessageTypeException(); + } + + @Override + public ArrayValue asArrayValue() { + throw new MessageTypeException(); + } + + @Override + public RawValue asRawValue() { + throw new MessageTypeException(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/AbstractRawValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/AbstractRawValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,149 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.Arrays; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; + +abstract class AbstractRawValue extends AbstractValue implements RawValue { + static final String UTF8 = "UTF-8"; + + @Override + public ValueType getType() { + return ValueType.RAW; + } + + @Override + public boolean isRawValue() { + return true; + } + + @Override + public RawValue asRawValue() { + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isRawValue()) { + return false; + } + + return Arrays.equals(getByteArray(), v.asRawValue().getByteArray()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(getByteArray()); + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + String s; + if (getClass() == StringRawValueImpl.class) { + // StringRawValueImpl.getString never throws exception + s = getString(); + } else { + // don't throw encoding error exception + // ignore malformed bytes + CharsetDecoder decoder = Charset.forName(UTF8).newDecoder() + .onMalformedInput(CodingErrorAction.IGNORE) + .onUnmappableCharacter(CodingErrorAction.IGNORE); + try { + s = decoder.decode(ByteBuffer.wrap(getByteArray())).toString(); + } catch (CharacterCodingException ex) { + // never comes here + s = new String(getByteArray()); + } + } + + sb.append("\""); + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (ch < 0x20) { + switch (ch) { + case '\n': + sb.append("\\n"); + break; + case '\r': + sb.append("\\r"); + break; + case '\t': + sb.append("\\t"); + break; + case '\f': + sb.append("\\f"); + break; + case '\b': + sb.append("\\b"); + break; + default: + // control chars + escapeChar(sb, ch); + break; + } + } else if (ch <= 0x7f) { + switch (ch) { + case '\\': + sb.append("\\\\"); + break; + case '"': + sb.append("\\\""); + break; + default: + sb.append(ch); + break; + } + } else if (ch >= 0xd800 && ch <= 0xdfff) { + // surrogates + escapeChar(sb, ch); + } else { + sb.append(ch); + } + } + sb.append("\""); + + return sb; + } + + private final static char[] HEX_TABLE = "0123456789ABCDEF".toCharArray(); + + private void escapeChar(StringBuilder sb, int ch) { + sb.append("\\u"); + sb.append(HEX_TABLE[(ch >> 12) & 0x0f]); + sb.append(HEX_TABLE[(ch >> 8) & 0x0f]); + sb.append(HEX_TABLE[(ch >> 4) & 0x0f]); + sb.append(HEX_TABLE[ch & 0x0f]); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/AbstractValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/AbstractValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,78 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import org.msgpack.MessageTypeException; + +abstract class AbstractValue implements Value { + public boolean isNilValue() { + return false; + } + + public boolean isBooleanValue() { + return false; + } + + public boolean isIntegerValue() { + return false; + } + + public boolean isFloatValue() { + return false; + } + + public boolean isArrayValue() { + return false; + } + + public boolean isMapValue() { + return false; + } + + public boolean isRawValue() { + return false; + } + + public NilValue asNilValue() { + throw new MessageTypeException(); + } + + public BooleanValue asBooleanValue() { + throw new MessageTypeException(); + } + + public IntegerValue asIntegerValue() { + throw new MessageTypeException(); + } + + public FloatValue asFloatValue() { + throw new MessageTypeException(); + } + + public ArrayValue asArrayValue() { + throw new MessageTypeException(); + } + + public MapValue asMapValue() { + throw new MessageTypeException(); + } + + public RawValue asRawValue() { + throw new MessageTypeException(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/ArrayValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/ArrayValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,26 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.List; + + +public interface ArrayValue extends Value, List { + public Value[] getElementArray(); +} + diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/ArrayValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/ArrayValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,171 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.ListIterator; +import java.io.IOException; +import org.msgpack.packer.Packer; + +class ArrayValueImpl extends AbstractArrayValue { + private static ArrayValueImpl emptyInstance = new ArrayValueImpl(new Value[0], true); + + public static ArrayValue getEmptyInstance() { + return emptyInstance; + } + + private Value[] array; + + @Override + public Value[] getElementArray() { + return array; + } + + ArrayValueImpl(Value[] array, boolean gift) { + if (gift) { + this.array = array; + } else { + this.array = new Value[array.length]; + System.arraycopy(array, 0, this.array, 0, array.length); + } + } + + @Override + public int size() { + return array.length; + } + + @Override + public boolean isEmpty() { + return array.length == 0; + } + + @Override + public Value get(int index) { + if (index < 0 || array.length <= index) { + throw new IndexOutOfBoundsException(); + } + return array[index]; + } + + @Override + public int indexOf(Object o) { + if (o == null) { + return -1; // FIXME NullPointerException? + } + for (int i = 0; i < array.length; i++) { + if (array[i].equals(o)) { + return i; + } + } + return -1; + } + + @Override + public int lastIndexOf(Object o) { + if (o == null) { + return -1; // FIXME NullPointerException? + } + for (int i = array.length - 1; i >= 0; i--) { + if (array[i].equals(o)) { + return i; + } + } + return -1; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.writeArrayBegin(array.length); + for (int i = 0; i < array.length; i++) { + array[i].writeTo(pk); + } + pk.writeArrayEnd(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isArrayValue()) { + return false; + } + + if (v.getClass() == ArrayValueImpl.class) { + return equals((ArrayValueImpl) v); + } + + ListIterator oi = v.asArrayValue().listIterator(); + int i = 0; + while (i < array.length) { + if (!oi.hasNext() || !array[i].equals(oi.next())) { + return false; + } + i++; + } + return !oi.hasNext(); + } + + private boolean equals(ArrayValueImpl o) { + if (array.length != o.array.length) { + return false; + } + for (int i = 0; i < array.length; i++) { + if (!array[i].equals(o.array[i])) { + return false; + } + } + return true; + } + + // TODO compareTo? + + @Override + public int hashCode() { + int h = 1; + for (int i = 0; i < array.length; i++) { + Value obj = array[i]; + h = 31 * h + obj.hashCode(); + } + return h; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + if (array.length == 0) { + return sb.append("[]"); + } + sb.append("["); + sb.append(array[0]); + for (int i = 1; i < array.length; i++) { + sb.append(","); + array[i].toString(sb); + } + sb.append("]"); + return sb; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/BigIntegerValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/BigIntegerValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,158 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.MessageTypeException; + +@SuppressWarnings("serial") +class BigIntegerValueImpl extends IntegerValue { + private BigInteger value; + + BigIntegerValueImpl(BigInteger value) { + this.value = value; + } + + private static BigInteger BYTE_MAX = BigInteger.valueOf((long) Byte.MAX_VALUE); + private static BigInteger SHORT_MAX = BigInteger.valueOf((long) Short.MAX_VALUE); + private static BigInteger INT_MAX = BigInteger.valueOf((long) Integer.MAX_VALUE); + private static BigInteger LONG_MAX = BigInteger.valueOf((long) Long.MAX_VALUE); + private static BigInteger BYTE_MIN = BigInteger.valueOf((long) Byte.MIN_VALUE); + private static BigInteger SHORT_MIN = BigInteger.valueOf((long) Short.MIN_VALUE); + private static BigInteger INT_MIN = BigInteger.valueOf((long) Integer.MIN_VALUE); + private static BigInteger LONG_MIN = BigInteger.valueOf((long) Long.MIN_VALUE); + + @Override + public byte getByte() { + if (value.compareTo(BYTE_MAX) > 0 || value.compareTo(BYTE_MIN) < 0) { + throw new MessageTypeException(); // TODO message + } + return value.byteValue(); + } + + @Override + public short getShort() { + if (value.compareTo(SHORT_MAX) > 0 || value.compareTo(SHORT_MIN) < 0) { + throw new MessageTypeException(); // TODO message + } + return value.shortValue(); + } + + @Override + public int getInt() { + if (value.compareTo(INT_MAX) > 0 || value.compareTo(INT_MIN) < 0) { + throw new MessageTypeException(); // TODO message + } + return value.intValue(); + } + + @Override + public long getLong() { + if (value.compareTo(LONG_MAX) > 0 || value.compareTo(LONG_MIN) < 0) { + throw new MessageTypeException(); // TODO message + } + return value.longValue(); + } + + @Override + public BigInteger getBigInteger() { + 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 writeTo(Packer pk) throws IOException { + pk.write(value); + } + + // TODO compareTo + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isIntegerValue()) { + return false; + } + + return value.equals(v.asIntegerValue().bigIntegerValue()); + } + + @Override + public int hashCode() { + if (INT_MIN.compareTo(value) <= 0 && value.compareTo(INT_MAX) <= 0) { + return (int) value.longValue(); + } else if (LONG_MIN.compareTo(value) <= 0 + && value.compareTo(LONG_MAX) <= 0) { + long v = value.longValue(); + return (int) (v ^ (v >>> 32)); + } + return value.hashCode(); + } + + @Override + public String toString() { + return value.toString(); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append(value.toString()); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/BooleanValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/BooleanValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,22 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +public interface BooleanValue extends Value { + public boolean getBoolean(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/ByteArrayRawValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/ByteArrayRawValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,103 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.Arrays; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import org.msgpack.packer.Packer; +import org.msgpack.MessageTypeException; + +class ByteArrayRawValueImpl extends AbstractRawValue { + private static ByteArrayRawValueImpl emptyInstance = new ByteArrayRawValueImpl(new byte[0], true); + + public static RawValue getEmptyInstance() { + return emptyInstance; + } + + private static final ThreadLocal decoderStore = new ThreadLocal() { + @Override + protected CharsetDecoder initialValue() { + return Charset.forName("UTF-8").newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT); + } + }; + + private byte[] bytes; + + ByteArrayRawValueImpl(byte[] bytes, boolean gift) { + if (gift) { + this.bytes = bytes; + } else { + this.bytes = new byte[bytes.length]; + System.arraycopy(bytes, 0, this.bytes, 0, bytes.length); + } + } + + ByteArrayRawValueImpl(byte[] b, int off, int len) { + // TODO reference + this.bytes = new byte[len]; + System.arraycopy(b, off, this.bytes, 0, len); + } + + @Override + public byte[] getByteArray() { + return bytes; + } + + @Override + public String getString() { + CharsetDecoder decoder = decoderStore.get(); + try { + return decoder.decode(ByteBuffer.wrap(bytes)).toString(); + } catch (CharacterCodingException ex) { + throw new MessageTypeException(ex); + } + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(bytes); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isRawValue()) { + return false; + } + + return Arrays.equals(bytes, v.asRawValue().getByteArray()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(bytes); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/DoubleValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/DoubleValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,116 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.math.BigDecimal; +import java.io.IOException; +import org.msgpack.packer.Packer; + +@SuppressWarnings("serial") +class DoubleValueImpl extends FloatValue { + private double value; + + DoubleValueImpl(double value) { + this.value = value; + } + + @Override + public float getFloat() { + return (float) value; + } + + @Override + public double getDouble() { + 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 new BigDecimal(value).toBigInteger(); + } + + @Override + public float floatValue() { + return (float) value; + } + + @Override + public double doubleValue() { + return value; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(value); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isFloatValue()) { + return false; + } + + return value == v.asFloatValue().getDouble(); + } + + // TODO compareTo + + @Override + public int hashCode() { + long v = Double.doubleToLongBits(value); + return (int) (v ^ (v >>> 32)); + } + + @Override + public String toString() { + return Double.toString(value); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append(Double.toString(value)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/FalseValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/FalseValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,73 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.io.IOException; +import org.msgpack.packer.Packer; + +class FalseValueImpl extends AbstractBooleanValue { + private FalseValueImpl() { + } + + private static FalseValueImpl instance = new FalseValueImpl(); + + static FalseValueImpl getInstance() { + return instance; + } + + @Override + public boolean getBoolean() { + return false; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(false); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isBooleanValue()) { + return false; + } + + return v.asBooleanValue().getBoolean() == false; + } + + @Override + public int hashCode() { + return 1237; + } + + @Override + public String toString() { + return "false"; + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append("false"); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/FloatValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/FloatValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,39 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +@SuppressWarnings("serial") +public abstract class FloatValue extends NumberValue { + @Override + public ValueType getType() { + return ValueType.FLOAT; + } + + @Override + public boolean isFloatValue() { + return true; + } + + public FloatValue asFloatValue() { + return this; + } + + public abstract float getFloat(); + + public abstract double getDouble(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/FloatValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/FloatValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,115 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.math.BigDecimal; +import java.io.IOException; +import org.msgpack.packer.Packer; + +@SuppressWarnings("serial") +class FloatValueImpl extends FloatValue { + private float value; + + FloatValueImpl(float value) { + this.value = value; + } + + @Override + public float getFloat() { + return value; + } + + @Override + public double getDouble() { + return (double) 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 new BigDecimal((double) value).toBigInteger(); + } + + @Override + public float floatValue() { + return value; + } + + @Override + public double doubleValue() { + return (double) value; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isFloatValue()) { + return false; + } + + return (double) value == v.asFloatValue().getDouble(); + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(value); + } + + // TODO compareTo + + @Override + public int hashCode() { + return Float.floatToIntBits(value); + } + + @Override + public String toString() { + return Float.toString(value); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append(Float.toString(value)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/IntValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/IntValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,147 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.MessageTypeException; + +@SuppressWarnings("serial") +class IntValueImpl extends IntegerValue { + private int value; + + IntValueImpl(int value) { + this.value = value; + } + + private static int BYTE_MAX = (int) Byte.MAX_VALUE; + private static int SHORT_MAX = (int) Short.MAX_VALUE; + + private static int BYTE_MIN = (int) Byte.MIN_VALUE; + private static int SHORT_MIN = (int) Short.MIN_VALUE; + + @Override + public byte getByte() { + if (value > BYTE_MAX || value < BYTE_MIN) { + throw new MessageTypeException(); // TODO message + } + return (byte) value; + } + + @Override + public short getShort() { + if (value > SHORT_MAX || value < SHORT_MIN) { + throw new MessageTypeException(); // TODO message + } + return (short) value; + } + + @Override + public int getInt() { + return value; + } + + @Override + public long getLong() { + return value; + } + + @Override + public BigInteger getBigInteger() { + return BigInteger.valueOf((long) value); + } + + @Override + public byte byteValue() { + return (byte) value; + } + + @Override + public short shortValue() { + return (short) value; + } + + @Override + public int intValue() { + return 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 writeTo(Packer pk) throws IOException { + pk.write(value); + } + + // TODO compareTo + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isIntegerValue()) { + return false; + } + + try { + // TODO + return value == v.asIntegerValue().getInt(); + } catch (MessageTypeException ex) { + return false; + } + } + + @Override + public int hashCode() { + return value; + } + + @Override + public String toString() { + return Integer.toString(value); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append(Integer.toString(value)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/IntegerValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/IntegerValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,53 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; + +@SuppressWarnings("serial") +public abstract class IntegerValue extends NumberValue { + @Override + public ValueType getType() { + return ValueType.INTEGER; + } + + @Override + public boolean isIntegerValue() { + return true; + } + + @Override + public IntegerValue asIntegerValue() { + return this; + } + + public abstract byte getByte(); + + public abstract short getShort(); + + public abstract int getInt(); + + public abstract long getLong(); + + public BigInteger getBigInteger() { + return bigIntegerValue(); + } + + // TODO equals + // TODO hashCode +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/LongValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/LongValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,156 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.MessageTypeException; + +@SuppressWarnings("serial") +class LongValueImpl extends IntegerValue { + private long value; + + LongValueImpl(long value) { + this.value = value; + } + + private static long BYTE_MAX = (long) Byte.MAX_VALUE; + private static long SHORT_MAX = (long) Short.MAX_VALUE; + private static long INT_MAX = (long) Integer.MAX_VALUE; + + private static long BYTE_MIN = (long) Byte.MIN_VALUE; + private static long SHORT_MIN = (long) Short.MIN_VALUE; + private static long INT_MIN = (long) Integer.MIN_VALUE; + + @Override + public byte getByte() { + if (value > BYTE_MAX || value < BYTE_MIN) { + throw new MessageTypeException(); // TODO message + } + return (byte) value; + } + + @Override + public short getShort() { + if (value > SHORT_MAX || value < SHORT_MIN) { + throw new MessageTypeException(); // TODO message + } + return (short) value; + } + + @Override + public int getInt() { + if (value > INT_MAX || value < INT_MIN) { + throw new MessageTypeException(); // TODO message + } + return (int) value; + } + + @Override + public long getLong() { + return value; + } + + @Override + public BigInteger getBigInteger() { + return BigInteger.valueOf(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 value; + } + + @Override + public BigInteger bigIntegerValue() { + return BigInteger.valueOf(value); + } + + @Override + public float floatValue() { + return (float) value; + } + + @Override + public double doubleValue() { + return (double) value; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(value); + } + + // TODO compareTo + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isIntegerValue()) { + return false; + } + + try { + // TODO + return value == v.asIntegerValue().getLong(); + } catch (MessageTypeException ex) { + return false; + } + } + + @Override + public int hashCode() { + if (INT_MIN <= value && value <= INT_MAX) { + return (int) value; + } else { + return (int) (value ^ (value >>> 32)); + } + } + + @Override + public String toString() { + return Long.toString(value); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append(Long.toString(value)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/MapValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/MapValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,24 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.Map; + +public interface MapValue extends Value, Map { + public Value[] getKeyValueArray(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/NilValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/NilValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,78 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.io.IOException; +import org.msgpack.packer.Packer; + +public class NilValue extends AbstractValue { + private NilValue() { + } + + private static NilValue instance = new NilValue(); + + static NilValue getInstance() { + return instance; + } + + @Override + public ValueType getType() { + return ValueType.NIL; + } + + @Override + public boolean isNilValue() { + return true; + } + + @Override + public NilValue asNilValue() { + return this; + } + + @Override + public String toString() { + return "null"; + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append("null"); + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.writeNil(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + return ((Value) o).isNilValue(); + } + + @Override + public int hashCode() { + return 0; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/NumberValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/NumberValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,96 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import org.msgpack.MessageTypeException; + +@SuppressWarnings("serial") +public abstract class NumberValue extends Number implements Value { + @Override + public boolean isNilValue() { + return false; + } + + @Override + public boolean isBooleanValue() { + return false; + } + + @Override + public boolean isIntegerValue() { + return false; + } + + @Override + public boolean isFloatValue() { + return false; + } + + @Override + public boolean isArrayValue() { + return false; + } + + @Override + public boolean isMapValue() { + return false; + } + + @Override + public boolean isRawValue() { + return false; + } + + @Override + public NilValue asNilValue() { + throw new MessageTypeException(); + } + + @Override + public BooleanValue asBooleanValue() { + throw new MessageTypeException(); + } + + @Override + public IntegerValue asIntegerValue() { + throw new MessageTypeException(); + } + + @Override + public FloatValue asFloatValue() { + throw new MessageTypeException(); + } + + @Override + public ArrayValue asArrayValue() { + throw new MessageTypeException(); + } + + @Override + public MapValue asMapValue() { + throw new MessageTypeException(); + } + + @Override + public RawValue asRawValue() { + throw new MessageTypeException(); + } + + public abstract BigInteger bigIntegerValue(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/RawValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/RawValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,24 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +public interface RawValue extends Value { + public byte[] getByteArray(); + + public String getString(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/SequentialMapValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/SequentialMapValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,337 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.Map; +import java.util.Set; +import java.util.Collection; +import java.util.Iterator; +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.AbstractCollection; +import java.util.NoSuchElementException; +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.util.android.PortedImmutableEntry; + +class SequentialMapValueImpl extends AbstractMapValue { + private static SequentialMapValueImpl emptyInstance = new SequentialMapValueImpl(new Value[0], true); + + public static MapValue getEmptyInstance() { + return emptyInstance; + } + + private Value[] array; + + @Override + public Value[] getKeyValueArray() { + return array; + } + + SequentialMapValueImpl(Value[] array, boolean gift) { + if (array.length % 2 != 0) { + throw new IllegalArgumentException(); // TODO message + } + if (gift) { + this.array = array; + } else { + this.array = new Value[array.length]; + System.arraycopy(array, 0, this.array, 0, array.length); + } + } + + @Override + public Value get(Object key) { + if (key == null) { + return null; + } + for (int i = array.length - 2; i >= 0; i -= 2) { + if (array[i].equals(key)) { + return array[i + 1]; + } + } + return null; + } + + private static class EntrySet extends AbstractSet> { + private Value[] array; + + EntrySet(Value[] array) { + this.array = array; + } + + @Override + public int size() { + return array.length / 2; + } + + @Override + public Iterator> iterator() { + return new EntrySetIterator(array); + } + } + + private static class EntrySetIterator implements + Iterator> { + private Value[] array; + private int pos; + private static final boolean hasDefaultImmutableEntry; + static { + boolean hasIt = true; + try { + Class.forName("java.util.AbstractMap.SimpleImmutableEntry"); + } catch (ClassNotFoundException e) { + hasIt = false; + } finally { + hasDefaultImmutableEntry = hasIt; + } + } + + EntrySetIterator(Value[] array) { + this.array = array; + this.pos = 0; + } + + @Override + public boolean hasNext() { + return pos < array.length; + } + + @Override + public Map.Entry next() { + if (pos >= array.length) { + throw new NoSuchElementException(); // TODO message + } + + Value key = array[pos]; + Value value = array[pos + 1]; + /** + * @see https://github.com/msgpack/msgpack-java/pull/27 + * + * msgpack-java was crashed on Android 2.2 or below because + * the method calls java.util.AbstractMap$SimpleImmutableEntry + * that doesn't exist in Android 2.2 or below. + */ + Map.Entry pair = hasDefaultImmutableEntry ? + new AbstractMap.SimpleImmutableEntry(key, value) : + new PortedImmutableEntry(key, value); + + pos += 2; + return pair; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); // TODO message + } + } + + private static class KeySet extends AbstractSet { + private Value[] array; + + KeySet(Value[] array) { + this.array = array; + } + + @Override + public int size() { + return array.length / 2; + } + + @Override + public Iterator iterator() { + return new ValueIterator(array, 0); + } + } + + private static class ValueCollection extends AbstractCollection { + private Value[] array; + + ValueCollection(Value[] array) { + this.array = array; + } + + @Override + public int size() { + return array.length / 2; + } + + @Override + public Iterator iterator() { + return new ValueIterator(array, 1); + } + } + + private static class ValueIterator implements Iterator { + private Value[] array; + private int pos; + + ValueIterator(Value[] array, int offset) { + this.array = array; + this.pos = offset; + } + + @Override + public boolean hasNext() { + return pos < array.length; + } + + @Override + public Value next() { + if (pos >= array.length) { + throw new NoSuchElementException(); // TODO message + } + Value v = array[pos]; + pos += 2; + return v; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); // TODO message + } + } + + @Override + public Set> entrySet() { + return new EntrySet(array); + } + + @Override + public Set keySet() { + return new KeySet(array); + } + + @Override + public Collection values() { + return new ValueCollection(array); + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.writeMapBegin(array.length / 2); + for (int i = 0; i < array.length; i++) { + array[i].writeTo(pk); + } + pk.writeMapEnd(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isMapValue()) { + return false; + } + + Map om = v.asMapValue(); + if (om.size() != array.length / 2) { + return false; + } + + try { + for (int i = 0; i < array.length; i += 2) { + Value key = array[i]; + Value value = array[i + 1]; + if (!value.equals(om.get(key))) { + return false; + } + } + } catch (ClassCastException ex) { + return false; + } catch (NullPointerException ex) { + return false; + } + + return true; + } + + // private boolean equals(SequentialMapValueImpl o) { + // if(array.length != o.array.length) { + // return false; + // } + // for(int i=0; i < array.length; i+=2) { + // if(!equalsValue(o.array, array[i], array[i+1], i)) { + // return false; + // } + // } + // return true; + // } + + // private boolean equalsValue(Value[] oarray, Value key, Value val, int hint) { + // for(int j=hint; j < array.length; j+=2) { + // if(key.equals(oarray[j])) { + // if(val.equals(oarray[j+1])) { + // return true; + // } else { + // return false; + // } + // } + // } + // for(int j=0; j < hint; j+=2) { + // if(key.equals(oarray[j])) { + // if(val.equals(oarray[j+1])) { + // return true; + // } else { + // return false; + // } + // } + // } + // return false; + // } + + // TODO compareTo? + + @Override + public int hashCode() { + int h = 0; + for (int i = 0; i < array.length; i += 2) { + h += array[i].hashCode() ^ array[i + 1].hashCode(); + } + return h; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + if (array.length == 0) { + return sb.append("{}"); + } + sb.append("{"); + sb.append(array[0]); + sb.append(":"); + sb.append(array[1]); + for (int i = 2; i < array.length; i += 2) { + sb.append(","); + array[i].toString(sb); + sb.append(":"); + array[i + 1].toString(sb); + } + sb.append("}"); + return sb; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/StringRawValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/StringRawValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,72 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.util.Arrays; +import java.io.UnsupportedEncodingException; +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.MessageTypeException; + +class StringRawValueImpl extends AbstractRawValue { + private String string; + + StringRawValueImpl(String string) { + this.string = string; + } + + @Override + public byte[] getByteArray() { + try { + // TODO encoding error? + return string.getBytes(UTF8); + } catch (UnsupportedEncodingException ex) { + throw new MessageTypeException(ex); + } + } + + @Override + public String getString() { + return string; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(string); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isRawValue()) { + return false; + } + + if (v.getClass() == StringRawValueImpl.class) { + return string.equals(((StringRawValueImpl) v).string); + } + + return Arrays.equals(getByteArray(), v.asRawValue().getByteArray()); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/TrueValueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/TrueValueImpl.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,73 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.io.IOException; +import org.msgpack.packer.Packer; + +class TrueValueImpl extends AbstractBooleanValue { + private TrueValueImpl() { + } + + private static TrueValueImpl instance = new TrueValueImpl(); + + static TrueValueImpl getInstance() { + return instance; + } + + @Override + public boolean getBoolean() { + return true; + } + + @Override + public void writeTo(Packer pk) throws IOException { + pk.write(true); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof Value)) { + return false; + } + Value v = (Value) o; + if (!v.isBooleanValue()) { + return false; + } + + return v.asBooleanValue().getBoolean() == true; + } + + @Override + public int hashCode() { + return 1231; + } + + @Override + public String toString() { + return "true"; + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return sb.append("true"); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/Value.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/Value.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,58 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.io.IOException; +import org.msgpack.packer.Packer; +import org.msgpack.type.ValueType; + +public interface Value { + public ValueType getType(); + + public boolean isNilValue(); + + public boolean isBooleanValue(); + + public boolean isIntegerValue(); + + public boolean isFloatValue(); + + public boolean isArrayValue(); + + public boolean isMapValue(); + + public boolean isRawValue(); + + public NilValue asNilValue(); + + public BooleanValue asBooleanValue(); + + public IntegerValue asIntegerValue(); + + public FloatValue asFloatValue(); + + public ArrayValue asArrayValue(); + + public MapValue asMapValue(); + + public RawValue asRawValue(); + + public void writeTo(Packer pk) throws IOException; + + public StringBuilder toString(StringBuilder sb); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/ValueFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/ValueFactory.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,142 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +public final class ValueFactory { + public static NilValue createNilValue() { + return NilValue.getInstance(); + } + + public static BooleanValue createBooleanValue(boolean v) { + if (v) { + return TrueValueImpl.getInstance(); + } else { + return FalseValueImpl.getInstance(); + } + } + + public static IntegerValue createIntegerValue(byte v) { + return new IntValueImpl((int) v); + } + + public static IntegerValue createIntegerValue(short v) { + return new IntValueImpl((int) v); + } + + public static IntegerValue createIntegerValue(int v) { + return new IntValueImpl(v); + } + + public static IntegerValue createIntegerValue(long v) { + return new LongValueImpl(v); + } + + public static IntegerValue createIntegerValue(BigInteger v) { + return new BigIntegerValueImpl(v); + } + + public static FloatValue createFloatValue(float v) { + return new FloatValueImpl(v); + } + + public static FloatValue createFloatValue(double v) { + return new DoubleValueImpl(v); + } + + public static RawValue createRawValue() { + return ByteArrayRawValueImpl.getEmptyInstance(); + } + + public static RawValue createRawValue(byte[] b) { + return createRawValue(b, false); + } + + public static RawValue createRawValue(byte[] b, boolean gift) { + return new ByteArrayRawValueImpl(b, gift); + } + + public static RawValue createRawValue(byte[] b, int off, int len) { + return new ByteArrayRawValueImpl(b, off, len); + } + + public static RawValue createRawValue(String s) { + return new StringRawValueImpl(s); + } + + public static RawValue createRawValue(ByteBuffer bb) { + int pos = bb.position(); + try { + byte[] buf = new byte[bb.remaining()]; + bb.get(buf); + return new ByteArrayRawValueImpl(buf, true); + } finally { + bb.position(pos); + } + } + + public static ArrayValue createArrayValue() { + return ArrayValueImpl.getEmptyInstance(); + } + + public static ArrayValue createArrayValue(Value[] array) { + if (array.length == 0) { + // TODO EmptyArrayValueImpl? + return ArrayValueImpl.getEmptyInstance(); + } + return createArrayValue(array, false); + } + + public static ArrayValue createArrayValue(Value[] array, boolean gift) { + if (array.length == 0) { + // TODO EmptyArrayValueImpl? + return ArrayValueImpl.getEmptyInstance(); + } + return new ArrayValueImpl(array, gift); + } + + public static MapValue createMapValue() { + return SequentialMapValueImpl.getEmptyInstance(); + } + + public static MapValue createMapValue(Value[] kvs) { + if (kvs.length == 0) { + // TODO EmptyMapValueImpl? + return SequentialMapValueImpl.getEmptyInstance(); + } + return createMapValue(kvs, false); + } + + public static MapValue createMapValue(Value[] kvs, boolean gift) { + if (kvs.length == 0) { + // TODO EmptyMapValueImpl? + return SequentialMapValueImpl.getEmptyInstance(); + } + return new SequentialMapValueImpl(kvs, gift); + } + + // TODO + // public static Value get(Object obj) { + // return new Unconverter().pack(obj).getResult(); + // } + + private ValueFactory() { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/type/ValueType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/type/ValueType.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,22 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.type; + +public enum ValueType { + NIL, BOOLEAN, INTEGER, FLOAT, ARRAY, MAP, RAW; +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/AbstractUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/AbstractUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,137 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.msgpack.type.Value; +import org.msgpack.MessagePack; +import org.msgpack.template.Template; +import org.msgpack.packer.Unconverter; + +public abstract class AbstractUnpacker implements Unpacker { + protected MessagePack msgpack; + + protected int rawSizeLimit = 134217728; + + protected int arraySizeLimit = 4194304; + + protected int mapSizeLimit = 2097152; + + protected AbstractUnpacker(MessagePack msgpack) { + this.msgpack = msgpack; + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + return ByteBuffer.wrap(readByteArray()); + } + + @Override + public void readArrayEnd() throws IOException { + readArrayEnd(false); + } + + @Override + public void readMapEnd() throws IOException { + readMapEnd(false); + } + + @Override + public UnpackerIterator iterator() { + return new UnpackerIterator(this); + } + + protected abstract void readValue(Unconverter uc) throws IOException; + + @Override + public Value readValue() throws IOException { + Unconverter uc = new Unconverter(msgpack); + readValue(uc); + return uc.getResult(); + } + + protected abstract boolean tryReadNil() throws IOException; + + @Override + public T read(Class klass) throws IOException { + if (tryReadNil()) { + return null; + } + Template tmpl = msgpack.lookup(klass); + return tmpl.read(this, null); + } + + @SuppressWarnings("unchecked") + @Override + public T read(T to) throws IOException { + if (tryReadNil()) { + return null; + } + Template tmpl = msgpack.lookup((Class) to.getClass()); + return tmpl.read(this, to); + } + + @Override + public T read(Template tmpl) throws IOException { + if (tryReadNil()) { + return null; + } + return (T) tmpl.read(this, null); + } + + @Override + public T read(T to, Template tmpl) throws IOException { + if (tryReadNil()) { + return null; + } + return (T) tmpl.read(this, to); + } + + public int getReadByteCount() { + throw new UnsupportedOperationException("Not implemented"); + } + + public void resetReadByteCount() { + throw new UnsupportedOperationException("Not implemented"); + } + + public void setRawSizeLimit(int size) { + if (size < 32) { + rawSizeLimit = 32; + } else { + rawSizeLimit = size; + } + } + + public void setArraySizeLimit(int size) { + if (size < 16) { + arraySizeLimit = 16; + } else { + arraySizeLimit = size; + } + } + + public void setMapSizeLimit(int size) { + if (size < 16) { + mapSizeLimit = 16; + } else { + mapSizeLimit = size; + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/Accept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/Accept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,111 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; +import org.msgpack.io.BufferReferer; +import org.msgpack.MessageTypeException; + +abstract class Accept implements BufferReferer { + private final String expected; + + Accept(String expected) { + this.expected = expected; + } + + void acceptBoolean(boolean v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got boolean", expected)); + } + + void acceptInteger(byte v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptInteger(short v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptInteger(int v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptInteger(long v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptUnsignedInteger(byte v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptUnsignedInteger(short v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptUnsignedInteger(int v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + void acceptUnsignedInteger(long v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got integer value", expected)); + } + + // void checkRawAcceptable() throws IOException { + // throw new MessageTypeException("Unexpected raw value"); + // } + + void acceptRaw(byte[] raw) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got raw value", expected)); + } + + void acceptEmptyRaw() throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got raw value", expected)); + } + + // void checkArrayAcceptable(int size) throws IOException { + // throw new MessageTypeException("Unexpected array value"); + // } + + void acceptArray(int size) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got array value", expected)); + } + + // void checkMapAcceptable(int size) throws IOException { + // throw new MessageTypeException("Unexpected map value"); + // } + + void acceptMap(int size) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got map value", expected)); + } + + void acceptNil() throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got nil value", expected)); + } + + void acceptFloat(float v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got float value", expected)); + } + + void acceptDouble(double v) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got float value", expected)); + } + + public void refer(ByteBuffer bb, boolean gift) throws IOException { + throw new MessageTypeException(String.format("Expected %s, but got raw value", expected)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/ArrayAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/ArrayAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +final class ArrayAccept extends Accept { + int size; + + ArrayAccept() { + super("array"); + } + + @Override + void acceptArray(int size) { + this.size = size; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/BigIntegerAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/BigIntegerAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,76 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.math.BigInteger; + +final class BigIntegerAccept extends Accept { + BigInteger value; + + BigIntegerAccept() { + super("integer"); + } + + @Override + void acceptInteger(byte v) { + this.value = BigInteger.valueOf((long) v); + } + + @Override + void acceptInteger(short v) { + this.value = BigInteger.valueOf((long) v); + } + + @Override + void acceptInteger(int v) { + this.value = BigInteger.valueOf((long) v); + } + + @Override + void acceptInteger(long v) { + this.value = BigInteger.valueOf(v); + } + + @Override + void acceptUnsignedInteger(byte v) { + this.value = BigInteger.valueOf((long) (v & 0xff)); + } + + @Override + void acceptUnsignedInteger(short v) { + this.value = BigInteger.valueOf((long) (v & 0xffff)); + } + + @Override + void acceptUnsignedInteger(int v) { + if (v < 0) { + this.value = BigInteger.valueOf((long) (v & 0x7fffffff) + 0x80000000L); + } else { + this.value = BigInteger.valueOf((long) v); + } + } + + @Override + void acceptUnsignedInteger(long v) { + if (v < 0L) { + this.value = BigInteger.valueOf(v + Long.MAX_VALUE + 1L).setBit(63); + } else { + this.value = BigInteger.valueOf(v); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/BufferUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/BufferUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,52 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.nio.ByteBuffer; + +/** + * This class is buffer-specific deserializer. + * + * @version 0.6.0 + * @see {@link org.msgpack.packer.Unpacker} + */ +public interface BufferUnpacker extends Unpacker { + public BufferUnpacker wrap(byte[] b); + + public BufferUnpacker wrap(byte[] b, int off, int len); + + public BufferUnpacker wrap(ByteBuffer buf); + + public BufferUnpacker feed(byte[] b); + + public BufferUnpacker feed(byte[] b, boolean reference); + + public BufferUnpacker feed(byte[] b, int off, int len); + + public BufferUnpacker feed(byte[] b, int off, int len, boolean reference); + + public BufferUnpacker feed(ByteBuffer b); + + public BufferUnpacker feed(ByteBuffer buf, boolean reference); + + public int getBufferSize(); + + public void copyReferencedBuffer(); + + public void clear(); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/ByteArrayAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/ByteArrayAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,46 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; + +final class ByteArrayAccept extends Accept { + byte[] value; + + ByteArrayAccept() { + super("raw value"); + } + + @Override + void acceptRaw(byte[] raw) { + this.value = raw; + } + + @Override + void acceptEmptyRaw() { + this.value = new byte[0]; + } + + @Override + public void refer(ByteBuffer bb, boolean gift) throws IOException { + // TODO gift + this.value = new byte[bb.remaining()]; + bb.get(value); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/Converter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/Converter.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,438 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.io.EOFException; +import java.math.BigInteger; + +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Unconverter; +import org.msgpack.type.Value; +import org.msgpack.type.ValueType; +import org.msgpack.type.ArrayValue; +import org.msgpack.type.MapValue; + +public class Converter extends AbstractUnpacker { + private final UnpackerStack stack; + private Object[] values; + protected Value value; + + public Converter(Value value) { + this(new MessagePack(), value); + } + + public Converter(MessagePack msgpack, Value value) { + super(msgpack); + this.stack = new UnpackerStack(); + this.values = new Object[UnpackerStack.MAX_STACK_SIZE]; + this.value = value; + } + + protected Value nextValue() throws IOException { + throw new EOFException(); + } + + private void ensureValue() throws IOException { + if (value == null) { + value = nextValue(); + } + } + + @Override + public boolean tryReadNil() throws IOException { + stack.checkCount(); + if (getTop().isNilValue()) { + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return true; + } + return false; + } + + @Override + public boolean trySkipNil() throws IOException { + ensureValue(); + + if (stack.getDepth() > 0 && stack.getTopCount() <= 0) { + // end of array or map + return true; + } + + if (getTop().isNilValue()) { + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return true; + } + return false; + } + + @Override + public void readNil() throws IOException { + if (!getTop().isNilValue()) { + throw new MessageTypeException("Expected nil but got not nil value"); + } + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + } + + @Override + public boolean readBoolean() throws IOException { + boolean v = getTop().asBooleanValue().getBoolean(); + stack.reduceCount(); + return v; + } + + @Override + public byte readByte() throws IOException { + byte v = getTop().asIntegerValue().getByte(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public short readShort() throws IOException { + short v = getTop().asIntegerValue().getShort(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public int readInt() throws IOException { + int v = getTop().asIntegerValue().getInt(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public long readLong() throws IOException { + long v = getTop().asIntegerValue().getLong(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public BigInteger readBigInteger() throws IOException { + BigInteger v = getTop().asIntegerValue().getBigInteger(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public float readFloat() throws IOException { + float v = getTop().asFloatValue().getFloat(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public double readDouble() throws IOException { + double v = getTop().asFloatValue().getDouble(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return v; + } + + @Override + public byte[] readByteArray() throws IOException { + byte[] raw = getTop().asRawValue().getByteArray(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return raw; + } + + @Override + public String readString() throws IOException { + String str = getTop().asRawValue().getString(); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return str; + } + + @Override + public int readArrayBegin() throws IOException { + Value v = getTop(); + if (!v.isArrayValue()) { + throw new MessageTypeException( + "Expected array but got not array value"); + } + ArrayValue a = v.asArrayValue(); + stack.reduceCount(); + stack.pushArray(a.size()); + values[stack.getDepth()] = a.getElementArray(); + return a.size(); + } + + @Override + public void readArrayEnd(boolean check) throws IOException { + if (!stack.topIsArray()) { + throw new MessageTypeException( + "readArrayEnd() is called but readArrayBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "readArrayEnd(check=true) is called but the array is not end"); + } + for (int i = 0; i < remain; i++) { + skip(); + } + } + stack.pop(); + + if (stack.getDepth() == 0) { + value = null; + } + } + + @Override + public int readMapBegin() throws IOException { + Value v = getTop(); + if (!v.isMapValue()) { + throw new MessageTypeException("Expected map but got not map value"); + } + MapValue m = v.asMapValue(); + stack.reduceCount(); + stack.pushMap(m.size()); + values[stack.getDepth()] = m.getKeyValueArray(); + return m.size(); + } + + @Override + public void readMapEnd(boolean check) throws IOException { + if (!stack.topIsMap()) { + throw new MessageTypeException( + "readMapEnd() is called but readMapBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "readMapEnd(check=true) is called but the map is not end"); + } + for (int i = 0; i < remain; i++) { + skip(); + } + } + stack.pop(); + + if (stack.getDepth() == 0) { + value = null; + } + } + + private Value getTop() throws IOException { + ensureValue(); + + stack.checkCount(); + if (stack.getDepth() == 0) { + // if(stack.getTopCount() < 0) { + // //throw new EOFException(); // TODO + // throw new RuntimeException(new EOFException()); + // } + return value; + } + Value[] array = (Value[]) values[stack.getDepth()]; + return array[array.length - stack.getTopCount()]; + } + + @Override + public Value readValue() throws IOException { + if (stack.getDepth() == 0) { + if (value == null) { + return nextValue(); + } else { + Value v = value; + value = null; + return v; + } + } + return super.readValue(); + } + + @Override + protected void readValue(Unconverter uc) throws IOException { + if (uc.getResult() != null) { + uc.resetResult(); + } + + stack.checkCount(); + Value v = getTop(); + if (!v.isArrayValue() && !v.isMapValue()) { + uc.write(v); + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + if (uc.getResult() != null) { + return; + } + } + + while (true) { + while (stack.getDepth() != 0 && stack.getTopCount() == 0) { + if (stack.topIsArray()) { + uc.writeArrayEnd(true); + stack.pop(); + } else if (stack.topIsMap()) { + uc.writeMapEnd(true); + stack.pop(); + } else { + throw new RuntimeException("invalid stack"); // FIXME error? + } + if (stack.getDepth() == 0) { + value = null; + } + if (uc.getResult() != null) { + return; + } + } + + stack.checkCount(); + v = getTop(); + if (v.isArrayValue()) { + ArrayValue a = v.asArrayValue(); + uc.writeArrayBegin(a.size()); + stack.reduceCount(); + stack.pushArray(a.size()); + values[stack.getDepth()] = a.getElementArray(); + + } else if (v.isMapValue()) { + MapValue m = v.asMapValue(); + uc.writeMapBegin(m.size()); + stack.reduceCount(); + stack.pushMap(m.size()); + values[stack.getDepth()] = m.getKeyValueArray(); + + } else { + uc.write(v); + stack.reduceCount(); + } + } + } + + @Override + public void skip() throws IOException { + stack.checkCount(); + Value v = getTop(); + if (!v.isArrayValue() && !v.isMapValue()) { + stack.reduceCount(); + if (stack.getDepth() == 0) { + value = null; + } + return; + } + int targetDepth = stack.getDepth(); + while (true) { + while (stack.getTopCount() == 0) { + stack.pop(); + if (stack.getDepth() == 0) { + value = null; + } + if (stack.getDepth() <= targetDepth) { + return; + } + } + + stack.checkCount(); + v = getTop(); + if (v.isArrayValue()) { + ArrayValue a = v.asArrayValue(); + stack.reduceCount(); + stack.pushArray(a.size()); + values[stack.getDepth()] = a.getElementArray(); + + } else if (v.isMapValue()) { + MapValue m = v.asMapValue(); + stack.reduceCount(); + stack.pushMap(m.size()); + values[stack.getDepth()] = m.getKeyValueArray(); + + } else { + stack.reduceCount(); + } + } + } + + public ValueType getNextType() throws IOException { + return getTop().getType(); + } + + public void reset() { + stack.clear(); + value = null; + } + + @Override + public void close() throws IOException { + } + + @Override + public int getReadByteCount() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void setRawSizeLimit(int size) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void setArraySizeLimit(int size) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void setMapSizeLimit(int size) { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/DoubleAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/DoubleAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,36 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +final class DoubleAccept extends Accept { + double value; + + DoubleAccept() { + super("float"); + } + + @Override + void acceptFloat(float v) { + this.value = (double) v; + } + + @Override + void acceptDouble(double v) { + this.value = v; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/IntAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/IntAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,77 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import org.msgpack.MessageTypeException; + +final class IntAccept extends Accept { + int value; + + IntAccept() { + super("integer"); + } + + @Override + void acceptInteger(byte v) { + this.value = (int) v; + } + + @Override + void acceptInteger(short v) { + this.value = (int) v; + } + + @Override + void acceptInteger(int v) { + this.value = v; + } + + @Override + void acceptInteger(long v) { + if (v < (long) Integer.MIN_VALUE || v > (long) Integer.MAX_VALUE) { + throw new MessageTypeException(); // TODO message + } + this.value = (int) v; + } + + @Override + void acceptUnsignedInteger(byte v) { + this.value = v & 0xff; + } + + @Override + void acceptUnsignedInteger(short v) { + this.value = v & 0xffff; + } + + @Override + void acceptUnsignedInteger(int v) { + if (v < 0) { + throw new MessageTypeException(); // TODO message + } + this.value = v; + } + + @Override + void acceptUnsignedInteger(long v) { + if (v < 0 || v > (long) Integer.MAX_VALUE) { + throw new MessageTypeException(); // TODO message + } + this.value = (int) v; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/LongAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/LongAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,75 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import org.msgpack.MessageTypeException; + +final class LongAccept extends Accept { + long value; + + LongAccept() { + super("integer"); + } + + @Override + void acceptInteger(byte v) { + this.value = (long) v; + } + + @Override + void acceptInteger(short v) { + this.value = (long) v; + } + + @Override + void acceptInteger(int v) { + this.value = (long) v; + } + + @Override + void acceptInteger(long v) { + this.value = v; + } + + @Override + void acceptUnsignedInteger(byte v) { + this.value = (long) (v & 0xff); + } + + @Override + void acceptUnsignedInteger(short v) { + this.value = (long) (v & 0xffff); + } + + @Override + void acceptUnsignedInteger(int v) { + if (v < 0) { + this.value = (long) (v & 0x7fffffff) + 0x80000000L; + } else { + this.value = (long) v; + } + } + + @Override + void acceptUnsignedInteger(long v) { + if (v < 0L) { + throw new MessageTypeException(); // TODO message + } + this.value = v; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/MapAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/MapAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,31 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +final class MapAccept extends Accept { + int size; + + MapAccept() { + super("map"); + } + + @Override + void acceptMap(int size) { + this.size = size; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/MessagePackBufferUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/MessagePackBufferUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,107 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.nio.ByteBuffer; + +import org.msgpack.MessagePack; +import org.msgpack.io.LinkedBufferInput; + +public class MessagePackBufferUnpacker extends MessagePackUnpacker implements BufferUnpacker { + private static final int DEFAULT_BUFFER_SIZE = 512; // TODO default buffer + // size + + public MessagePackBufferUnpacker(MessagePack msgpack) { + this(msgpack, DEFAULT_BUFFER_SIZE); + } + + public MessagePackBufferUnpacker(MessagePack msgpack, int bufferSize) { + super(msgpack, new LinkedBufferInput(bufferSize)); + } + + @Override + public MessagePackBufferUnpacker wrap(byte[] b) { + return wrap(b, 0, b.length); + } + + @Override + public MessagePackBufferUnpacker wrap(byte[] b, int off, int len) { + ((LinkedBufferInput) in).clear(); + ((LinkedBufferInput) in).feed(b, off, len, true); + return this; + } + + @Override + public MessagePackBufferUnpacker wrap(ByteBuffer buf) { + ((LinkedBufferInput) in).clear(); + ((LinkedBufferInput) in).feed(buf, true); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(byte[] b) { + ((LinkedBufferInput) in).feed(b); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(byte[] b, boolean reference) { + ((LinkedBufferInput) in).feed(b, reference); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(byte[] b, int off, int len) { + ((LinkedBufferInput) in).feed(b, off, len); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(byte[] b, int off, int len, boolean reference) { + ((LinkedBufferInput) in).feed(b, off, len, reference); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(ByteBuffer b) { + ((LinkedBufferInput) in).feed(b); + return this; + } + + @Override + public MessagePackBufferUnpacker feed(ByteBuffer buf, boolean reference) { + ((LinkedBufferInput) in).feed(buf, reference); + return this; + } + + @Override + public int getBufferSize() { + return ((LinkedBufferInput) in).getSize(); + } + + @Override + public void copyReferencedBuffer() { + ((LinkedBufferInput) in).copyReferencedBuffer(); + } + + @Override + public void clear() { + ((LinkedBufferInput) in).clear(); + reset(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/MessagePackUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/MessagePackUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,685 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.io.EOFException; +import java.io.InputStream; +import java.math.BigInteger; +import org.msgpack.io.Input; +import org.msgpack.io.StreamInput; +import org.msgpack.io.BufferReferer; +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Unconverter; +import org.msgpack.type.ValueType; + +public class MessagePackUnpacker extends AbstractUnpacker { + private static final byte REQUIRE_TO_READ_HEAD = (byte) 0xc1; + + protected final Input in; + private final UnpackerStack stack = new UnpackerStack(); + + private byte headByte = REQUIRE_TO_READ_HEAD; + + private byte[] raw; + private int rawFilled; + + private final IntAccept intAccept = new IntAccept(); + private final LongAccept longAccept = new LongAccept(); + private final BigIntegerAccept bigIntegerAccept = new BigIntegerAccept(); + private final DoubleAccept doubleAccept = new DoubleAccept(); + private final ByteArrayAccept byteArrayAccept = new ByteArrayAccept(); + private final StringAccept stringAccept = new StringAccept(); + private final ArrayAccept arrayAccept = new ArrayAccept(); + private final MapAccept mapAccept = new MapAccept(); + private final ValueAccept valueAccept = new ValueAccept(); + private final SkipAccept skipAccept = new SkipAccept(); + + public MessagePackUnpacker(MessagePack msgpack, InputStream stream) { + this(msgpack, new StreamInput(stream)); + } + + protected MessagePackUnpacker(MessagePack msgpack, Input in) { + super(msgpack); + this.in = in; + } + + private byte getHeadByte() throws IOException { + byte b = headByte; + if (b == REQUIRE_TO_READ_HEAD) { + b = headByte = in.readByte(); + } + return b; + } + + final void readOne(Accept a) throws IOException { + stack.checkCount(); + if (readOneWithoutStack(a)) { + stack.reduceCount(); + } + } + + final boolean readOneWithoutStack(Accept a) throws IOException { + if (raw != null) { + readRawBodyCont(); + a.acceptRaw(raw); + raw = null; + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + + final int b = (int) getHeadByte(); + + if ((b & 0x80) == 0) { // Positive Fixnum + // System.out.println("positive fixnum "+b); + a.acceptInteger(b); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + + if ((b & 0xe0) == 0xe0) { // Negative Fixnum + // System.out.println("negative fixnum "+b); + a.acceptInteger(b); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + + if ((b & 0xe0) == 0xa0) { // FixRaw + int count = b & 0x1f; + if (count == 0) { + a.acceptEmptyRaw(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + if (!tryReferRawBody(a, count)) { + readRawBody(count); + a.acceptRaw(raw); + raw = null; + } + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + + if ((b & 0xf0) == 0x90) { // FixArray + int count = b & 0x0f; + // System.out.println("fixarray count:"+count); + a.acceptArray(count); + stack.reduceCount(); + stack.pushArray(count); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + + if ((b & 0xf0) == 0x80) { // FixMap + int count = b & 0x0f; + // System.out.println("fixmap count:"+count/2); + a.acceptMap(count); + stack.reduceCount(); + stack.pushMap(count); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + + return readOneWithoutStackLarge(a, b); + } + + private boolean readOneWithoutStackLarge(Accept a, final int b) + throws IOException { + switch (b & 0xff) { + case 0xc0: // nil + a.acceptNil(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xc2: // false + a.acceptBoolean(false); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xc3: // true + a.acceptBoolean(true); + headByte = REQUIRE_TO_READ_HEAD; + return true; + //case 0xc4: // bin 8 -> see 0xd9 + //case 0xc5: // bin 16 -> see 0xda + //case 0xc6: // bin 32 -> see 0xdb + case 0xca: // float + a.acceptFloat(in.getFloat()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xcb: // double + a.acceptDouble(in.getDouble()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xcc: // unsigned int 8 + a.acceptUnsignedInteger(in.getByte()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xcd: // unsigned int 16 + a.acceptUnsignedInteger(in.getShort()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xce: // unsigned int 32 + a.acceptUnsignedInteger(in.getInt()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xcf: // unsigned int 64 + a.acceptUnsignedInteger(in.getLong()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xd0: // signed int 8 + a.acceptInteger(in.getByte()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xd1: // signed int 16 + a.acceptInteger(in.getShort()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xd2: // signed int 32 + a.acceptInteger(in.getInt()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xd3: // signed int 64 + a.acceptInteger(in.getLong()); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + case 0xc4: // bin 8 + case 0xd9: // str 8 + { + int count = in.getByte() & 0xff; + if (count == 0) { + a.acceptEmptyRaw(); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + if (count >= rawSizeLimit) { + String reason = String.format( + "Size of raw (%d) over limit at %d", + new Object[] { count, rawSizeLimit }); + throw new SizeLimitException(reason); + } + in.advance(); + if (!tryReferRawBody(a, count)) { + readRawBody(count); + a.acceptRaw(raw); + raw = null; + } + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + case 0xc5: // bin 16 + case 0xda: // raw 16 + { + int count = in.getShort() & 0xffff; + if (count == 0) { + a.acceptEmptyRaw(); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + if (count >= rawSizeLimit) { + String reason = String.format( + "Size of raw (%d) over limit at %d", + new Object[] { count, rawSizeLimit }); + throw new SizeLimitException(reason); + } + in.advance(); + if (!tryReferRawBody(a, count)) { + readRawBody(count); + a.acceptRaw(raw); + raw = null; + } + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + case 0xc6: // bin 32 + case 0xdb: // raw 32 + { + int count = in.getInt(); + if (count == 0) { + a.acceptEmptyRaw(); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + if (count < 0 || count >= rawSizeLimit) { + String reason = String.format( + "Size of raw (%d) over limit at %d", + new Object[] { count, rawSizeLimit }); + throw new SizeLimitException(reason); + } + in.advance(); + if (!tryReferRawBody(a, count)) { + readRawBody(count); + a.acceptRaw(raw); + raw = null; + } + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + case 0xdc: // array 16 + { + int count = in.getShort() & 0xffff; + if (count >= arraySizeLimit) { + String reason = String.format( + "Size of array (%d) over limit at %d", + new Object[] { count, arraySizeLimit }); + throw new SizeLimitException(reason); + } + a.acceptArray(count); + stack.reduceCount(); + stack.pushArray(count); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + case 0xdd: // array 32 + { + int count = in.getInt(); + if (count < 0 || count >= arraySizeLimit) { + String reason = String.format( + "Size of array (%d) over limit at %d", + new Object[] { count, arraySizeLimit }); + throw new SizeLimitException(reason); + } + a.acceptArray(count); + stack.reduceCount(); + stack.pushArray(count); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + case 0xde: // map 16 + { + int count = in.getShort() & 0xffff; + if (count >= mapSizeLimit) { + String reason = String.format( + "Size of map (%d) over limit at %d", + new Object[] { count, mapSizeLimit }); + throw new SizeLimitException(reason); + } + a.acceptMap(count); + stack.reduceCount(); + stack.pushMap(count); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + case 0xdf: // map 32 + { + int count = in.getInt(); + if (count < 0 || count >= mapSizeLimit) { + String reason = String.format( + "Size of map (%d) over limit at %d", + new Object[] { count, mapSizeLimit }); + throw new SizeLimitException(reason); + } + a.acceptMap(count); + stack.reduceCount(); + stack.pushMap(count); + in.advance(); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } + default: + // System.out.println("unknown b "+(b&0xff)); + // headByte = CS_INVALID + headByte = REQUIRE_TO_READ_HEAD; + throw new IOException("Invalid byte: " + b); // TODO error FormatException + } + } + + private boolean tryReferRawBody(BufferReferer referer, int size) throws IOException { + return in.tryRefer(referer, size); + } + + private void readRawBody(int size) throws IOException { + raw = new byte[size]; + rawFilled = 0; + readRawBodyCont(); + } + + private void readRawBodyCont() throws IOException { + int len = in.read(raw, rawFilled, raw.length - rawFilled); + rawFilled += len; + if (rawFilled < raw.length) { + throw new EOFException(); + } + } + + @Override + protected boolean tryReadNil() throws IOException { + stack.checkCount(); + int b = getHeadByte() & 0xff; + if (b == 0xc0) { + // nil is read + stack.reduceCount(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + // not nil + return false; + } + + @Override + public boolean trySkipNil() throws IOException { + if (stack.getDepth() > 0 && stack.getTopCount() <= 0) { + // end of array or map + return true; + } + + int b = getHeadByte() & 0xff; + if (b == 0xc0) { + // nil is skipped + stack.reduceCount(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + // not nil + return false; + } + + @Override + public void readNil() throws IOException { + // optimized not to allocate nilAccept + stack.checkCount(); + int b = getHeadByte() & 0xff; + if (b == 0xc0) { + stack.reduceCount(); + headByte = REQUIRE_TO_READ_HEAD; + return; + } + throw new MessageTypeException("Expected nil but got not nil value"); + } + + @Override + public boolean readBoolean() throws IOException { + // optimized not to allocate booleanAccept + stack.checkCount(); + int b = getHeadByte() & 0xff; + if (b == 0xc2) { + stack.reduceCount(); + headByte = REQUIRE_TO_READ_HEAD; + return false; + } else if (b == 0xc3) { + stack.reduceCount(); + headByte = REQUIRE_TO_READ_HEAD; + return true; + } + throw new MessageTypeException( + "Expected Boolean but got not boolean value"); + } + + @Override + public byte readByte() throws IOException { + // optimized not to allocate byteAccept + stack.checkCount(); + readOneWithoutStack(intAccept); + int value = intAccept.value; + if (value < (int) Byte.MIN_VALUE || value > (int) Byte.MAX_VALUE) { + throw new MessageTypeException(); // TODO message + } + stack.reduceCount(); + return (byte) value; + } + + @Override + public short readShort() throws IOException { + // optimized not to allocate shortAccept + stack.checkCount(); + readOneWithoutStack(intAccept); + int value = intAccept.value; + if (value < (int) Short.MIN_VALUE || value > (int) Short.MAX_VALUE) { + throw new MessageTypeException(); // TODO message + } + stack.reduceCount(); + return (short) value; + } + + @Override + public int readInt() throws IOException { + readOne(intAccept); + return intAccept.value; + } + + @Override + public long readLong() throws IOException { + readOne(longAccept); + return longAccept.value; + } + + @Override + public BigInteger readBigInteger() throws IOException { + readOne(bigIntegerAccept); + return bigIntegerAccept.value; + } + + @Override + public float readFloat() throws IOException { + readOne(doubleAccept); + return (float) doubleAccept.value; + } + + @Override + public double readDouble() throws IOException { + readOne(doubleAccept); + return doubleAccept.value; + } + + @Override + public byte[] readByteArray() throws IOException { + readOne(byteArrayAccept); + return byteArrayAccept.value; + } + + @Override + public String readString() throws IOException { + readOne(stringAccept); + return stringAccept.value; + } + + @Override + public int readArrayBegin() throws IOException { + readOne(arrayAccept); + return arrayAccept.size; + } + + @Override + public void readArrayEnd(boolean check) throws IOException { + if (!stack.topIsArray()) { + throw new MessageTypeException( + "readArrayEnd() is called but readArrayBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "readArrayEnd(check=true) is called but the array is not end"); + } + for (int i = 0; i < remain; i++) { + skip(); + } + } + stack.pop(); + } + + @Override + public int readMapBegin() throws IOException { + readOne(mapAccept); + return mapAccept.size; + } + + @Override + public void readMapEnd(boolean check) throws IOException { + if (!stack.topIsMap()) { + throw new MessageTypeException( + "readMapEnd() is called but readMapBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "readMapEnd(check=true) is called but the map is not end"); + } + for (int i = 0; i < remain; i++) { + skip(); + } + } + stack.pop(); + } + + @Override + protected void readValue(Unconverter uc) throws IOException { + if (uc.getResult() != null) { + uc.resetResult(); + } + valueAccept.setUnconverter(uc); + + stack.checkCount(); + if (readOneWithoutStack(valueAccept)) { + stack.reduceCount(); + if (uc.getResult() != null) { + return; + } + } + while (true) { + while (stack.getTopCount() == 0) { + if (stack.topIsArray()) { + uc.writeArrayEnd(true); + stack.pop(); + // stack.reduceCount(); + } else if (stack.topIsMap()) { + uc.writeMapEnd(true); + stack.pop(); + // stack.reduceCount(); + } else { + throw new RuntimeException("invalid stack"); // FIXME error? + } + if (uc.getResult() != null) { + return; + } + } + readOne(valueAccept); + } + } + + @Override + public void skip() throws IOException { + stack.checkCount(); + if (readOneWithoutStack(skipAccept)) { + stack.reduceCount(); + return; + } + int targetDepth = stack.getDepth() - 1; + while (true) { + while (stack.getTopCount() == 0) { + stack.pop(); + if (stack.getDepth() <= targetDepth) { + return; + } + } + readOne(skipAccept); + } + } + + public ValueType getNextType() throws IOException { + final int b = (int) getHeadByte(); + if ((b & 0x80) == 0) { // Positive Fixnum + return ValueType.INTEGER; + } + if ((b & 0xe0) == 0xe0) { // Negative Fixnum + return ValueType.INTEGER; + } + if ((b & 0xe0) == 0xa0) { // FixRaw + return ValueType.RAW; + } + if ((b & 0xf0) == 0x90) { // FixArray + return ValueType.ARRAY; + } + if ((b & 0xf0) == 0x80) { // FixMap + return ValueType.MAP; + } + switch (b & 0xff) { + case 0xc0: // nil + return ValueType.NIL; + case 0xc2: // false + case 0xc3: // true + return ValueType.BOOLEAN; + case 0xca: // float + case 0xcb: // double + return ValueType.FLOAT; + case 0xcc: // unsigned int 8 + case 0xcd: // unsigned int 16 + case 0xce: // unsigned int 32 + case 0xcf: // unsigned int 64 + case 0xd0: // signed int 8 + case 0xd1: // signed int 16 + case 0xd2: // signed int 32 + case 0xd3: // signed int 64 + return ValueType.INTEGER; + // The definition based on a minor upgrade guide. + // https://github.com/msgpack/msgpack/blob/master/spec.md#impl-upgrade + case 0xc4: // bin 8 + case 0xc5: // bin 16 + case 0xc6: // bin 32 + case 0xd9: // str8 + case 0xda: // raw 16 + case 0xdb: // raw 32 + return ValueType.RAW; + case 0xdc: // array 16 + case 0xdd: // array 32 + return ValueType.ARRAY; + case 0xde: // map 16 + case 0xdf: // map 32 + return ValueType.MAP; + default: + throw new IOException("Invalid byte: " + b); // TODO error FormatException + } + } + + public void reset() { + raw = null; + stack.clear(); + } + + public void close() throws IOException { + in.close(); + } + + @Override + public int getReadByteCount() { + return in.getReadByteCount(); + } + + @Override + public void resetReadByteCount() { + in.resetReadByteCount(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/SizeLimitException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/SizeLimitException.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,39 @@ +// +// MessagePack for Java +// +// Copyright (C) 2011 - 2013 Muga Nishizawa +// +// 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.unpacker; + +import java.io.IOException; + +@SuppressWarnings("serial") +public class SizeLimitException extends IOException { + public SizeLimitException() { + super(); + } + + public SizeLimitException(String message) { + super(message); + } + + public SizeLimitException(String message, Throwable cause) { + super(message, cause); + } + + public SizeLimitException(Throwable cause) { + super(cause); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/SkipAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/SkipAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,95 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; + +final class SkipAccept extends Accept { + SkipAccept() { + super(null); + } + + @Override + void acceptBoolean(boolean v) { + } + + @Override + void acceptInteger(byte v) { + } + + @Override + void acceptInteger(short v) { + } + + @Override + void acceptInteger(int v) { + } + + @Override + void acceptInteger(long v) { + } + + @Override + void acceptUnsignedInteger(byte v) { + } + + @Override + void acceptUnsignedInteger(short v) { + } + + @Override + void acceptUnsignedInteger(int v) { + } + + @Override + void acceptUnsignedInteger(long v) { + } + + @Override + void acceptRaw(byte[] raw) { + } + + @Override + void acceptEmptyRaw() { + } + + @Override + public void refer(ByteBuffer bb, boolean gift) throws IOException { + } + + @Override + void acceptArray(int size) { + } + + @Override + void acceptMap(int size) { + } + + @Override + void acceptNil() { + } + + @Override + void acceptFloat(float v) { + } + + @Override + void acceptDouble(double v) { + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/StringAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/StringAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,61 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import org.msgpack.MessageTypeException; + +final class StringAccept extends Accept { + String value; + private CharsetDecoder decoder; + + public StringAccept() { + super("raw value"); + this.decoder = Charset.forName("UTF-8").newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT); + } + + @Override + void acceptRaw(byte[] raw) { + try { + this.value = decoder.decode(ByteBuffer.wrap(raw)).toString(); + } catch (CharacterCodingException ex) { + throw new MessageTypeException(ex); + } + } + + @Override + void acceptEmptyRaw() { + this.value = ""; + } + + @Override + public void refer(ByteBuffer bb, boolean gift) throws IOException { + try { + this.value = decoder.decode(bb).toString(); + } catch (CharacterCodingException ex) { + throw new MessageTypeException(ex); + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/Unpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/Unpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,99 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.io.Closeable; +import java.nio.ByteBuffer; +import java.math.BigInteger; +import java.lang.Iterable; + +import org.msgpack.template.Template; +import org.msgpack.type.Value; +import org.msgpack.type.ValueType; + +/** + * Standard deserializer. + * + * @version 0.6.0 + */ +public interface Unpacker extends Iterable, Closeable { + public T read(Class klass) throws IOException; + + public T read(T to) throws IOException; + + public T read(Template tmpl) throws IOException; + + public T read(T to, Template tmpl) throws IOException; + + public void skip() throws IOException; + + public int readArrayBegin() throws IOException; + + public void readArrayEnd(boolean check) throws IOException; + + public void readArrayEnd() throws IOException; + + public int readMapBegin() throws IOException; + + public void readMapEnd(boolean check) throws IOException; + + public void readMapEnd() throws IOException; + + public void readNil() throws IOException; + + public boolean trySkipNil() throws IOException; + + public boolean readBoolean() throws IOException; + + public byte readByte() throws IOException; + + public short readShort() throws IOException; + + public int readInt() throws IOException; + + public long readLong() throws IOException; + + public BigInteger readBigInteger() throws IOException; + + public float readFloat() throws IOException; + + public double readDouble() throws IOException; + + public byte[] readByteArray() throws IOException; + + public ByteBuffer readByteBuffer() throws IOException; + + public String readString() throws IOException; + + public Value readValue() throws IOException; + + public ValueType getNextType() throws IOException; + + public UnpackerIterator iterator(); + + public int getReadByteCount(); + + public void resetReadByteCount(); + + public void setRawSizeLimit(int size); + + public void setArraySizeLimit(int size); + + public void setMapSizeLimit(int size); +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/UnpackerIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/UnpackerIterator.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,69 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.io.EOFException; +import java.util.Iterator; +import java.util.NoSuchElementException; +import org.msgpack.type.Value; +import org.msgpack.packer.Unconverter; + +public class UnpackerIterator implements Iterator { + private final AbstractUnpacker u; // FIXME -> Unpacker + private final Unconverter uc; + private IOException exception; + + public UnpackerIterator(AbstractUnpacker u) { + this.u = u; + this.uc = new Unconverter(u.msgpack); + } + + public boolean hasNext() { + if (uc.getResult() != null) { + return true; + } + try { + u.readValue(uc); + } catch (EOFException ex) { + return false; + } catch (IOException ex) { + // TODO error + exception = ex; + return false; + } + return uc.getResult() != null; + } + + public Value next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + Value v = uc.getResult(); + uc.resetResult(); + return v; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + public IOException getException() { + return exception; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/UnpackerStack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/UnpackerStack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,98 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import org.msgpack.MessageTypeException; + +public final class UnpackerStack { + private int top; + private byte[] types; + private int[] counts; + + public static final int MAX_STACK_SIZE = 128; + + private static final byte TYPE_INVALID = 0; + private static final byte TYPE_ARRAY = 1; + private static final byte TYPE_MAP = 2; + + public UnpackerStack() { + this.top = 0; + this.types = new byte[MAX_STACK_SIZE]; + this.counts = new int[MAX_STACK_SIZE]; + this.types[0] = TYPE_INVALID; + } + + public void pushArray(int size) { + top++; + types[top] = TYPE_ARRAY; + counts[top] = size; + } + + public void pushMap(int size) { + top++; + types[top] = TYPE_MAP; + counts[top] = size * 2; + } + + /** + * throws MessageTypeException if stack is invalid + */ + public void checkCount() { + if (counts[top] > 0) { + return; + } + + if (types[top] == TYPE_ARRAY) { + throw new MessageTypeException( + "Array is end but readArrayEnd() is not called"); + } else if (types[top] == TYPE_MAP) { + throw new MessageTypeException( + "Map is end but readMapEnd() is not called"); + } else { // empty + return; + } + } + + public void reduceCount() { + counts[top]--; + } + + public void pop() { + top--; + } + + public int getDepth() { + return top; + } + + public int getTopCount() { + return counts[top]; + } + + public boolean topIsArray() { + return types[top] == TYPE_ARRAY; + } + + public boolean topIsMap() { + return types[top] == TYPE_MAP; + } + + public void clear() { + top = 0; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/unpacker/ValueAccept.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/unpacker/ValueAccept.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,135 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.unpacker; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.math.BigInteger; +import org.msgpack.type.ValueFactory; +import org.msgpack.packer.Unconverter; + +final class ValueAccept extends Accept { + private Unconverter uc = null; + + ValueAccept() { + super(null); + } + + void setUnconverter(Unconverter uc) throws IOException { + this.uc = uc; + } + + @Override + void acceptBoolean(boolean v) throws IOException { + uc.write(ValueFactory.createBooleanValue(v)); + } + + @Override + void acceptInteger(byte v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v)); + } + + @Override + void acceptInteger(short v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v)); + } + + @Override + void acceptInteger(int v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v)); + } + + @Override + void acceptInteger(long v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v)); + } + + @Override + void acceptUnsignedInteger(byte v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v & 0xff)); + } + + @Override + void acceptUnsignedInteger(short v) throws IOException { + uc.write(ValueFactory.createIntegerValue(v & 0xffff)); + } + + @Override + void acceptUnsignedInteger(int v) throws IOException { + if (v < 0) { + long value = (long) (v & 0x7fffffff) + 0x80000000L; + uc.write(ValueFactory.createIntegerValue(value)); + } else { + uc.write(ValueFactory.createIntegerValue(v)); + } + } + + @Override + void acceptUnsignedInteger(long v) throws IOException { + if (v < 0L) { + BigInteger value = BigInteger.valueOf(v + Long.MAX_VALUE + 1L) + .setBit(63); + uc.write(ValueFactory.createIntegerValue(value)); + } else { + uc.write(ValueFactory.createIntegerValue(v)); + } + } + + @Override + void acceptRaw(byte[] raw) throws IOException { + uc.write(ValueFactory.createRawValue(raw)); + } + + @Override + void acceptEmptyRaw() throws IOException { + uc.write(ValueFactory.createRawValue()); + } + + @Override + public void refer(ByteBuffer bb, boolean gift) throws IOException { + // TODO gift + byte[] raw = new byte[bb.remaining()]; + bb.get(raw); + uc.write(ValueFactory.createRawValue(raw, true)); + } + + @Override + void acceptArray(int size) throws IOException { + uc.writeArrayBegin(size); + } + + @Override + void acceptMap(int size) throws IOException { + uc.writeMapBegin(size); + } + + @Override + void acceptNil() throws IOException { + uc.write(ValueFactory.createNilValue()); + } + + @Override + void acceptFloat(float v) throws IOException { + uc.write(ValueFactory.createFloatValue(v)); + } + + @Override + void acceptDouble(double v) throws IOException { + uc.write(ValueFactory.createFloatValue(v)); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/TemplatePrecompiler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/TemplatePrecompiler.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,163 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.JavassistTemplateBuilder; + +/** + * This class is a template precompiler, which is used for saving templates that + * TemplateBuilder generated. It saves templates as .class files. + * Application enables to load the .class files and use templates. + * + */ +public class TemplatePrecompiler { + + private static final Logger LOG = Logger.getLogger(TemplatePrecompiler.class.getName()); + + public static final String DEST = "msgpack.template.destdir"; + + public static final String DEFAULT_DEST = "."; + + public static void saveTemplates(final String[] classNames) + throws IOException, ClassNotFoundException { + // TODO #MN + TemplateRegistry registry = new TemplateRegistry(null); + List ret = new ArrayList(); + for (String className : classNames) { + matchClassNames(ret, className); + } + List> ret0 = toClass(ret); + for (Class c : ret0) { + saveTemplateClass(registry, c); + } + } + + @SuppressWarnings("serial") + private static void matchClassNames(List ret, final String className) + throws IOException { + String packageName = className.substring(0, className.lastIndexOf('.')); + String relativedName = className.substring( + className.lastIndexOf('.') + 1, className.length()); + String patName = relativedName.replace("*", "(\\w+)"); + Pattern pat = Pattern.compile(patName); + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + JavaFileManager fm = compiler.getStandardFileManager( + new DiagnosticCollector(), null, null); + HashSet kind = new HashSet() { + { + add(JavaFileObject.Kind.CLASS); + } + }; + + for (JavaFileObject f : fm.list(StandardLocation.PLATFORM_CLASS_PATH, packageName, kind, false)) { + String relatived0 = f.getName(); + String name0 = relatived0.substring(0, relatived0.length() - ".class".length()); + Matcher m = pat.matcher(name0); + if (m.matches()) { + String name = packageName + '.' + name0; + if (!ret.contains(name)) { + ret.add(name); + } + } + } + } + + private static List> toClass(List classNames) + throws ClassNotFoundException { + List> ret = new ArrayList>(classNames.size()); + ClassLoader cl = TemplatePrecompiler.class.getClassLoader(); + for (String className : classNames) { + Class c = cl.loadClass(className); + ret.add(c); + } + return ret; + } + + public static void saveTemplateClasses(TemplateRegistry registry, Class[] targetClasses) + throws IOException { + for (Class c : targetClasses) { + saveTemplateClass(registry, c); + } + } + + public static void saveTemplateClass(TemplateRegistry registry, Class targetClass) + throws IOException { + LOG.info("Saving template of " + targetClass.getName() + "..."); + Properties props = System.getProperties(); + String distDirName = getDirName(props, DEST, DEFAULT_DEST); + if (targetClass.isEnum()) { + throw new UnsupportedOperationException( + "Not supported enum type yet: " + targetClass.getName()); + } else { + new JavassistTemplateBuilder(registry).writeTemplate(targetClass, + distDirName); + } + LOG.info("Saved .class file of template class of " + targetClass.getName()); + } + + public static boolean deleteTemplateClass(Class targetClass) + throws IOException { + LOG.info("Deleting template of " + targetClass.getName() + "..."); + Properties props = System.getProperties(); + String distDirName = getDirName(props, DEST, DEFAULT_DEST); + String targetClassName = targetClass.getName(); + String targetClassFileName = targetClassName.replace('.', + File.separatorChar) + "_$$_Template.class"; + File targetFile = new File(distDirName + File.separatorChar + + targetClassFileName); + boolean deleted = false; + if (!targetFile.isDirectory() && targetFile.exists()) { + deleted = targetFile.delete(); + } + LOG.info("Deleted .class file of template class of " + targetClass.getName()); + return deleted; + } + + private static String getDirName(Properties props, String dirName, String defaultDirName) + throws IOException { + String dName = props.getProperty(dirName, defaultDirName); + File d = new File(dName); + if (!d.isDirectory() && !d.exists()) { + throw new IOException("Directory not exists: " + dName); + } + return d.getAbsolutePath(); + } + + public static void main(final String[] args) throws Exception { + TemplatePrecompiler.saveTemplates(args); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/android/DalvikVmChecker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/android/DalvikVmChecker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,17 @@ +package org.msgpack.util.android; + +public final class DalvikVmChecker { + private static final boolean isDalvikVm; + static { + boolean isIt = false; + try { + isIt = System.getProperty("java.vm.name").equals("Dalvik"); + } finally { + isDalvikVm = isIt; + } + } + + public static boolean isDalvikVm() { + return isDalvikVm; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/android/PortedImmutableEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/android/PortedImmutableEntry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.util.android; + +import java.io.Serializable; +import java.util.Map; + +/** + * An immutable key-value mapping. Despite the name, this class is non-final + * and its subclasses may be mutable. + * + * This class is ported from java.util.AbstractMap$SimpleImmutableEntry of + * https://github.com/OESF/OHA-Android-4.0.3_r1.0 (Apache License). + */ +public class PortedImmutableEntry implements Map.Entry, Serializable { + private static final long serialVersionUID = -4564047655287765373L; + + private final K key; + private final V value; + + public PortedImmutableEntry(K theKey, V theValue) { + key = theKey; + value = theValue; + } + + /** + * Constructs an instance with the key and value of {@code copyFrom}. + */ + public PortedImmutableEntry(Map.Entry copyFrom) { + key = copyFrom.getKey(); + value = copyFrom.getValue(); + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + /** + * This base implementation throws {@code UnsupportedOperationException} + * always. + */ + public V setValue(V object) { + throw new UnsupportedOperationException(); + } + + @Override public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof Map.Entry) { + Map.Entry entry = (Map.Entry) object; + return (key == null ? entry.getKey() == null : key.equals(entry + .getKey())) + && (value == null ? entry.getValue() == null : value + .equals(entry.getValue())); + } + return false; + } + + @Override public int hashCode() { + return (key == null ? 0 : key.hashCode()) + ^ (value == null ? 0 : value.hashCode()); + } + + @Override public String toString() { + return key + "=" + value; + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/json/JSON.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/json/JSON.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,77 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util.json; + +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.unpacker.BufferUnpacker; + +public class JSON extends MessagePack { + public JSON() { + super(); + } + + public JSON(MessagePack msgpack) { + super(msgpack); + } + + @Override + public Packer createPacker(OutputStream stream) { + return new JSONPacker(this, stream); + } + + @Override + public BufferPacker createBufferPacker() { + return new JSONBufferPacker(this); + } + + @Override + public BufferPacker createBufferPacker(int bufferSize) { + return new JSONBufferPacker(this, bufferSize); + } + + @Override + public Unpacker createUnpacker(InputStream stream) { + return new JSONUnpacker(this, stream); + } + + @Override + public BufferUnpacker createBufferUnpacker() { + return new JSONBufferUnpacker(); + } + + @Override + public BufferUnpacker createBufferUnpacker(byte[] b) { + return createBufferUnpacker().wrap(b); + } + + @Override + public BufferUnpacker createBufferUnpacker(byte[] b, int off, int len) { + return createBufferUnpacker().wrap(b, off, len); + } + + @Override + public BufferUnpacker createBufferUnpacker(ByteBuffer bb) { + return createBufferUnpacker().wrap(bb); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/json/JSONBufferPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/json/JSONBufferPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,55 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util.json; + +import org.msgpack.MessagePack; +import org.msgpack.io.LinkedBufferOutput; +import org.msgpack.packer.BufferPacker; + +public class JSONBufferPacker extends JSONPacker implements BufferPacker { + private static final int DEFAULT_BUFFER_SIZE = 512; // TODO default buffer size + + public JSONBufferPacker() { + this(DEFAULT_BUFFER_SIZE); + } + + public JSONBufferPacker(int bufferSize) { + this(new MessagePack(), bufferSize); + } + + public JSONBufferPacker(MessagePack msgpack) { + this(msgpack, DEFAULT_BUFFER_SIZE); + } + + public JSONBufferPacker(MessagePack msgpack, int bufferSize) { + super(msgpack, new LinkedBufferOutput(bufferSize)); + } + + public int getBufferSize() { + return ((LinkedBufferOutput) out).getSize(); + } + + public byte[] toByteArray() { + return ((LinkedBufferOutput) out).toByteArray(); + } + + public void clear() { + reset(); + ((LinkedBufferOutput) out).clear(); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/json/JSONBufferUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/json/JSONBufferUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,121 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util.json; + +import java.io.ByteArrayInputStream; +import java.io.Reader; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; +import org.msgpack.MessagePack; +import org.msgpack.unpacker.BufferUnpacker; + +public class JSONBufferUnpacker extends JSONUnpacker implements BufferUnpacker { + private static final int DEFAULT_BUFFER_SIZE = 512; // TODO default buffer size + + public JSONBufferUnpacker() { + this(DEFAULT_BUFFER_SIZE); + } + + public JSONBufferUnpacker(int bufferSize) { + this(new MessagePack(), bufferSize); + } + + public JSONBufferUnpacker(MessagePack msgpack) { + this(msgpack, DEFAULT_BUFFER_SIZE); + } + + public JSONBufferUnpacker(MessagePack msgpack, int bufferSize) { + super(msgpack, newEmptyReader()); + } + + @Override + public JSONBufferUnpacker wrap(byte[] b) { + return wrap(b, 0, b.length); + } + + @Override + public JSONBufferUnpacker wrap(byte[] b, int off, int len) { + ByteArrayInputStream in = new ByteArrayInputStream(b, off, len); + this.in = new InputStreamReader(in); + return this; + } + + @Override + public JSONBufferUnpacker wrap(ByteBuffer buf) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support wrap(ByteBuffer buf)"); + } + + @Override + public JSONBufferUnpacker feed(byte[] b) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public JSONBufferUnpacker feed(byte[] b, boolean reference) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public JSONBufferUnpacker feed(byte[] b, int off, int len) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public JSONBufferUnpacker feed(byte[] b, int off, int len, boolean reference) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public JSONBufferUnpacker feed(ByteBuffer buf) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public JSONBufferUnpacker feed(ByteBuffer buf, boolean reference) { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support feed()"); + } + + @Override + public int getBufferSize() { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support getBufferSize()"); + } + + @Override + public void copyReferencedBuffer() { + throw new UnsupportedOperationException( + "JSONBufferUnpacker doesn't support copyReferencedBuffer()"); + } + + @Override + public void clear() { + reset(); + in = newEmptyReader(); + } + + private static Reader newEmptyReader() { + return new InputStreamReader(new ByteArrayInputStream(new byte[0])); + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/json/JSONPacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/json/JSONPacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,386 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util.json; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; +import org.msgpack.io.Output; +import org.msgpack.io.StreamOutput; +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.packer.AbstractPacker; +import org.msgpack.packer.PackerStack; + +public class JSONPacker extends AbstractPacker { + private static final byte[] NULL = new byte[] { 0x6e, 0x75, 0x6c, 0x6c }; + private static final byte[] TRUE = new byte[] { 0x74, 0x72, 0x75, 0x65 }; + private static final byte[] FALSE = new byte[] { 0x66, 0x61, 0x6c, 0x73, 0x65 }; + + private static final byte COMMA = 0x2c; + private static final byte COLON = 0x3a; + private static final byte QUOTE = 0x22; + private static final byte LEFT_BR = 0x5b; + private static final byte RIGHT_BR = 0x5d; + private static final byte LEFT_WN = 0x7b; + private static final byte RIGHT_WN = 0x7d; + private static final byte BACKSLASH = 0x5c; + private static final byte ZERO = 0x30; + + private static final int FLAG_FIRST_ELEMENT = 0x01; + private static final int FLAG_MAP_KEY = 0x02; + private static final int FLAG_MAP_VALUE = 0x04; + // private static final int FLAG_MAP = FLAG_MAP_KEY | FLAG_MAP_VALUE; + + protected final Output out; + private int[] flags; + + private PackerStack stack = new PackerStack(); + private CharsetDecoder decoder; + + public JSONPacker(OutputStream stream) { + this(new MessagePack(), stream); + } + + public JSONPacker(MessagePack msgpack, OutputStream stream) { + this(msgpack, new StreamOutput(stream)); + } + + protected JSONPacker(MessagePack msgpack, Output out) { + super(msgpack); + this.out = out; + this.stack = new PackerStack(); + this.flags = new int[PackerStack.MAX_STACK_SIZE]; + this.decoder = Charset.forName("UTF-8").newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT); + } + + @Override + protected void writeBoolean(boolean v) throws IOException { + beginElement(); + if (v) { + out.write(TRUE, 0, TRUE.length); + } else { + out.write(FALSE, 0, FALSE.length); + } + endElement(); + } + + @Override + protected void writeByte(byte v) throws IOException { + beginElement(); + byte[] b = Byte.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeShort(short v) throws IOException { + beginElement(); + byte[] b = Short.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeInt(int v) throws IOException { + beginElement(); + byte[] b = Integer.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeLong(long v) throws IOException { + beginElement(); + byte[] b = Long.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeBigInteger(BigInteger v) throws IOException { + beginElement(); + byte[] b = v.toString().getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeFloat(float v) throws IOException { + beginElement(); + Float r = v; + if (r.isInfinite() || r.isNaN()) { + throw new IOException( + "JSONPacker doesn't support NaN and infinite float value"); + } + byte[] b = Float.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeDouble(double v) throws IOException { + beginElement(); + Double r = v; + if (r.isInfinite() || r.isNaN()) { + throw new IOException( + "JSONPacker doesn't support NaN and infinite float value"); + } + byte[] b = Double.toString(v).getBytes(); // TODO optimize + out.write(b, 0, b.length); + endElement(); + } + + @Override + protected void writeByteArray(byte[] b, int off, int len) throws IOException { + beginStringElement(); + out.writeByte(QUOTE); + escape(out, b, off, len); + out.writeByte(QUOTE); + endElement(); + } + + @Override + protected void writeByteBuffer(ByteBuffer bb) throws IOException { + beginStringElement(); + out.writeByte(QUOTE); + int pos = bb.position(); + try { + escape(out, bb); + } finally { + bb.position(pos); + } + out.writeByte(QUOTE); + endElement(); + } + + @Override + protected void writeString(String s) throws IOException { + beginStringElement(); + out.writeByte(QUOTE); + escape(out, s); + out.writeByte(QUOTE); + endElement(); + } + + @Override + public Packer writeNil() throws IOException { + beginElement(); + out.write(NULL, 0, NULL.length); + endElement(); + return this; + } + + @Override + public Packer writeArrayBegin(int size) throws IOException { + beginElement(); + out.writeByte(LEFT_BR); + endElement(); + stack.pushArray(size); + flags[stack.getDepth()] = FLAG_FIRST_ELEMENT; + return this; + } + + @Override + public Packer writeArrayEnd(boolean check) throws IOException { + if (!stack.topIsArray()) { + throw new MessageTypeException( + "writeArrayEnd() is called but writeArrayBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeArrayEnd(check=true) is called but the array is not end: " + remain); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + + out.writeByte(RIGHT_BR); + return this; + } + + @Override + public Packer writeMapBegin(int size) throws IOException { + beginElement(); + out.writeByte(LEFT_WN); + endElement(); + stack.pushMap(size); + flags[stack.getDepth()] = FLAG_FIRST_ELEMENT | FLAG_MAP_KEY; + return this; + } + + @Override + public Packer writeMapEnd(boolean check) throws IOException { + if (!stack.topIsMap()) { + throw new MessageTypeException( + "writeMapEnd() is called but writeMapBegin() is not called"); + } + + int remain = stack.getTopCount(); + if (remain > 0) { + if (check) { + throw new MessageTypeException( + "writeMapEnd(check=true) is called but the map is not end: " + remain); + } + for (int i = 0; i < remain; i++) { + writeNil(); + } + } + stack.pop(); + + out.writeByte(RIGHT_WN); + return this; + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + out.close(); + } + + public void reset() { + stack.clear(); + } + + private void beginElement() throws IOException { + int flag = flags[stack.getDepth()]; + if ((flag & FLAG_MAP_KEY) != 0) { + throw new IOException("Key of a map must be a string in JSON"); + } + beginStringElement(); + } + + private void beginStringElement() throws IOException { + int flag = flags[stack.getDepth()]; + if ((flag & FLAG_MAP_VALUE) != 0) { + out.writeByte(COLON); + } else if (stack.getDepth() > 0 && (flag & FLAG_FIRST_ELEMENT) == 0) { + out.writeByte(COMMA); + } + } + + private void endElement() throws IOException { + int flag = flags[stack.getDepth()]; + if ((flag & FLAG_MAP_KEY) != 0) { + flag &= ~FLAG_MAP_KEY; + flag |= FLAG_MAP_VALUE; + } else if ((flag & FLAG_MAP_VALUE) != 0) { + flag &= ~FLAG_MAP_VALUE; + flag |= FLAG_MAP_KEY; + } + flag &= ~FLAG_FIRST_ELEMENT; + flags[stack.getDepth()] = flag; + stack.reduceCount(); + } + + private void escape(Output out, byte[] b, int off, int len) throws IOException { + escape(out, ByteBuffer.wrap(b, off, len)); + } + + private void escape(Output out, ByteBuffer bb) throws IOException { + // TODO optimize + String str = decoder.decode(bb).toString(); + escape(out, str); + } + + private final static int[] ESCAPE_TABLE; + private final static byte[] HEX_TABLE; + + static { + ESCAPE_TABLE = new int[128]; + for (int i = 0; i < 0x20; ++i) { + // control char + ESCAPE_TABLE[i] = -1; + } + ESCAPE_TABLE['"'] = '"'; + ESCAPE_TABLE['\\'] = '\\'; + ESCAPE_TABLE[0x08] = 'b'; + ESCAPE_TABLE[0x09] = 't'; + ESCAPE_TABLE[0x0C] = 'f'; + ESCAPE_TABLE[0x0A] = 'n'; + ESCAPE_TABLE[0x0D] = 'r'; + + char[] hex = "0123456789ABCDEF".toCharArray(); + HEX_TABLE = new byte[hex.length]; + for (int i = 0; i < hex.length; ++i) { + HEX_TABLE[i] = (byte) hex[i]; + } + } + + private static void escape(Output out, String s) throws IOException { + byte[] tmp = new byte[] { (byte) '\\', (byte) 'u', 0, 0, 0, 0 }; + char[] chars = s.toCharArray(); + for (int i = 0; i < chars.length; i++) { + int ch = chars[i]; + if (ch <= 0x7f) { + int e = ESCAPE_TABLE[ch]; + if (e == 0) { + // ascii char + tmp[2] = (byte) ch; + out.write(tmp, 2, 1); + } else if (e > 0) { + // popular control char + tmp[2] = BACKSLASH; + tmp[3] = (byte) e; + out.write(tmp, 2, 2); + } else { + // control char uXXXXXX + tmp[2] = ZERO; + tmp[3] = ZERO; + tmp[4] = HEX_TABLE[ch >> 4]; + tmp[5] = HEX_TABLE[ch & 0x0f]; + out.write(tmp, 0, 6); + } + } else if (ch <= 0x7ff) { + // 2-bytes char + tmp[2] = (byte) (0xc0 | (ch >> 6)); + tmp[3] = (byte) (0x80 | (ch & 0x3f)); + out.write(tmp, 2, 2); + } else if (ch >= 0xd800 && ch <= 0xdfff) { + // surrogates + tmp[2] = HEX_TABLE[(ch >> 12) & 0x0f]; + tmp[3] = HEX_TABLE[(ch >> 8) & 0x0f]; + tmp[4] = HEX_TABLE[(ch >> 4) & 0x0f]; + tmp[5] = HEX_TABLE[ch & 0x0f]; + out.write(tmp, 0, 6); + } else { + // 3-bytes char + tmp[2] = (byte) (0xe0 | (ch >> 12)); + tmp[3] = (byte) (0x80 | ((ch >> 6) & 0x3f)); + tmp[4] = (byte) (0x80 | (ch & 0x3f)); + out.write(tmp, 2, 3); + } + } + } +} diff -r 000000000000 -r cb825acd883a src/main/java/org/msgpack/util/json/JSONUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/msgpack/util/json/JSONUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,120 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009 - 2013 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack.util.json; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Map; +import java.util.Iterator; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.msgpack.MessagePack; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + +public class JSONUnpacker extends Converter { + protected Reader in; + private JSONParser parser; + + public JSONUnpacker(InputStream in) { + this(new MessagePack(), in); + } + + public JSONUnpacker(MessagePack msgpack, InputStream in) { + this(msgpack, new InputStreamReader(in)); + } + + JSONUnpacker(MessagePack msgpack, Reader in) { + super(msgpack, null); + this.in = in; + this.parser = new JSONParser(); + } + + @Override + protected Value nextValue() throws IOException { + try { + Object obj = parser.parse(in); + return objectToValue(obj); + } catch (ParseException e) { + throw new IOException(e); // TODO error FormatException + } catch (IOException e) { + throw new IOException(e); // TODO error FormatException + } + } + + @SuppressWarnings("rawtypes") + private Value objectToValue(Object obj) { + if (obj instanceof String) { + return ValueFactory.createRawValue((String) obj); + } else if (obj instanceof Integer) { + return ValueFactory.createIntegerValue((Integer) obj); + } else if (obj instanceof Long) { + return ValueFactory.createIntegerValue((Long) obj); + } else if (obj instanceof Map) { + return mapToValue((Map) obj); + } else if (obj instanceof List) { + return listToValue((List) obj); + } else if (obj instanceof Boolean) { + return ValueFactory.createBooleanValue((Boolean) obj); + } else if (obj instanceof Double) { + return ValueFactory.createFloatValue((Double) obj); + } else { + return ValueFactory.createNilValue(); + } + } + + @SuppressWarnings("rawtypes") + private Value listToValue(List list) { + Value[] array = new Value[list.size()]; + for (int i = 0; i < array.length; i++) { + array[i] = objectToValue(list.get(i)); + } + return ValueFactory.createArrayValue(array, true); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private Value mapToValue(Map map) { + Value[] kvs = new Value[map.size() * 2]; + Iterator it = map.entrySet().iterator(); + for (int i = 0; i < kvs.length; i += 2) { + Map.Entry pair = it.next(); + kvs[i] = objectToValue(pair.getKey()); + kvs[i + 1] = objectToValue(pair.getValue()); + } + return ValueFactory.createMapValue(kvs, true); + } + + @Override + public int getReadByteCount() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void resetReadByteCount() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void close() throws IOException { + in.close(); + super.close(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,293 @@ +package org.msgpack; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestBufferPackBufferUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + short ret = unpacker.readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + int ret = unpacker.readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + long ret = unpacker.readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.writeNil(); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + unpacker.readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + byte[] ret = unpacker.read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + K key = unpacker.read(keyElementClass); + V value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestBufferPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestBufferPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,318 @@ +package org.msgpack; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; + + +public class TestBufferPackConvert extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isBooleanValue()); + boolean ret = new Converter(value).readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + byte ret = new Converter(value).readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + short ret = new Converter(value).readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + int ret = new Converter(value).readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + long ret = new Converter(value).readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isFloatValue()); + float ret = new Converter(value).readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isFloatValue()); + double ret = new Converter(value).readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.writeNil(); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isNilValue()); + new Converter(value).readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + BigInteger ret = new Converter(value).read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + String ret = new Converter(value).read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + byte[] ret = new Converter(value).read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + Value value = unpacker.readValue(); + ret.add(new Converter(value).read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Value keyValue = unpacker.readValue(); + K key = new Converter(keyValue).read(keyElementClass); + Value valueValue = unpacker.readValue(); + V value = new Converter(valueValue).read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,294 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.io.ByteArrayInputStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestBufferPackUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + short ret = unpacker.readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + int ret = unpacker.readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + long ret = unpacker.readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.writeNil(); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + unpacker.readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + byte[] ret = unpacker.read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + K key = unpacker.read(keyElementClass); + V value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestCrossLang.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestCrossLang.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,84 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.util.Iterator; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; + +import org.junit.Test; + + +public class TestCrossLang { + private byte[] readData(String path) throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + FileInputStream input = new FileInputStream(path); + byte[] buffer = new byte[32*1024]; + while(true) { + int count = input.read(buffer); + if(count < 0) { + break; + } + bo.write(buffer, 0, count); + } + return bo.toByteArray(); + } + + private byte[] readCompactTestData() throws IOException { + return readData("src/test/resources/cases_compact.mpac"); + } + + private byte[] readTestData() throws IOException { + return readData("src/test/resources/cases.mpac"); + } + + @Test + public void testReadValue() throws IOException { + MessagePack msgpack = new MessagePack(); + byte[] a = readTestData(); + byte[] b = readCompactTestData(); + + BufferUnpacker au = msgpack.createBufferUnpacker().wrap(a); + BufferUnpacker bu = msgpack.createBufferUnpacker().wrap(b); + + Iterator at = au.iterator(); + Iterator bt = bu.iterator(); + + while(at.hasNext()) { + assertTrue(bt.hasNext()); + Value av = at.next(); + Value bv = bt.next(); + assertEquals(av, bv); + } + assertFalse(bt.hasNext()); + } + + @Test + public void testCompactSerialize() throws IOException { + MessagePack msgpack = new MessagePack(); + byte[] a = readTestData(); + byte[] b = readCompactTestData(); + + BufferPacker pk = msgpack.createBufferPacker(); + + BufferUnpacker au = msgpack.createBufferUnpacker().wrap(a); + for(Value av : au) { + pk.write(av); + } + + byte[] c = pk.toByteArray(); + + assertEquals(b.length, c.length); + assertArrayEquals(b, c); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestMessagePack01.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestMessagePack01.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,721 @@ +package org.msgpack; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.template.Template; +import static org.msgpack.template.Templates.tList; +import static org.msgpack.template.Templates.tMap; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + + +public class TestMessagePack01 { + + @Test + public void testBigIntegerBufferPackBufferUnpack() throws Exception { + new TestBigIntegerBufferPackBufferUnpack().testBigInteger(); + } + + @Test + public void testBigIntegerBufferPackConvert() throws Exception { + new TestBigIntegerBufferPackConvert().testBigInteger(); + } + + @Test + public void testBigIntegerBufferPackUnpack() throws Exception { + new TestBigIntegerBufferPackUnpack().testBigInteger(); + } + + @Test + public void testBigIntegerPackConvert() throws Exception { + new TestBigIntegerPackConvert().testBigInteger(); + } + + @Test + public void testBigIntegerPackUnpack() throws Exception { + new TestBigIntegerPackUnpack().testBigInteger(); + } + + @Test + public void testBigIntegerUnconvertConvert() throws Exception { + new TestBigIntegerUnconvertConvert().testBigInteger(); + } + + @Test + public void testStringBufferPackBufferUnpack() throws Exception { + new TestStringBufferPackBufferUnpack().testString(); + } + + @Test + public void testStringBufferPackConvert() throws Exception { + new TestStringBufferPackConvert().testString(); + } + + @Test + public void testStringBufferPackUnpack() throws Exception { + new TestStringBufferPackUnpack().testString(); + } + + @Test + public void testStringPackConvert() throws Exception { + new TestStringPackConvert().testString(); + } + + @Test + public void testStringPackUnpack() throws Exception { + new TestStringPackUnpack().testString(); + } + + @Test + public void testStringUnconvertConvert() throws Exception { + new TestStringUnconvertConvert().testString(); + } + + @Test + public void testByteArrayBufferPackBufferUnpack() throws Exception { + new TestByteArrayBufferPackBufferUnpack().testByteArray(); + } + + @Test + public void testByteArrayBufferPackConvert() throws Exception { + new TestByteArrayBufferPackConvert().testByteArray(); + } + + @Test + public void testByteArrayBufferPackUnpack() throws Exception { + new TestByteArrayBufferPackUnpack().testByteArray(); + } + + @Test + public void testByteArrayPackConvert() throws Exception { + new TestByteArrayPackConvert().testByteArray(); + } + + @Test + public void testByteArrayPackUnpack() throws Exception { + new TestByteArrayPackUnpack().testByteArray(); + } + + @Test + public void testByteArrayUnconvertConvert() throws Exception { + new TestByteArrayUnconvertConvert().testByteArray(); + } + + @Test + public void testListBufferPackBufferUnpack() throws Exception { + new TestListBufferPackBufferUnpack().testList(); + } + + @Test + public void testListBufferPackUnpack() throws Exception { + new TestListBufferPackUnpack().testList(); + } + + @Test + public void testListPackBufferUnpack() throws Exception { + new TestListPackBufferUnpack().testList(); + } + + @Test + public void testListPackUnpack() throws Exception { + new TestListPackUnpack().testList(); + } + + @Test + public void testMapBufferPackBufferUnpack() throws Exception { + new TestMapBufferPackBufferUnpack().testMap(); + } + + @Test + public void testMapBufferPackUnpack() throws Exception { + new TestMapBufferPackUnpack().testMap(); + } + + @Test + public void testMapPackBufferUnpack() throws Exception { + new TestMapPackBufferUnpack().testMap(); + } + @Test + public void testMapPackUnpack() throws Exception { + new TestMapPackUnpack().testMap(); + } + + public static class TestBigIntegerBufferPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + BigInteger ret = msgpack.read(bytes, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerBufferPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + BigInteger ret = msgpack.convert(value, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerBufferPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + BigInteger ret = msgpack.read(in, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + BigInteger ret = msgpack.read(bytes, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + BigInteger ret = msgpack.convert(value, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + BigInteger ret = msgpack.read(in, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestBigIntegerUnconvertConvert extends org.msgpack.TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + BigInteger ret = msgpack.convert(value, BigInteger.class); + assertEquals(v, ret); + } + } + + public static class TestStringBufferPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + String ret = msgpack.read(bytes, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringBufferPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + String ret = msgpack.convert(value, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringBufferPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + String ret = msgpack.read(in, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + String ret = msgpack.read(bytes, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + String ret = msgpack.convert(value, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + String ret = msgpack.read(in, String.class); + assertEquals(v, ret); + } + } + + public static class TestStringUnconvertConvert extends org.msgpack.TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + String ret = msgpack.convert(value, String.class); + assertEquals(v, ret); + } + } + + public static class TestByteArrayBufferPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + byte[] ret = msgpack.read(bytes, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayBufferPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + byte[] ret = msgpack.convert(value, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayBufferPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + byte[] ret = msgpack.read(in, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + byte[] ret = msgpack.read(bytes, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayPackConvert extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + byte[] ret = msgpack.convert(value, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + byte[] ret = msgpack.read(in, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestByteArrayUnconvertConvert extends org.msgpack.TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + byte[] ret = msgpack.convert(value, byte[].class); + assertArrayEquals(v, ret); + } + } + + public static class TestListBufferPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tElm = msgpack.lookup(elementClass); + byte[] bytes = msgpack.write(v, tList(tElm)); + List ret = msgpack.read(bytes, new ArrayList(), tList(tElm)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + } + + public static class TestListBufferPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tElm = msgpack.lookup(elementClass); + byte[] bytes = msgpack.write(v, tList(tElm)); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + List ret = msgpack.read(in, new ArrayList(), tList(tElm)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + } + + public static class TestListPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Template tElm = msgpack.lookup(elementClass); + msgpack.write(out, v, tList(tElm)); + byte[] bytes = out.toByteArray(); + List ret = msgpack.read(bytes, tList(tElm)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + } + + public static class TestListPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Template tElm = msgpack.lookup(elementClass); + msgpack.write(out, v, tList(tElm)); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + List ret = msgpack.read(in, new ArrayList(), tList(tElm)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + } + + public static class TestMapBufferPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tKey = msgpack.lookup(keyElementClass); + Template tValue = msgpack.lookup(valueElementClass); + byte[] bytes = msgpack.write(v, tMap(tKey, tValue)); + Map ret = msgpack.read(bytes, new HashMap(), tMap(tKey, tValue)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } + } + + public static class TestMapBufferPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tKey = msgpack.lookup(keyElementClass); + Template tValue = msgpack.lookup(valueElementClass); + byte[] bytes = msgpack.write(v, tMap(tKey, tValue)); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Map ret = msgpack.read(in, new HashMap(), tMap(tKey, tValue)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } + } + + public static class TestMapPackBufferUnpack extends org.msgpack.TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Template tKey = msgpack.lookup(keyElementClass); + Template tValue = msgpack.lookup(valueElementClass); + msgpack.write(out, v, tMap(tKey, tValue)); + byte[] bytes = out.toByteArray(); + Map ret = msgpack.read(bytes, new HashMap(), tMap(tKey, tValue)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } + } + + public static class TestMapPackUnpack extends org.msgpack.TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Template tKey = msgpack.lookup(keyElementClass); + Template tValue = msgpack.lookup(valueElementClass); + msgpack.write(out, v, tMap(tKey, tValue)); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Map ret = msgpack.read(in, new HashMap(), tMap(tKey, tValue)); + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } + } + + /*:* + * test pack org.msgpack.type.Value, but compiler recognize it as java.lang.Object + */ + @Test + public void testValuePassedAsObject() throws IOException { + MessagePack msgpack = new MessagePack(); + String text = "This class is Value but..."; + Object value = ValueFactory.createRawValue("This class is Value but..."); + + byte[] strValue = msgpack.write(value); + // should be raw type + assertEquals(0xa0 + text.length(),0xff & strValue[0]); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestMessagePack02.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestMessagePack02.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,3244 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; + + +public class TestMessagePack02 { + + @Test + public void testPrimitiveTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassBufferPackBufferUnpack().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassBufferPackConvert() throws Exception { + new TestPrimitiveTypeFieldsClassBufferPackConvert().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassBufferPackUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassBufferPackUnpack().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassPackBufferUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassPackBufferUnpack().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassPackConvert() throws Exception { + new TestPrimitiveTypeFieldsClassPackConvert().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassPackUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassPackUnpack().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassUnconvertConvert() throws Exception { + new TestPrimitiveTypeFieldsClassUnconvertConvert().testPrimitiveTypeFieldsClass(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullableBufferPackBufferUnpack().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullableBufferPackConvert().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullableBufferPackUnpack().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullablePackBufferUnpack().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullablePackConvert().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullablePackUnpack().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testPrimitiveTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestPrimitiveTypeFieldsClassNotNullableUnconvertConvert().testPrimitiveTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestReferenceTypeFieldsClassBufferPackBufferUnpack().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassBufferPackConvert() throws Exception { + new TestReferenceTypeFieldsClassBufferPackConvert().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassBufferPackUnpack() throws Exception { + new TestReferenceTypeFieldsClassBufferPackUnpack().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassPackBufferUnpack() throws Exception { + new TestReferenceTypeFieldsClassPackBufferUnpack().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassPackConvert() throws Exception { + new TestReferenceTypeFieldsClassPackConvert().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassPackUnpack() throws Exception { + new TestReferenceTypeFieldsClassPackUnpack().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassUnconvertConvert() throws Exception { + new TestReferenceTypeFieldsClassUnconvertConvert().testReferenceTypeFieldsClass(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestReferenceTypeFieldsClassNotNullableBufferPackBufferUnpack().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestReferenceTypeFieldsClassNotNullableBufferPackConvert().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestReferenceTypeFieldsClassNotNullableBufferPackUnpack().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestReferenceTypeFieldsClassNotNullablePackBufferUnpack().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestReferenceTypeFieldsClassNotNullablePackConvert().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestReferenceTypeFieldsClassNotNullablePackUnpack().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestReferenceTypeFieldsClassNotNullableUnconvertConvert().testReferenceTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestListTypeFieldsClassBufferPackBufferUnpack().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassBufferPackConvert() throws Exception { + new TestListTypeFieldsClassBufferPackConvert().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassBufferPackUnpack() throws Exception { + new TestListTypeFieldsClassBufferPackUnpack().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassPackBufferUnpack() throws Exception { + new TestListTypeFieldsClassPackBufferUnpack().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassPackConvert() throws Exception { + new TestListTypeFieldsClassPackConvert().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassPackUnpack() throws Exception { + new TestListTypeFieldsClassPackUnpack().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassUnconvertConvert() throws Exception { + new TestListTypeFieldsClassUnconvertConvert().testListTypeFieldsClass(); + } + + @Test + public void testListTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestListTypeFieldsClassNotNullableBufferPackBufferUnpack().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestListTypeFieldsClassNotNullableBufferPackConvert().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestListTypeFieldsClassNotNullableBufferPackUnpack().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestListTypeFieldsClassNotNullablePackBufferUnpack().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestListTypeFieldsClassNotNullablePackConvert().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestListTypeFieldsClassNotNullablePackUnpack().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testListTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestListTypeFieldsClassNotNullableUnconvertConvert().testListTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestMapTypeFieldsClassBufferPackBufferUnpack().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassBufferPackConvert() throws Exception { + new TestMapTypeFieldsClassBufferPackConvert().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassBufferPackUnpack() throws Exception { + new TestMapTypeFieldsClassBufferPackUnpack().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassPackBufferUnpack() throws Exception { + new TestMapTypeFieldsClassPackBufferUnpack().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassPackConvert() throws Exception { + new TestMapTypeFieldsClassPackConvert().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassPackUnpack() throws Exception { + new TestMapTypeFieldsClassPackUnpack().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassUnconvertConvert() throws Exception { + new TestMapTypeFieldsClassUnconvertConvert().testMapTypeFieldsClass(); + } + + @Test + public void testMapTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestMapTypeFieldsClassNotNullableBufferPackBufferUnpack().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestMapTypeFieldsClassNotNullableBufferPackConvert().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestMapTypeFieldsClassNotNullableBufferPackUnpack().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestMapTypeFieldsClassNotNullablePackBufferUnpack().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestMapTypeFieldsClassNotNullablePackConvert().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestMapTypeFieldsClassNotNullablePackUnpack().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testMapTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestMapTypeFieldsClassNotNullableUnconvertConvert().testMapTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestEnumTypeFieldsClassBufferPackBufferUnpack().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassBufferPackConvert() throws Exception { + new TestEnumTypeFieldsClassBufferPackConvert().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassBufferPackUnpack() throws Exception { + new TestEnumTypeFieldsClassBufferPackUnpack().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassPackBufferUnpack() throws Exception { + new TestEnumTypeFieldsClassPackBufferUnpack().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassPackConvert() throws Exception { + new TestEnumTypeFieldsClassPackConvert().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassPackUnpack() throws Exception { + new TestEnumTypeFieldsClassPackUnpack().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassUnconvertConvert() throws Exception { + new TestEnumTypeFieldsClassUnconvertConvert().testEnumTypeFieldsClass(); + } + + @Test + public void testEnumTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestEnumTypeFieldsClassNotNullableBufferPackBufferUnpack().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestEnumTypeFieldsClassNotNullableBufferPackConvert().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestEnumTypeFieldsClassNotNullableBufferPackUnpack().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestEnumTypeFieldsClassNotNullablePackBufferUnpack().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestEnumTypeFieldsClassNotNullablePackConvert().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestEnumTypeFieldsClassNotNullablePackUnpack().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testEnumTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestEnumTypeFieldsClassNotNullableUnconvertConvert().testEnumTypeFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassBufferPackBufferUnpack() throws Exception { + new TestModifiersFieldsClassBufferPackBufferUnpack().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassBufferPackConvert() throws Exception { + new TestModifiersFieldsClassBufferPackConvert().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassBufferPackUnpack() throws Exception { + new TestModifiersFieldsClassBufferPackUnpack().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassPackBufferUnpack() throws Exception { + new TestModifiersFieldsClassPackBufferUnpack().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassPackConvert() throws Exception { + new TestModifiersFieldsClassPackConvert().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassPackUnpack() throws Exception { + new TestModifiersFieldsClassPackUnpack().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassUnconvertConvert() throws Exception { + new TestModifiersFieldsClassUnconvertConvert().testModifiersFieldsClass(); + } + + @Test + public void testModifiersFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestModifiersFieldsClassNotNullableBufferPackBufferUnpack().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestModifiersFieldsClassNotNullableBufferPackConvert().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestModifiersFieldsClassNotNullableBufferPackUnpack().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestModifiersFieldsClassNotNullablePackBufferUnpack().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullablePackConvert() throws Exception { + new TestModifiersFieldsClassNotNullablePackConvert().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullablePackUnpack() throws Exception { + new TestModifiersFieldsClassNotNullablePackUnpack().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testModifiersFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestModifiersFieldsClassNotNullableUnconvertConvert().testModifiersFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassBufferPackBufferUnpack().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassBufferPackConvert() throws Exception { + new TestUserDefinedTypeFieldsClassBufferPackConvert().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassBufferPackUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassBufferPackUnpack().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassPackBufferUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassPackBufferUnpack().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassPackConvert() throws Exception { + new TestUserDefinedTypeFieldsClassPackConvert().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassPackUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassPackUnpack().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassUnconvertConvert() throws Exception { + new TestUserDefinedTypeFieldsClassUnconvertConvert().testUserDefinedTypeFieldsClass(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullableBufferPackBufferUnpack().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullableBufferPackConvert().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullableBufferPackUnpack().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullablePackBufferUnpack().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullablePackConvert().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullablePackUnpack().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testUserDefinedTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestUserDefinedTypeFieldsClassNotNullableUnconvertConvert().testUserDefinedTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassBufferPackBufferUnpack().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassBufferPackConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassBufferPackConvert().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassBufferPackUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassBufferPackUnpack().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassPackBufferUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassPackBufferUnpack().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassPackConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassPackConvert().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassPackUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassPackUnpack().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassUnconvertConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassUnconvertConvert().testReferenceCycleTypeFieldsClass(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullableBufferPackBufferUnpack().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullableBufferPackConvert().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullableBufferPackUnpack().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullablePackBufferUnpack().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullablePackConvert().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullablePackUnpack().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testReferenceCycleTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestReferenceCycleTypeFieldsClassNotNullableUnconvertConvert().testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Test + public void testInheritanceClassBufferPackBufferUnpack() throws Exception { + new TestInheritanceClassBufferPackBufferUnpack().testInheritanceClass(); + } + + @Test + public void testInheritanceClassBufferPackConvert() throws Exception { + new TestInheritanceClassBufferPackConvert().testInheritanceClass(); + } + + @Test + public void testInheritanceClassBufferPackUnpack() throws Exception { + new TestInheritanceClassBufferPackUnpack().testInheritanceClass(); + } + + @Test + public void testInheritanceClassPackBufferUnpack() throws Exception { + new TestInheritanceClassPackBufferUnpack().testInheritanceClass(); + } + + @Test + public void testInheritanceClassPackConvert() throws Exception { + new TestInheritanceClassPackConvert().testInheritanceClass(); + } + + @Test + public void testInheritanceClassPackUnpack() throws Exception { + new TestInheritanceClassPackUnpack().testInheritanceClass(); + } + + @Test + public void testInheritanceClassUnconvertConvert() throws Exception { + new TestInheritanceClassUnconvertConvert().testInheritanceClass(); + } + + @Test + public void testInheritanceClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestInheritanceClassNotNullableBufferPackBufferUnpack().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullableBufferPackConvert() throws Exception { + new TestInheritanceClassNotNullableBufferPackConvert().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullableBufferPackUnpack() throws Exception { + new TestInheritanceClassNotNullableBufferPackUnpack().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullablePackBufferUnpack() throws Exception { + new TestInheritanceClassNotNullablePackBufferUnpack().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullablePackConvert() throws Exception { + new TestInheritanceClassNotNullablePackConvert().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullablePackUnpack() throws Exception { + new TestInheritanceClassNotNullablePackUnpack().testInheritanceClassNotNullable(); + } + + @Test + public void testInheritanceClassNotNullableUnconvertConvert() throws Exception { + new TestInheritanceClassNotNullableUnconvertConvert().testInheritanceClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassBufferPackBufferUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassBufferPackBufferUnpack().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassBufferPackConvert() throws Exception { + new TestMessagePackableTypeFieldsClassBufferPackConvert().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassBufferPackUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassBufferPackUnpack().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassPackBufferUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassPackBufferUnpack().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassPackConvert() throws Exception { + new TestMessagePackableTypeFieldsClassPackConvert().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassPackUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassPackUnpack().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassUnconvertConvert() throws Exception { + new TestMessagePackableTypeFieldsClassUnconvertConvert().testMessagePackableTypeFieldsClass(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullableBufferPackBufferUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullableBufferPackBufferUnpack().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullableBufferPackConvert() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullableBufferPackConvert().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullableBufferPackUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullableBufferPackUnpack().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullablePackBufferUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullablePackBufferUnpack().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullablePackConvert() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullablePackConvert().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullablePackUnpack() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullablePackUnpack().testMessagePackableTypeFieldsClassNotNullable(); + } + + @Test + public void testMessagePackableTypeFieldsClassNotNullableUnconvertConvert() throws Exception { + new TestMessagePackableTypeFieldsClassNotNullableUnconvertConvert().testMessagePackableTypeFieldsClassNotNullable(); + } + + public static class TestPrimitiveTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + PrimitiveTypeFieldsClass ret = msgpack.read(bytes, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + PrimitiveTypeFieldsClass ret = msgpack.convert(value, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + PrimitiveTypeFieldsClass ret = msgpack.read(in, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + PrimitiveTypeFieldsClass ret = msgpack.read(bytes, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + PrimitiveTypeFieldsClass ret = msgpack.convert(value, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + PrimitiveTypeFieldsClass ret = msgpack.read(in, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + PrimitiveTypeFieldsClass ret = msgpack.convert(value, PrimitiveTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.read(bytes, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.convert(value, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.read(in, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.read(bytes, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.convert(value, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.read(in, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestPrimitiveTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + PrimitiveTypeFieldsClassNotNullable ret = msgpack.convert(value, PrimitiveTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ReferenceTypeFieldsClass ret = msgpack.read(bytes, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ReferenceTypeFieldsClass ret = msgpack.convert(value, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ReferenceTypeFieldsClass ret = msgpack.read(in, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ReferenceTypeFieldsClass ret = msgpack.read(bytes, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ReferenceTypeFieldsClass ret = msgpack.convert(value, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ReferenceTypeFieldsClass ret = msgpack.read(in, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ReferenceTypeFieldsClass ret = msgpack.convert(value, ReferenceTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ReferenceTypeFieldsClassNotNullable ret = msgpack.read(bytes, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ReferenceTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ReferenceTypeFieldsClassNotNullable ret = msgpack.read(in, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ReferenceTypeFieldsClassNotNullable ret = msgpack.read(bytes, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ReferenceTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ReferenceTypeFieldsClassNotNullable ret = msgpack.read(in, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ReferenceTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ListTypeFieldsClass ret = msgpack.read(bytes, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ListTypeFieldsClass ret = msgpack.convert(value, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ListTypeFieldsClass ret = msgpack.read(in, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ListTypeFieldsClass ret = msgpack.read(bytes, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ListTypeFieldsClass ret = msgpack.convert(value, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ListTypeFieldsClass ret = msgpack.read(in, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ListTypeFieldsClass ret = msgpack.convert(value, ListTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ListTypeFieldsClassNotNullable ret = msgpack.read(bytes, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ListTypeFieldsClassNotNullable ret = msgpack.convert(value, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ListTypeFieldsClassNotNullable ret = msgpack.read(in, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ListTypeFieldsClassNotNullable ret = msgpack.read(bytes, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ListTypeFieldsClassNotNullable ret = msgpack.convert(value, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ListTypeFieldsClassNotNullable ret = msgpack.read(in, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestListTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ListTypeFieldsClassNotNullable ret = msgpack.convert(value, ListTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + MapTypeFieldsClass ret = msgpack.read(bytes, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + MapTypeFieldsClass ret = msgpack.convert(value, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + MapTypeFieldsClass ret = msgpack.read(in, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + MapTypeFieldsClass ret = msgpack.read(bytes, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + MapTypeFieldsClass ret = msgpack.convert(value, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + MapTypeFieldsClass ret = msgpack.read(in, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + MapTypeFieldsClass ret = msgpack.convert(value, MapTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + MapTypeFieldsClassNotNullable ret = msgpack.read(bytes, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + MapTypeFieldsClassNotNullable ret = msgpack.convert(value, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + MapTypeFieldsClassNotNullable ret = msgpack.read(in, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + MapTypeFieldsClassNotNullable ret = msgpack.read(bytes, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + MapTypeFieldsClassNotNullable ret = msgpack.convert(value, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + MapTypeFieldsClassNotNullable ret = msgpack.read(in, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMapTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + MapTypeFieldsClassNotNullable ret = msgpack.convert(value, MapTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + EnumTypeFieldsClass ret = msgpack.read(bytes, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + EnumTypeFieldsClass ret = msgpack.convert(value, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + EnumTypeFieldsClass ret = msgpack.read(in, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + EnumTypeFieldsClass ret = msgpack.read(bytes, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + EnumTypeFieldsClass ret = msgpack.convert(value, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + EnumTypeFieldsClass ret = msgpack.read(in, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + EnumTypeFieldsClass ret = msgpack.convert(value, EnumTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + EnumTypeFieldsClassNotNullable ret = msgpack.read(bytes, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + EnumTypeFieldsClassNotNullable ret = msgpack.convert(value, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + EnumTypeFieldsClassNotNullable ret = msgpack.read(in, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + EnumTypeFieldsClassNotNullable ret = msgpack.read(bytes, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + EnumTypeFieldsClassNotNullable ret = msgpack.convert(value, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + EnumTypeFieldsClassNotNullable ret = msgpack.read(in, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestEnumTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + EnumTypeFieldsClassNotNullable ret = msgpack.convert(value, EnumTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ModifiersFieldsClass ret = msgpack.read(bytes, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ModifiersFieldsClass ret = msgpack.convert(value, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ModifiersFieldsClass ret = msgpack.read(in, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ModifiersFieldsClass ret = msgpack.read(bytes, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ModifiersFieldsClass ret = msgpack.convert(value, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ModifiersFieldsClass ret = msgpack.read(in, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ModifiersFieldsClass ret = msgpack.convert(value, ModifiersFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ModifiersFieldsClassNotNullable ret = msgpack.read(bytes, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ModifiersFieldsClassNotNullable ret = msgpack.convert(value, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ModifiersFieldsClassNotNullable ret = msgpack.read(in, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ModifiersFieldsClassNotNullable ret = msgpack.read(bytes, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ModifiersFieldsClassNotNullable ret = msgpack.convert(value, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ModifiersFieldsClassNotNullable ret = msgpack.read(in, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestModifiersFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ModifiersFieldsClassNotNullable ret = msgpack.convert(value, ModifiersFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + UserDefinedTypeFieldsClass ret = msgpack.read(bytes, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + UserDefinedTypeFieldsClass ret = msgpack.convert(value, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + UserDefinedTypeFieldsClass ret = msgpack.read(in, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + UserDefinedTypeFieldsClass ret = msgpack.read(bytes, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + UserDefinedTypeFieldsClass ret = msgpack.convert(value, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + UserDefinedTypeFieldsClass ret = msgpack.read(in, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + UserDefinedTypeFieldsClass ret = msgpack.convert(value, UserDefinedTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.read(bytes, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.convert(value, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.read(in, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.read(bytes, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.convert(value, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.read(in, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestUserDefinedTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + UserDefinedTypeFieldsClassNotNullable ret = msgpack.convert(value, UserDefinedTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ReferenceCycleTypeFieldsClass ret = msgpack.read(bytes, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ReferenceCycleTypeFieldsClass ret = msgpack.convert(value, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ReferenceCycleTypeFieldsClass ret = msgpack.read(in, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ReferenceCycleTypeFieldsClass ret = msgpack.read(bytes, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ReferenceCycleTypeFieldsClass ret = msgpack.convert(value, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ReferenceCycleTypeFieldsClass ret = msgpack.read(in, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ReferenceCycleTypeFieldsClass ret = msgpack.convert(value, ReferenceCycleTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.read(bytes, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.read(in, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.read(bytes, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.read(in, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestReferenceCycleTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + ReferenceCycleTypeFieldsClassNotNullable ret = msgpack.convert(value, ReferenceCycleTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + IndexedFieldsBeanClass ret = msgpack.read(bytes, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + IndexedFieldsBeanClass ret = msgpack.convert(value, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + IndexedFieldsBeanClass ret = msgpack.read(in, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + IndexedFieldsBeanClass ret = msgpack.read(bytes, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + IndexedFieldsBeanClass ret = msgpack.convert(value, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + IndexedFieldsBeanClass ret = msgpack.read(in, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + IndexedFieldsBeanClass ret = msgpack.convert(value, IndexedFieldsBeanClass.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + IndexedFieldsBeanClassNotNullable ret = msgpack.read(bytes, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + IndexedFieldsBeanClassNotNullable ret = msgpack.convert(value, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + IndexedFieldsBeanClassNotNullable ret = msgpack.read(in, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + IndexedFieldsBeanClassNotNullable ret = msgpack.read(bytes, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + IndexedFieldsBeanClassNotNullable ret = msgpack.convert(value, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + IndexedFieldsBeanClassNotNullable ret = msgpack.read(in, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestIndexedFieldsBeanClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + IndexedFieldsBeanClassNotNullable ret = msgpack.convert(value, IndexedFieldsBeanClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + InheritanceClass ret = msgpack.read(bytes, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + InheritanceClass ret = msgpack.convert(value, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + InheritanceClass ret = msgpack.read(in, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + InheritanceClass ret = msgpack.read(bytes, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + InheritanceClass ret = msgpack.convert(value, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + InheritanceClass ret = msgpack.read(in, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + InheritanceClass ret = msgpack.convert(value, InheritanceClass.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + InheritanceClassNotNullable ret = msgpack.read(bytes, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + InheritanceClassNotNullable ret = msgpack.convert(value, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + InheritanceClassNotNullable ret = msgpack.read(in, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + InheritanceClassNotNullable ret = msgpack.read(bytes, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + InheritanceClassNotNullable ret = msgpack.convert(value, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + InheritanceClassNotNullable ret = msgpack.read(in, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestInheritanceClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + InheritanceClassNotNullable ret = msgpack.convert(value, InheritanceClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + MessagePackableTypeFieldsClass ret = msgpack.read(bytes, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + MessagePackableTypeFieldsClass ret = msgpack.convert(value, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + MessagePackableTypeFieldsClass ret = msgpack.read(in, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + MessagePackableTypeFieldsClass ret = msgpack.read(bytes, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + MessagePackableTypeFieldsClass ret = msgpack.convert(value, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + MessagePackableTypeFieldsClass ret = msgpack.read(in, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + MessagePackableTypeFieldsClass ret = msgpack.convert(value, MessagePackableTypeFieldsClass.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullableBufferPackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.read(bytes, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullableBufferPackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + Value value = msgpack.read(bytes); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.convert(value, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullableBufferPackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(v); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.read(in, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullablePackBufferUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.read(bytes, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullablePackConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + byte[] bytes = out.toByteArray(); + Value value = msgpack.read(bytes); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.convert(value, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullablePackUnpack extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, v); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.read(in, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + + public static class TestMessagePackableTypeFieldsClassNotNullableUnconvertConvert extends org.msgpack.template.builder.TestSet { + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(v); + MessagePackableTypeFieldsClassNotNullable ret = msgpack.convert(value, MessagePackableTypeFieldsClassNotNullable.class); + assertEquals(v, ret); + } + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestNestedList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestNestedList.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,96 @@ +package org.msgpack; + +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; +import org.msgpack.annotation.Message; +import org.msgpack.type.ArrayValue; +import org.msgpack.type.Value; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * User: takeshita + * Create: 11/10/17 23:17 + */ +public class TestNestedList { + + MessagePack messagePack; + + @Before + public void before(){ + messagePack = new MessagePack(); + } + + @Test + public void testTestNestedList() throws IOException { + NestedList obj = new NestedList(); + obj.list.add(list("aaa", "bbb")); + obj.list.add(list(new MyClass("obj1"), new MyClass("obj2"))); + obj.list2.add((List)list(new MyClass("obj3"))); + + byte[] bytes = messagePack.write(obj); + + // Can't unpack as NestedList + Value unpacked = messagePack.read(bytes); + ArrayValue root = unpacked.asArrayValue().getElementArray()[0].asArrayValue(); + ArrayValue list1 = root.getElementArray()[0].asArrayValue(); + ArrayValue list2 = root.getElementArray()[1].asArrayValue(); + ArrayValue list3 = unpacked.asArrayValue().getElementArray()[1].asArrayValue(); + list3 = list3.getElementArray()[0].asArrayValue(); + + Assert.assertEquals("aaa",list1.getElementArray()[0].asRawValue().getString()); + Assert.assertEquals("bbb",list1.getElementArray()[1].asRawValue().getString()); + Assert.assertEquals("obj1",messagePack.convert(list2.getElementArray()[0],MyClass.class).name); + Assert.assertEquals("obj2",messagePack.convert(list2.getElementArray()[1],MyClass.class).name); + Assert.assertEquals("obj3",messagePack.convert(list3.getElementArray()[0],MyClass.class).name); + + } + + @Test + public void testNestedListToValue() throws IOException { + + List values = list( list("hoge",4) , list(list(2,"aaa"),list("bbb"))); + + Value value = messagePack.unconvert(values); + + Value[] rootArray = value.asArrayValue().getElementArray(); + Value[] list1 = rootArray[0].asArrayValue().getElementArray(); + Value[] list2 = rootArray[1].asArrayValue().getElementArray(); + Value[] list3 = list2[0].asArrayValue().getElementArray(); + Value[] list4 = list2[1].asArrayValue().getElementArray(); + Assert.assertEquals("hoge",list1[0].asRawValue().getString()); + Assert.assertEquals(4,list1[1].asIntegerValue().getInt()); + Assert.assertEquals(2,list3[0].asIntegerValue().getInt()); + Assert.assertEquals("aaa",list3[1].asRawValue().getString()); + Assert.assertEquals("bbb",list4[0].asRawValue().getString()); + + } + + private List list( Object ... elements){ + List list = new ArrayList(); + for(Object o : elements){ + list.add(o); + } + return list; + } + + @Message + public static class NestedList{ + public List list = new ArrayList(); + + public List> list2 = new ArrayList>(); + + } + + @Message + public static class MyClass{ + String name; + + public MyClass(){} + public MyClass(String n ){ name = n;} + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,294 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.io.ByteArrayOutputStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestPackBufferUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + short ret = unpacker.readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + int ret = unpacker.readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + long ret = unpacker.readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.writeNil(); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + byte[] ret = unpacker.read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + K key = unpacker.read(keyElementClass); + V value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,363 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import junit.framework.Assert; +import org.junit.Test; +import org.msgpack.packer.Packer; +import org.msgpack.type.ValueFactory; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; + + +public class TestPackConvert extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isBooleanValue()); + boolean ret = new Converter(value).readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + byte ret = new Converter(value).readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + short ret = new Converter(value).readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + int ret = new Converter(value).readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isIntegerValue()); + long ret = new Converter(value).readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isFloatValue()); + float ret = new Converter(value).readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isFloatValue()); + double ret = new Converter(value).readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.writeNil(); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + assertTrue(value.isNilValue()); + new Converter(value).readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + BigInteger ret = new Converter(value).read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + String ret = new Converter(value).read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Value value = unpacker.readValue(); + byte[] ret = new Converter(value).read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + Value value = unpacker.readValue(); + ret.add(new Converter(value).read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Value keyValue = unpacker.readValue(); + K key = new Converter(keyValue).read(keyElementClass); + Value valueValue = unpacker.readValue(); + V value = new Converter(valueValue).read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test + public void testPackValue() throws IOException { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + String text = "This is Value"; + Value value = ValueFactory.createRawValue(text); + packer.write(value); + byte[] bytes = out.toByteArray(); + Assert.assertEquals(text.length() + 1,bytes.length); + Assert.assertEquals(0xa0 + text.length(), 0xff & bytes[0]); + } + + @Test + public void testPackValuePassedAsObject() throws IOException{ + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + String text = "This is Value"; + Object value = ValueFactory.createRawValue(text); + packer.write(value); // passed as object + byte[] bytes = out.toByteArray(); + Assert.assertEquals(text.length() + 1,bytes.length); + Assert.assertEquals(0xa0 + text.length(), 0xff & bytes[0]); + + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,344 @@ +package org.msgpack; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + + +public class TestPackUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + short ret = unpacker.readShort(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + int ret = unpacker.readInt(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + long ret = unpacker.readLong(); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test(expected=MessageTypeException.class) + public void testReadIntOverUpperBound() throws Exception { + long v = Integer.MAX_VALUE + 1L; + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + unpacker.readInt(); + } + + @Test(expected=MessageTypeException.class) + public void testReadIntUnderLowerBound() throws Exception { + long v = Integer.MIN_VALUE - 1L; + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + unpacker.readInt(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.writeNil(); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + unpacker.readNil(); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + byte[] ret = unpacker.read(byte[].class); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + K key = unpacker.read(keyElementClass); + V value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestSet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestSet.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,453 @@ +package org.msgpack; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import org.junit.Ignore; + + +@Ignore +public class TestSet { + + public void testBoolean() throws Exception { + testBoolean(false); + testBoolean(true); + } + + public void testBoolean(boolean v) throws Exception { + } + + public void testBooleanArray() throws Exception { + testBooleanArray(null); + testBooleanArray(new boolean[0]); + testBooleanArray(new boolean[] { true }); + testBooleanArray(new boolean[] { false }); + testBooleanArray(new boolean[] { true, false }); + Random rand = new Random(); + boolean[] v = new boolean[100]; + for (int i = 0; i < v.length; ++i) { + v[i] = rand.nextBoolean(); + } + testBooleanArray(v); + } + + public void testBooleanArray(boolean[] v) throws Exception { + } + + public void testByte() throws Exception { + testByte((byte) 0); + testByte((byte) -1); + testByte((byte) 1); + testByte(Byte.MIN_VALUE); + testByte(Byte.MAX_VALUE); + byte[] bytes = new byte[1000]; + Random rand = new Random(); + rand.nextBytes(bytes); + for (int i = 0; i < bytes.length; ++i) { + testByte(bytes[i]); + } + } + + public void testByte(byte v) throws Exception { + } + + public void testByteArray() throws Exception { + testByteArray(null); + Random rand = new Random(System.currentTimeMillis()); + byte[] b0 = new byte[0]; + testByteArray(b0); + byte[] b1 = new byte[10]; + rand.nextBytes(b1); + testByteArray(b1); + byte[] b2 = new byte[1024]; + rand.nextBytes(b2); + testByteArray(b2); + } + + public void testByteArray(byte[] v) throws Exception { + } + + public void testShort() throws Exception { + testShort((short) 0); + testShort((short) -1); + testShort((short) 1); + testShort(Short.MIN_VALUE); + testShort(Short.MAX_VALUE); + Random rand = new Random(); + byte[] bytes = new byte[2000]; + rand.nextBytes(bytes); + for (int i = 0; i < bytes.length; i = i + 2) { + testShort((short) ((bytes[i] << 8) | (bytes[i + 1] & 0xff))); + } + } + + public void testShort(short v) throws Exception { + } + + public void testShortArray() throws Exception { + testShortArray(null); + testShortArray(new short[0]); + testShortArray(new short[] { 0 }); + testShortArray(new short[] { -1 }); + testShortArray(new short[] { 1 }); + testShortArray(new short[] { 0, -1, 1 }); + testShortArray(new short[] { Short.MIN_VALUE }); + testShortArray(new short[] { Short.MAX_VALUE }); + testShortArray(new short[] { Short.MIN_VALUE, Short.MAX_VALUE }); + Random rand = new Random(); + byte[] bytes = new byte[2]; + short[] v = new short[100]; + for (int i = 0; i < v.length; ++i) { + rand.nextBytes(bytes); + v[i] = (short) ((bytes[0] << 8) | (bytes[1] & 0xff)); + } + testShortArray(v); + } + + public void testShortArray(short[] v) throws Exception { + } + + public void testInteger() throws Exception { + testInteger(0); + testInteger(-1); + testInteger(1); + testInteger(Integer.MIN_VALUE); + testInteger(Integer.MAX_VALUE); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) { + testInteger(rand.nextInt()); + } + } + + public void testInteger(int v) throws Exception { + } + + public void testIntegerArray() throws Exception { + testIntegerArray(null); + testIntegerArray(new int[0]); + testIntegerArray(new int[] { 0 }); + testIntegerArray(new int[] { -1 }); + testIntegerArray(new int[] { 1 }); + testIntegerArray(new int[] { 0, -1, 1 }); + testIntegerArray(new int[] { Integer.MIN_VALUE }); + testIntegerArray(new int[] { Integer.MAX_VALUE }); + testIntegerArray(new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }); + Random rand = new Random(); + int[] v = new int[100]; + for (int i = 0; i < v.length; ++i) { + v[i] = rand.nextInt(); + } + testIntegerArray(v); + } + + public void testIntegerArray(int[] v) throws Exception { + } + + public void testLong() throws Exception { + testLong(0); + testLong(-1); + testLong(1); + testLong(Long.MIN_VALUE); + testLong(Long.MAX_VALUE); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) { + testLong(rand.nextLong()); + } + } + + public void testLong(long v) throws Exception { + } + + public void testLongArray() throws Exception { + testLongArray(null); + testLongArray(new long[0]); + testLongArray(new long[] { 0 }); + testLongArray(new long[] { -1 }); + testLongArray(new long[] { 1 }); + testLongArray(new long[] { 0, -1, 1 }); + testLongArray(new long[] { Long.MIN_VALUE }); + testLongArray(new long[] { Long.MAX_VALUE }); + testLongArray(new long[] { Long.MIN_VALUE, Long.MAX_VALUE }); + Random rand = new Random(); + long[] v = new long[100]; + for (int i = 0; i < v.length; ++i) { + v[i] = rand.nextLong(); + } + testLongArray(v); + } + + public void testLongArray(long[] v) throws Exception { + } + + public void testFloat() throws Exception { + testFloat((float) 0.0); + testFloat((float) -0.0); + testFloat((float) 1.0); + testFloat((float) -1.0); + testFloat(Float.MAX_VALUE); + testFloat(Float.MIN_VALUE); + testFloat(Float.NaN); + testFloat(Float.NEGATIVE_INFINITY); + testFloat(Float.POSITIVE_INFINITY); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) { + testFloat(rand.nextFloat()); + } + } + + public void testFloat(float v) throws Exception { + } + + public void testFloatArray() throws Exception { + testFloatArray(null); + testFloatArray(new float[0]); + testFloatArray(new float[] { (float) 0.0 }); + testFloatArray(new float[] { (float) -0.0 }); + testFloatArray(new float[] { (float) -1.0 }); + testFloatArray(new float[] { (float) 1.0 }); + testFloatArray(new float[] { (float) 0.0, (float) -0.0, (float) -1.0, (float) 1.0 }); + testFloatArray(new float[] { Float.MAX_VALUE }); + testFloatArray(new float[] { Float.MIN_VALUE }); + testFloatArray(new float[] { Float.NaN }); + testFloatArray(new float[] { Float.NEGATIVE_INFINITY }); + testFloatArray(new float[] { Float.POSITIVE_INFINITY }); + testFloatArray(new float[] { Float.MAX_VALUE, Float.MIN_VALUE, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY }); + Random rand = new Random(); + float[] v = new float[100]; + for (int i = 0; i < v.length; ++i) { + v[i] = rand.nextFloat(); + } + testFloatArray(v); + } + + public void testFloatArray(float[] v) throws Exception { + } + + public void testDouble() throws Exception { + testDouble((double) 0.0); + testDouble((double) -0.0); + testDouble((double) 1.0); + testDouble((double) -1.0); + testDouble(Double.MAX_VALUE); + testDouble(Double.MIN_VALUE); + testDouble(Double.NaN); + testDouble(Double.NEGATIVE_INFINITY); + testDouble(Double.POSITIVE_INFINITY); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) { + testDouble(rand.nextDouble()); + } + } + + public void testDouble(double v) throws Exception { + } + + public void testDoubleArray() throws Exception { + testDoubleArray(null); + testDoubleArray(new double[0]); + testDoubleArray(new double[] { (double) 0.0 }); + testDoubleArray(new double[] { (double) -0.0 }); + testDoubleArray(new double[] { (double) -1.0 }); + testDoubleArray(new double[] { (double) 1.0 }); + testDoubleArray(new double[] { (double) 0.0, (double) -0.0, (double) -1.0, (double) 1.0 }); + testDoubleArray(new double[] { Double.MAX_VALUE }); + testDoubleArray(new double[] { Double.MIN_VALUE }); + testDoubleArray(new double[] { Double.NaN }); + testDoubleArray(new double[] { Double.NEGATIVE_INFINITY }); + testDoubleArray(new double[] { Double.POSITIVE_INFINITY }); + testDoubleArray(new double[] { Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }); + Random rand = new Random(); + double[] v = new double[100]; + for (int i = 0; i < v.length; ++i) { + v[i] = rand.nextDouble(); + } + testDoubleArray(v); + } + + public void testDoubleArray(double[] v) throws Exception { + } + + public void testNil() throws Exception { + } + + public void testString() throws Exception { + testString(null); + testString(""); + testString("a"); + testString("ab"); + testString("abc"); + StringBuilder sb; + int len; + // small size string + { + for (int i = 0; i < 100; i++) { + sb = new StringBuilder(); + len = (int) Math.random() % 31 + 1; + for (int j = 0; j < len; j++) { + sb.append('a' + ((int) Math.random()) & 26); + } + testString(sb.toString()); + } + } + // medium size string + { + for (int i = 0; i < 100; i++) { + sb = new StringBuilder(); + len = (int) Math.random() % 100 + (1 << 15); + for (int j = 0; j < len; j++) { + sb.append('a' + ((int) Math.random()) & 26); + } + testString(sb.toString()); + } + } + // large size string + { + for (int i = 0; i < 10; i++) { + sb = new StringBuilder(); + len = (int) Math.random() % 100 + (1 << 31); + for (int j = 0; j < len; j++) { + sb.append('a' + ((int) Math.random()) & 26); + } + testString(sb.toString()); + } + } + } + + public void testString(String v) throws Exception { + } + + public void testByteBuffer() throws Exception { + testByteBuffer(null); + Random rand = new Random(System.currentTimeMillis()); + byte[] b0 = new byte[0]; + testByteBuffer(ByteBuffer.wrap(b0)); + byte[] b1 = new byte[10]; + rand.nextBytes(b1); + testByteBuffer(ByteBuffer.wrap(b1)); + byte[] b2 = new byte[1024]; + rand.nextBytes(b2); + testByteBuffer(ByteBuffer.wrap(b2)); + } + + public void testByteBuffer(ByteBuffer v) throws Exception { + } + + public void testList() throws Exception { + testList(null, Integer.class); + List list0 = new ArrayList(); + testList(list0, Integer.class); + List list1 = new ArrayList(); + Random rand1 = new Random(); + for (int i = 0; i < 10; ++i) { + list1.add(rand1.nextInt()); + } + testList(list1, Integer.class); + List list2 = new ArrayList(); + Random rand2 = new Random(); + for (int i = 0; i < 100; ++i) { + list2.add("xx" + rand2.nextInt()); + } + testList(list2, String.class); + List list3 = new ArrayList(); + Random rand3 = new Random(); + for (int i = 0; i < 1000; ++i) { + list3.add("xx" + rand3.nextInt()); + } + testList(list3, String.class); + } + + public void testList(List v, Class elementClass) throws Exception { + } + + public void testMap() throws Exception { + testMap(null, Integer.class, Integer.class); + Map map0 = new HashMap(); + testMap(map0, Integer.class, Integer.class); + Map map1 = new HashMap(); + Random rand1 = new Random(); + for (int i = 0; i < 10; ++i) { + map1.put(rand1.nextInt(), rand1.nextInt()); + } + testMap(map1, Integer.class, Integer.class); + Map map2 = new HashMap(); + Random rand2 = new Random(); + for (int i = 0; i < 100; ++i) { + map2.put("xx" + rand2.nextInt(), rand2.nextInt()); + } + testMap(map2, String.class, Integer.class); + Map map3 = new HashMap(); + Random rand3= new Random(); + for (int i = 0; i < 1000; ++i) { + map3.put("xx" + rand3.nextInt(), rand3.nextInt()); + } + testMap(map3, String.class, Integer.class); + } + + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + } + + public void testBigInteger() throws Exception { + testBigInteger(null); + testBigInteger(BigInteger.valueOf(0)); + testBigInteger(BigInteger.valueOf(-1)); + testBigInteger(BigInteger.valueOf(1)); + testBigInteger(BigInteger.valueOf(128l)); + testBigInteger(BigInteger.valueOf(512l)); + testBigInteger(BigInteger.valueOf(Integer.MIN_VALUE)); + testBigInteger(BigInteger.valueOf(Integer.MAX_VALUE)); + testBigInteger(BigInteger.valueOf(Long.MIN_VALUE)); + testBigInteger(BigInteger.valueOf(Long.MAX_VALUE)); + BigInteger max = BigInteger.valueOf(Long.MAX_VALUE).setBit(63); + testBigInteger(max); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) { + testBigInteger(max.subtract(BigInteger.valueOf(Math.abs(rand.nextLong())))); + } + } + + public void testBigInteger(BigInteger v) throws Exception { + } + + public void testBigDecimal() throws Exception { + testBigDecimal(null); + testBigDecimal(BigDecimal.valueOf(0)); + testBigDecimal(BigDecimal.valueOf(-1)); + testBigDecimal(BigDecimal.valueOf(1)); + testBigDecimal(BigDecimal.valueOf(Integer.MIN_VALUE)); + testBigDecimal(BigDecimal.valueOf(Integer.MAX_VALUE)); + testBigDecimal(BigDecimal.valueOf(Long.MIN_VALUE)); + testBigDecimal(BigDecimal.valueOf(Long.MAX_VALUE)); + } + + public void testBigDecimal(BigDecimal v) throws Exception { + } + + public void testDate() throws Exception { + testDate(null); + Date d0 = new Date(); + testDate(d0); + } + + public void testDate(Date v) throws Exception { + } + + public void testCharacter() throws Exception { + testCharacter(null); + testCharacter('a'); + testCharacter('あ'); + testCharacter((char) 1); + testCharacter(Character.MIN_VALUE); + testCharacter(Character.MAX_VALUE); + } + + public void testCharacter(Character v) throws Exception { + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestSimpleArrays.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestSimpleArrays.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,476 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.annotation.Message; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Unconverter; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + +public class TestSimpleArrays { + + @Message + public static class PrimitiveTest { + public boolean[] b = new boolean[0]; + public short[] s = new short[0]; + public int[] i = new int[0]; + // public long[] l = new long[0]; // FIXME javassist? + public float[] f = new float[0]; + + // public double[] d = new double[0]; // FIXME javassist? + + public PrimitiveTest() { + } + } + + @Test + public void testPrimitive() throws Exception { + MessagePack msgpack = new MessagePack(); + + PrimitiveTest t = new PrimitiveTest(); + t.b = new boolean[] { true, false }; + t.s = new short[] { 0, 1 }; + t.i = new int[] { 2, 3 }; + // t.l = new long[] {4, 5}; + t.f = new float[] { 2.0f, 4.0f }; + // t.d = new double[] {8.0, 16.0}; + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(t); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + PrimitiveTest u = unpacker.read(PrimitiveTest.class); + assertEquals(t.b.length, u.b.length); + for (int i = 0; i < t.b.length; i++) { + assertEquals(t.b[i], u.b[i]); + } + assertEquals(t.s.length, u.s.length); + for (int i = 0; i < t.s.length; i++) { + assertEquals(t.s[i], u.s[i]); + } + assertEquals(t.i.length, u.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i], u.i[i]); + } + // assertEquals(t.l.length, u.l.length); + // for(int i=0; i < t.l.length; i++) { assertEquals(t.l[i], u.l[i]); } + assertEquals(t.f.length, u.f.length); + for (int i = 0; i < t.f.length; i++) { + assertEquals(t.f[i], u.f[i], 10e-10); + } + // assertEquals(t.d.length, u.d.length); + // for(int i=0; i < t.d.length; i++) { assertEquals(t.d[i], u.d[i]); } + + Unconverter unconverter = new Unconverter(msgpack); + unconverter.write(t); + Value value = unconverter.getResult(); + Converter converter = new Converter(msgpack, value); + PrimitiveTest c = converter.read(PrimitiveTest.class); + assertEquals(t.b.length, c.b.length); + for (int i = 0; i < t.b.length; i++) { + assertEquals(t.b[i], c.b[i]); + } + assertEquals(t.s.length, c.s.length); + for (int i = 0; i < t.s.length; i++) { + assertEquals(t.s[i], c.s[i]); + } + assertEquals(t.i.length, c.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i], c.i[i]); + } + // assertEquals(t.l.length, c.l.length); + // for(int i=0; i < t.l.length; i++) { assertEquals(t.l[i], c.l[i]); } + assertEquals(t.f.length, c.f.length); + for (int i = 0; i < t.f.length; i++) { + assertEquals(t.f[i], c.f[i], 10e-10); + } + // assertEquals(t.d.length, c.d.length); + // for(int i=0; i < t.d.length; i++) { assertEquals(t.d[i], c.d[i]); } + } + + @Message + public static class ReferenceTest { + public ReferenceTest() { + } + + public Boolean[] b; + public Short[] s; + public Integer[] i; + public Long[] l; + public Float[] f; + public Double[] d; + public String[] str; + } + + @Test + public void testReference() throws Exception { + MessagePack msgpack = new MessagePack(); + + ReferenceTest t = new ReferenceTest(); + t.b = new Boolean[] { true, false }; + t.s = new Short[] { 0, 1 }; + t.i = new Integer[] { 2, 3 }; + t.l = new Long[] { 4l, 5l }; + t.f = new Float[] { 2.0f, 4.0f }; + t.d = new Double[] { 8.0, 16.0 }; + t.str = new String[] { "furuhashi", "java" }; + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(t); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + ReferenceTest u = unpacker.read(ReferenceTest.class); + assertEquals(t.b.length, u.b.length); + for (int i = 0; i < t.b.length; i++) { + assertEquals(t.b[i], u.b[i]); + } + assertEquals(t.s.length, u.s.length); + for (int i = 0; i < t.s.length; i++) { + assertEquals(t.s[i], u.s[i]); + } + assertEquals(t.i.length, u.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i], u.i[i]); + } + assertEquals(t.l.length, u.l.length); + for (int i = 0; i < t.l.length; i++) { + assertEquals(t.l[i], u.l[i]); + } + assertEquals(t.f.length, u.f.length); + for (int i = 0; i < t.f.length; i++) { + assertEquals(t.f[i], u.f[i]); + } + assertEquals(t.d.length, u.d.length); + for (int i = 0; i < t.d.length; i++) { + assertEquals(t.d[i], u.d[i]); + } + assertEquals(t.str.length, u.str.length); + for (int i = 0; i < t.str.length; i++) { + assertEquals(t.str[i], u.str[i]); + } + + Unconverter unconverter = new Unconverter(msgpack); + unconverter.write(t); + Value value = unconverter.getResult(); + Converter converter = new Converter(msgpack, value); + ReferenceTest c = converter.read(ReferenceTest.class); + assertEquals(t.b.length, c.b.length); + for (int i = 0; i < t.b.length; i++) { + assertEquals(t.b[i], c.b[i]); + } + assertEquals(t.s.length, c.s.length); + for (int i = 0; i < t.s.length; i++) { + assertEquals(t.s[i], c.s[i]); + } + assertEquals(t.i.length, c.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i], c.i[i]); + } + assertEquals(t.l.length, c.l.length); + for (int i = 0; i < t.l.length; i++) { + assertEquals(t.l[i], c.l[i]); + } + assertEquals(t.f.length, c.f.length); + for (int i = 0; i < t.f.length; i++) { + assertEquals(t.f[i], c.f[i]); + } + assertEquals(t.d.length, c.d.length); + for (int i = 0; i < t.d.length; i++) { + assertEquals(t.d[i], c.d[i]); + } + assertEquals(t.str.length, c.str.length); + for (int i = 0; i < t.str.length; i++) { + assertEquals(t.str[i], c.str[i]); + } + } + + @Message + public static class GenericsTest { + public List[] slist; + public Map[] imap; + + public GenericsTest() { + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Ignore + @Test + public void testGenerics() throws Exception { + MessagePack msgpack = new MessagePack(); + + GenericsTest t = new GenericsTest(); + t.slist = new List[2]; + t.slist[0] = new ArrayList(); + t.slist[0].add("aa"); + t.slist[0].add("bb"); + t.slist[1] = new ArrayList(); + t.slist[1].add("cc"); + t.imap = new Map[2]; + t.imap[0] = new HashMap(); + t.imap[0].put("aa", 1); + t.imap[0].put("bb", 2); + t.imap[1] = new HashMap(); + t.imap[1].put("cc", 3); + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(t); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + GenericsTest u = unpacker.read(GenericsTest.class); + assertEquals(t.slist.length, u.slist.length); + for (int i = 0; i < t.slist.length; i++) { + assertEquals(t.slist[i].size(), u.slist[i].size()); + for (int j = 0; j < t.slist[i].size(); j++) { + assertEquals(t.slist[i].get(j), u.slist[i].get(j)); + } + } + for (int i = 0; i < t.imap.length; i++) { + assertEquals(t.imap[i].size(), u.imap[i].size()); + for (String j : t.imap[i].keySet()) { + assertEquals(t.imap[i].get(j), u.imap[i].get(j)); + } + } + + Unconverter unconverter = new Unconverter(msgpack); + unconverter.write(t); + Value value = unconverter.getResult(); + Converter converter = new Converter(msgpack, value); + GenericsTest c = converter.read(GenericsTest.class); + assertEquals(t.slist.length, c.slist.length); + for (int i = 0; i < t.slist.length; i++) { + assertEquals(t.slist[i].size(), c.slist[i].size()); + for (int j = 0; j < t.slist[i].size(); j++) { + assertEquals(t.slist[i].get(j), c.slist[i].get(j)); + } + } + for (int i = 0; i < t.imap.length; i++) { + assertEquals(t.imap[i].size(), c.imap[i].size()); + for (String j : t.imap[i].keySet()) { + assertEquals(t.imap[i].get(j), c.imap[i].get(j)); + } + } + } + + @Message + public static class Dim2Test { + public int[][] i; + public byte[][] b; + public String[][] str; + //public List[][] slist; + + public Dim2Test() { + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + public void testDim2() throws Exception { + MessagePack msgpack = new MessagePack(); + Dim2Test t = new Dim2Test(); + t.i = new int[2][]; + t.i[0] = new int[] { 0, 1 }; + t.i[1] = new int[] { 2, 3, 4 }; + t.b = new byte[2][]; + t.b[0] = new byte[] { 5, 6 }; + t.b[1] = new byte[] { 7, 8, 9 }; + t.str = new String[2][]; + t.str[0] = new String[] { "aa", "bb" }; + t.str[1] = new String[] { "cc", "dd", "ee" }; + /** + t.slist = new List[2][]; + t.slist[0] = new List[1]; + t.slist[0][0] = new ArrayList(); + t.slist[0][0].add("ff"); + t.slist[0][0].add("gg"); + t.slist[1] = new List[2]; + t.slist[1][0] = new ArrayList(); + t.slist[1][0].add("hh"); + t.slist[1][0].add("ii"); + t.slist[1][1] = new ArrayList(); + t.slist[1][1].add("jj"); + t.slist[1][1].add("kk"); + */ + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(t); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + Dim2Test u = unpacker.read(Dim2Test.class); + assertEquals(t.i.length, u.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i].length, u.i[i].length); + for (int j = 0; j < t.i[i].length; j++) { + assertEquals(t.i[i][j], u.i[i][j]); + } + } + assertEquals(t.b.length, u.b.length); + for (int i = 0; i < t.b.length; i++) { + assertEquals(t.b[i].length, u.b[i].length); + for (int j = 0; j < t.i[i].length; j++) { + assertEquals(t.b[i][j], u.b[i][j]); + } + } + assertEquals(t.str.length, u.str.length); + for (int i = 0; i < t.str.length; i++) { + assertEquals(t.str[i].length, u.str[i].length); + for (int j = 0; j < t.str[i].length; j++) { + assertEquals(t.str[i][j], u.str[i][j]); + } + } + /** + assertEquals(t.slist.length, u.slist.length); + for (int i = 0; i < t.slist.length; i++) { + assertEquals(t.slist[i].length, u.slist[i].length); + for (int j = 0; j < t.slist[i].length; j++) { + assertEquals(t.slist[i][j].size(), u.slist[i][j].size()); + for (int k = 0; k < t.slist[i][j].size(); k++) { + assertEquals(t.slist[i][j].get(k), u.slist[i][j].get(k)); + } + } + } + */ + } + + @Message + public static class Dim3Test { + public int[][][] i; + public String[][][] str; + public List[][][] slist; + + public Dim3Test() { + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Ignore + @Test + public void testDim3() throws Exception { + MessagePack msgpack = new MessagePack(); + + Dim3Test t = new Dim3Test(); + t.i = new int[2][][]; + t.i[0] = new int[2][]; + t.i[0][0] = new int[] { 0, 1 }; + t.i[0][1] = new int[] { 2, 3, 4 }; + t.i[1] = new int[1][]; + t.i[1][0] = new int[] { 5 }; + t.str = new String[2][][]; + t.str[0] = new String[1][]; + t.str[0][0] = new String[] { "aa", "bb" }; + t.str[1] = new String[2][]; + t.str[1][0] = new String[] { "cc", "dd", "ee" }; + t.str[1][1] = new String[] { "ff" }; + t.slist = new List[2][][]; + t.slist[0] = new List[2][]; + t.slist[0][0] = new List[1]; + t.slist[0][0][0] = new ArrayList(); + t.slist[0][0][0].add("ff"); + t.slist[0][0][0].add("gg"); + t.slist[0][1] = new List[2]; + t.slist[0][1][0] = new ArrayList(); + t.slist[0][1][0].add("hh"); + t.slist[0][1][0].add("ii"); + t.slist[0][1][1] = new ArrayList(); + t.slist[0][1][1].add("jj"); + t.slist[0][1][1].add("kk"); + t.slist[1] = new List[1][]; + t.slist[1][0] = new List[0]; + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(t); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + Dim3Test u = unpacker.read(Dim3Test.class); + assertEquals(t.i.length, t.i.length); + for (int i = 0; i < t.i.length; i++) { + assertEquals(t.i[i].length, u.i[i].length); + for (int j = 0; j < t.i[i].length; j++) { + for (int k = 0; k < t.i[i].length; k++) { + assertEquals(t.i[i][j][k], u.i[i][j][k]); + } + } + } + assertEquals(t.str.length, t.str.length); + for (int i = 0; i < t.str.length; i++) { + assertEquals(t.str[i].length, u.str[i].length); + for (int j = 0; j < t.str[i].length; j++) { + assertEquals(t.str[i][j].length, u.str[i][j].length); + for (int k = 0; k < t.str[i][j].length; k++) { + assertEquals(t.str[i][j][k], u.str[i][j][k]); + } + } + } + assertEquals(t.slist.length, t.slist.length); + for (int i = 0; i < t.slist.length; i++) { + assertEquals(t.slist[i].length, u.slist[i].length); + for (int j = 0; j < t.slist[i].length; j++) { + assertEquals(t.slist[i][j].length, u.slist[i][j].length); + for (int k = 0; k < t.slist[i][j].length; k++) { + assertEquals(t.slist[i][j][k].size(), + u.slist[i][j][k].size()); + for (int l = 0; l < t.slist[i][j][k].size(); l++) { + assertEquals(t.slist[i][j][k].get(l), + u.slist[i][j][k].get(l)); + } + } + } + } + } + + @Test + public void testLocal() throws IOException { + MessagePack msgpack = new MessagePack(); + + int[][][] src = new int[10][20][30]; + for (int i = 0; i < 10; ++i) { + for (int j = 0; j < 20; ++j) { + for (int k = 0; k < 30; ++k) { + src[i][j][k] = (int) (Math.random() * 100); + } + } + } + + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(src); + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + int[][][] u = unpacker.read(int[][][].class); + assertEquals(src.length, u.length); + for (int i = 0; i < src.length; ++i) { + assertEquals(src[i].length, u[i].length); + for (int j = 0; j < src[i].length; ++j) { + assertEquals(src[i][j].length, u[i][j].length); + for (int k = 0; k < src[i][j].length; ++k) { + assertEquals(src[i][j][k], u[i][j][k]); + } + } + } + + Unconverter unconverter = new Unconverter(msgpack); + unconverter.write(src); + Value value = unconverter.getResult(); + Converter converter = new Converter(msgpack, value); + int[][][] c = converter.read(int[][][].class); + assertEquals(src.length, c.length); + for (int i = 0; i < src.length; ++i) { + assertEquals(src[i].length, c[i].length); + for (int j = 0; j < src[i].length; ++j) { + assertEquals(src[i][j].length, c[i][j].length); + for (int k = 0; k < src[i][j].length; ++k) { + assertEquals(src[i][j][k], c[i][j][k]); + } + } + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestSimpleConvertUnconvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestSimpleConvertUnconvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,29 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import org.junit.Test; + + +public class TestSimpleConvertUnconvert { + @Test + public void testSimpleConvert() throws IOException { + MessagePack msgpack = new MessagePack(); + byte[] raw = msgpack.write(new int[] {1,2,3}); + + Value v = msgpack.read(raw); + + int[] array = msgpack.convert(v, new int[3]); + assertArrayEquals(new int[] {1,2,3}, array); + + Value v2 = msgpack.unconvert(array); + assertEquals(v, v2); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestSimplePackable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestSimplePackable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,155 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.unpacker.BufferUnpacker; + +import org.junit.Test; + + +public class TestSimplePackable { + // all files are REQUIRED + public static class Sample01 implements MessagePackable { + public String f0; + public int[] f1; + public List f2; + + public Sample01() { } + + public void writeTo(Packer pk) throws IOException { + pk.writeArrayBegin(3); + pk.write(f0); + pk.writeArrayBegin(f1.length); + for(int e : f1) { + pk.write(e); + } + pk.writeArrayEnd(); + pk.writeArrayBegin(f2.size()); + for(String e : f2) { + pk.write(e); + } + pk.writeArrayEnd(); + pk.writeArrayEnd(); + } + + public void readFrom(Unpacker u) throws IOException { + u.readArrayBegin(); + f0 = u.readString(); + int nf1 = u.readArrayBegin(); + f1 = new int[nf1]; + for(int i=0; i < nf1; i++) { + f1[i] = u.readInt(); + } + u.readArrayEnd(); + int nf2 = u.readArrayBegin(); + f2 = new ArrayList(nf2); + for(int i=0; i < nf2; i++) { + f2.add(u.readString()); + } + u.readArrayEnd(); + u.readArrayEnd(); + } + } + + @Test + public void testSample01() throws IOException { + MessagePack msgpack = new MessagePack(); + + Sample01 a = new Sample01(); + a.f0 = "aaa"; + a.f1 = new int[3]; + a.f1[0] = 1010; + a.f1[1] = 2020; + a.f1[2] = 3030; + a.f2 = new ArrayList(); + a.f2.add("xx"); + a.f2.add("yy"); + + BufferPacker pk = msgpack.createBufferPacker(); + a.writeTo(pk); + + byte[] raw = pk.toByteArray(); + + BufferUnpacker u = msgpack.createBufferUnpacker().wrap(raw); + Sample01 b = new Sample01(); + b.readFrom(u); + + assertEquals(a.f0, b.f0); + assertArrayEquals(a.f1, b.f1); + assertEquals(a.f2, b.f2); + } + + // some files are OPTIONAL or NULLABLE + public static class Sample02 implements MessagePackable { + public String f0; // nullable + public long f1; // primitive + public Integer f2; // required + public String f3; // optional + + public Sample02() { } + + public void writeTo(Packer pk) throws IOException { + pk.writeArrayBegin(4); + pk.write(f0); + pk.write(f1); + if(f2 == null) { + throw new MessageTypeException("f2 is required but null"); + } + pk.write(f2); + pk.write(f3); + pk.writeArrayEnd(); + } + + public void readFrom(Unpacker u) throws IOException { + u.readArrayBegin(); + f0 = u.read(String.class); + f1 = u.readLong(); + if(u.trySkipNil()) { + f2 = null; + } else { + f2 = u.read(Integer.class); + } + if(u.trySkipNil()) { + f3 = null; + } else { + f3 = u.read(String.class); + } + u.readArrayEnd(); + } + } + + @Test + public void testSample02() throws IOException { + MessagePack msgpack = new MessagePack(); + + Sample02 a = new Sample02(); + a.f0 = "aaa"; + a.f1 = 1; + a.f2 = 22; + a.f3 = null; + + BufferPacker pk = msgpack.createBufferPacker(); + a.writeTo(pk); + + byte[] raw = pk.toByteArray(); + + BufferUnpacker u = msgpack.createBufferUnpacker().wrap(raw); + Sample02 b = new Sample02(); + b.readFrom(u); + + assertEquals(a.f0, b.f0); + assertEquals(a.f1, b.f1); + assertEquals(a.f2, b.f2); + assertEquals(a.f3, b.f3); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestThreadSafety.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestThreadSafety.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,139 @@ +package org.msgpack; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.junit.Before; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.type.ArrayValue; +import org.msgpack.type.MapValue; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; + +public class TestThreadSafety { + private List list = createList(1000); + private Map map = createMap(1000); + private static final String EXAMPLE_STRING; + static { + StringBuilder buf = new StringBuilder(); + for (int i = 0; i < 10; i++) { + buf.append("0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"); + } + EXAMPLE_STRING = buf.toString(); + } + + private List createList(int n) { + List src = new ArrayList(); + for (int i = 0; i < n; i++) { + src.add(EXAMPLE_STRING); + } + return src; + } + + private Map createMap(int n) { + Map src = new HashMap(); + for (int i = 0; i < n; i++) { + src.put(String.valueOf(i), EXAMPLE_STRING); + } + return src; + } + + private void testMsgpackDynamicString(int n) throws IOException { + MessagePack msgpack = new MessagePack(); + BufferPacker packer = msgpack.createBufferPacker(); + for (int i = 0; i < n; i++) { + packer.write(EXAMPLE_STRING); + } + + byte[] raw = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(raw); + + for (int i = 0; i < n; i++) { + String dst = unpacker.read(String.class); + if (!dst.equals(EXAMPLE_STRING)) { + throw new AssertionError(); + } + } + } + + private void testMsgpackDynamicArray() throws IOException { + List src = list; + + MessagePack msgpack = new MessagePack(); + byte[] raw; + raw = msgpack.write(src); + + List dst = new LinkedList(); + ArrayValue arrayValue = msgpack.read(raw).asArrayValue(); + for (Value v : arrayValue) { + dst.add(v.asRawValue().getString()); + + if (!v.asRawValue().getString().equals(EXAMPLE_STRING)) { + throw new AssertionError(); + } + } + } + + private void testMsgpackDynamicMap() throws IOException { + Map src = map; + + MessagePack msgpack = new MessagePack(); + byte[] raw; + raw = msgpack.write(src); + + MapValue mv = msgpack.read(raw).asMapValue(); + for (Entry kv : mv.entrySet()) { + if (!kv.getValue().asRawValue().getString().equals(EXAMPLE_STRING)) { + throw new AssertionError(); + } + } + } + + static class TestRunner implements Callable { + private final TestThreadSafety main; + + public TestRunner(TestThreadSafety main) { + this.main = main; + } + + @Override + public Void call() throws Exception { + try { + main.testMsgpackDynamicString(1000); + main.testMsgpackDynamicArray(); + main.testMsgpackDynamicMap(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return null; + } + } + + @Test + public void testWithBulkData() throws InterruptedException, ExecutionException, TimeoutException { + final TestThreadSafety main = new TestThreadSafety(); + List> futures = new LinkedList>(); + ExecutorService executorService = Executors.newCachedThreadPool(); + for (int i = 0; i < 20; i++) { + futures.add(executorService.submit(new TestRunner(main))); + } + + for (Future future : futures) { + future.get(30, TimeUnit.SECONDS); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestUnconvertConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestUnconvertConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,269 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.Unconverter; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; + + +public class TestUnconvertConvert extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.writeNil(); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + unpacker.readNil(); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + byte[] ret = unpacker.read(byte[].class); + assertArrayEquals(v, ret); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + K key = unpacker.read(keyElementClass); + V value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/TestUnconvertReconvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/TestUnconvertReconvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,244 @@ +package org.msgpack; + +import static org.junit.Assert.assertEquals; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.packer.Unconverter; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.Value; + + +public class TestUnconvertReconvert extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.writeNil(); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + unpacker.readNil(); + } + + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + Value r = packer.getResult(); + Converter unpacker = new Converter(msgpack, r); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + Value ret = unpacker.readValue(); + assertEquals(r, ret); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,78 @@ +package org.msgpack.annotation; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; + + +public class TestOptionalBufferPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + return msgpack.read(bytes, MyMessage01.class); + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + return msgpack.read(bytes, MyMessage02.class); + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + return msgpack.read(bytes, MyMessage03.class); + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + return msgpack.read(bytes, MyMessage03.class); + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,74 @@ +package org.msgpack.annotation; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; + + +public class TestOptionalBufferPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage01.class); + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage02.class); + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage03.class); + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage03.class); + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalJavassistBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalJavassistBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.annotation; + +import java.io.ByteArrayOutputStream; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.JavassistTemplateBuilder; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestOptionalJavassistBufferPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl02.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalJavassistBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalJavassistBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,120 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.JavassistTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalJavassistBufferPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl02.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalJavassistPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalJavassistPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,120 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.JavassistTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalJavassistPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl02.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalJavassistPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalJavassistPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.JavassistTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalJavassistPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl02.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,68 @@ +package org.msgpack.annotation; + +import org.junit.Test; +import org.msgpack.MessagePack; + + +public class TestOptionalPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + return msgpack.read(bytes, MyMessage01.class); + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + return msgpack.read(bytes, MyMessage02.class); + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + return msgpack.read(bytes, MyMessage03.class); + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + byte[] bytes = msgpack.write(src); + return msgpack.read(bytes, MyMessage03.class); + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,83 @@ +package org.msgpack.annotation; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; + + +public class TestOptionalPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage01.class); + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage02.class); + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage03.class); + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + msgpack.write(out, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + return msgpack.read(in, MyMessage03.class); + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalReflectionBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalReflectionBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.ReflectionTemplateBuilder; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestOptionalReflectionBufferPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl02.write(packer, src); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalReflectionBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalReflectionBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,120 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.ReflectionTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalReflectionBufferPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl02.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalReflectionPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalReflectionPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,120 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.ReflectionTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalReflectionPackBufferUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl01.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl02.write(packer, src); + byte[] bytes = packer.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestOptionalReflectionPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestOptionalReflectionPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.Template; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.builder.ReflectionTemplateBuilder; +import org.msgpack.unpacker.Unpacker; + + +public class TestOptionalReflectionPackUnpack { + + @org.junit.Ignore + public static class TestMessagePack extends TestSetOptional { + public void testOptional0101() throws Exception { + super.testOptional0101(); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage01 dst = tmpl01.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0102() throws Exception { + super.testOptional0102(); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage02 dst = tmpl02.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0103() throws Exception { + super.testOptional0103(); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl01 = builder.buildTemplate(MyMessage01.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl01.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + + public void testOptional0203() throws Exception { + super.testOptional0203(); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl02 = builder.buildTemplate(MyMessage02.class); + Template tmpl03 = builder.buildTemplate(MyMessage03.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl02.write(packer, src); + byte[] bytes = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + Unpacker unpacker = msgpack.createUnpacker(in); + unpacker.resetReadByteCount(); + MyMessage03 dst = tmpl03.read(unpacker, null); + assertEquals(bytes.length, unpacker.getReadByteCount()); + return dst; + } + } + + @Test + public void test0101() throws Exception { + new TestMessagePack().testOptional0101(); + } + @Test + public void test0102() throws Exception { + new TestMessagePack().testOptional0102(); + } + @Test + public void test0103() throws Exception { + new TestMessagePack().testOptional0103(); + } + @Test + public void test0203() throws Exception { + new TestMessagePack().testOptional0203(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/annotation/TestSetOptional.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/annotation/TestSetOptional.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,94 @@ +package org.msgpack.annotation; + +import static org.junit.Assert.assertEquals; + +@org.junit.Ignore +public class TestSetOptional { + + @Message + public static class MyMessage01 { + public String f0; + public int f1; + public MyMessage01() { + } + } + + @Message + public static class MyMessage02 { + public String f0; + public int f1; + @Optional + public int f2 = 20; + public MyMessage02() { + } + } + + @Message + public static class MyMessage03 { + public String f0; + public int f1; + @Optional + public int f2 = 20; + @Optional + public String f3 = "frsyuki"; + public MyMessage03() { + } + } + + public void testOptional0101() throws Exception { + MyMessage01 src = new MyMessage01(); + src.f0 = "muga"; + src.f1 = 10; + MyMessage01 dst = testOptional0101(src); + assertEquals(src.f0, dst.f0); + assertEquals(src.f1, dst.f1); + } + + public MyMessage01 testOptional0101(MyMessage01 src) throws Exception { + throw new UnsupportedOperationException(); + } + + public void testOptional0102() throws Exception { + MyMessage01 src = new MyMessage01(); + src.f0 = "muga"; + src.f1 = 10; + MyMessage02 dst = testOptional0102(src); + assertEquals(src.f0, dst.f0); + assertEquals(src.f1, dst.f1); + assertEquals(20, dst.f2); + } + + public MyMessage02 testOptional0102(MyMessage01 src) throws Exception { + throw new UnsupportedOperationException(); + } + + public void testOptional0103() throws Exception { + MyMessage01 src = new MyMessage01(); + src.f0 = "muga"; + src.f1 = 10; + MyMessage03 dst = testOptional0103(src); + assertEquals(src.f0, dst.f0); + assertEquals(src.f1, dst.f1); + assertEquals(20, dst.f2); + assertEquals("frsyuki", dst.f3); + } + + public MyMessage03 testOptional0103(MyMessage01 src) throws Exception { + throw new UnsupportedOperationException(); + } + + public void testOptional0203() throws Exception { + MyMessage02 src = new MyMessage02(); + src.f0 = "muga"; + src.f1 = 10; + MyMessage03 dst = testOptional0202(src); + assertEquals(src.f0, dst.f0); + assertEquals(src.f1, dst.f1); + assertEquals(src.f2, dst.f2); + assertEquals("frsyuki", dst.f3); + } + + public MyMessage03 testOptional0202(MyMessage02 src) throws Exception { + throw new UnsupportedOperationException(); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/io/TestLinkedBufferInput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/io/TestLinkedBufferInput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,752 @@ +package org.msgpack.io; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +import java.nio.ByteBuffer; +import java.io.IOException; +import java.io.DataInputStream; +import java.io.ByteArrayInputStream; +import java.io.DataOutputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; + + +public class TestLinkedBufferInput { + @Test + public void testReadByte() throws IOException { + byte[] src = new byte[8]; + src[0] = (byte)1; + src[2] = (byte)1; + src[4] = (byte)1; + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + LinkedBufferInput b2 = new LinkedBufferInput(8); + b2.feed(src); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testFeedByteArrayCopy() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(small); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(large); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testFeedByteArrayReference() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(small, true); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(large, true); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testFeedByteArrayCopyReference() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(small); + } + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(small, true); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(large); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(large, true); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + try { + b2.readByte(); + fail(); + } catch(EndOfBufferException eof) { + } + } + + @Test + public void testGetPrimitives() throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + DataOutputStream o = new DataOutputStream(bo); + o.writeByte((byte)2); + o.writeShort((short)2); + o.writeInt(2); + o.writeLong(2L); + o.writeFloat(1.1f); + o.writeDouble(1.1); + byte[] src = bo.toByteArray(); + + LinkedBufferInput b = new LinkedBufferInput(1024); + + for(int i=0; i < 2; i++) { + b.feed(src); + + assertEquals((byte)2, b.getByte()); + assertEquals((byte)2, b.getByte()); + b.advance(); + assertEquals((short)2, b.getShort()); + assertEquals((short)2, b.getShort()); + b.advance(); + assertEquals(2, b.getInt()); + assertEquals(2, b.getInt()); + b.advance(); + assertEquals(2L, b.getLong()); + assertEquals(2L, b.getLong()); + b.advance(); + assertEquals(1.1f, b.getFloat(), 0.000001f); + assertEquals(1.1f, b.getFloat(), 0.000001f); + b.advance(); + assertEquals(1.1, b.getDouble(), 0.000001); + assertEquals(1.1, b.getDouble(), 0.000001); + b.advance(); + } + } + + @Test + public void testGetPrimitivesChunks() throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + DataOutputStream o = new DataOutputStream(bo); + o.writeByte((byte)2); + o.writeShort((short)2); + o.writeInt(2); + o.writeLong(2L); + o.writeFloat(1.1f); + o.writeDouble(1.1); + byte[] src = bo.toByteArray(); + + LinkedBufferInput b = new LinkedBufferInput(1024); + + for(int i=0; i < 2; i++) { + int p = 0; + + b.feed(src, p++, 1, true); + assertEquals((byte)2, b.getByte()); + assertEquals((byte)2, b.getByte()); + b.advance(); + + for(int j=0; j < 2; j++) { + try { + b.getShort(); + fail(); + } catch(EndOfBufferException eof) { + } + b.feed(src, p++, 1, true); + } + assertEquals((short)2, b.getShort()); + assertEquals((short)2, b.getShort()); + b.advance(); + + for(int j=0; j < 4; j++) { + try { + b.getInt(); + fail(); + } catch(EndOfBufferException eof) { + } + b.feed(src, p++, 1, true); + } + assertEquals(2, b.getInt()); + assertEquals(2, b.getInt()); + b.advance(); + + for(int j=0; j < 8; j++) { + try { + b.getLong(); + fail(); + } catch(EndOfBufferException eof) { + } + b.feed(src, p++, 1, true); + } + assertEquals(2L, b.getLong()); + assertEquals(2L, b.getLong()); + b.advance(); + + for(int j=0; j < 4; j++) { + try { + b.getFloat(); + fail(); + } catch(EndOfBufferException eof) { + } + b.feed(src, p++, 1, true); + } + assertEquals(1.1f, b.getFloat(), 0.000001f); + assertEquals(1.1f, b.getFloat(), 0.000001f); + b.advance(); + + for(int j=0; j < 8; j++) { + try { + b.getDouble(); + fail(); + } catch(EndOfBufferException eof) { + } + b.feed(src, p++, 1, true); + } + assertEquals(1.1, b.getDouble(), 0.000001); + assertEquals(1.1, b.getDouble(), 0.000001); + b.advance(); + } + } + + + @Test + public void testFeedByteBufferCopy() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(ByteBuffer.wrap(small)); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(ByteBuffer.wrap(large)); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testFeedByteBufferReference() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(ByteBuffer.wrap(small), true); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(ByteBuffer.wrap(large), true); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testFeedByteBufferCopyReference() throws IOException { + byte[] small = new byte[8]; + small[0] = (byte)1; + small[2] = (byte)1; + small[4] = (byte)1; + + byte[] large = new byte[16]; + large[0] = (byte)1; + large[3] = (byte)1; + large[6] = (byte)1; + large[10] = (byte)1; + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + LinkedBufferInput b2 = new LinkedBufferInput(11); + + for(int i=0; i < 3; i++) { + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(ByteBuffer.wrap(small)); + } + for(int j=0; j < 7; j++) { + bout.write(small); + b2.feed(ByteBuffer.wrap(small), true); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(ByteBuffer.wrap(large)); + } + for(int j=0; j < 4; j++) { + bout.write(large); + b2.feed(ByteBuffer.wrap(large), true); + } + } + + byte[] src = bout.toByteArray(); + ByteArrayInputStream bin = new ByteArrayInputStream(src); + DataInputStream b1 = new DataInputStream(bin); + + for(int i=0; i < src.length; i++) { + assertEquals(b1.readByte(), b2.readByte()); + } + + assertEndOfBuffer(b2); + } + + @Test + public void testClear() throws IOException { + byte[] src = new byte[8]; + + LinkedBufferInput b = new LinkedBufferInput(11); + + for(int i=0; i < 2; i++) { + try { + b.readByte(); + fail(); + } catch(EndOfBufferException eof) { + } + + b.feed(src); + + b.clear(); + + assertEndOfBuffer(b); + + b.feed(src); + + for(int j=0; j < src.length; j++) { + b.readByte(); + } + + b.clear(); + } + } + + @Test + public void testClearRecycle() throws IOException { + byte[] data = new byte[8]; + data[0] = (byte)1; + data[2] = (byte)1; + data[4] = (byte)1; + + LinkedBufferInput b = new LinkedBufferInput(16); + + b.feed(data); + assertEquals(1, b.link.size()); + assertEquals(8, b.writable); + b.clear(); + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + + b.feed(data); + b.feed(data); + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); + b.clear(); + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + } + + @Test + public void testCopyReferencedBuffer() throws IOException { + byte[] data = new byte[16]; + data[0] = (byte)4; + data[3] = (byte)5; + data[6] = (byte)6; + data[10] = (byte)7; + + LinkedBufferInput b = new LinkedBufferInput(32); + int n; + byte[] buf = new byte[16]; + + b.feed(data, true); + b.feed(data, true); + b.feed(data, true); + assertEquals(3, b.link.size()); + assertEquals(-1, b.writable); + + b.copyReferencedBuffer(); + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + } + + @Test + public void testCopyReferencedBufferOptimized() throws IOException { + byte[] data = new byte[16]; + data[0] = (byte)4; + data[3] = (byte)5; + data[6] = (byte)6; + data[10] = (byte)7; + + LinkedBufferInput b = new LinkedBufferInput(32); + int n; + byte[] buf = new byte[16]; + + b.feed(data, true); + b.feed(data, true); + b.feed(data); // buffer allocated + assertEquals(3, b.link.size()); + assertEquals(16, b.writable); + + b.copyReferencedBuffer(); + assertEquals(2, b.link.size()); + assertEquals(16, b.writable); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + + n = b.read(buf, 0, 16); + assertEquals(n, 16); + assertArrayEquals(data, buf); + } + + @Test + public void testBufferRecycleByteArray() throws IOException { + byte[] data = new byte[16]; + data[0] = (byte)4; + data[3] = (byte)5; + data[6] = (byte)6; + data[10] = (byte)7; + + LinkedBufferInput b = new LinkedBufferInput(32); + int n; + byte[] buf = new byte[16]; + + b.feed(data); // feed 1; buffer allocated; remains 32-16 = 16 bytes + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + ByteBuffer allocated = b.link.peekLast(); + + b.feed(data); // feed 2; remains 16-16 = 0 bytes + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume 16 bytes 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); // no writable + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume 16 bytes 2; comsume all buffer; recycled + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEndOfBuffer(b); + assertEquals(1, b.link.size()); + assertEquals(32, b.writable); // recycled + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(data); // feed 1; remains 32-16 = 16 bytes + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + b.clear(); // clear; recycled + assertEndOfBuffer(b); + assertEquals(1, b.link.size()); + assertEquals(32, b.writable); // recycled + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(data, true); // feed reference 1; + assertEquals(2, b.link.size()); // leaves last writable buffer + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(data, true); // feed reference 2; + assertEquals(3, b.link.size()); // leaves last writable buffer + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume first link 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(2, b.link.size()); // first link is removed + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume first link 2 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); // first link is removed + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(data); // feed 1; remains 32-16 = 16 bytes; + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(data, true); // feed reference 2; writable buffer is hidden + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(2, b.link.size()); + assertEquals(-1, b.writable); // now not writable + assertEquals(true, allocated != b.link.peekLast()); + assertEquals(true, allocated == b.link.peekFirst()); + + n = b.read(buf, 0, 16); // consume data 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); // recycled buffer is removed + assertEquals(-1, b.writable); + assertEquals(true, allocated != b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume data 2 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEndOfBuffer(b); + assertEquals(0, b.link.size()); + assertEquals(-1, b.writable); + } + + // copied from testBufferRecycleByteArray + @Test + public void testBufferRecycleByteBuffer() throws IOException { + byte[] data = new byte[16]; + data[0] = (byte)4; + data[3] = (byte)5; + data[6] = (byte)6; + data[10] = (byte)7; + + ByteBuffer bb = ByteBuffer.wrap(data); + + LinkedBufferInput b = new LinkedBufferInput(32); + int n; + byte[] buf = new byte[16]; + + b.feed(bb.duplicate()); // feed 1; buffer allocated; remains 32-16 = 16 bytes + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + ByteBuffer allocated = b.link.peekLast(); + + b.feed(bb.duplicate()); // feed 2; remains 16-16 = 0 bytes + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume 16 bytes 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); + assertEquals(0, b.writable); // no writable + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume 16 bytes 2; comsume all buffer; recycled + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEndOfBuffer(b); + assertEquals(1, b.link.size()); + assertEquals(32, b.writable); // recycled + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(bb.duplicate()); // feed 1; remains 32-16 = 16 bytes + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + b.clear(); // clear; recycled + assertEndOfBuffer(b); + assertEquals(1, b.link.size()); + assertEquals(32, b.writable); // recycled + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(bb.duplicate(), true); // feed reference 1; + assertEquals(2, b.link.size()); // leaves last writable buffer + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(bb.duplicate(), true); // feed reference 2; + assertEquals(3, b.link.size()); // leaves last writable buffer + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume first link 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(2, b.link.size()); // first link is removed + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume first link 2 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); // first link is removed + assertEquals(32, b.writable); // which remains 32 bytes + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(bb.duplicate()); // feed 1; remains 32-16 = 16 bytes; + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); + assertEquals(16, b.writable); + assertEquals(true, allocated == b.link.peekLast()); + + b.feed(bb.duplicate(), true); // feed reference 2; writable buffer is hidden + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(2, b.link.size()); + assertEquals(-1, b.writable); // now not writable + assertEquals(true, allocated != b.link.peekLast()); + assertEquals(true, allocated == b.link.peekFirst()); + + n = b.read(buf, 0, 16); // consume data 1 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEquals(1, b.link.size()); // recycled buffer is removed + assertEquals(-1, b.writable); + assertEquals(true, allocated != b.link.peekLast()); + + n = b.read(buf, 0, 16); // consume data 2 + assertEquals(n, 16); + assertArrayEquals(data, buf); + assertEndOfBuffer(b); + assertEquals(0, b.link.size()); + assertEquals(-1, b.writable); + } + + private void assertEndOfBuffer(LinkedBufferInput b) throws IOException { + try { + b.readByte(); + fail(); + } catch(EndOfBufferException eof) { + } + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/io/TestLinkedBufferOutput.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/io/TestLinkedBufferOutput.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,93 @@ +package org.msgpack.io; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; +import java.io.DataOutputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; + + +public class TestLinkedBufferOutput { + @Test + public void testGetSize() throws IOException { + LinkedBufferOutput o = new LinkedBufferOutput(10); + for(int i=0; i < 21; i++) { + o.writeByte((byte)1); + assertEquals(i+1, o.getSize()); + } + } + + @Test + public void testWritePrimitives() throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + DataOutputStream o1 = new DataOutputStream(bo); + LinkedBufferOutput o2 = new LinkedBufferOutput(10); + o1.writeByte((byte)2); + o2.writeByte((byte)2); + o1.writeShort((short)2); + o2.writeShort((short)2); + o1.writeInt(2); + o2.writeInt(2); + o1.writeLong(2L); + o2.writeLong(2L); + o1.writeFloat(1.1f); + o2.writeFloat(1.1f); + o1.writeDouble(1.1); + o2.writeDouble(1.1); + byte[] b1 = bo.toByteArray(); + byte[] b2 = o2.toByteArray(); + assertEquals(b1.length, b2.length); + assertArrayEquals(b1, b2); + } + + @Test + public void testWriteByteAndPrimitives() throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + DataOutputStream o1 = new DataOutputStream(bo); + LinkedBufferOutput o2 = new LinkedBufferOutput(10); + o1.writeByte((byte)9); + o1.writeByte((byte)2); + o2.writeByteAndByte((byte)9, (byte)2); + o1.writeByte((byte)9); + o1.writeShort((short)2); + o2.writeByteAndShort((byte)9, (short)2); + o1.writeByte((byte)9); + o1.writeInt(2); + o2.writeByteAndInt((byte)9, 2); + o1.writeByte((byte)9); + o1.writeLong(2L); + o2.writeByteAndLong((byte)9, 2L); + o1.writeByte((byte)9); + o1.writeFloat(1.1f); + o2.writeByteAndFloat((byte)9, 1.1f); + o1.writeByte((byte)9); + o1.writeDouble(1.1); + o2.writeByteAndDouble((byte)9, 1.1); + byte[] b1 = bo.toByteArray(); + byte[] b2 = o2.toByteArray(); + assertEquals(b1.length, b2.length); + assertArrayEquals(b1, b2); + } + + @Test + public void testWrite() throws IOException { + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + DataOutputStream o1 = new DataOutputStream(bo); + LinkedBufferOutput o2 = new LinkedBufferOutput(10); + byte[] raw = new byte[9]; + raw[0] = (byte)1; + raw[7] = (byte)1; + for(int i=0; i < 11; i++) { + o1.write(raw, 0, raw.length); + o2.write(raw, 0, raw.length); + } + byte[] b1 = bo.toByteArray(); + byte[] b2 = o2.toByteArray(); + assertEquals(b1.length, b2.length); + assertArrayEquals(b1, b2); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/simple/TestSimpleDynamicTyping.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/simple/TestSimpleDynamicTyping.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,69 @@ +package org.msgpack.simple; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; +import org.msgpack.type.IntegerValue; +import org.msgpack.type.RawValue; +import org.msgpack.type.ArrayValue; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import org.junit.Test; + + +public class TestSimpleDynamicTyping { + @Test + @SuppressWarnings("unused") + public void testTypes() throws IOException { + MessagePack msgpack = new MessagePack(); + + byte[] raw = msgpack.write(new int[] {1,2,3}); + Value v = msgpack.read(raw); + + if(v.isArrayValue()) { + // ArrayValue extends List + ArrayValue array = v.asArrayValue(); + int n0 = array.get(0).asIntegerValue().intValue(); + assertEquals(1, n0); + int n1 = array.get(1).asIntegerValue().intValue(); + assertEquals(2, n1); + int n2 = array.get(2).asIntegerValue().intValue(); + assertEquals(3, n2); + + } else if(v.isIntegerValue()) { + // IntegerValue extends Number + int num = v.asIntegerValue().intValue(); + + } else if(v.isRawValue()) { + // getString() or getByteArray() + String str = v.asRawValue().getString(); + } + // other types: + // NilValue asNilValue() / isNilValue() + // BooleanValue asBooleanValue() / isBooleanValue() + // IntegerValue asIntegerValue() / isIntegerValue() + // FloatValue asFloatValue() / isFloatValue() + // ArrayValue asArrayValue() / isArrayValue() + // MapValue asMapValue() / isMapValue() + // RawValue asRawValue() / isRawValue + } + + @Test + public void testSimpleConvert() throws IOException { + MessagePack msgpack = new MessagePack(); + + byte[] raw = msgpack.write(new int[] {1,2,3}); + Value v = msgpack.read(raw); + + // convert from dynamic type (Value) to static type (int[]) + int[] array = msgpack.convert(v, new int[3]); + assertArrayEquals(new int[] {1,2,3}, array); + + // unconvert from static type (int[]) to dynamic type (Value) + Value v2 = msgpack.unconvert(array); + assertEquals(v, v2); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/simple/TestSimplePackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/simple/TestSimplePackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,35 @@ +package org.msgpack.simple; + +import java.nio.ByteBuffer; +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import org.junit.Test; + + +public class TestSimplePackUnpack { + @SuppressWarnings("unused") + @Test + public void testSimplePackUnpack() throws IOException { + MessagePack msgpack = new MessagePack(); + + // serialize + byte[] raw = msgpack.write(new int[] {1,2,3}); + + // deserialize to static type + int[] a = msgpack.read(raw, new int[3]); + assertArrayEquals(new int[] {1,2,3}, a); + + // deserialize to dynamic type (see TestSimpleDynamicTyping.java) + Value v = msgpack.read(raw); + + // ByteBuffer is also supported + int[] ab = msgpack.read(ByteBuffer.wrap(raw), new int[3]); + assertArrayEquals(new int[] {1,2,3}, ab); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/simple/TestSimpleStreaming.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/simple/TestSimpleStreaming.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,70 @@ +package org.msgpack.simple; + +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; + +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import org.junit.Test; + + +public class TestSimpleStreaming { + @SuppressWarnings("unused") + @Test + public void testSimpleStreamingSerialize() throws IOException { + MessagePack msgpack = new MessagePack(); + + // streaming serialize + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + + packer.write(new String[] {"a", "b", "c"}); + packer.write(new int[] {1, 2, 3}); + packer.write(9.1); + + // streaming deserialize + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker unpacker = msgpack.createUnpacker(in); + + String[] msg1 = unpacker.read(new String[3]); + int[] msg2 = unpacker.read(new int[3]); + double msg3 = unpacker.read(double.class); + + assertArrayEquals(new String[] {"a", "b", "c"}, msg1); + assertArrayEquals(new int[] {1, 2, 3}, msg2); + assertEquals(9.1, msg3, 0.001); + } + + @SuppressWarnings("unused") + @Test + public void testBufferPackUnpacker() throws IOException { + MessagePack msgpack = new MessagePack(); + + // streaming serialize into efficient buffer + BufferPacker packer = msgpack.createBufferPacker(); + + packer.write(new String[] {"a", "b", "c"}); + packer.write(new int[] {1, 2, 3}); + packer.write(9.1); + + // streaming deserialize from the buffer + // BufferUnpacker reduces copies + BufferUnpacker unpacker = msgpack.createBufferUnpacker(packer.toByteArray()); + + String[] msg1 = unpacker.read(new String[3]); + int[] msg2 = unpacker.read(new int[3]); + double msg3 = unpacker.read(double.class); + + assertArrayEquals(new String[] {"a", "b", "c"}, msg1); + assertArrayEquals(new int[] {1, 2, 3}, msg2); + assertEquals(9.1, msg3, 0.01); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestBigDecimalTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestBigDecimalTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.math.BigDecimal; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestBigDecimalTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testBigDecimal(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testBigDecimal(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testBigDecimal(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testBigDecimal(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testBigDecimal() throws Exception { + super.testBigDecimal(); + } + + @Override + public void testBigDecimal(BigDecimal v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigDecimalTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + BigDecimal ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testBigDecimal() throws Exception { + super.testBigDecimal(); + } + + @Override + public void testBigDecimal(BigDecimal v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigDecimalTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + BigDecimal ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testBigDecimal() throws Exception { + super.testBigDecimal(); + } + + @Override + public void testBigDecimal(BigDecimal v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigDecimalTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + BigDecimal ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testBigDecimal() throws Exception { + super.testBigDecimal(); + } + + @Override + public void testBigDecimal(BigDecimal v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigDecimalTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + BigDecimal ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestBigIntegerTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestBigIntegerTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.math.BigInteger; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestBigIntegerTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testBigInteger(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testBigInteger(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testBigInteger(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testBigInteger(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigIntegerTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + BigInteger ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigIntegerTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + BigInteger ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigIntegerTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + BigInteger ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BigIntegerTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + BigInteger ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestBooleanArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestBooleanArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,287 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestBooleanArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testBooleanArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testBooleanArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testBooleanArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testBooleanArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testBooleanArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testBooleanArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testBooleanArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testBooleanArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testBooleanArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testBooleanArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testBooleanArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testBooleanArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testBooleanArray() throws Exception { + super.testBooleanArray(); + } + + @Override + public void testBooleanArray(boolean[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + boolean[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + boolean[] ret = tmpl.read(unpacker, ret0); + assertBooleanArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testBooleanArray() throws Exception { + super.testBooleanArray(); + } + + @Override + public void testBooleanArray(boolean[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + boolean[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + boolean[] ret = tmpl.read(unpacker, ret0); + assertBooleanArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testBooleanArray() throws Exception { + super.testBooleanArray(); + } + + @Override + public void testBooleanArray(boolean[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + boolean[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[(int) v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + boolean[] ret = tmpl.read(unpacker, ret0); + assertBooleanArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testBooleanArray() throws Exception { + super.testBooleanArray(); + } + + @Override + public void testBooleanArray(boolean[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + boolean[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new boolean[0]; + } else { + ret0 = new boolean[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + boolean[] ret = tmpl.read(unpacker, ret0); + assertBooleanArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertBooleanArrayEquals(boolean[] v, boolean[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i]); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestBooleanTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestBooleanTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestBooleanTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testBoolean(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testBoolean(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testBoolean(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testBoolean(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + boolean ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + boolean ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + boolean ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = BooleanTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + boolean ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestByteArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestByteArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestByteArrayTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testByteArray(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testByteArray(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testByteArray(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testByteArray(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + byte[] ret = tmpl.read(unpacker, null); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + byte[] ret = tmpl.read(unpacker, null); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + byte[] ret = tmpl.read(unpacker, null); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + byte[] ret = tmpl.read(unpacker, null); + assertArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestByteBufferTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestByteBufferTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,135 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestByteBufferTemplate { + + private static byte[] toByteArray(ByteBuffer from) { + if (from == null) { + return null; + } + byte[] bytes = new byte[from.remaining()]; + from.get(bytes, from.arrayOffset() + from.position(), from.remaining()); + return bytes; + } + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testByteBuffer(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testByteBuffer(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testByteBuffer(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testByteBuffer(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testByteBuffer() throws Exception { + super.testByteBuffer(); + } + + @Override + public void testByteBuffer(ByteBuffer v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteBufferTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ByteBuffer ret = tmpl.read(unpacker, null); + assertArrayEquals(toByteArray(v), toByteArray(ret)); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testByteBuffer() throws Exception { + super.testByteBuffer(); + } + + @Override + public void testByteBuffer(ByteBuffer v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteBufferTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + ByteBuffer ret = tmpl.read(unpacker, null); + assertArrayEquals(toByteArray(v), toByteArray(ret)); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testByteBuffer() throws Exception { + super.testByteBuffer(); + } + + @Override + public void testByteBuffer(ByteBuffer v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteBufferTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + ByteBuffer ret = tmpl.read(unpacker, null); + assertArrayEquals(toByteArray(v), toByteArray(ret)); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testByteBuffer() throws Exception { + super.testByteBuffer(); + } + + @Override + public void testByteBuffer(ByteBuffer v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ByteBufferTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ByteBuffer ret = tmpl.read(unpacker, null); + assertArrayEquals(toByteArray(v), toByteArray(ret)); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestCharacterTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestCharacterTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,123 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + +public class TestCharacterTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testCharacter(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testCharacter(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testCharacter(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testCharacter(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testCharacter() throws Exception { + super.testCharacter(); + } + + @Override + public void testCharacter(Character v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = CharacterTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Character ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testCharacter() throws Exception { + super.testCharacter(); + } + + @Override + public void testCharacter(Character v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = CharacterTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Character ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testCharacter() throws Exception { + super.testCharacter(); + } + + @Override + public void testCharacter(Character v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = CharacterTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Character ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testCharacter() throws Exception { + super.testCharacter(); + } + + @Override + public void testCharacter(Character v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = CharacterTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Character ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestDateTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestDateTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,125 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Date; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestDateTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testDate(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testDate(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testDate(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testDate(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testDate() throws Exception { + super.testDate(); + } + + @Override + public void testDate(Date v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DateTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Date ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testDate() throws Exception { + super.testDate(); + } + + @Override + public void testDate(Date v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DateTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Date ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testDate() throws Exception { + super.testDate(); + } + + @Override + public void testDate(Date v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DateTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Date ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testDate() throws Exception { + super.testDate(); + } + + @Override + public void testDate(Date v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DateTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Date ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestDoubleArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestDoubleArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,287 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestDoubleArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testDoubleArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testDoubleArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testDoubleArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testDoubleArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testDoubleArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testDoubleArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testDoubleArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testDoubleArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testDoubleArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testDoubleArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testDoubleArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testDoubleArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testDoubleArray() throws Exception { + super.testDoubleArray(); + } + + @Override + public void testDoubleArray(double[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + double[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + double[] ret = tmpl.read(unpacker, ret0); + assertDoubleArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testDoubleArray() throws Exception { + super.testDoubleArray(); + } + + @Override + public void testDoubleArray(double[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + double[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + double[] ret = tmpl.read(unpacker, ret0); + assertDoubleArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testDoubleArray() throws Exception { + super.testDoubleArray(); + } + + @Override + public void testDoubleArray(double[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + double[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + double[] ret = tmpl.read(unpacker, ret0); + assertDoubleArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testDoubleArray() throws Exception { + super.testDoubleArray(); + } + + @Override + public void testDoubleArray(double[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + double[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new double[0]; + } else { + ret0 = new double[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + double[] ret = tmpl.read(unpacker, ret0); + assertDoubleArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertDoubleArrayEquals(double[] v, double[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i], 10e-10); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestDoubleTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestDoubleTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestDoubleTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testDouble(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testDouble(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testDouble(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testDouble(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + double ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + double ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + double ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = DoubleTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + double ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestFloatArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestFloatArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,288 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestFloatArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testFloatArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testFloatArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testFloatArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testFloatArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testFloatArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testFloatArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testFloatArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testFloatArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testFloatArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testFloatArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testFloatArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testFloatArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testFloatArray() throws Exception { + super.testFloatArray(); + } + + @Override + public void testFloatArray(float[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + float[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + float[] ret = tmpl.read(unpacker, ret0); + assertFloatArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testFloatArray() throws Exception { + super.testFloatArray(); + } + + @Override + public void testFloatArray(float[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + float[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + float[] ret = tmpl.read(unpacker, ret0); + assertFloatArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testFloatArray() throws Exception { + super.testFloatArray(); + } + + @Override + public void testFloatArray(float[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + float[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + float[] ret = tmpl.read(unpacker, ret0); + assertFloatArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testFloatArray() throws Exception { + super.testFloatArray(); + } + + @Override + public void testFloatArray(float[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + float[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new float[0]; + } else { + ret0 = new float[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + float[] ret = tmpl.read(unpacker, ret0); + assertFloatArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertFloatArrayEquals(float[] v, float[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i], 10e-10); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestFloatTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestFloatTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestFloatTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testFloat(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testFloat(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testFloat(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testFloat(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Float ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Float ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Float ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = FloatTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Float ret = tmpl.read(unpacker, null); + assertEquals(v, ret, 10e-10); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestIntegerArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestIntegerArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,287 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestIntegerArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testIntegerArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testIntegerArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testIntegerArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testIntegerArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testIntegerArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testIntegerArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testIntegerArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testIntegerArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testIntegerArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testIntegerArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testIntegerArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testIntegerArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testIntegerArray() throws Exception { + super.testIntegerArray(); + } + + @Override + public void testIntegerArray(int[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + int[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + int[] ret = tmpl.read(unpacker, ret0); + assertIntegerArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testIntegerArray() throws Exception { + super.testIntegerArray(); + } + + @Override + public void testIntegerArray(int[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + int[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + int[] ret = tmpl.read(unpacker, ret0); + assertIntegerArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testIntegerArray() throws Exception { + super.testIntegerArray(); + } + + @Override + public void testIntegerArray(int[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + int[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + int[] ret = tmpl.read(unpacker, ret0); + assertIntegerArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testIntegerArray() throws Exception { + super.testIntegerArray(); + } + + @Override + public void testIntegerArray(int[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + int[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new int[0]; + } else { + ret0 = new int[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + int[] ret = tmpl.read(unpacker, ret0); + assertIntegerArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertIntegerArrayEquals(int[] v, int[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i]); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestIntegerTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestIntegerTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestIntegerTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testInteger(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testInteger(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testInteger(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testInteger(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + int ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + int ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + int ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = IntegerTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + int ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestListTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestListTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,129 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.List; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestListTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testList(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testList(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testList(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testList(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template elementTemplate = msgpack.lookup(elementClass); + Template> tmpl = new ListTemplate(elementTemplate); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + List ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template elementTemplate = msgpack.lookup(elementClass); + Template> tmpl = new ListTemplate(elementTemplate); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + List ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template elementTemplate = msgpack.lookup(elementClass); + Template> tmpl = new ListTemplate(elementTemplate); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + List ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template elementTemplate = msgpack.lookup(elementClass); + Template> tmpl = new ListTemplate(elementTemplate); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + List ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestLongArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestLongArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,287 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestLongArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testLongArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testLongArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testLongArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testLongArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testLongArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testLongArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testLongArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testLongArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testLongArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testLongArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testLongArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testLongArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testLongArray() throws Exception { + super.testLongArray(); + } + + @Override + public void testLongArray(long[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + long[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + long[] ret = tmpl.read(unpacker, ret0); + assertLongArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testLongArray() throws Exception { + super.testLongArray(); + } + + @Override + public void testLongArray(long[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + long[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + long[] ret = tmpl.read(unpacker, ret0); + assertLongArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testLongArray() throws Exception { + super.testLongArray(); + } + + @Override + public void testLongArray(long[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + long[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + long[] ret = tmpl.read(unpacker, ret0); + assertLongArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testLongArray() throws Exception { + super.testLongArray(); + } + + @Override + public void testLongArray(long[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + long[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new long[0]; + } else { + ret0 = new long[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + long[] ret = tmpl.read(unpacker, ret0); + assertLongArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertLongArrayEquals(long[] v, long[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i]); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestLongTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestLongTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestLongTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testLong(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testLong(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testLong(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testLong(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + long ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + long ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + long ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = LongTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + long ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestMapTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestMapTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,133 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestMapTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testMap(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testMap(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testMap(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testMap(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template keyElementTemplate = msgpack.lookup(keyElementClass); + Template valueElementTemplate = msgpack.lookup(valueElementClass); + Template> tmpl = new MapTemplate(keyElementTemplate, valueElementTemplate); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Map ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template keyElementTemplate = msgpack.lookup(keyElementClass); + Template valueElementTemplate = msgpack.lookup(valueElementClass); + Template> tmpl = new MapTemplate(keyElementTemplate, valueElementTemplate); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Map ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template keyElementTemplate = msgpack.lookup(keyElementClass); + Template valueElementTemplate = msgpack.lookup(valueElementClass); + Template> tmpl = new MapTemplate(keyElementTemplate, valueElementTemplate); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + Map ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new MessagePack(); + Template keyElementTemplate = msgpack.lookup(keyElementClass); + Template valueElementTemplate = msgpack.lookup(valueElementClass); + Template> tmpl = new MapTemplate(keyElementTemplate, valueElementTemplate); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + Map ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestShortArrayTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestShortArrayTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,287 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestShortArrayTemplate { + + @Test + public void testPackUnpack00() throws Exception { + new TestPackUnpack(0).testShortArray(); + } + + @Test + public void testPackUnpack01() throws Exception { + new TestPackUnpack(1).testShortArray(); + } + + @Test + public void testPackUnpack02() throws Exception { + new TestPackUnpack(2).testShortArray(); + } + + @Test + public void testPackBufferUnpack00() throws Exception { + new TestPackBufferUnpack(0).testShortArray(); + } + + @Test + public void testPackBufferUnpack01() throws Exception { + new TestPackBufferUnpack(1).testShortArray(); + } + + @Test + public void testPackBufferUnpack02() throws Exception { + new TestPackBufferUnpack(2).testShortArray(); + } + + @Test + public void testBufferPackBufferUnpack00() throws Exception { + new TestBufferPackBufferUnpack(0).testShortArray(); + } + + @Test + public void testBufferPackBufferUnpack01() throws Exception { + new TestBufferPackBufferUnpack(1).testShortArray(); + } + + @Test + public void testBufferPackBufferUnpack02() throws Exception { + new TestBufferPackBufferUnpack(2).testShortArray(); + } + + @Test + public void testBufferPackUnpack00() throws Exception { + new TestBufferPackUnpack(0).testShortArray(); + } + + @Test + public void testBufferPackUnpack01() throws Exception { + new TestBufferPackUnpack(1).testShortArray(); + } + + @Test + public void testBufferPackUnpack02() throws Exception { + new TestBufferPackUnpack(2).testShortArray(); + } + + private static class TestPackUnpack extends TestSet { + private int index; + + TestPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testShortArray() throws Exception { + super.testShortArray(); + } + + @Override + public void testShortArray(short[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + short[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + short[] ret = tmpl.read(unpacker, ret0); + assertShortArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + private int index; + + TestPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testShortArray() throws Exception { + super.testShortArray(); + } + + @Override + public void testShortArray(short[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortArrayTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + short[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + short[] ret = tmpl.read(unpacker, ret0); + assertShortArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + private int index; + + TestBufferPackBufferUnpack(int i) { + index = i; + } + + @Test @Override + public void testShortArray() throws Exception { + super.testShortArray(); + } + + @Override + public void testShortArray(short[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + short[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + short[] ret = tmpl.read(unpacker, ret0); + assertShortArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + private int index; + + TestBufferPackUnpack(int i) { + index = i; + } + + @Test @Override + public void testShortArray() throws Exception { + super.testShortArray(); + } + + @Override + public void testShortArray(short[] v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortArrayTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + short[] ret0; + switch (index) { + case 0: + ret0 = null; + break; + case 1: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[v.length]; + } + break; + case 2: + if (v == null) { + ret0 = new short[0]; + } else { + ret0 = new short[(int) v.length / 2]; + } + break; + default: + throw new IllegalArgumentException(); + } + short[] ret = tmpl.read(unpacker, ret0); + assertShortArrayEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + public static void assertShortArrayEquals(short[] v, short[] ret) { + if (v == null) { + assertEquals(null, ret); + return; + } + assertEquals(v.length, ret.length); + for (int i = 0; i < v.length; ++i) { + assertEquals(v[i], ret[i]); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestShortTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestShortTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestShortTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testShort(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testShort(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testShort(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testShort(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + short ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + short ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + short ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = ShortTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + short ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestStringTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestStringTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,124 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Unpacker; + + +public class TestStringTemplate { + + @Test + public void testPackUnpack() throws Exception { + new TestPackUnpack().testString(); + } + + @Test + public void testPackBufferUnpack() throws Exception { + new TestPackBufferUnpack().testString(); + } + + @Test + public void testBufferPackBufferUnpack() throws Exception { + new TestBufferPackBufferUnpack().testString(); + } + + @Test + public void testBufferPackUnpack() throws Exception { + new TestBufferPackUnpack().testString(); + } + + private static class TestPackUnpack extends TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = StringTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + String ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestPackBufferUnpack extends TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = StringTemplate.instance; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + String ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackBufferUnpack extends TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = StringTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.resetReadByteCount(); + String ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } + + private static class TestBufferPackUnpack extends TestSet { + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = StringTemplate.instance; + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + String ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestTemplateRegistry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestTemplateRegistry.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,38 @@ +package org.msgpack.template; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +public class TestTemplateRegistry { + + private static final TemplateRegistry root = new TemplateRegistry(null); + + static class MyArrayList extends ArrayList { + private static final long serialVersionUID = 1L; + } + + @Test + public void testTraverseInterface() throws Exception { + Template template = root.lookup(List.class); + assertThat(template, is(instanceOf(ListTemplate.class))); + } + + @Test + public void testTraverseDescentInterface() throws Exception { + Template template = root.lookup(MyArrayList.class); + assertThat(template, is(instanceOf(ListTemplate.class))); + } + + @Test + public void testArraysAsListIsPackable() throws Exception { + Template template = root.lookup(Arrays.asList().getClass()); + assertThat(template, is(instanceOf(ListTemplate.class))); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/TestTemplates.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/TestTemplates.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,72 @@ +package org.msgpack.template; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; +import java.util.Collection; +import java.util.Date; +import java.math.BigInteger; +import java.math.BigDecimal; +import java.util.ArrayList; + +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; + +import static org.msgpack.template.Templates.*; + +import org.junit.Test; + + +public class TestTemplates { + public static enum MyEnum { + A, B, C; + } + + @SuppressWarnings("unused") + @Test + public void testGenericsTypesCompliable() throws IOException { + Template tbyte = TByte; + Template tshort = TShort; + Template tinteger = TInteger; + Template tlong = TLong; + Template tcharacter = TCharacter; + Template tbiginteger = TBigInteger; + Template tbigdecimail = TBigDecimal; + Template tfloat = TFloat; + Template tdouble = TDouble; + Template tboolean = TBoolean; + Template tstring = TString; + Template tbytearray = TByteArray; + Template tbytebuffer = TByteBuffer; + Template tdate = TDate; + + Template> tlist = tList(TString); + Template> tmap = tMap(TString, TInteger); + Template> tcollection = tCollection(TLong); + Template tordinalenum = tOrdinalEnum(MyEnum.class); + } + + @Test + public void testList() throws IOException { + MessagePack msgpack = new MessagePack(); + + BufferPacker pk = msgpack.createBufferPacker(); + + Template> t = tList(TString); + List list1 = new ArrayList(); + list1.add("a"); + list1.add("b"); + t.write(pk, list1); + + byte[] raw = pk.toByteArray(); + Unpacker u = msgpack.createBufferUnpacker(raw); + List list2 = t.read(u, new ArrayList()); + + assertEquals(list1, list2); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,480 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestJavassistBufferPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistBufferPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistBufferPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,520 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestJavassistBufferPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,463 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestJavassistBufferPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,501 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestJavassistPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,522 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestJavassistPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestJavassistPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestJavassistPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,483 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestJavassistPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + JavassistTemplateBuilder builder = new JavassistTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,64 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestOrdinalEnumBufferPackBufferUnpack extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,70 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestOrdinalEnumBufferPackConvert extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,64 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestOrdinalEnumBufferPackUnpack extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,68 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestOrdinalEnumPackBufferUnpack extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,74 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestOrdinalEnumPackConvert extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestOrdinalEnumPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,67 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestOrdinalEnumPackUnpack extends TestSet { + + @Test @Override + public void testEnumTypeFieldsClass() throws Exception { + super.testEnumTypeFieldsClass(); + } + + @Override + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClass.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClass.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + EnumTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testEnumTypeFieldsClassNotNullable() throws Exception { + super.testEnumTypeFieldsClassNotNullable(); + } + + @Override + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + registry.register(EnumTypeFieldsClassNotNullable.SampleEnum.class, + new OrdinalEnumTemplateBuilder(registry).buildTemplate(EnumTypeFieldsClassNotNullable.SampleEnum.class)); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(EnumTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + EnumTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,575 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestReflectionBeansBufferPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassFieldsUnpackedInOrder(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + + @Override + public void testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,570 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestReflectionBeansBufferPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,553 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestReflectionBeansBufferPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassFieldsUnpackedInOrder(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,599 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestReflectionBeansPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassFieldsUnpackedInOrder(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,593 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestReflectionBeansPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBeansPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBeansPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,577 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestReflectionBeansPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClass() throws Exception { + super.testIndexedFieldsBeanClass(); + } + + @Override + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + IndexedFieldsBeanClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassFieldsUnpackedInOrder(IndexedFieldsBeanClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + super.testIndexedFieldsBeanClassNotNullable(); + } + + @Override + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + IndexedFieldsBeanClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Override + public void testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(IndexedFieldsBeanClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(IndexedFieldsBeanClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + + unpacker.readArrayBegin(); + assertEquals("alpha", unpacker.readString()); + assertEquals("bravo", unpacker.readString()); + assertEquals("charlie", unpacker.readString()); + assertEquals("delta", unpacker.readString()); + assertEquals("echo", unpacker.readString()); + unpacker.readArrayEnd(); + + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionBeansTemplateBuilder builder = new ReflectionBeansTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,480 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestReflectionBufferPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBufferPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBufferPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,520 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestReflectionBufferPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,463 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestReflectionBufferPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,501 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + + +public class TestReflectionPackBufferUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.resetReadByteCount(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionPackConvert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionPackConvert.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,541 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.type.Value; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.Converter; + + +public class TestReflectionPackConvert extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + BufferUnpacker u = msgpack.createBufferUnpacker(); + u.resetReadByteCount(); + u.wrap(bytes); + Value value = u.readValue(); + Converter unpacker = new Converter(value); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, u.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestReflectionPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestReflectionPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,483 @@ +package org.msgpack.template.builder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.testclasses.AbstractClass; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.Interface; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.Unpacker; + + +public class TestReflectionPackUnpack extends TestSet { + + @Test @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(PrimitiveTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ListTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MapTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(FinalClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testAbstractClass() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(AbstractClass.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testInterface() throws Exception { + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + try { + builder.buildTemplate(Interface.class); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof TemplateBuildException); + } + } + + @Test @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ModifiersFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(UserDefinedTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @Override + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(ReferenceCycleTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(InheritanceClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClass.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + + @Test @Override + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + MessagePack msgpack = new MessagePack(); + TemplateRegistry registry = new TemplateRegistry(null); + ReflectionTemplateBuilder builder = new ReflectionTemplateBuilder(registry); + Template tmpl = builder.buildTemplate(MessagePackableTypeFieldsClassNotNullable.class); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + tmpl.write(packer, v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.resetReadByteCount(); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + assertEquals(bytes.length, unpacker.getReadByteCount()); + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/template/builder/TestSet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/template/builder/TestSet.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,554 @@ +package org.msgpack.template.builder; + +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.junit.Assert; +import org.junit.Ignore; +import org.msgpack.MessageTypeException; +import org.msgpack.testclasses.EnumTypeFieldsClass; +import org.msgpack.testclasses.EnumTypeFieldsClassNotNullable; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.IndexedFieldsBeanClass; +import org.msgpack.testclasses.IndexedFieldsBeanClassNotNullable; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; + + +@Ignore +public class TestSet { + public static byte[] toByteArray(ByteBuffer from) { + byte[] bytes = new byte[from.remaining()]; + from.get(bytes, from.arrayOffset() + from.position(), from.remaining()); + return bytes; + } + + public void testPrimitiveTypeFieldsClass() throws Exception { + testPrimitiveTypeFieldsClass(null); + testPrimitiveTypeFieldsClass(new PrimitiveTypeFieldsClass()); + PrimitiveTypeFieldsClass v = new PrimitiveTypeFieldsClass(); + v.f0 = (byte) 0; + v.f1 = 1; + v.f2 = 2; + v.f3 = 3; + v.f4 = 4; + v.f5 = 5; + v.f6 = false; + testPrimitiveTypeFieldsClass(v); + } + + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) throws Exception { + } + + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + testPrimitiveTypeFieldsClassNotNullable(null); + testPrimitiveTypeFieldsClassNotNullable(new PrimitiveTypeFieldsClassNotNullable()); + PrimitiveTypeFieldsClassNotNullable v = new PrimitiveTypeFieldsClassNotNullable(); + v.f0 = (byte) 0; + v.f1 = 1; + v.f2 = 2; + v.f3 = 3; + v.f4 = 4; + v.f5 = 5; + v.f6 = false; + testPrimitiveTypeFieldsClassNotNullable(v); + } + + public void testPrimitiveTypeFieldsClassNotNullable(PrimitiveTypeFieldsClassNotNullable v) throws Exception { + } + + public void testReferenceTypeFieldsClass() throws Exception { + testReferenceTypeFieldsClass(null); + testReferenceTypeFieldsClass(new ReferenceTypeFieldsClass()); + ReferenceTypeFieldsClass v = new ReferenceTypeFieldsClass(); + v.f0 = 0; + v.f1 = 1; + v.f2 = 2; + v.f3 = (long) 3; + v.f4 = (float) 4; + v.f5 = (double) 5; + v.f6 = false; + v.f7 = new BigInteger("7"); + v.f8 = "8"; + v.f9 = new byte[] { 0x01, 0x02 }; + v.f10 = ByteBuffer.wrap("muga".getBytes()); + testReferenceTypeFieldsClass(v); + } + + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) throws Exception { + } + + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + testReferenceTypeFieldsClassNotNullable(null); + try { + testReferenceTypeFieldsClassNotNullable(new ReferenceTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + ReferenceTypeFieldsClassNotNullable v = new ReferenceTypeFieldsClassNotNullable(); + v.f0 = 0; + v.f1 = 1; + v.f2 = 2; + v.f3 = (long) 3; + v.f4 = (float) 4; + v.f5 = (double) 5; + v.f6 = false; + v.f7 = new BigInteger("7"); + v.f8 = "8"; + v.f9 = new byte[] { 0x01, 0x02 }; + v.f10 = ByteBuffer.wrap("muga".getBytes()); + testReferenceTypeFieldsClassNotNullable(v); + } + + public void testReferenceTypeFieldsClassNotNullable(ReferenceTypeFieldsClassNotNullable v) throws Exception { + } + + public void testListTypeFieldsClass() throws Exception { + testListTypeFieldsClass(null); + testListTypeFieldsClass(new ListTypeFieldsClass()); + ListTypeFieldsClass v = new ListTypeFieldsClass(); + v.f0 = new ArrayList(); + v.f1 = new ArrayList(); + v.f1.add(1); + v.f1.add(2); + v.f1.add(3); + v.f2 = new ArrayList(); + v.f2.add("e1"); + v.f2.add("e2"); + v.f2.add("e3"); + v.f3 = new ArrayList>(); + v.f3.add(v.f2); + v.f4 = new ArrayList(); + ListTypeFieldsClass.NestedClass nested = new ListTypeFieldsClass.NestedClass(); + nested.f0 = new byte[] { 0x01, 0x02 }; + nested.f1 = "muga"; + v.f4.add(nested); + v.f5 = new ArrayList(); + v.f5.add(ByteBuffer.wrap("e1".getBytes())); + v.f5.add(ByteBuffer.wrap("e2".getBytes())); + v.f5.add(ByteBuffer.wrap("e3".getBytes())); + v.f6 = new ArrayList(); + v.f6.add(new int[] { 1, 2, 3 }); + v.f6.add(new int[] { 3, 3, 3 }); + v.f7 = new ArrayList(); + v.f7.add(new String[] { "muga", "nishizawa", "fryusuki" }); + v.f8 = new ArrayList(); + ListTypeFieldsClass.NestedClass nested01 = new ListTypeFieldsClass.NestedClass(); + nested01.f0 = new byte[] { 0x01, 0x02 }; + nested01.f1 = "muga"; + ListTypeFieldsClass.NestedClass nested02 = new ListTypeFieldsClass.NestedClass(); + nested02.f0 = new byte[] { 0x01, 0x02 }; + nested02.f1 = "muga"; + v.f8.add(new ListTypeFieldsClass.NestedClass[] { nested01, nested02 }); + testListTypeFieldsClass(v); + } + + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + } + + public void testListTypeFieldsClassNotNullable() throws Exception { + testListTypeFieldsClassNotNullable(null); + try { + testListTypeFieldsClassNotNullable(new ListTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + ListTypeFieldsClassNotNullable v = new ListTypeFieldsClassNotNullable(); + v.f0 = new ArrayList(); + v.f1 = new ArrayList(); + v.f1.add(1); + v.f1.add(2); + v.f1.add(3); + v.f2 = new ArrayList(); + v.f2.add("e1"); + v.f2.add("e2"); + v.f2.add("e3"); + v.f3 = new ArrayList>(); + v.f3.add(v.f2); + v.f4 = new ArrayList(); + ListTypeFieldsClassNotNullable.NestedClass nested = new ListTypeFieldsClassNotNullable.NestedClass(); + nested.f0 = new byte[] { 0x01, 0x02 }; + nested.f1 = "muga"; + v.f4.add(nested); + v.f5 = new ArrayList(); + v.f5.add(ByteBuffer.wrap("e1".getBytes())); + v.f5.add(ByteBuffer.wrap("e2".getBytes())); + v.f5.add(ByteBuffer.wrap("e3".getBytes())); + v.f6 = new ArrayList(); + v.f6.add(new int[] { 1, 2, 3 }); + v.f6.add(new int[] { 3, 3, 3 }); + v.f7 = new ArrayList(); + v.f7.add(new String[] { "muga", "nishizawa", "fryusuki" }); + v.f8 = new ArrayList(); + ListTypeFieldsClassNotNullable.NestedClass nested01 = new ListTypeFieldsClassNotNullable.NestedClass(); + nested01.f0 = new byte[] { 0x01, 0x02 }; + nested01.f1 = "muga"; + ListTypeFieldsClassNotNullable.NestedClass nested02 = new ListTypeFieldsClassNotNullable.NestedClass(); + nested02.f0 = new byte[] { 0x01, 0x02 }; + nested02.f1 = "muga"; + v.f8.add(new ListTypeFieldsClassNotNullable.NestedClass[] { nested01, nested02 }); + testListTypeFieldsClassNotNullable(v); + } + + public void testListTypeFieldsClassNotNullable(ListTypeFieldsClassNotNullable v) throws Exception { + } + + public void testMapTypeFieldsClass() throws Exception { + testMapTypeFieldsClass(null); + testMapTypeFieldsClass(new MapTypeFieldsClass()); + MapTypeFieldsClass v = new MapTypeFieldsClass(); + v.f0 = new HashMap(); + v.f1 = new HashMap(); + v.f1.put(1, 1); + v.f1.put(2, 2); + v.f1.put(3, 3); + v.f2 = new HashMap(); + v.f2.put("k1", 1); + v.f2.put("k2", 2); + v.f2.put("k3", 3); + v.f3 = new HashMap(); + MapTypeFieldsClass.NestedClass nested01 = new MapTypeFieldsClass.NestedClass(); + nested01.f0 = "muga"; + v.f3.put("muga", nested01); + v.f4 = new HashMap(); + v.f4.put("nishizawa", new int[] { 1, 2, 3 }); + v.f4.put("fryusuki", new int[] { 3, 3, 3 }); + v.f5 = new HashMap(); + v.f5.put("muga", new String[] { "f1", "f2", "f3" }); + v.f5.put("nishizawa", new String[] { "f3", "f2", "f1" }); + v.f6 = new HashMap(); + MapTypeFieldsClass.NestedClass nested02 = new MapTypeFieldsClass.NestedClass(); + nested02.f0 = "nishizawa"; + v.f6.put("muga", new MapTypeFieldsClass.NestedClass[] { nested02 }); + testMapTypeFieldsClass(v); + } + + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + } + + public void testMapTypeFieldsClassNotNullable() throws Exception { + testMapTypeFieldsClass(null); + try { + testMapTypeFieldsClassNotNullable(new MapTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + MapTypeFieldsClassNotNullable v = new MapTypeFieldsClassNotNullable(); + v.f0 = new HashMap(); + v.f1 = new HashMap(); + v.f1.put(1, 1); + v.f1.put(2, 2); + v.f1.put(3, 3); + v.f2 = new HashMap(); + v.f2.put("k1", 1); + v.f2.put("k2", 2); + v.f2.put("k3", 3); + v.f3 = new HashMap(); + MapTypeFieldsClassNotNullable.NestedClass nested = new MapTypeFieldsClassNotNullable.NestedClass(); + nested.f0 = "muga"; + v.f3.put("muga", nested); + v.f4 = new HashMap(); + v.f4.put("nishizawa", new int[] { 1, 2, 3 }); + v.f4.put("fryusuki", new int[] { 3, 3, 3 }); + v.f5 = new HashMap(); + v.f5.put("muga", new String[] { "f1", "f2", "f3" }); + v.f5.put("nishizawa", new String[] { "f3", "f2", "f1" }); + v.f6 = new HashMap(); + MapTypeFieldsClassNotNullable.NestedClass nested02 = new MapTypeFieldsClassNotNullable.NestedClass(); + nested02.f0 = "nishizawa"; + v.f6.put("muga", new MapTypeFieldsClassNotNullable.NestedClass[] { nested02 }); + testMapTypeFieldsClassNotNullable(v); + } + + public void testMapTypeFieldsClassNotNullable(MapTypeFieldsClassNotNullable v) throws Exception { + } + + public void testFinalClass() throws Exception { + testFinalClass(null); + testFinalClass(new FinalClass()); + FinalClass v = new FinalClass(); + v.f0 = 10; + v.f1 = "muga"; + testFinalClass(v); + } + + public void testFinalClass(FinalClass v) throws Exception { + } + + public void testAbstractClass() throws Exception { + } + + public void testInterface() throws Exception { + } + + public void testEnumTypeFieldsClass() throws Exception { + testEnumTypeFieldsClass(null); + testEnumTypeFieldsClass(new EnumTypeFieldsClass()); + EnumTypeFieldsClass v = new EnumTypeFieldsClass(); + v.f0 = 0; + v.f1 = EnumTypeFieldsClass.SampleEnum.ONE; + testEnumTypeFieldsClass(v); + } + + public void testEnumTypeFieldsClass(EnumTypeFieldsClass v) throws Exception { + } + + public void testEnumTypeFieldsClassNotNullable() throws Exception { + testEnumTypeFieldsClassNotNullable(null); + try { + testEnumTypeFieldsClassNotNullable(new EnumTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + EnumTypeFieldsClassNotNullable v = new EnumTypeFieldsClassNotNullable(); + v.f0 = 0; + v.f1 = EnumTypeFieldsClassNotNullable.SampleEnum.ONE; + testEnumTypeFieldsClassNotNullable(v); + } + + public void testEnumTypeFieldsClassNotNullable(EnumTypeFieldsClassNotNullable v) throws Exception { + } + + public void testModifiersFieldsClass() throws Exception { + testModifiersFieldsClass(null); + testModifiersFieldsClass(new ModifiersFieldsClass()); + ModifiersFieldsClass v = new ModifiersFieldsClass(); + v.f0 = 0; + v.f4 = "muga"; + testModifiersFieldsClass(v); + } + + public void testModifiersFieldsClass(ModifiersFieldsClass v) throws Exception { + } + + public void testModifiersFieldsClassNotNullable() throws Exception { + testModifiersFieldsClassNotNullable(null); + try { + testModifiersFieldsClassNotNullable(new ModifiersFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + ModifiersFieldsClassNotNullable v = new ModifiersFieldsClassNotNullable(); + v.f0 = 0; + v.f4 = "muga"; + testModifiersFieldsClassNotNullable(v); + } + + public void testModifiersFieldsClassNotNullable(ModifiersFieldsClassNotNullable v) throws Exception { + } + + public void testUserDefinedTypeFieldsClass() throws Exception { + testUserDefinedTypeFieldsClass(null); + testUserDefinedTypeFieldsClass(new UserDefinedTypeFieldsClass()); + UserDefinedTypeFieldsClass v = new UserDefinedTypeFieldsClass(); + v.f0 = new UserDefinedTypeFieldsClass.NestedClass1(); + v.f0.f0 = 0; + v.f0.f1 = "muga"; + v.f1 = new UserDefinedTypeFieldsClass.NestedClass2(); + v.f1.f0 = 0; + v.f1.f1 = "nishizawa"; + testUserDefinedTypeFieldsClass(v); + } + + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) throws Exception { + } + + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + testUserDefinedTypeFieldsClassNotNullable(null); + try { + testUserDefinedTypeFieldsClassNotNullable(new UserDefinedTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + UserDefinedTypeFieldsClassNotNullable v = new UserDefinedTypeFieldsClassNotNullable(); + v.f0 = new UserDefinedTypeFieldsClassNotNullable.NestedClass1(); + v.f0.f0 = 0; + v.f0.f1 = "muga"; + v.f1 = new UserDefinedTypeFieldsClassNotNullable.NestedClass2(); + v.f1.f0 = 0; + v.f1.f1 = "nishizawa"; + testUserDefinedTypeFieldsClassNotNullable(v); + } + + public void testUserDefinedTypeFieldsClassNotNullable(UserDefinedTypeFieldsClassNotNullable v) throws Exception { + } + + public void testReferenceCycleTypeFieldsClass() throws Exception { + testReferenceCycleTypeFieldsClass(null); + testReferenceCycleTypeFieldsClass(new ReferenceCycleTypeFieldsClass()); + ReferenceCycleTypeFieldsClass v = new ReferenceCycleTypeFieldsClass(); + v.f0 = new ReferenceCycleTypeFieldsClass(); + v.f1 = new ReferenceCycleTypeFieldsClass.NestedClass(); + v.f1.f0 = new ReferenceCycleTypeFieldsClass(); + v.f2 = "muga"; + testReferenceCycleTypeFieldsClass(v); + } + + public void testReferenceCycleTypeFieldsClass(ReferenceCycleTypeFieldsClass v) throws Exception { + } + + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + testReferenceCycleTypeFieldsClassNotNullable(null); + try { + testReferenceCycleTypeFieldsClassNotNullable(new ReferenceCycleTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + try { + ReferenceCycleTypeFieldsClassNotNullable v = new ReferenceCycleTypeFieldsClassNotNullable(); + v.f0 = new ReferenceCycleTypeFieldsClassNotNullable(); + v.f1 = new ReferenceCycleTypeFieldsClassNotNullable.NestedClass(); + v.f1.f0 = new ReferenceCycleTypeFieldsClassNotNullable(); + v.f2 = "muga"; + testReferenceCycleTypeFieldsClassNotNullable(v); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + } + + public void testReferenceCycleTypeFieldsClassNotNullable(ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + } + + public void testIndexedFieldsBeanClass() throws Exception { + testIndexedFieldsBeanClass(null); + testIndexedFieldsBeanClass(new IndexedFieldsBeanClass()); + IndexedFieldsBeanClass v = new IndexedFieldsBeanClass(); + v.f5 = "alpha"; + v.f4 = "echo"; + v.f3 = "bravo"; + v.f2 = "delta"; + v.f1 = "charlie"; + testIndexedFieldsBeanClass(v); + testIndexedFieldsBeanClassFieldsUnpackedInOrder(v); + } + + public void testIndexedFieldsBeanClass(IndexedFieldsBeanClass v) throws Exception { + } + + public void testIndexedFieldsBeanClassFieldsUnpackedInOrder(IndexedFieldsBeanClass v) throws Exception { + } + + public void testIndexedFieldsBeanClassNotNullable() throws Exception { + testIndexedFieldsBeanClassNotNullable(null); + try { + testIndexedFieldsBeanClassNotNullable(new IndexedFieldsBeanClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + + IndexedFieldsBeanClassNotNullable v = new IndexedFieldsBeanClassNotNullable(); + v.f5 = "alpha"; + v.f4 = "echo"; + v.f3 = "bravo"; + v.f2 = "delta"; + v.f1 = "charlie"; + testIndexedFieldsBeanClassNotNullable(v); + testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(v); + } + + public void testIndexedFieldsBeanClassNotNullable(IndexedFieldsBeanClassNotNullable v) throws Exception { + } + + public void testIndexedFieldsBeanClassNotNullableFieldsUnpackedInOrder(IndexedFieldsBeanClassNotNullable v) throws Exception { + } + + public void testInheritanceClass() throws Exception { + testInheritanceClass(null); + testInheritanceClass(new InheritanceClass()); + InheritanceClass v = new InheritanceClass(); + v.f0 = "muga"; + v.f1 = "furuhashi"; + v.f2 = 10; + testInheritanceClass(v); + } + + public void testInheritanceClass(InheritanceClass v) throws Exception { + } + + public void testInheritanceClassNotNullable() throws Exception { + testInheritanceClassNotNullable(null); + try { + testInheritanceClassNotNullable(new InheritanceClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + InheritanceClassNotNullable v = new InheritanceClassNotNullable(); + v.f0 = "muga"; + v.f1 = "furuhashi"; + v.f2 = 10; + testInheritanceClassNotNullable(v); + } + + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) throws Exception { + } + + public void testMessagePackableTypeFieldsClass() throws Exception { + testMessagePackableTypeFieldsClass(null); + testMessagePackableTypeFieldsClass(new MessagePackableTypeFieldsClass()); + MessagePackableTypeFieldsClass v = new MessagePackableTypeFieldsClass(); + v.f0 = "muga"; + v.f1 = new MessagePackableTypeFieldsClass.NestedClass(); + v.f1.f0 = "nishizawa"; + v.f1.f1 = new int[] { 1, 2, 3 }; + v.f1.f2 = new ArrayList(); + v.f1.f2.add("muga"); + v.f1.f2.add("frsyuki"); + v.f1.f2.add("msgpack"); + testMessagePackableTypeFieldsClass(v); + } + + public void testMessagePackableTypeFieldsClass(MessagePackableTypeFieldsClass v) throws Exception { + } + + public void testMessagePackableTypeFieldsClassNotNullable() throws Exception { + testMessagePackableTypeFieldsClassNotNullable(null); + try { + testMessagePackableTypeFieldsClassNotNullable(new MessagePackableTypeFieldsClassNotNullable()); + Assert.fail(); + } catch (Throwable t) { + Assert.assertTrue(t instanceof MessageTypeException); + } + MessagePackableTypeFieldsClassNotNullable v = new MessagePackableTypeFieldsClassNotNullable(); + v.f0 = "muga"; + v.f1 = new MessagePackableTypeFieldsClassNotNullable.NestedClass(); + v.f1.f0 = "nishizawa"; + v.f1.f1 = new int[] { 1, 2, 3 }; + v.f1.f2 = new ArrayList(); + v.f1.f2.add("muga"); + v.f1.f2.add("frsyuki"); + v.f1.f2.add("msgpack"); + testMessagePackableTypeFieldsClassNotNullable(v); + } + + public void testMessagePackableTypeFieldsClassNotNullable(MessagePackableTypeFieldsClassNotNullable v) throws Exception { + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/AbstractClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/AbstractClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,15 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public abstract class AbstractClass { + + @Override + public boolean equals(Object o) { + return o instanceof AbstractClass; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/EnumTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/EnumTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,52 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.OrdinalEnum; + + +@Ignore @Message @Beans +public class EnumTypeFieldsClass { + public int f0; + + public SampleEnum f1; + + public EnumTypeFieldsClass() {} + + public int getF0() { + return f0; + } + + public void setF0(int f0) { + this.f0 = f0; + } + + public SampleEnum getF1() { + return f1; + } + + public void setF1(SampleEnum f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof EnumTypeFieldsClass)) { + return false; + } + EnumTypeFieldsClass that = (EnumTypeFieldsClass) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + return true; + } + + @Ignore @OrdinalEnum + public static enum SampleEnum { + ONE, TWO, THREE; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/EnumTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/EnumTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,59 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; +import org.msgpack.annotation.OrdinalEnum; + + +@Ignore @Message @Beans +public class EnumTypeFieldsClassNotNullable { + @NotNullable + public int f0; + + @NotNullable + public SampleEnum f1; + + public EnumTypeFieldsClassNotNullable() {} + + @NotNullable + public int getF0() { + return f0; + } + + @NotNullable + public void setF0(int f0) { + this.f0 = f0; + } + + @NotNullable + public SampleEnum getF1() { + return f1; + } + + @NotNullable + public void setF1(SampleEnum f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof EnumTypeFieldsClassNotNullable)) { + return false; + } + EnumTypeFieldsClassNotNullable that = (EnumTypeFieldsClassNotNullable) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + return true; + } + + @Ignore @OrdinalEnum + public static enum SampleEnum { + ONE, TWO, THREE; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/FinalClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/FinalClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,54 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public final class FinalClass { + public int f0; + + public String f1; + + public FinalClass() { + } + + public int getF0() { + return f0; + } + + public void setF0(int f0) { + this.f0 = f0; + } + + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof FinalClass)) { + return false; + } + FinalClass that = (FinalClass) o; + if (f0 != that.f0) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/IndexedFieldsBeanClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/IndexedFieldsBeanClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,114 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Index; +import org.msgpack.annotation.MessagePackBeans; + +@Ignore @MessagePackBeans +public class IndexedFieldsBeanClass { + + public String f5; + + public String f4; + + public String f3; + + public String f2; + + public String f1; + + @Index(0) + public String getF5() { + return f5; + } + + public void setF5(String f5) { + this.f5 = f5; + } + + @Index(4) + public String getF4() { + return f4; + } + + public void setF4(String f4) { + this.f4 = f4; + } + + public String getF3() { + return f3; + } + + @Index(1) + public void setF3(String f3) { + this.f3 = f3; + } + + public String getF2() { + return f2; + } + + @Index(3) + public void setF2(String f2) { + this.f2 = f2; + } + + @Index(2) + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof IndexedFieldsBeanClass)) { + return false; + } + IndexedFieldsBeanClass that = (IndexedFieldsBeanClass) o; + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null && ! f3.equals(that.f3)) { + return false; + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null && ! f2.equals(that.f2)) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null && ! f1.equals(that.f1)) { + return false; + } + + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/IndexedFieldsBeanClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/IndexedFieldsBeanClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,118 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.*; + +@Ignore @MessagePackBeans +public class IndexedFieldsBeanClassNotNullable { + + public String f5; + + public String f4; + + public String f3; + + public String f2; + + public String f1; + + @Index(0) @NotNullable + public String getF5() { + return f5; + } + + @NotNullable + public void setF5(String f5) { + this.f5 = f5; + } + + @Index(4) @NotNullable + public String getF4() { + return f4; + } + + @NotNullable + public void setF4(String f4) { + this.f4 = f4; + } + + @NotNullable + public String getF3() { + return f3; + } + + @Index(1) @NotNullable + public void setF3(String f3) { + this.f3 = f3; + } + + @NotNullable + public String getF2() { + return f2; + } + + @Index(3) @NotNullable + public void setF2(String f2) { + this.f2 = f2; + } + + @Index(2) @NotNullable + public String getF1() { + return f1; + } + + @NotNullable + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof IndexedFieldsBeanClassNotNullable)) { + return false; + } + IndexedFieldsBeanClassNotNullable that = (IndexedFieldsBeanClassNotNullable) o; + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null && ! f3.equals(that.f3)) { + return false; + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null && ! f2.equals(that.f2)) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null && ! f1.equals(that.f1)) { + return false; + } + + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/InheritanceClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/InheritanceClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,66 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class InheritanceClass extends SuperClass { + public String f1; + + public int f2; + + public InheritanceClass() {} + + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + public int getF2() { + return f2; + } + + public void setF2(int f2) { + this.f2 = f2; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof InheritanceClass)) { + return false; + } + InheritanceClass that = (InheritanceClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + // f2 + if (f2 != that.f2) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/InheritanceClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/InheritanceClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,73 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class InheritanceClassNotNullable extends SuperClassNotNullable { + @NotNullable + public String f1; + + @NotNullable + public int f2; + + public InheritanceClassNotNullable() {} + + @NotNullable + public String getF1() { + return f1; + } + + @NotNullable + public void setF1(String f1) { + this.f1 = f1; + } + + @NotNullable + public int getF2() { + return f2; + } + + @NotNullable + public void setF2(int f2) { + this.f2 = f2; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof InheritanceClassNotNullable)) { + return false; + } + InheritanceClassNotNullable that = (InheritanceClassNotNullable) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + // f2 + if (f2 != that.f2) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/Interface.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/Interface.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,10 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public interface Interface { +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ListTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ListTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,369 @@ +package org.msgpack.testclasses; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.List; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.template.builder.TestSet; + + +@Ignore @Message @Beans +public class ListTypeFieldsClass { + public List f0; + + public List f1; + + public List f2; + + public List> f3; + + public List f4; + + public List f5; + + public List f6; + + public List f7; + + public List f8; + + public ListTypeFieldsClass() { + } + + public List getF0() { + return f0; + } + + public void setF0(List f0) { + this.f0 = f0; + } + + public List getF1() { + return f1; + } + + public void setF1(List f1) { + this.f1 = f1; + } + + public List getF2() { + return f2; + } + + public void setF2(List f2) { + this.f2 = f2; + } + + public List> getF3() { + return f3; + } + + public void setF3(List> f3) { + this.f3 = f3; + } + + public List getF4() { + return f4; + } + + public void setF4(List f4) { + this.f4 = f4; + } + + public List getF5() { + return f5; + } + + public void setF5(List f5) { + this.f5 = f5; + } + + public List getF6() { + return f6; + } + + public void setF6(List f6) { + this.f6 = f6; + } + + public List getF7() { + return f7; + } + + public void setF7(List f7) { + this.f7 = f7; + } + + public List getF8() { + return f8; + } + + public void setF8(List f8) { + this.f8 = f8; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ListTypeFieldsClass)) { + return false; + } + ListTypeFieldsClass that = (ListTypeFieldsClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (f0.size() != that.f0.size()) { + return false; + } + Iterator this_f0_iter = f0.iterator(); + Iterator that_f0_iter = that.f0.iterator(); + for (; this_f0_iter.hasNext();) { + if (!this_f0_iter.next().equals(that_f0_iter.next())) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (f1.size() != that.f1.size()) { + return false; + } + Iterator this_f1_iter = f1.iterator(); + Iterator that_f1_iter = that.f1.iterator(); + for (; this_f1_iter.hasNext();) { + if (!this_f1_iter.next().equals(that_f1_iter.next())) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + if (f2.size() != that.f2.size()) { + return false; + } + Iterator this_f2_iter = f2.iterator(); + Iterator that_f2_iter = that.f2.iterator(); + for (; this_f2_iter.hasNext();) { + if (!this_f2_iter.next().equals(that_f2_iter.next())) { + return false; + } + } + } + // f3 + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null) { + if (f3.size() != that.f3.size()) { + return false; + } + Iterator> this_f3_iter = f3.iterator(); + Iterator> that_f3_iter = that.f3.iterator(); + for (; this_f3_iter.hasNext();) { + List l0 = this_f3_iter.next(); + List l1 = that_f3_iter.next(); + if (l0.size() != l1.size()) { + return false; + } + Iterator l0_iter = l0.iterator(); + Iterator l1_iter = l1.iterator(); + for (; l0_iter.hasNext();) { + if (!l0_iter.next().equals(l1_iter.next())) { + return false; + } + } + } + } + // f4 + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null) { + if (f4.size() != that.f4.size()) { + return false; + } + Iterator this_f4_iter = f4.iterator(); + Iterator that_f4_iter = that.f4.iterator(); + for (; this_f4_iter.hasNext();) { + if (!this_f4_iter.next().equals(that_f4_iter.next())) { + return false; + } + } + } + // f5 + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null) { + if (f5.size() != that.f5.size()) { + return false; + } + Iterator this_f5_iter = f5.iterator(); + Iterator that_f5_iter = that.f5.iterator(); + for (; this_f5_iter.hasNext();) { + byte[] b0 = TestSet.toByteArray(this_f5_iter.next()); + byte[] b1 = TestSet.toByteArray(that_f5_iter.next()); + if (b0.length != b1.length) { + return false; + } + for (int i = 0; i < b0.length; ++i) { + if (b0[i] != b1[i]) { + return false; + } + } + } + } + // f6 + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null) { + if (f6.size() != that.f6.size()) { + return false; + } + Iterator this_f6_iter = f6.iterator(); + Iterator that_f6_iter = that.f6.iterator(); + for (; this_f6_iter.hasNext();) { + int[] this_f6_elm = this_f6_iter.next(); + int[] that_f6_elm = that_f6_iter.next(); + for (int i = 0; i < this_f6_elm.length; i++) { + if (this_f6_elm[i] != that_f6_elm[i]) { + return false; + } + } + } + } + // f7 + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null) { + if (f7.size() != that.f7.size()) { + return false; + } + Iterator this_f7_iter = f7.iterator(); + Iterator that_f7_iter = that.f7.iterator(); + for (; this_f7_iter.hasNext();) { + String[] this_f7_elm = this_f7_iter.next(); + String[] that_f7_elm = that_f7_iter.next(); + for (int i = 0; i < this_f7_elm.length; i++) { + if (!this_f7_elm[i].equals(that_f7_elm[i])) { + return false; + } + } + } + } + // f8 + if (f8 == null) { + if (that.f8 != null) { + return false; + } + } + if (that.f8 != null) { + if (f8.size() != that.f8.size()) { + return false; + } + Iterator this_f8_iter = f8.iterator(); + Iterator that_f8_iter = that.f8.iterator(); + for (; this_f8_iter.hasNext();) { + NestedClass[] this_f8_elm = this_f8_iter.next(); + NestedClass[] that_f8_elm = that_f8_iter.next(); + for (int i = 0; i < this_f8_elm.length; i++) { + if (!this_f8_elm[i].equals(that_f8_elm[i])) { + return false; + } + } + } + } + + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + public byte[] f0; + + public String f1; + + public NestedClass() {} + + public byte[] getF0() { + return f0; + } + + public void setF0(byte[] f0) { + this.f0 = f0; + } + + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (f0.length != that.f0.length) { + return false; + } + for (int i = 0; i < f0.length; ++i) { + if (f0[i] != that.f0[i]) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (!f1.equals(that.f1)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ListTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ListTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,403 @@ +package org.msgpack.testclasses; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.List; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; +import org.msgpack.template.builder.TestSet; + + +@Ignore @Message @Beans +public class ListTypeFieldsClassNotNullable { + @NotNullable + public List f0; + + @NotNullable + public List f1; + + @NotNullable + public List f2; + + @NotNullable + public List> f3; + + @NotNullable + public List f4; + + @NotNullable + public List f5; + + @NotNullable + public List f6; + + @NotNullable + public List f7; + + @NotNullable + public List f8; + + public ListTypeFieldsClassNotNullable() { + } + + @NotNullable + public List getF0() { + return f0; + } + + @NotNullable + public void setF0(List f0) { + this.f0 = f0; + } + + @NotNullable + public List getF1() { + return f1; + } + + @NotNullable + public void setF1(List f1) { + this.f1 = f1; + } + + @NotNullable + public List getF2() { + return f2; + } + + @NotNullable + public void setF2(List f2) { + this.f2 = f2; + } + + @NotNullable + public List> getF3() { + return f3; + } + + @NotNullable + public void setF3(List> f3) { + this.f3 = f3; + } + + @NotNullable + public List getF4() { + return f4; + } + + @NotNullable + public void setF4(List f4) { + this.f4 = f4; + } + + @NotNullable + public List getF5() { + return f5; + } + + @NotNullable + public void setF5(List f5) { + this.f5 = f5; + } + + @NotNullable + public List getF6() { + return f6; + } + + @NotNullable + public void setF6(List f6) { + this.f6 = f6; + } + + @NotNullable + public List getF7() { + return f7; + } + + @NotNullable + public void setF7(List f7) { + this.f7 = f7; + } + + @NotNullable + public List getF8() { + return f8; + } + + @NotNullable + public void setF8(List f8) { + this.f8 = f8; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ListTypeFieldsClassNotNullable)) { + return false; + } + ListTypeFieldsClassNotNullable that = (ListTypeFieldsClassNotNullable) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (f0.size() != that.f0.size()) { + return false; + } + Iterator this_f0_iter = f0.iterator(); + Iterator that_f0_iter = that.f0.iterator(); + for (; this_f0_iter.hasNext();) { + if (!this_f0_iter.next().equals(that_f0_iter.next())) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (f1.size() != that.f1.size()) { + return false; + } + Iterator this_f1_iter = f1.iterator(); + Iterator that_f1_iter = that.f1.iterator(); + for (; this_f1_iter.hasNext();) { + if (!this_f1_iter.next().equals(that_f1_iter.next())) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + if (f2.size() != that.f2.size()) { + return false; + } + Iterator this_f2_iter = f2.iterator(); + Iterator that_f2_iter = that.f2.iterator(); + for (; this_f2_iter.hasNext();) { + if (!this_f2_iter.next().equals(that_f2_iter.next())) { + return false; + } + } + } + // f3 + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null) { + if (f3.size() != that.f3.size()) { + return false; + } + Iterator> this_f3_iter = f3.iterator(); + Iterator> that_f3_iter = that.f3.iterator(); + for (; this_f3_iter.hasNext();) { + List l0 = this_f3_iter.next(); + List l1 = that_f3_iter.next(); + if (l0.size() != l1.size()) { + return false; + } + Iterator l0_iter = l0.iterator(); + Iterator l1_iter = l1.iterator(); + for (; l0_iter.hasNext();) { + if (!l0_iter.next().equals(l1_iter.next())) { + return false; + } + } + } + } + // f4 + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null) { + if (f4.size() != that.f4.size()) { + return false; + } + Iterator this_f4_iter = f4.iterator(); + Iterator that_f4_iter = that.f4.iterator(); + for (; this_f4_iter.hasNext();) { + if (!this_f4_iter.next().equals(that_f4_iter.next())) { + return false; + } + } + } + // f5 + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null) { + if (f5.size() != that.f5.size()) { + return false; + } + Iterator this_f5_iter = f5.iterator(); + Iterator that_f5_iter = that.f5.iterator(); + for (; this_f5_iter.hasNext();) { + byte[] b0 = TestSet.toByteArray(this_f5_iter.next()); + byte[] b1 = TestSet.toByteArray(that_f5_iter.next()); + if (b0.length != b1.length) { + return false; + } + for (int i = 0; i < b0.length; ++i) { + if (b0[i] != b1[i]) { + return false; + } + } + } + } + // f6 + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null) { + if (f6.size() != that.f6.size()) { + return false; + } + Iterator this_f6_iter = f6.iterator(); + Iterator that_f6_iter = that.f6.iterator(); + for (; this_f6_iter.hasNext();) { + int[] this_f6_elm = this_f6_iter.next(); + int[] that_f6_elm = that_f6_iter.next(); + for (int i = 0; i < this_f6_elm.length; i++) { + if (this_f6_elm[i] != that_f6_elm[i]) { + return false; + } + } + } + } + // f7 + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null) { + if (f7.size() != that.f7.size()) { + return false; + } + Iterator this_f7_iter = f7.iterator(); + Iterator that_f7_iter = that.f7.iterator(); + for (; this_f7_iter.hasNext();) { + String[] this_f7_elm = this_f7_iter.next(); + String[] that_f7_elm = that_f7_iter.next(); + for (int i = 0; i < this_f7_elm.length; i++) { + if (!this_f7_elm[i].equals(that_f7_elm[i])) { + return false; + } + } + } + } + // f8 + if (f8 == null) { + if (that.f8 != null) { + return false; + } + } + if (that.f8 != null) { + if (f8.size() != that.f8.size()) { + return false; + } + Iterator this_f8_iter = f8.iterator(); + Iterator that_f8_iter = that.f8.iterator(); + for (; this_f8_iter.hasNext();) { + NestedClass[] this_f8_elm = this_f8_iter.next(); + NestedClass[] that_f8_elm = that_f8_iter.next(); + for (int i = 0; i < this_f8_elm.length; i++) { + if (!this_f8_elm[i].equals(that_f8_elm[i])) { + return false; + } + } + } + } + + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + @NotNullable + public byte[] f0; + + @NotNullable + public String f1; + + public NestedClass() {} + + @NotNullable + public byte[] getF0() { + return f0; + } + + @NotNullable + public void setF0(byte[] f0) { + this.f0 = f0; + } + + @NotNullable + public String getF1() { + return f1; + } + + @NotNullable + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (f0.length != that.f0.length) { + return false; + } + for (int i = 0; i < f0.length; ++i) { + if (f0[i] != that.f0[i]) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (!f1.equals(that.f1)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/MapTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/MapTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,243 @@ +package org.msgpack.testclasses; + +import java.util.Map; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class MapTypeFieldsClass { + public Map f0; + + public Map f1; + + public Map f2; + + public Map f3; + + public Map f4; + + public Map f5; + + public Map f6; + + public MapTypeFieldsClass() { + } + + public Map getF0() { + return f0; + } + + public void setF0(Map f0) { + this.f0 = f0; + } + + public Map getF1() { + return f1; + } + + public void setF1(Map f1) { + this.f1 = f1; + } + + public Map getF2() { + return f2; + } + + public void setF2(Map f2) { + this.f2 = f2; + } + + public Map getF3() { + return f3; + } + + public void setF3(Map f3) { + this.f3 = f3; + } + + public Map getF4() { + return f4; + } + + public void setF4(Map f4) { + this.f4 = f4; + } + + public Map getF5() { + return f5; + } + + public void setF5(Map f5) { + this.f5 = f5; + } + + public Map getF6() { + return f6; + } + + public void setF6(Map f6) { + this.f6 = f6; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof MapTypeFieldsClass)) { + return false; + } + MapTypeFieldsClass that = (MapTypeFieldsClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + for (Map.Entry e : f0.entrySet()) { + Integer key = e.getKey(); + Integer val = that.f0.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + for (Map.Entry e : f1.entrySet()) { + Integer key = e.getKey(); + Integer val = that.f1.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + for (Map.Entry e : f2.entrySet()) { + String key = e.getKey(); + Integer val = that.f2.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f3 + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null) { + for (Map.Entry e : f3.entrySet()) { + String key = e.getKey(); + NestedClass val = that.f3.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f4 + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null) { + for (Map.Entry e : f4.entrySet()) { + String key = e.getKey(); + int[] this_val = e.getValue(); + int[] that_val = that.f4.get(key); + for (int i = 0; i < this_val.length; i++) { + if (this_val[i] != that_val[i]) { + return false; + } + } + } + } + // f5 + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null) { + for (Map.Entry e : f5.entrySet()) { + String key = e.getKey(); + String[] this_val = e.getValue(); + String[] that_val = that.f5.get(key); + for (int i = 0; i < this_val.length; i++) { + if (!this_val[i].equals(that_val[i])) { + return false; + } + } + } + } + // f6 + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null) { + for (Map.Entry e : f6.entrySet()) { + String key = e.getKey(); + NestedClass[] this_val = e.getValue(); + NestedClass[] that_val = that.f6.get(key); + for (int i = 0; i < this_val.length; i++) { + if (!this_val[i].equals(that_val[i])) { + return false; + } + } + } + } + + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + public String f0; + + public NestedClass() {} + + public String getF0() { + return f0; + } + + public void setF0(String f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/MapTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/MapTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,268 @@ +package org.msgpack.testclasses; + +import java.util.Map; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class MapTypeFieldsClassNotNullable { + @NotNullable + public Map f0; + + @NotNullable + public Map f1; + + @NotNullable + public Map f2; + + @NotNullable + public Map f3; + + @NotNullable + public Map f4; + + @NotNullable + public Map f5; + + @NotNullable + public Map f6; + + public MapTypeFieldsClassNotNullable() { + } + + @NotNullable + public Map getF0() { + return f0; + } + + @NotNullable + public void setF0(Map f0) { + this.f0 = f0; + } + + @NotNullable + public Map getF1() { + return f1; + } + + @NotNullable + public void setF1(Map f1) { + this.f1 = f1; + } + + @NotNullable + public Map getF2() { + return f2; + } + + @NotNullable + public void setF2(Map f2) { + this.f2 = f2; + } + + @NotNullable + public Map getF3() { + return f3; + } + + @NotNullable + public void setF3(Map f3) { + this.f3 = f3; + } + + @NotNullable + public Map getF4() { + return f4; + } + + @NotNullable + public void setF4(Map f4) { + this.f4 = f4; + } + + @NotNullable + public Map getF5() { + return f5; + } + + @NotNullable + public void setF5(Map f5) { + this.f5 = f5; + } + + @NotNullable + public Map getF6() { + return f6; + } + + @NotNullable + public void setF6(Map f6) { + this.f6 = f6; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof MapTypeFieldsClassNotNullable)) { + return false; + } + MapTypeFieldsClassNotNullable that = (MapTypeFieldsClassNotNullable) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + for (Map.Entry e : f0.entrySet()) { + Integer key = e.getKey(); + Integer val = that.f0.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + for (Map.Entry e : f1.entrySet()) { + Integer key = e.getKey(); + Integer val = that.f1.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + for (Map.Entry e : f2.entrySet()) { + String key = e.getKey(); + Integer val = that.f2.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f3 + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null) { + for (Map.Entry e : f3.entrySet()) { + String key = e.getKey(); + NestedClass val = that.f3.get(key); + if (!e.getValue().equals(val)) { + return false; + } + } + } + // f4 + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null) { + for (Map.Entry e : f4.entrySet()) { + String key = e.getKey(); + int[] this_val = e.getValue(); + int[] that_val = that.f4.get(key); + for (int i = 0; i < this_val.length; i++) { + if (this_val[i] != that_val[i]) { + return false; + } + } + } + } + // f5 + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null) { + for (Map.Entry e : f5.entrySet()) { + String key = e.getKey(); + String[] this_val = e.getValue(); + String[] that_val = that.f5.get(key); + for (int i = 0; i < this_val.length; i++) { + if (!this_val[i].equals(that_val[i])) { + return false; + } + } + } + } + // f6 + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null) { + for (Map.Entry e : f6.entrySet()) { + String key = e.getKey(); + NestedClass[] this_val = e.getValue(); + NestedClass[] that_val = that.f6.get(key); + for (int i = 0; i < this_val.length; i++) { + if (!this_val[i].equals(that_val[i])) { + return false; + } + } + } + } + + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + @NotNullable + public String f0; + + public NestedClass() {} + + @NotNullable + public String getF0() { + return f0; + } + + @NotNullable + public void setF0(String f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/MessagePackableTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/MessagePackableTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,202 @@ +package org.msgpack.testclasses; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Ignore; +import org.msgpack.MessagePackable; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + + +@Ignore @Message @Beans +public class MessagePackableTypeFieldsClass { + public String f0; + + public NestedClass f1; + + public MessagePackableTypeFieldsClass() {} + + public String getF0() { + return f0; + } + + public void setF0(String f0) { + this.f0 = f0; + } + + public NestedClass getF1() { + return f1; + } + + public void setF1(NestedClass f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof MessagePackableTypeFieldsClass)) { + return false; + } + MessagePackableTypeFieldsClass that = (MessagePackableTypeFieldsClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + + @Ignore + public static class NestedClass implements MessagePackable { + public String f0; + + public int[] f1; + + public List f2; + + public NestedClass() { } + + public String getF0() { + return f0; + } + + public void setF0(String f0) { + this.f0 = f0; + } + + public int[] getF1() { + return f1; + } + + public void setF1(int[] f1) { + this.f1 = f1; + } + + public List getF2() { + return f2; + } + + public void setF2(List f2) { + this.f2 = f2; + } + + public void writeTo(Packer packer) throws IOException { + packer.writeArrayBegin(3); + { + packer.write(f0); + packer.writeArrayBegin(f1.length); + { + for(int e : f1) { + packer.write(e); + } + } + packer.writeArrayEnd(); + packer.writeArrayBegin(f2.size()); + { + for(String e : f2) { + packer.write(e); + } + } + packer.writeArrayEnd(); + } + packer.writeArrayEnd(); + } + + public void readFrom(Unpacker uunpacker) throws IOException { + uunpacker.readArrayBegin(); + { + f0 = uunpacker.readString(); + int nf1 = uunpacker.readArrayBegin(); + { + f1 = new int[nf1]; + for(int i=0; i < nf1; i++) { + f1[i] = uunpacker.readInt(); + } + } + uunpacker.readArrayEnd(); + int nf2 = uunpacker.readArrayBegin(); + { + f2 = new ArrayList(nf2); + for(int i=0; i < nf2; i++) { + f2.add(uunpacker.readString()); + } + } + uunpacker.readArrayEnd(); + } + uunpacker.readArrayEnd(); + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (f1.length != that.f1.length) { + return false; + } + for (int i = 0; i < f1.length; ++i) { + if (f1[i] != that.f1[i]) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + Iterator this_f2_iter = f2.iterator(); + Iterator that_f2_iter = that.f2.iterator(); + for (; this_f2_iter.hasNext(); ) { + if (! this_f2_iter.next().equals(that_f2_iter.next())) { + return false; + } + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/MessagePackableTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/MessagePackableTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,204 @@ +package org.msgpack.testclasses; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Ignore; +import org.msgpack.MessagePackable; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; + + +@Ignore @Message @Beans +public class MessagePackableTypeFieldsClassNotNullable { + @NotNullable + public String f0; + + @NotNullable + public NestedClass f1; + + public MessagePackableTypeFieldsClassNotNullable() { + } + + @NotNullable + public String getF0() { + return f0; + } + + @NotNullable + public void setF0(String f0) { + this.f0 = f0; + } + + @NotNullable + public NestedClass getF1() { + return f1; + } + + @NotNullable + public void setF1(NestedClass f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof MessagePackableTypeFieldsClassNotNullable)) { + return false; + } + MessagePackableTypeFieldsClassNotNullable that = (MessagePackableTypeFieldsClassNotNullable) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + + @Ignore + public static class NestedClass implements MessagePackable { + public String f0; + + public int[] f1; + + public List f2; + + public NestedClass() { } + + @NotNullable + public String getF0() { + return f0; + } + + @NotNullable + public void setF0(String f0) { + this.f0 = f0; + } + + @NotNullable + public int[] getF1() { + return f1; + } + + @NotNullable + public void setF1(int[] f1) { + this.f1 = f1; + } + + @NotNullable + public List getF2() { + return f2; + } + + @NotNullable + public void setF2(List f2) { + this.f2 = f2; + } + + public void writeTo(Packer packer) throws IOException { + packer.writeArrayBegin(3); + packer.write(f0); + packer.writeArrayBegin(f1.length); + for(int e : f1) { + packer.write(e); + } + packer.writeArrayEnd(); + packer.writeArrayBegin(f2.size()); + for(String e : f2) { + packer.write(e); + } + packer.writeArrayEnd(); + packer.writeArrayEnd(); + } + + public void readFrom(Unpacker uunpacker) throws IOException { + uunpacker.readArrayBegin(); + f0 = uunpacker.readString(); + int nf1 = uunpacker.readArrayBegin(); + f1 = new int[nf1]; + for(int i=0; i < nf1; i++) { + f1[i] = uunpacker.readInt(); + } + uunpacker.readArrayEnd(); + int nf2 = uunpacker.readArrayBegin(); + f2 = new ArrayList(nf2); + for(int i=0; i < nf2; i++) { + f2.add(uunpacker.readString()); + } + uunpacker.readArrayEnd(); + uunpacker.readArrayEnd(); + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (f1.length != that.f1.length) { + return false; + } + for (int i = 0; i < f1.length; ++i) { + if (f1[i] != that.f1[i]) { + return false; + } + } + } + // f2 + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + Iterator this_f2_iter = f2.iterator(); + Iterator that_f2_iter = that.f2.iterator(); + for (; this_f2_iter.hasNext(); ) { + if (! this_f2_iter.next().equals(that_f2_iter.next())) { + return false; + } + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ModifiersFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ModifiersFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,136 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class ModifiersFieldsClass { + public int f0; + + private int f1 = 5; + + protected int f2 = 10; + + int f3 = 15; + + public String f4; + + private String f5 = "nishizawa"; + + protected String f6 = "muga"; + + String f7 = "hello"; + + public ModifiersFieldsClass() {} + + public int getF0() { + return f0; + } + + public void setF0(int f0) { + this.f0 = f0; + } + + public int getF2() { + return f2; + } + + public void setF2(int f2) { + this.f2 = f2; + } + + public int getF3() { + return f3; + } + + public void setF3(int f3) { + this.f3 = f3; + } + + public String getF4() { + return f4; + } + + public void setF4(String f4) { + this.f4 = f4; + } + + public String getF5() { + return f5; + } + + public void setF5(String f5) { + this.f5 = f5; + } + + public String getF6() { + return f6; + } + + public void setF6(String f6) { + this.f6 = f6; + } + + public String getF7() { + return f7; + } + + public void setF7(String f7) { + this.f7 = f7; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ModifiersFieldsClass)) { + return false; + } + ModifiersFieldsClass that = (ModifiersFieldsClass) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + if (f2 != that.f2) { + return false; + } + if (f3 != that.f3) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null && ! f6.equals(that.f6)) { + return false; + } + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null && ! f7.equals(that.f7)) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ModifiersFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ModifiersFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,159 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class ModifiersFieldsClassNotNullable { + @NotNullable + public int f0; + + @NotNullable + private int f1 = 5; + + @NotNullable + protected int f2 = 10; + + @NotNullable + int f3 = 15; + + @NotNullable + public String f4; + + @NotNullable + private String f5 = "nishizawa"; + + @NotNullable + protected String f6 = "hello"; + + @NotNullable + String f7 = "muga"; + + public ModifiersFieldsClassNotNullable() {} + + @NotNullable + public int getF0() { + return f0; + } + + @NotNullable + public void setF0(int f0) { + this.f0 = f0; + } + + @NotNullable + public int getF2() { + return f2; + } + + @NotNullable + public void setF2(int f2) { + this.f2 = f2; + } + + @NotNullable + public int getF3() { + return f3; + } + + @NotNullable + public void setF3(int f3) { + this.f3 = f3; + } + + @NotNullable + public String getF4() { + return f4; + } + + @NotNullable + public void setF4(String f4) { + this.f4 = f4; + } + + @NotNullable + public String getF5() { + return f5; + } + + @NotNullable + public void setF5(String f5) { + this.f5 = f5; + } + + @NotNullable + public String getF6() { + return f6; + } + + @NotNullable + public void setF6(String f6) { + this.f6 = f6; + } + + @NotNullable + public String getF7() { + return f7; + } + + @NotNullable + public void setF7(String f7) { + this.f7 = f7; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ModifiersFieldsClassNotNullable)) { + return false; + } + ModifiersFieldsClassNotNullable that = (ModifiersFieldsClassNotNullable) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + if (f2 != that.f2) { + return false; + } + if (f3 != that.f3) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null && ! f6.equals(that.f6)) { + return false; + } + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null && ! f7.equals(that.f7)) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/PrimitiveTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/PrimitiveTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,111 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class PrimitiveTypeFieldsClass { + public byte f0; + + public short f1; + + public int f2; + + public long f3; + + public float f4; + + public double f5; + + public boolean f6; + + public PrimitiveTypeFieldsClass() {} + + public byte getF0() { + return f0; + } + + public void setF0(byte f0) { + this.f0 = f0; + } + + public short getF1() { + return f1; + } + + public void setF1(short f1) { + this.f1 = f1; + } + + public int getF2() { + return f2; + } + + public void setF2(int f2) { + this.f2 = f2; + } + + public long getF3() { + return f3; + } + + public void setF3(long f3) { + this.f3 = f3; + } + + public float getF4() { + return f4; + } + + public void setF4(float f4) { + this.f4 = f4; + } + + public double getF5() { + return f5; + } + + public void setF5(double f5) { + this.f5 = f5; + } + + public boolean isF6() { + return f6; + } + + public void setF6(boolean f6) { + this.f6 = f6; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof PrimitiveTypeFieldsClass)) { + return false; + } + PrimitiveTypeFieldsClass that = (PrimitiveTypeFieldsClass) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + if (f2 != that.f2) { + return false; + } + if (f3 != that.f3) { + return false; + } + if (f4 != that.f4) { + return false; + } + if (f5 != that.f5) { + return false; + } + if (f6 != that.f6) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/PrimitiveTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/PrimitiveTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,132 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class PrimitiveTypeFieldsClassNotNullable { + @NotNullable + public byte f0; + + @NotNullable + public short f1; + + @NotNullable + public int f2; + + @NotNullable + public long f3; + + @NotNullable + public float f4; + + @NotNullable + public double f5; + + @NotNullable + public boolean f6; + + public PrimitiveTypeFieldsClassNotNullable() {} + + public byte getF0() { + return f0; + } + + @NotNullable + public void setF0(byte f0) { + this.f0 = f0; + } + + @NotNullable + public short getF1() { + return f1; + } + + @NotNullable + public void setF1(short f1) { + this.f1 = f1; + } + + @NotNullable + public int getF2() { + return f2; + } + + @NotNullable + public void setF2(int f2) { + this.f2 = f2; + } + + @NotNullable + public long getF3() { + return f3; + } + + @NotNullable + public void setF3(long f3) { + this.f3 = f3; + } + + @NotNullable + public float getF4() { + return f4; + } + + @NotNullable + public void setF4(float f4) { + this.f4 = f4; + } + + @NotNullable + public double getF5() { + return f5; + } + + @NotNullable + public void setF5(double f5) { + this.f5 = f5; + } + + @NotNullable + public boolean isF6() { + return f6; + } + + @NotNullable + public void setF6(boolean f6) { + this.f6 = f6; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof PrimitiveTypeFieldsClassNotNullable)) { + return false; + } + PrimitiveTypeFieldsClassNotNullable that = (PrimitiveTypeFieldsClassNotNullable) o; + if (f0 != that.f0) { + return false; + } + if (f1 != that.f1) { + return false; + } + if (f2 != that.f2) { + return false; + } + if (f3 != that.f3) { + return false; + } + if (f4 != that.f4) { + return false; + } + if (f5 != that.f5) { + return false; + } + if (f6 != that.f6) { + return false; + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ReferenceCycleTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ReferenceCycleTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,115 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class ReferenceCycleTypeFieldsClass { + + public ReferenceCycleTypeFieldsClass f0; + + public NestedClass f1; + + public String f2; + + public ReferenceCycleTypeFieldsClass() {} + + public void setF0(ReferenceCycleTypeFieldsClass f0) { + this.f0 = f0; + } + + public ReferenceCycleTypeFieldsClass getF0() { + return f0; + } + + public void setF1(NestedClass f1) { + this.f1 = f1; + } + + public NestedClass getF1() { + return f1; + } + + public void setF2(String f2) { + this.f2 = f2; + } + + public String getF2() { + return f2; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof ReferenceCycleTypeFieldsClass)) { + return false; + } + ReferenceCycleTypeFieldsClass that = (ReferenceCycleTypeFieldsClass) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (!f0.equals(that.f0)) { + return false; + } + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (!f1.equals(that.f1)) { + return false; + } + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + if (!f2.equals(that.f2)) { + return false; + } + } + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + public ReferenceCycleTypeFieldsClass f0; + + public NestedClass() {} + + public ReferenceCycleTypeFieldsClass getF0() { + return f0; + } + + public void setF0(ReferenceCycleTypeFieldsClass f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ReferenceCycleTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ReferenceCycleTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,123 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class ReferenceCycleTypeFieldsClassNotNullable { + + @NotNullable + public ReferenceCycleTypeFieldsClassNotNullable f0; + + @NotNullable + public NestedClass f1; + + @NotNullable + public String f2; + + public ReferenceCycleTypeFieldsClassNotNullable() {} + + @NotNullable + public ReferenceCycleTypeFieldsClassNotNullable getF0() { + return f0; + } + + @NotNullable + public void setF1(NestedClass f1) { + this.f1 = f1; + } + + @NotNullable + public NestedClass getF1() { + return f1; + } + + @NotNullable + public void setF2(String f2) { + this.f2 = f2; + } + + @NotNullable + public String getF2() { + return f2; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof ReferenceCycleTypeFieldsClassNotNullable)) { + return false; + } + ReferenceCycleTypeFieldsClassNotNullable that = (ReferenceCycleTypeFieldsClassNotNullable) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (!f0.equals(that.f0)) { + return false; + } + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (!f1.equals(that.f1)) { + return false; + } + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null) { + if (!f2.equals(that.f2)) { + return false; + } + } + return true; + } + + @Ignore @Message @Beans + public static class NestedClass { + @NotNullable + public ReferenceCycleTypeFieldsClassNotNullable f0; + + public NestedClass() {} + + @NotNullable + public ReferenceCycleTypeFieldsClassNotNullable getF0() { + return f0; + } + + @NotNullable + public void setF0(ReferenceCycleTypeFieldsClassNotNullable f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass)) { + return false; + } + NestedClass that = (NestedClass) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } + } +} \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ReferenceTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ReferenceTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,232 @@ +package org.msgpack.testclasses; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.template.builder.TestSet; + + +@Ignore @Message @Beans +public class ReferenceTypeFieldsClass { + public Byte f0; + + public Short f1; + + public Integer f2; + + public Long f3; + + public Float f4; + + public Double f5; + + public Boolean f6; + + public BigInteger f7; + + public String f8; + + public byte[] f9; + + public ByteBuffer f10; + + public ReferenceTypeFieldsClass() {} + + public Byte getF0() { + return f0; + } + + public void setF0(Byte f0) { + this.f0 = f0; + } + + public Short getF1() { + return f1; + } + + public void setF1(Short f1) { + this.f1 = f1; + } + + public Integer getF2() { + return f2; + } + + public void setF2(Integer f2) { + this.f2 = f2; + } + + public Long getF3() { + return f3; + } + + public void setF3(Long f3) { + this.f3 = f3; + } + + public Float getF4() { + return f4; + } + + public void setF4(Float f4) { + this.f4 = f4; + } + + public Double getF5() { + return f5; + } + + public void setF5(Double f5) { + this.f5 = f5; + } + + public Boolean getF6() { + return f6; + } + + public void setF6(Boolean f6) { + this.f6 = f6; + } + + public BigInteger getF7() { + return f7; + } + + public void setF7(BigInteger f7) { + this.f7 = f7; + } + + public String getF8() { + return f8; + } + + public void setF8(String f8) { + this.f8 = f8; + } + + public byte[] getF9() { + return f9; + } + + public void setF9(byte[] f9) { + this.f9 = f9; + } + + public ByteBuffer getF10() { + return f10; + } + + public void setF10(ByteBuffer f10) { + this.f10 = f10; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ReferenceTypeFieldsClass)) { + return false; + } + ReferenceTypeFieldsClass that = (ReferenceTypeFieldsClass) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null && ! f0.equals(that.f0)) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null && ! f1.equals(that.f1)) { + return false; + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null && ! f2.equals(that.f2)) { + return false; + } + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null && ! f3.equals(that.f3)) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null && ! f6.equals(that.f6)) { + return false; + } + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null && ! f7.equals(that.f7)) { + return false; + } + if (f8 == null) { + if (that.f8 != null) { + return false; + } + } + if (that.f8 != null && ! f8.equals(that.f8)) { + return false; + } + if (f9 == null) { + if (that.f9 != null) { + return false; + } + } + if (that.f9 != null) { + for (int i = 0; i < f9.length; ++i) { + if (f9[i] != that.f9[i]) { + return false; + } + } + } + if (f10 == null) { + if (that.f10 != null) { + return false; + } + } + if (that.f10 != null) { + byte[] b0 = TestSet.toByteArray(f10); + byte[] b1 = TestSet.toByteArray(that.f10); + for (int i = 0; i < b0.length; ++i) { + if (b0[i] != b1[i]) { + return false; + } + } + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/ReferenceTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/ReferenceTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,266 @@ +package org.msgpack.testclasses; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; +import org.msgpack.template.builder.TestSet; + + +@Ignore @Message @Beans +public class ReferenceTypeFieldsClassNotNullable { + @NotNullable + public Byte f0; + + @NotNullable + public Short f1; + + @NotNullable + public Integer f2; + + @NotNullable + public Long f3; + + @NotNullable + public Float f4; + + @NotNullable + public Double f5; + + @NotNullable + public Boolean f6; + + @NotNullable + public BigInteger f7; + + @NotNullable + public String f8; + + @NotNullable + public byte[] f9; + + @NotNullable + public ByteBuffer f10; + + public ReferenceTypeFieldsClassNotNullable() {} + + @NotNullable + public Byte getF0() { + return f0; + } + + @NotNullable + public void setF0(Byte f0) { + this.f0 = f0; + } + + @NotNullable + public Short getF1() { + return f1; + } + + @NotNullable + public void setF1(Short f1) { + this.f1 = f1; + } + + @NotNullable + public Integer getF2() { + return f2; + } + + @NotNullable + public void setF2(Integer f2) { + this.f2 = f2; + } + + @NotNullable + public Long getF3() { + return f3; + } + + @NotNullable + public void setF3(Long f3) { + this.f3 = f3; + } + + @NotNullable + public Float getF4() { + return f4; + } + + @NotNullable + public void setF4(Float f4) { + this.f4 = f4; + } + + @NotNullable + public Double getF5() { + return f5; + } + + @NotNullable + public void setF5(Double f5) { + this.f5 = f5; + } + + @NotNullable + public Boolean getF6() { + return f6; + } + + @NotNullable + public void setF6(Boolean f6) { + this.f6 = f6; + } + + @NotNullable + public BigInteger getF7() { + return f7; + } + + @NotNullable + public void setF7(BigInteger f7) { + this.f7 = f7; + } + + @NotNullable + public String getF8() { + return f8; + } + + @NotNullable + public void setF8(String f8) { + this.f8 = f8; + } + + @NotNullable + public byte[] getF9() { + return f9; + } + + @NotNullable + public void setF9(byte[] f9) { + this.f9 = f9; + } + + @NotNullable + public ByteBuffer getF10() { + return f10; + } + + @NotNullable + public void setF10(ByteBuffer f10) { + this.f10 = f10; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof ReferenceTypeFieldsClassNotNullable)) { + return false; + } + ReferenceTypeFieldsClassNotNullable that = (ReferenceTypeFieldsClassNotNullable) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null && ! f0.equals(that.f0)) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null && ! f1.equals(that.f1)) { + return false; + } + if (f2 == null) { + if (that.f2 != null) { + return false; + } + } + if (that.f2 != null && ! f2.equals(that.f2)) { + return false; + } + if (f3 == null) { + if (that.f3 != null) { + return false; + } + } + if (that.f3 != null && ! f3.equals(that.f3)) { + return false; + } + if (f4 == null) { + if (that.f4 != null) { + return false; + } + } + if (that.f4 != null && ! f4.equals(that.f4)) { + return false; + } + if (f5 == null) { + if (that.f5 != null) { + return false; + } + } + if (that.f5 != null && ! f5.equals(that.f5)) { + return false; + } + if (f6 == null) { + if (that.f6 != null) { + return false; + } + } + if (that.f6 != null && ! f6.equals(that.f6)) { + return false; + } + if (f7 == null) { + if (that.f7 != null) { + return false; + } + } + if (that.f7 != null && ! f7.equals(that.f7)) { + return false; + } + if (f8 == null) { + if (that.f8 != null) { + return false; + } + } + if (that.f8 != null && ! f8.equals(that.f8)) { + return false; + } + if (f9 == null) { + if (that.f9 != null) { + return false; + } + } + if (that.f9 != null) { + for (int i = 0; i < f9.length; ++i) { + if (f9[i] != that.f9[i]) { + return false; + } + } + } + if (f10 == null) { + if (that.f10 != null) { + return false; + } + } + if (that.f10 != null) { + byte[] b0 = TestSet.toByteArray(f10); + byte[] b1 = TestSet.toByteArray(that.f10); + for (int i = 0; i < b0.length; ++i) { + if (b0[i] != b1[i]) { + return false; + } + } + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/SuperClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/SuperClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,40 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class SuperClass { + public String f0; + + public SuperClass() {} + + public String getF0() { + return f0; + } + + public void setF0(String f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof SuperClass)) { + return false; + } + SuperClass that = (SuperClass) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/SuperClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/SuperClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,44 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class SuperClassNotNullable { + @NotNullable + public String f0; + + public SuperClassNotNullable() {} + + @NotNullable + public String getF0() { + return f0; + } + + @NotNullable + public void setF0(String f0) { + this.f0 = f0; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof SuperClassNotNullable)) { + return false; + } + SuperClassNotNullable that = (SuperClassNotNullable) o; + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + return true; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/UserDefinedTypeFieldsClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/UserDefinedTypeFieldsClass.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,156 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; + + +@Ignore @Message @Beans +public class UserDefinedTypeFieldsClass { + public NestedClass1 f0; + + public NestedClass2 f1; + + public UserDefinedTypeFieldsClass () {} + + public NestedClass1 getF0() { + return f0; + } + + public void setF0(NestedClass1 f0) { + this.f0 = f0; + } + + public NestedClass2 getF1() { + return f1; + } + + public void setF1(NestedClass2 f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof UserDefinedTypeFieldsClass)) { + return false; + } + UserDefinedTypeFieldsClass that = (UserDefinedTypeFieldsClass) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + + @Ignore @Message @Beans + public static class NestedClass1 { + public int f0; + + public String f1; + + public NestedClass1() {} + + public int getF0() { + return f0; + } + + public void setF0(int f0) { + this.f0 = f0; + } + + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass1)) { + return false; + } + NestedClass1 that = (NestedClass1) o; + if (f0 != that.f0) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + } + + @Ignore @Message @Beans + public static class NestedClass2 { + public int f0; + + public String f1; + + public NestedClass2() {} + + public int getF0() { + return f0; + } + + public void setF0(int f0) { + this.f0 = f0; + } + + public String getF1() { + return f1; + } + + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass2)) { + return false; + } + NestedClass2 that = (NestedClass2) o; + if (f0 != that.f0) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/testclasses/UserDefinedTypeFieldsClassNotNullable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/testclasses/UserDefinedTypeFieldsClassNotNullable.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,175 @@ +package org.msgpack.testclasses; + +import org.junit.Ignore; +import org.msgpack.annotation.Beans; +import org.msgpack.annotation.Message; +import org.msgpack.annotation.NotNullable; + + +@Ignore @Message @Beans +public class UserDefinedTypeFieldsClassNotNullable { + @NotNullable + public NestedClass1 f0; + + @NotNullable + public NestedClass2 f1; + + public UserDefinedTypeFieldsClassNotNullable () {} + + @NotNullable + public NestedClass1 getF0() { + return f0; + } + + @NotNullable + public void setF0(NestedClass1 f0) { + this.f0 = f0; + } + + @NotNullable + public NestedClass2 getF1() { + return f1; + } + + @NotNullable + public void setF1(NestedClass2 f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof UserDefinedTypeFieldsClassNotNullable)) { + return false; + } + UserDefinedTypeFieldsClassNotNullable that = (UserDefinedTypeFieldsClassNotNullable) o; + // f0 + if (f0 == null) { + if (that.f0 != null) { + return false; + } + } + if (that.f0 != null) { + if (! f0.equals(that.f0)) { + return false; + } + } + // f1 + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + + @Ignore @Message @Beans + public static class NestedClass1 { + @NotNullable + public int f0; + + @NotNullable + public String f1; + + public NestedClass1() {} + + @NotNullable + public int getF0() { + return f0; + } + + @NotNullable + public void setF0(int f0) { + this.f0 = f0; + } + + @NotNullable + public String getF1() { + return f1; + } + + @NotNullable + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass1)) { + return false; + } + NestedClass1 that = (NestedClass1) o; + if (f0 != that.f0) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + } + + @Ignore @Message @Beans + public static class NestedClass2 { + @NotNullable + public int f0; + + @NotNullable + public String f1; + + public NestedClass2() {} + + @NotNullable + public int getF0() { + return f0; + } + + @NotNullable + public void setF0(int f0) { + this.f0 = f0; + } + + @NotNullable + public String getF1() { + return f1; + } + + @NotNullable + public void setF1(String f1) { + this.f1 = f1; + } + + @Override + public boolean equals(Object o) { + if (! (o instanceof NestedClass2)) { + return false; + } + NestedClass2 that = (NestedClass2) o; + if (f0 != that.f0) { + return false; + } + if (f1 == null) { + if (that.f1 != null) { + return false; + } + } + if (that.f1 != null) { + if (! f1.equals(that.f1)) { + return false; + } + } + return true; + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/type/ProxyValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/type/ProxyValue.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,111 @@ +package org.msgpack.type; + +import java.io.IOException; + +import org.msgpack.packer.Packer; + +public abstract class ProxyValue implements Value { + public ProxyValue() { + } + + protected abstract Value getValue(); + + public ValueType getType() { + return getValue().getType(); + } + + @Override + public boolean isNilValue() { + return getValue().isNilValue(); + } + + @Override + public boolean isBooleanValue() { + return getValue().isBooleanValue(); + } + + @Override + public boolean isIntegerValue() { + return getValue().isIntegerValue(); + } + + @Override + public boolean isFloatValue() { + return getValue().isFloatValue(); + } + + @Override + public boolean isArrayValue() { + return getValue().isArrayValue(); + } + + @Override + public boolean isMapValue() { + return getValue().isMapValue(); + } + + @Override + public boolean isRawValue() { + return getValue().isRawValue(); + } + + @Override + public NilValue asNilValue() { + return getValue().asNilValue(); + } + + @Override + public BooleanValue asBooleanValue() { + return getValue().asBooleanValue(); + } + + @Override + public IntegerValue asIntegerValue() { + return getValue().asIntegerValue(); + } + + @Override + public FloatValue asFloatValue() { + return getValue().asFloatValue(); + } + + @Override + public ArrayValue asArrayValue() { + return getValue().asArrayValue(); + } + + @Override + public MapValue asMapValue() { + return getValue().asMapValue(); + } + + @Override + public RawValue asRawValue() { + return getValue().asRawValue(); + } + + @Override + public void writeTo(Packer pk) throws IOException { + getValue().writeTo(pk); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + return getValue().toString(sb); + } + + @Override + public String toString() { + return getValue().toString(); + } + + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + return getValue().equals(o); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/type/TestEquals.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/type/TestEquals.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,300 @@ +package org.msgpack.type; + +import static org.junit.Assert.assertTrue; + +import java.math.BigInteger; + +import org.junit.Test; +import org.msgpack.TestSet; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + +public class TestEquals extends TestSet { + @Override + public void testBoolean(boolean v) throws Exception { + Value a = ValueFactory.createBooleanValue(v); + Value b = ValueFactory.createBooleanValue(v); + testEquals(a, b); + } + + @Override + public void testBooleanArray(boolean[] v) throws Exception { + Value[] vs1 = new Value[v.length]; + Value[] vs2 = new Value[v.length]; + for (int i = 0; i < v.length; i++) { + vs1[i] = ValueFactory.createBooleanValue(v[i]); + vs2[i] = ValueFactory.createBooleanValue(v[i]); + } + Value v1 = ValueFactory.createArrayValue(vs1); + Value v2 = ValueFactory.createArrayValue(vs2); + testEquals(v1, v2); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + Value v1 = ValueFactory.createRawValue(v); + Value v2 = ValueFactory.createRawValue(v); + testEquals(v1, v2); + } + + @Override + public void testString(String v) throws Exception { + Value v1 = ValueFactory.createRawValue(v); + Value v2 = ValueFactory.createRawValue(v); + testEquals(v1, v2); + } + + @Override + public void testFloat(float v) throws Exception { + Value v1 = ValueFactory.createFloatValue(v); + Value v2 = ValueFactory.createFloatValue(v); + testEquals(v1, v2); + } + + @Override + public void testDouble(double v) throws Exception { + Value v1 = ValueFactory.createFloatValue(v); + Value v2 = ValueFactory.createFloatValue(v); + testEquals(v1, v2); + } + + @Test + public void testMapOrder() throws Exception { + Value v1 = ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k0"), + ValueFactory.createNilValue(), + ValueFactory.createRawValue("k1"), + ValueFactory.createRawValue("v1"), + ValueFactory.createRawValue("k2"), + ValueFactory.createRawValue("v2"), + ValueFactory.createRawValue("k3"), + ValueFactory.createRawValue("v3"), + ValueFactory.createRawValue("k4"), + ValueFactory.createRawValue("v4"), + ValueFactory.createRawValue("k5"), + ValueFactory.createRawValue("v5"), + ValueFactory.createRawValue("k6"), + ValueFactory.createRawValue("v6"), + ValueFactory.createRawValue("k7"), + ValueFactory.createRawValue("v7"), + ValueFactory.createRawValue("k8"), + ValueFactory.createRawValue("v8"), + ValueFactory.createRawValue("k9"), + ValueFactory.createRawValue("v9"), + ValueFactory.createRawValue("k10"), + ValueFactory.createRawValue("v10"), + ValueFactory.createRawValue("k11"), + ValueFactory.createRawValue("v11"), + ValueFactory.createRawValue("k12"), + ValueFactory.createRawValue("v12"), + ValueFactory.createRawValue("k13"), + ValueFactory.createRawValue("v13"), + ValueFactory.createRawValue("k14"), + ValueFactory.createRawValue("v14"), + ValueFactory.createRawValue("k15"), + ValueFactory.createRawValue("v15"), + ValueFactory.createRawValue("k16"), + ValueFactory.createRawValue("v16"), + ValueFactory.createRawValue("k17"), + ValueFactory.createRawValue("v17"), + ValueFactory.createRawValue("k18"), + ValueFactory.createRawValue("v18"), + ValueFactory.createRawValue("k19"), + ValueFactory.createRawValue("v19"), }); + Value v2 = ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k3"), + ValueFactory.createRawValue("v3"), + ValueFactory.createRawValue("k11"), + ValueFactory.createRawValue("v11"), + ValueFactory.createRawValue("k4"), + ValueFactory.createRawValue("v4"), + ValueFactory.createRawValue("k10"), + ValueFactory.createRawValue("v10"), + ValueFactory.createRawValue("k5"), + ValueFactory.createRawValue("v5"), + ValueFactory.createRawValue("k6"), + ValueFactory.createRawValue("v6"), + ValueFactory.createRawValue("k15"), + ValueFactory.createRawValue("v15"), + ValueFactory.createRawValue("k7"), + ValueFactory.createRawValue("v7"), + ValueFactory.createRawValue("k14"), + ValueFactory.createRawValue("v14"), + ValueFactory.createRawValue("k8"), + ValueFactory.createRawValue("v8"), + ValueFactory.createRawValue("k13"), + ValueFactory.createRawValue("v13"), + ValueFactory.createRawValue("k9"), + ValueFactory.createRawValue("v9"), + ValueFactory.createRawValue("k12"), + ValueFactory.createRawValue("v12"), + ValueFactory.createRawValue("k0"), + ValueFactory.createNilValue(), + ValueFactory.createRawValue("k1"), + ValueFactory.createRawValue("v1"), + ValueFactory.createRawValue("k2"), + ValueFactory.createRawValue("v2"), + ValueFactory.createRawValue("k18"), + ValueFactory.createRawValue("v18"), + ValueFactory.createRawValue("k19"), + ValueFactory.createRawValue("v19"), + ValueFactory.createRawValue("k16"), + ValueFactory.createRawValue("v16"), + ValueFactory.createRawValue("k17"), + ValueFactory.createRawValue("v17"), }); + testEquals(v1, v2); + } + + @Override + public void testByte(byte v) throws Exception { + testLong((long) v); + } + + @Override + public void testShort(short v) throws Exception { + testLong((long) v); + } + + @Override + public void testInteger(int v) throws Exception { + testLong((long) v); + } + + @Override + public void testLong(long v) throws Exception { + testBigInteger(BigInteger.valueOf(v)); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + if (compatibleWithByte(v)) { + Value vt = ValueFactory.createIntegerValue(v); + Value vByte = ValueFactory.createIntegerValue(v.byteValue()); + Value vShort = ValueFactory.createIntegerValue(v.shortValue()); + Value vInt = ValueFactory.createIntegerValue(v.intValue()); + Value vLong = ValueFactory.createIntegerValue(v.longValue()); + Value vBigInteger = ValueFactory.createIntegerValue(v); + testEquals(vt, vByte); + testEquals(vt, vShort); + testEquals(vt, vInt); + testEquals(vt, vLong); + testEquals(vt, vBigInteger); + } + if (compatibleWithShort(v)) { + Value vt = ValueFactory.createIntegerValue(v); + Value vShort = ValueFactory.createIntegerValue(v.shortValue()); + Value vInt = ValueFactory.createIntegerValue(v.intValue()); + Value vLong = ValueFactory.createIntegerValue(v.longValue()); + Value vBigInteger = ValueFactory.createIntegerValue(v); + testEquals(vt, vShort); + testEquals(vt, vInt); + testEquals(vt, vLong); + testEquals(vt, vBigInteger); + } + if (compatibleWithInt(v)) { + Value vt = ValueFactory.createIntegerValue(v); + Value vInt = ValueFactory.createIntegerValue(v.intValue()); + Value vLong = ValueFactory.createIntegerValue(v.longValue()); + Value vBigInteger = ValueFactory.createIntegerValue(v); + testEquals(vt, vInt); + testEquals(vt, vLong); + testEquals(vt, vBigInteger); + } + if (compatibleWithLong(v)) { + Value vt = ValueFactory.createIntegerValue(v); + Value vLong = ValueFactory.createIntegerValue(v.longValue()); + Value vBigInteger = ValueFactory.createIntegerValue(v); + testEquals(vt, vLong); + testEquals(vt, vBigInteger); + } + { + Value vt = ValueFactory.createIntegerValue(v); + Value vInt = ValueFactory.createIntegerValue(v.intValue()); + Value vBigInteger = ValueFactory.createIntegerValue(v); + testEquals(vt, vInt); + testEquals(vt, vBigInteger); + } + } + + @Test + public void testNull() { + Value v1 = ValueFactory.createNilValue(); + Value v2 = ValueFactory.createNilValue(); + testEquals(v1, v2); + } + + @SuppressWarnings("unused") + private boolean compatibleWithByte(long v) { + return (long) Byte.MIN_VALUE <= v && v <= (long) Byte.MAX_VALUE; + } + + @SuppressWarnings("unused") + private boolean compatibleWithShort(long v) { + return (long) Short.MIN_VALUE <= v && v <= (long) Short.MAX_VALUE; + } + + @SuppressWarnings("unused") + private boolean compatibleWithInt(long v) { + return (long) Integer.MIN_VALUE <= v && v <= (long) Integer.MAX_VALUE; + } + + private static BigInteger BYTE_MAX = BigInteger + .valueOf((long) Byte.MAX_VALUE); + private static BigInteger SHORT_MAX = BigInteger + .valueOf((long) Short.MAX_VALUE); + private static BigInteger INT_MAX = BigInteger + .valueOf((long) Integer.MAX_VALUE); + private static BigInteger LONG_MAX = BigInteger + .valueOf((long) Long.MAX_VALUE); + + private static BigInteger BYTE_MIN = BigInteger + .valueOf((long) Byte.MIN_VALUE); + private static BigInteger SHORT_MIN = BigInteger + .valueOf((long) Short.MIN_VALUE); + private static BigInteger INT_MIN = BigInteger + .valueOf((long) Integer.MIN_VALUE); + private static BigInteger LONG_MIN = BigInteger + .valueOf((long) Long.MIN_VALUE); + + protected boolean compatibleWithByte(BigInteger v) { + if (v.compareTo(BYTE_MAX) > 0 || v.compareTo(BYTE_MIN) < 0) { + return false; + } + return true; + } + + protected boolean compatibleWithShort(BigInteger v) { + if (v.compareTo(SHORT_MAX) > 0 || v.compareTo(SHORT_MIN) < 0) { + return false; + } + return true; + } + + protected boolean compatibleWithInt(BigInteger v) { + if (v.compareTo(INT_MAX) > 0 || v.compareTo(INT_MIN) < 0) { + return false; + } + return true; + } + + protected boolean compatibleWithLong(BigInteger v) { + if (v.compareTo(LONG_MAX) > 0 || v.compareTo(LONG_MIN) < 0) { + return false; + } + return true; + } + + protected void testEquals(final Value v1, final Value v2) { + assertTrue(v2.equals(v1)); + assertTrue(v2.equals(new ProxyValue() { + protected Value getValue() { + return v1; + } + })); + assertTrue(v1.equals(new ProxyValue() { + protected Value getValue() { + return v2; + } + })); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/type/TestHashCode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/type/TestHashCode.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,10 @@ +package org.msgpack.type; + +import static org.junit.Assert.assertEquals; + +public class TestHashCode extends TestEquals { + @Override + protected void testEquals(Value v1, Value v2) { + assertEquals(v1.hashCode(), v2.hashCode()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestBufferUnpacker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestBufferUnpacker.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,131 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.unpacker.UnpackerIterator; + +import org.junit.Test; + +public class TestBufferUnpacker { + @Test + public void testEachByte() throws Exception { + List vs = new ArrayList(); + + BufferPacker pk = new MessagePack().createBufferPacker(); + for (int i = 0; i < 50; i++) { + Value v = createComplexType(); + vs.add(v); + pk.write(v); + } + byte[] raw = pk.toByteArray(); + + int n = 0; + BufferUnpacker u = new MessagePack().createBufferUnpacker(); + UnpackerIterator it = u.iterator(); + + for (int i = 0; i < raw.length; i++) { + u.feed(raw, i, 1); + while (it.hasNext()) { + Value v = it.next(); + assertEquals(vs.get(n), v); + n++; + } + } + assertEquals(50, n); + } + + @Test + public void testElevenBytes() throws Exception { + List vs = new ArrayList(); + + BufferPacker pk = new MessagePack().createBufferPacker(); + for (int i = 0; i < 55; i++) { + Value v = createComplexType(); + vs.add(v); + pk.write(v); + } + byte[] raw = pk.toByteArray(); + + int n = 0; + BufferUnpacker u = new MessagePack().createBufferUnpacker(); + UnpackerIterator it = u.iterator(); + + for (int i = 0; i < raw.length; i += 11) { + u.feed(raw, i, 11); + while (it.hasNext()) { + Value v = it.next(); + assertEquals(vs.get(n), v); + n++; + } + } + assertEquals(55, n); + } + + @Test + public void testEachObject() throws Exception { + BufferUnpacker u = new MessagePack().createBufferUnpacker(); + UnpackerIterator it = u.iterator(); + + for (int i = 0; i < 50; i++) { + Value v = createComplexType(); + BufferPacker pk = new MessagePack().createBufferPacker(); + pk.write(v); + byte[] raw = pk.toByteArray(); + // pk.reset(); + + u.feed(raw, 0, raw.length); + + assertTrue(it.hasNext()); + Value ov = it.next(); + assertEquals(v, ov); + // assertFalse(it.hasNext()); + } + } + + public Value createComplexType() throws Exception { + Random rand = new Random(System.currentTimeMillis()); + byte[] b0 = new byte[0]; + byte[] b1 = new byte[10]; + rand.nextBytes(b1); + byte[] b2 = new byte[1024]; + rand.nextBytes(b2); + + Value list = ValueFactory.createArrayValue(new Value[] { + ValueFactory.createRawValue(b0), + ValueFactory.createRawValue(b1), + ValueFactory.createRawValue(b2), }); + + Value map = ValueFactory.createMapValue(new Value[] { + ValueFactory.createIntegerValue(0), + ValueFactory.createIntegerValue(Integer.MIN_VALUE), + ValueFactory.createIntegerValue(rand.nextInt()), + ValueFactory.createIntegerValue(Integer.MAX_VALUE), + ValueFactory.createFloatValue(rand.nextFloat()), + ValueFactory.createBooleanValue(true), + ValueFactory.createFloatValue(rand.nextDouble()), + ValueFactory.createNilValue(), }); + + List values = new ArrayList(); + + for (int i = 0; i < 2; i++) { + values.add(list); + for (int j = 0; j < 100; j++) { + values.add(map); + } + } + + Value complex = ValueFactory.createArrayValue(values + .toArray(new Value[values.size()])); + return complex; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestMalformedEncoding.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestMalformedEncoding.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,131 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.nio.charset.CharacterCodingException; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.MessageTypeException; +import org.msgpack.packer.Packer; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.unpacker.Converter; +import org.msgpack.type.RawValue; +import org.msgpack.type.ValueFactory; +import org.msgpack.util.json.JSON; + +public class TestMalformedEncoding { + private byte[][] malforms = new byte[][] { { (byte) 0xc0, (byte) 0xaf }, // '/' + // in + // 2 + // bytes + { (byte) 0xe0, (byte) 0x80, (byte) 0xaf } // '/' in 3 bytes + }; + + @Test + public void testRawValueGetString() throws Exception { + for (byte[] malform : malforms) { + RawValue r = ValueFactory.createRawValue(malform); + try { + r.getString(); + fail("no exception"); + } catch (MessageTypeException expected) { + } + byte[] a = r.getByteArray(); + assertArrayEquals(malform, a); + } + } + + @Test + public void testBufferUnpackerUnpackString() throws Exception { + for (byte[] malform : malforms) { + MessagePack msgpack = new MessagePack(); + BufferPacker pk = msgpack.createBufferPacker(); + pk.write(malform); + byte[] b = pk.toByteArray(); + Unpacker u = msgpack.createBufferUnpacker(b); + try { + u.readString(); + fail("no exception"); + } catch (MessageTypeException expected) { + } + byte[] a = u.readByteArray(); + assertArrayEquals(malform, a); + } + } + + @Test + public void testUnpackerUnpackString() throws Exception { + for (byte[] malform : malforms) { + MessagePack msgpack = new MessagePack(); + BufferPacker pk = msgpack.createBufferPacker(); + pk.write(malform); + byte[] b = pk.toByteArray(); + Unpacker u = msgpack.createUnpacker(new ByteArrayInputStream(b)); + try { + u.readString(); + fail("no exception"); + } catch (MessageTypeException expected) { + } + byte[] a = u.readByteArray(); + assertArrayEquals(malform, a); + } + } + + @Test + public void testConverterUnpackString() throws Exception { + for (byte[] malform : malforms) { + MessagePack msgpack = new MessagePack(); + RawValue r = ValueFactory.createRawValue(malform); + Converter u = new Converter(msgpack, r); + try { + u.readString(); + fail("no exception"); + } catch (MessageTypeException expected) { + } + byte[] a = u.readByteArray(); + assertArrayEquals(malform, a); + } + } + + @Test + public void testJSONPackerWriteString() throws Exception { + for (byte[] malform : malforms) { + JSON json = new JSON(); + Packer pk = json.createPacker(new ByteArrayOutputStream()); + try { + pk.write(malform); + fail("no exception"); + } catch (CharacterCodingException expected) { + } + } + } + + @Test + public void testJSONBufferPackerWriteString() throws Exception { + for (byte[] malform : malforms) { + JSON json = new JSON(); + Packer pk = json.createBufferPacker(); + try { + pk.write(malform); + fail("no exception"); + } catch (CharacterCodingException expected) { + } + } + } + + @Test + public void testValueToString() throws Exception { + for (byte[] malform : malforms) { + RawValue r = ValueFactory.createRawValue(malform); + String str = r.toString(); + // malformed bytes will be ignored + assertEquals("\"\"", str); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestReadTemplate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestReadTemplate.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,93 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Map; +import java.util.Collection; +import java.util.Date; +import java.math.BigInteger; +import java.math.BigDecimal; + +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.Templates; +import org.msgpack.unpacker.Unpacker; + +import org.junit.Test; + +public class TestReadTemplate { + public static enum MyEnum { + A, B, C; + } + + @Test + public void testReadTemplateNull() throws IOException { + Byte tbyte = u().read(Templates.TByte); + assertNull(tbyte); + + Short tshort = u().read(Templates.TShort); + assertNull(tshort); + + Integer tinteger = u().read(Templates.TInteger); + assertNull(tinteger); + + Long tlong = u().read(Templates.TLong); + assertNull(tlong); + + Character tcharacter = u().read(Templates.TCharacter); + assertNull(tcharacter); + + BigInteger tbiginteger = u().read(Templates.TBigInteger); + assertNull(tbiginteger); + + BigDecimal tbigdecimail = u().read(Templates.TBigDecimal); + assertNull(tbigdecimail); + + Float tfloat = u().read(Templates.TFloat); + assertNull(tfloat); + + Double tdouble = u().read(Templates.TDouble); + assertNull(tdouble); + + Boolean tboolean = u().read(Templates.TBoolean); + assertNull(tboolean); + + String tstring = u().read(Templates.TString); + assertNull(tstring); + + byte[] tbytearray = u().read(Templates.TByteArray); + assertNull(tbytearray); + + ByteBuffer tbytebuffer = u().read(Templates.TByteBuffer); + assertNull(tbytebuffer); + + Date tdate = u().read(Templates.TDate); + assertNull(tdate); + + List tlist = u().read(Templates.tList(Templates.TString)); + assertNull(tlist); + + Map tmap = u().read( + Templates.tMap(Templates.TString, Templates.TInteger)); + assertNull(tmap); + + Collection tcollection = u().read( + Templates.tCollection(Templates.TLong)); + assertNull(tcollection); + + MyEnum tordinalenum = u().read(Templates.tOrdinalEnum(MyEnum.class)); + assertNull(tordinalenum); + } + + // return unpacker that can read a nil + private Unpacker u() throws IOException { + MessagePack msgpack = new MessagePack(); + BufferPacker pk = msgpack.createBufferPacker(); + pk.writeNil(); + Unpacker u = msgpack.createBufferUnpacker(pk.toByteArray()); + return u; + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestSizeLimit.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestSizeLimit.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,712 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; +import org.msgpack.template.ListTemplate; +import org.msgpack.template.MapTemplate; +import org.msgpack.template.Template; +import org.msgpack.template.Templates; +import org.msgpack.unpacker.SizeLimitException; +import org.msgpack.unpacker.Unpacker; + +public class TestSizeLimit { + + @Test + public void testRawSizeLimit() throws Exception { + MessagePack msgpack = new MessagePack(); + Template tmpl = Templates.TByteArray; + { // set limit == 10, size < 10 + int len = 9; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(10); + byte[] dst = unpacker.read(tmpl); + assertEquals(src.length, dst.length); + } + { // set limit == 10, size == 10 + int len = 10; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(10); + byte[] dst = unpacker.read(tmpl); + assertEquals(src.length, dst.length); + } + { // set limit == 10, 10 < size < 32 + int len = 11; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(10); + byte[] dst = unpacker.read(tmpl); + assertEquals(src.length, dst.length); + } + { // set limit == 10, size == 32 + int len = 32; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 10, size > 32 + int len = 33; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 33, size < 33 + int len = 32; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(33); + byte[] dst = unpacker.read(tmpl); + assertEquals(src.length, dst.length); + } + { // set limit == 33, size == 33 + int len = 33; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(33); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 33, size > 33 + int len = 34; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(33); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size < 65536 + int len = 65535; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(65536); + byte[] dst = unpacker.read(tmpl); + assertEquals(src.length, dst.length); + } + { // set limit == 65536, size == 65536 + int len = 65536; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size > 65536 + int len = 65537; + byte[] src = new byte[len]; + for (int i = 0; i < len; i++) { + src[i] = 0x0a; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setRawSizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + } + + @Test + public void testArraySizeLimit() throws Exception { + MessagePack msgpack = new MessagePack(); + Template> tmpl = new ListTemplate( + Templates.TInteger); + { // set limit == 10, size < 10 + int len = 9; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(10); + List dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, size == 10 + int len = 10; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(10); + List dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, 10 < size < 16 + int len = 11; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(10); + List dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, size == 16 + int len = 16; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 10, size > 16 + int len = 17; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 20, size < 20 + int len = 19; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(20); + List dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 20, size == 20 + int len = 20; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(20); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 20, size > 20 + int len = 21; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(20); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size < 65536 + int len = 65535; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(65536); + List dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 65536, size == 65536 + int len = 65536; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size > 65536 + int len = 65537; + List src = new ArrayList(len); + for (int i = 0; i < len; i++) { + src.add(i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setArraySizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + } + + @Test + public void testMapSizeLimit() throws Exception { + MessagePack msgpack = new MessagePack(); + Template> tmpl = new MapTemplate( + Templates.TInteger, Templates.TInteger); + { // set limit == 10, size < 10 + int len = 9; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(10); + Map dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, size == 10 + int len = 10; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(10); + Map dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, 10 < size < 16 + int len = 11; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(10); + Map dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 10, size == 16 + int len = 16; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 10, size > 16 + int len = 17; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(10); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 20, size < 20 + int len = 19; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(20); + Map dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 20, size == 20 + int len = 20; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(20); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 20, size > 20 + int len = 21; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(20); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size < 65536 + int len = 65535; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(65536); + Map dst = unpacker.read(tmpl); + assertEquals(src.size(), dst.size()); + } + { // set limit == 65536, size == 65536 + int len = 65536; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + { // set limit == 65536, size > 65536 + int len = 65537; + Map src = new HashMap(len); + for (int i = 0; i < len; i++) { + src.put(i, i); + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(src); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack + .createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.setMapSizeLimit(65536); + try { + unpacker.read(tmpl); + fail(); + } catch (Throwable t) { + assertTrue(t instanceof SizeLimitException); + } + } + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestUnpackerIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestUnpackerIterator.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,41 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.Packer; + +public class TestUnpackerIterator { + + @Test + public void testSample() throws Exception { + MessagePack msgpack = new MessagePack(); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(1); + packer.write(2); + packer.write(3); + byte[] bytes = out.toByteArray(); + + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + UnpackerIterator iter = unpacker.iterator(); + unpacker.resetReadByteCount(); + iter.hasNext(); + iter.next(); + assertEquals(1, unpacker.getReadByteCount()); + unpacker.resetReadByteCount(); + iter.hasNext(); + iter.next(); + assertEquals(1, unpacker.getReadByteCount()); + unpacker.resetReadByteCount(); + iter.hasNext(); + iter.next(); + assertEquals(1, unpacker.getReadByteCount()); + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/unpacker/TestUnpackerSkip.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/unpacker/TestUnpackerSkip.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,83 @@ +package org.msgpack.unpacker; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.BufferUnpacker; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; + +public class TestUnpackerSkip { + @Test + public void testPrimitive() throws Exception { + MessagePack msgpack = new MessagePack(); + + BufferPacker packer = msgpack.createBufferPacker(); + + for (int i = 0; i < 10; i++) { + packer.write(1); + packer.write(i); + } + + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + + for (int i = 0; i < 10; i++) { + unpacker.skip(); + int n = unpacker.readInt(); + assertEquals(i, n); + } + } + + @Test + public void testNested() throws Exception { + MessagePack msgpack = new MessagePack(); + + BufferPacker packer = msgpack.createBufferPacker(); + + Value v1 = ValueFactory.createArrayValue(new Value[] { + ValueFactory.createRawValue("a"), + ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k1"), + ValueFactory + .createArrayValue(new Value[] { ValueFactory + .createIntegerValue(1) }) }) }); + + Value v2 = ValueFactory.createArrayValue(new Value[] { + ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k1"), + ValueFactory + .createArrayValue(new Value[] { ValueFactory + .createIntegerValue(1) }), + ValueFactory.createRawValue("k2"), + ValueFactory + .createArrayValue(new Value[] { ValueFactory + .createIntegerValue(2) }) }), + ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k1"), + ValueFactory + .createArrayValue(new Value[] { ValueFactory + .createIntegerValue(1) }), + ValueFactory.createRawValue("k2"), + ValueFactory + .createArrayValue(new Value[] { ValueFactory + .createIntegerValue(2) }) }), + ValueFactory.createRawValue("a") }); + + for (int i = 0; i < 10; i++) { + packer.write(v1); + packer.write(v2); + } + + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes); + + for (int i = 0; i < 10; i++) { + unpacker.skip(); + Value v2a = unpacker.readValue(); + assertEquals(v2, v2a); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/TestTemplatePreCompilerBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/TestTemplatePreCompilerBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,625 @@ +package org.msgpack.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.packer.BufferPacker; +import org.msgpack.template.TemplateRegistry; +import org.msgpack.template.Template; +import org.msgpack.template.builder.TestSet; +import org.msgpack.testclasses.FinalClass; +import org.msgpack.testclasses.InheritanceClass; +import org.msgpack.testclasses.InheritanceClassNotNullable; +import org.msgpack.testclasses.ListTypeFieldsClass; +import org.msgpack.testclasses.ListTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MapTypeFieldsClass; +import org.msgpack.testclasses.MapTypeFieldsClassNotNullable; +import org.msgpack.testclasses.MessagePackableTypeFieldsClass; +import org.msgpack.testclasses.MessagePackableTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ModifiersFieldsClass; +import org.msgpack.testclasses.ModifiersFieldsClassNotNullable; +import org.msgpack.testclasses.PrimitiveTypeFieldsClass; +import org.msgpack.testclasses.PrimitiveTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClass; +import org.msgpack.testclasses.ReferenceCycleTypeFieldsClassNotNullable; +import org.msgpack.testclasses.ReferenceTypeFieldsClass; +import org.msgpack.testclasses.ReferenceTypeFieldsClassNotNullable; +import org.msgpack.testclasses.UserDefinedTypeFieldsClass; +import org.msgpack.testclasses.UserDefinedTypeFieldsClassNotNullable; +import org.msgpack.unpacker.BufferUnpacker; + +public class TestTemplatePreCompilerBufferPackBufferUnpack extends TestSet { + + @Test + @Override + public void testPrimitiveTypeFieldsClass() throws Exception { + super.testPrimitiveTypeFieldsClass(); + } + + @Override + public void testPrimitiveTypeFieldsClass(PrimitiveTypeFieldsClass v) + throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + PrimitiveTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(PrimitiveTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(PrimitiveTypeFieldsClass.class); + msgpack.unregister(PrimitiveTypeFieldsClass.class); + } + } + + @Test + @Override + public void testPrimitiveTypeFieldsClassNotNullable() throws Exception { + super.testPrimitiveTypeFieldsClassNotNullable(); + } + + @Override + public void testPrimitiveTypeFieldsClassNotNullable( + PrimitiveTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + PrimitiveTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(PrimitiveTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + PrimitiveTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(PrimitiveTypeFieldsClassNotNullable.class); + msgpack.unregister(PrimitiveTypeFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testReferenceTypeFieldsClass() throws Exception { + super.testReferenceTypeFieldsClass(); + } + + @Override + public void testReferenceTypeFieldsClass(ReferenceTypeFieldsClass v) + throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ReferenceTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(ReferenceTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ReferenceTypeFieldsClass.class); + msgpack.unregister(ReferenceTypeFieldsClass.class); + } + } + + @Test + @Override + public void testReferenceTypeFieldsClassNotNullable() throws Exception { + super.testReferenceTypeFieldsClassNotNullable(); + } + + @Override + public void testReferenceTypeFieldsClassNotNullable( + ReferenceTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ReferenceTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(ReferenceTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ReferenceTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ReferenceTypeFieldsClassNotNullable.class); + msgpack.unregister(ReferenceTypeFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testListTypeFieldsClass() throws Exception { + super.testListTypeFieldsClass(); + } + + @Override + public void testListTypeFieldsClass(ListTypeFieldsClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ListTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(ListTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ListTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler.deleteTemplateClass(ListTypeFieldsClass.class); + msgpack.unregister(ListTypeFieldsClass.class); + } + } + + @Test + @Override + public void testListTypeFieldsClassNotNullable() throws Exception { + super.testListTypeFieldsClassNotNullable(); + } + + @Override + public void testListTypeFieldsClassNotNullable( + ListTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ListTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(ListTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ListTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ListTypeFieldsClassNotNullable.class); + msgpack.unregister(ListTypeFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testMapTypeFieldsClass() throws Exception { + super.testMapTypeFieldsClass(); + } + + @Override + public void testMapTypeFieldsClass(MapTypeFieldsClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + MapTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(MapTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + MapTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler.deleteTemplateClass(MapTypeFieldsClass.class); + msgpack.unregister(MapTypeFieldsClass.class); + } + } + + @Test + @Override + public void testMapTypeFieldsClassNotNullable() throws Exception { + super.testMapTypeFieldsClassNotNullable(); + } + + @Override + public void testMapTypeFieldsClassNotNullable( + MapTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + MapTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(MapTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + MapTypeFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(MapTypeFieldsClassNotNullable.class); + msgpack.unregister(MapTypeFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testFinalClass() throws Exception { + super.testFinalClass(); + } + + @Override + public void testFinalClass(FinalClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + FinalClass.class); + Template tmpl = msgpack.lookup(FinalClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + FinalClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler.deleteTemplateClass(FinalClass.class); + msgpack.unregister(FinalClass.class); + } + } + + @Test + @Override + public void testModifiersFieldsClass() throws Exception { + super.testModifiersFieldsClass(); + } + + @Override + public void testModifiersFieldsClass(ModifiersFieldsClass v) + throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ModifiersFieldsClass.class); + Template tmpl = msgpack + .lookup(ModifiersFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ModifiersFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler.deleteTemplateClass(ModifiersFieldsClass.class); + msgpack.unregister(ModifiersFieldsClass.class); + } + } + + @Test + @Override + public void testModifiersFieldsClassNotNullable() throws Exception { + super.testModifiersFieldsClassNotNullable(); + } + + @Override + public void testModifiersFieldsClassNotNullable( + ModifiersFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ModifiersFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(ModifiersFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ModifiersFieldsClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ModifiersFieldsClassNotNullable.class); + msgpack.unregister(ModifiersFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testUserDefinedTypeFieldsClass() throws Exception { + super.testUserDefinedTypeFieldsClass(); + } + + @Override + public void testUserDefinedTypeFieldsClass(UserDefinedTypeFieldsClass v) + throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + UserDefinedTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(UserDefinedTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(UserDefinedTypeFieldsClass.class); + msgpack.unregister(UserDefinedTypeFieldsClass.class); + } + } + + @Test + @Override + public void testUserDefinedTypeFieldsClassNotNullable() throws Exception { + super.testUserDefinedTypeFieldsClassNotNullable(); + } + + @Override + public void testUserDefinedTypeFieldsClassNotNullable( + UserDefinedTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + UserDefinedTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(UserDefinedTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + UserDefinedTypeFieldsClassNotNullable ret = tmpl.read(unpacker, + null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(UserDefinedTypeFieldsClassNotNullable.class); + msgpack.unregister(UserDefinedTypeFieldsClassNotNullable.class); + } + } + + @org.junit.Ignore + @Test + @Override + // FIXME #MN next version + public void testReferenceCycleTypeFieldsClass() throws Exception { + super.testReferenceCycleTypeFieldsClass(); + } + + @org.junit.Ignore + @Override + // FIXME #MN next version + public void testReferenceCycleTypeFieldsClass( + ReferenceCycleTypeFieldsClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ReferenceCycleTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(ReferenceCycleTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ReferenceCycleTypeFieldsClass.class); + msgpack.unregister(ReferenceCycleTypeFieldsClass.class); + } + } + + @org.junit.Ignore + @Test + @Override + // FIXME #MN next version + public void testReferenceCycleTypeFieldsClassNotNullable() throws Exception { + super.testReferenceCycleTypeFieldsClassNotNullable(); + } + + @org.junit.Ignore + @Override + // FIXME #MN next version + public void testReferenceCycleTypeFieldsClassNotNullable( + ReferenceCycleTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + ReferenceCycleTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(ReferenceCycleTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + ReferenceCycleTypeFieldsClassNotNullable ret = tmpl.read(unpacker, + null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(ReferenceCycleTypeFieldsClassNotNullable.class); + msgpack.unregister(ReferenceCycleTypeFieldsClassNotNullable.class); + } + } + + @Test + @Override + public void testInheritanceClass() throws Exception { + super.testInheritanceClass(); + } + + @Override + public void testInheritanceClass(InheritanceClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + InheritanceClass.class); + Template tmpl = msgpack + .lookup(InheritanceClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + InheritanceClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler.deleteTemplateClass(InheritanceClass.class); + msgpack.unregister(InheritanceClass.class); + } + } + + @Test + @Override + public void testInheritanceClassNotNullable() throws Exception { + super.testInheritanceClassNotNullable(); + } + + @Override + public void testInheritanceClassNotNullable(InheritanceClassNotNullable v) + throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + InheritanceClassNotNullable.class); + Template tmpl = msgpack + .lookup(InheritanceClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + InheritanceClassNotNullable ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(InheritanceClassNotNullable.class); + msgpack.unregister(InheritanceClassNotNullable.class); + } + } + + @Test + @Override + public void testMessagePackableTypeFieldsClass() throws Exception { + super.testMessagePackableTypeFieldsClass(); + } + + @Override + public void testMessagePackableTypeFieldsClass( + MessagePackableTypeFieldsClass v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + MessagePackableTypeFieldsClass.class); + Template tmpl = msgpack + .lookup(MessagePackableTypeFieldsClass.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClass ret = tmpl.read(unpacker, null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(MessagePackableTypeFieldsClass.class); + msgpack.unregister(MessagePackableTypeFieldsClass.class); + } + } + + @Test + @Override + public void testMessagePackableTypeFieldsClassNotNullable() + throws Exception { + super.testMessagePackableTypeFieldsClassNotNullable(); + } + + @Override + public void testMessagePackableTypeFieldsClassNotNullable( + MessagePackableTypeFieldsClassNotNullable v) throws Exception { + System.getProperties().setProperty(TemplatePrecompiler.DEST, + "./target/test-classes"); + MessagePack msgpack = new MessagePack(); + try { + TemplatePrecompiler.saveTemplateClass(new TemplateRegistry(null), + MessagePackableTypeFieldsClassNotNullable.class); + Template tmpl = msgpack + .lookup(MessagePackableTypeFieldsClassNotNullable.class); + BufferPacker packer = msgpack.createBufferPacker(); + tmpl.write(packer, v); + byte[] bytes = packer.toByteArray(); + BufferUnpacker unpacker = msgpack.createBufferUnpacker(); + unpacker.wrap(bytes); + MessagePackableTypeFieldsClassNotNullable ret = tmpl.read(unpacker, + null); + assertEquals(v, ret); + } finally { + TemplatePrecompiler + .deleteTemplateClass(MessagePackableTypeFieldsClassNotNullable.class); + msgpack.unregister(MessagePackableTypeFieldsClassNotNullable.class); + } + } + +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestJSONBufferPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestJSONBufferPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,322 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.util.json.JSON; + +public class TestJSONBufferPackBufferUnpack extends TestSet { + + @Test + @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test + @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test + @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test + @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test + @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test + @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (((Float) v).isInfinite() || ((Float) v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test + @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (((Double) v).isInfinite() || ((Double) v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test + @Override + public void testNil() throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.writeNil(); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.readNil(); + } + + @Ignore + @Test + @Override + // FIXME #SF JSON Unpacker doesn't support BigInteger (bug) + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test + @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Ignore + @Test + @Override + // FIXME #SF JSONPacker doesn't support bytes + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + // packer.write(v); + String str = new String(v); + packer.write(str); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(str, ret); + } + + @Test + @Override + public void testList() throws Exception { + super.testList(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test + @Override + public void testMap() throws Exception { + super.testMap(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void testMap(Map v, Class keyElementClass, + Class valueElementClass) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v) + .entrySet()) { + if (!(e.getKey() instanceof String)) { + try { + packer.write(e.getKey()); + fail("JSONPacker should reject non-String value for the map key"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Object key = unpacker.read(keyElementClass); + Object value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestJSONBufferPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestJSONBufferPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,336 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.BufferPacker; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.util.json.JSON; + +public class TestJSONBufferPackUnpack extends TestSet { + + @Test + @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test + @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test + @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test + @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test + @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test + @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (((Float) v).isInfinite() || ((Float) v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test + @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (((Double) v).isInfinite() || ((Double) v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test + @Override + public void testNil() throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.writeNil(); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + unpacker.readNil(); + } + + @Ignore + @Test + @Override + // FIXME #SF JSON Unpacker doesn't support BigInteger (bug) + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test + @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + packer.write(v); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Ignore + @Test + @Override + // FIXME #SF JSONPacker doesn't support bytes + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + // packer.write(v); + String str = new String(v); + packer.write(str); + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + String ret = unpacker.read(String.class); + assertEquals(str, ret); + } + + @Test + @Override + public void testList() throws Exception { + super.testList(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test + @Override + public void testMap() throws Exception { + super.testMap(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testMap(Map v, Class keyElementClass, + Class valueElementClass) throws Exception { + MessagePack msgpack = new JSON(); + BufferPacker packer = msgpack.createBufferPacker(); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v) + .entrySet()) { + if (!(e.getKey() instanceof String)) { + try { + packer.write(e.getKey()); + fail("JSONPacker should reject non-String value for the map key"); + } catch (Exception ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker( + new ByteArrayInputStream(bytes)); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Object key = unpacker.read(keyElementClass); + Object value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestJSONPackBufferUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestJSONPackBufferUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,318 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.util.json.JSON; + + +public class TestJSONPackBufferUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if(((Float)v).isInfinite() || ((Float)v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if(((Double)v).isInfinite() || ((Double)v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.writeNil(); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.readNil(); + } + + @Ignore @Test @Override // FIXME #SF JSON Unpacker doesn't support BigInteger + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Ignore @Test @Override // FIXME #SF JSONPacker doesn't support bytes + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + //packer.write(v); + String str = new String(v); + packer.write(str); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(str, ret); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + if (!(e.getKey() instanceof String)) { + try { + packer.write(e.getKey()); + fail("JSONPacker should reject non-String value for the map key"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Object key = unpacker.read(keyElementClass); + Object value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestJSONPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestJSONPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,319 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.packer.Packer; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.util.json.JSON; + + +public class TestJSONPackUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if(((Float)v).isInfinite() || ((Float)v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if(((Double)v).isInfinite() || ((Double)v).isNaN()) { + try { + packer.write(v); + fail("JSONPacker should reject infinite and NaN value"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.writeNil(); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + unpacker.readNil(); + } + + @Ignore @Test @Override // FIXME #SF JSON Unpacker doesn't support BigInteger + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + packer.write(v); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Ignore @Test @Override // FIXME #SF JSONPacker doesn't support bytes + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + //packer.write(v); + String str = new String(v); + packer.write(str); + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + String ret = unpacker.read(String.class); + assertEquals(str, ret); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new JSON(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Packer packer = msgpack.createPacker(out); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + if (!(e.getKey() instanceof String)) { + try { + packer.write(e.getKey()); + fail("JSONPacker should reject non-String value for the map key"); + } catch (IOException ex) { + assertTrue(ex instanceof IOException); + } + return; + } + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = out.toByteArray(); + Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes)); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Object key = unpacker.read(keyElementClass); + Object value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestSimpleJSONPackUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestSimpleJSONPackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,47 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; +import org.msgpack.type.ValueFactory; +import org.msgpack.util.json.JSONBufferPacker; +import org.msgpack.util.json.JSONBufferUnpacker; + + +public class TestSimpleJSONPackUnpack { + @Test + public void testSimplePackUnpack() throws IOException { + MessagePack msgpack = new MessagePack(); + + Value v = ValueFactory.createMapValue(new Value[] { + ValueFactory.createRawValue("k1"), + ValueFactory.createIntegerValue(1), + ValueFactory.createRawValue("k2"), + ValueFactory.createArrayValue(new Value[] { + ValueFactory.createNilValue(), + ValueFactory.createBooleanValue(true), + ValueFactory.createBooleanValue(false) + }), + ValueFactory.createRawValue("k3"), + ValueFactory.createFloatValue(0.1) + }); + + JSONBufferPacker pk = new JSONBufferPacker(msgpack); + pk.write(v); + + byte[] raw = pk.toByteArray(); + + String str = new String(raw); + assertEquals("{\"k1\":1,\"k2\":[null,true,false],\"k3\":0.1}", str); + + JSONBufferUnpacker u = new JSONBufferUnpacker(msgpack).wrap(raw); + Value v2 = u.readValue(); + + assertEquals(v, v2); + } +} + diff -r 000000000000 -r cb825acd883a src/test/java/org/msgpack/util/json/TestValueToStringJSONUnpack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/util/json/TestValueToStringJSONUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,308 @@ +package org.msgpack.util.json; + +import static org.junit.Assert.assertEquals; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; +import org.msgpack.MessagePack; +import org.msgpack.TestSet; +import org.msgpack.unpacker.Unpacker; +import org.msgpack.packer.Unconverter; +import org.msgpack.util.json.JSON; + + +public class TestValueToStringJSONUnpack extends TestSet { + + @Test @Override + public void testBoolean() throws Exception { + super.testBoolean(); + } + + @Override + public void testBoolean(boolean v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + boolean ret = unpacker.readBoolean(); + assertEquals(v, ret); + } + + @Test @Override + public void testByte() throws Exception { + super.testByte(); + } + + @Override + public void testByte(byte v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + byte ret = unpacker.readByte(); + assertEquals(v, ret); + } + + @Test @Override + public void testShort() throws Exception { + super.testShort(); + } + + @Override + public void testShort(short v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + short ret = unpacker.readShort(); + assertEquals(v, ret); + } + + @Test @Override + public void testInteger() throws Exception { + super.testInteger(); + } + + @Override + public void testInteger(int v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + int ret = unpacker.readInt(); + assertEquals(v, ret); + } + + @Test @Override + public void testLong() throws Exception { + super.testLong(); + } + + @Override + public void testLong(long v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + long ret = unpacker.readLong(); + assertEquals(v, ret); + } + + @Test @Override + public void testFloat() throws Exception { + super.testFloat(); + } + + @Override + public void testFloat(float v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + if(((Float)v).isInfinite()) { + packer.write(v); + String str = packer.getResult().toString(); + if(v < 0) { + assertEquals("-Infinity", str); + } else { + assertEquals("Infinity", str); + } + return; + } else if(((Float)v).isNaN()) { + packer.write(v); + String str = packer.getResult().toString(); + assertEquals("NaN", str); + return; + } + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + float ret = unpacker.readFloat(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testDouble() throws Exception { + super.testDouble(); + } + + @Override + public void testDouble(double v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + if(((Double)v).isInfinite()) { + packer.write(v); + String str = packer.getResult().toString(); + if(v < 0) { + assertEquals("-Infinity", str); + } else { + assertEquals("Infinity", str); + } + return; + } else if(((Double)v).isNaN()) { + packer.write(v); + String str = packer.getResult().toString(); + assertEquals("NaN", str); + return; + } + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + double ret = unpacker.readDouble(); + assertEquals(v, ret, 10e-10); + } + + @Test @Override + public void testNil() throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.writeNil(); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + unpacker.readNil(); + } + + @Ignore @Test @Override // FIXME #SF JSON Unpacker doesn't support BigInteger + public void testBigInteger() throws Exception { + super.testBigInteger(); + } + + @Override + public void testBigInteger(BigInteger v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + BigInteger ret = unpacker.read(BigInteger.class); + assertEquals(v, ret); + } + + @Test @Override + public void testString() throws Exception { + super.testString(); + } + + @Override + public void testString(String v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + packer.write(v); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(v, ret); + } + + @Ignore @Test @Override // FIXME JSONPacker doesn't support bytes + public void testByteArray() throws Exception { + super.testByteArray(); + } + + @Override + public void testByteArray(byte[] v) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + //packer.write(v); + String str = new String(v); + packer.write(str); + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + String ret = unpacker.read(String.class); + assertEquals(str, ret); + } + + @Test @Override + public void testList() throws Exception { + super.testList(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void testList(List v, Class elementClass) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeArrayBegin(v.size()); + for (Object o : v) { + packer.write(o); + } + packer.writeArrayEnd(); + } + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readArrayBegin(); + List ret = new ArrayList(size); + for (int i = 0; i < size; ++i) { + ret.add(unpacker.read(elementClass)); + } + unpacker.readArrayEnd(); + assertEquals(v.size(), ret.size()); + Iterator v_iter = v.iterator(); + Iterator ret_iter = ret.iterator(); + while (v_iter.hasNext()) { + assertEquals(v_iter.next(), ret_iter.next()); + } + } + + @Test @Override + public void testMap() throws Exception { + super.testMap(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void testMap(Map v, Class keyElementClass, Class valueElementClass) throws Exception { + MessagePack msgpack = new JSON(); + Unconverter packer = new Unconverter(msgpack); + if (v == null) { + packer.writeNil(); + } else { + packer.writeMapBegin(v.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + packer.write(e.getKey()); + packer.write(e.getValue()); + } + packer.writeMapEnd(); + } + byte[] bytes = packer.getResult().toString().getBytes("UTF-8"); + if(!keyElementClass.equals(String.class)) { + // TODO JSONUnpacker rejects maps whose keys are not string + return; + } + Unpacker unpacker = msgpack.createBufferUnpacker(bytes); + if (unpacker.trySkipNil()) { + assertEquals(null, v); + return; + } + int size = unpacker.readMapBegin(); + Map ret = new HashMap(size); + for (int i = 0; i < size; ++i) { + Object key = unpacker.read(keyElementClass); + Object value = unpacker.read(valueElementClass); + ret.put(key, value); + } + unpacker.readMapEnd(); + assertEquals(v.size(), ret.size()); + for (Map.Entry e : ((Map) v).entrySet()) { + Object value = ret.get(e.getKey()); + assertEquals(e.getValue(), value); + } + } +} diff -r 000000000000 -r cb825acd883a src/test/resources/cases.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/cases.json Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,1 @@ +[false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,127,127,255,65535,4294967295,-32,-32,-128,-32768,-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",[0],[0],[0],[],[],[],{},{},{},{"a":97},{"a":97},{"a":97},[[]],[["a"]]] \ No newline at end of file diff -r 000000000000 -r cb825acd883a src/test/resources/cases.mpac Binary file src/test/resources/cases.mpac has changed diff -r 000000000000 -r cb825acd883a src/test/resources/cases_compact.mpac Binary file src/test/resources/cases_compact.mpac has changed