Skip to content

Commit a2881a5

Browse files
committed
Merge branch 'v07-develop' into v07-value
2 parents 64d397c + d0c87ae commit a2881a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3107
-445
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ jdk:
66
- openjdk6
77
- openjdk7
88
- oraclejdk7
9+
- oraclejdk8
910

1011
branches:
1112
only:
12-
- master
13-
- develop
1413
- v07
14+
- v07-develop
1515

1616
script: sbt ++$TRAVIS_SCALA_VERSION test
1717

1818
notifications:
1919
email:
20-
- muga.nishizawa@gmail.com
2120
- ozawa.tsuyoshi@gmail.com
2221
- leo@xerial.org
22+
- komamitsu@gmail.com

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
MessagePack for Java
1+
MessagePack for Java
22
===
33

44
[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. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
55

66
* Message Pack specification: <https://github.com/msgpack/msgpack/blob/master/spec.md>
77

8+
MessagePack v7 (0.7.x) is a faster implementation of the previous version [v06](https://github.com/msgpack/msgpack-java/tree/v06), and supports all of the message pack types, including [extended format](https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext).
9+
810
## Quick Start
911

1012
For Maven users:
1113
```
1214
<dependency>
1315
<groupId>org.msgpack</groupId>
1416
<artifactId>msgpack-core</artifactId>
15-
<version>0.7.0</version>
17+
<version>0.7.0-p2</version>
1618
</dependency>
1719
```
1820

1921
For sbt users:
2022
```
21-
libraryDependencies += "org.msgpack" % "msgpack-core" % "0.7.0"
23+
libraryDependencies += "org.msgpack" % "msgpack-core" % "0.7.0-p2"
2224
```
2325

26+
- [Usage examples](msgpack-core/src/main/java/org/msgpack/core/example/MessagePackExample.java)
27+
28+
msgpack-java supports serialization and deserialization of Java objects through [jackson-databind](https://github.com/FasterXML/jackson-databind).
29+
For details, see [msgpack-jackson/README.md](msgpack-jackson/README.md). The template-based serialization mechanism used in v06 is deprecated.
2430

25-
## For Developers
31+
## For MessagePack Developers [![Travis CI](https://travis-ci.org/msgpack/msgpack-java.svg?branch=v07-develop)](https://travis-ci.org/msgpack/msgpack-java)
2632

2733
msgpack-java uses [sbt](http://www.scala-sbt.org/) for building the projects. For the basic usage of sbt, see:
2834
* [Building Java projects with sbt](http://xerial.org/blog/2014/03/24/sbt/)
@@ -70,4 +76,5 @@ credentials += Credentials("Sonatype Nexus Repository Manager",
7076

7177
```
7278
msgpack-core # Contains packer/unpacker implementation that never uses third-party libraries
79+
msgpack-jackson # Contains jackson-dataformat-java implementation
7380
```

msgpack-core/pom.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

msgpack-core/src/main/java/org/msgpack/core/MessageFormat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private MessageFormat(ValueType valueType) {
6161

6262
/**
6363
* Retruns the ValueType corresponding to this MessageFormat
64-
* @return
64+
* @return value type
6565
* @throws MessageFormatException if this == NEVER_USED type
6666
*/
6767
public ValueType getValueType() throws MessageFormatException {
@@ -82,7 +82,7 @@ public ValueType getValueType() throws MessageFormatException {
8282

8383
/**
8484
* Returns a MessageFormat type of the specified byte value
85-
* @param b
85+
* @param b MessageFormat of the given byte
8686
* @return
8787
*/
8888
public static MessageFormat valueOf(final byte b) {
@@ -91,7 +91,7 @@ public static MessageFormat valueOf(final byte b) {
9191

9292
/**
9393
* Converting a byte value into MessageFormat. For faster performance, use {@link #valueOf}
94-
* @param b
94+
* @param b MessageFormat of the given byte
9595
* @return
9696
*/
9797
@VisibleForTesting

msgpack-core/src/main/java/org/msgpack/core/MessagePack.java

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1+
//
2+
// MessagePack for Java
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
116
package org.msgpack.core;
217

18+
import org.msgpack.core.buffer.*;
19+
20+
import java.io.InputStream;
21+
import java.io.OutputStream;
22+
import java.nio.channels.ReadableByteChannel;
23+
import java.nio.channels.WritableByteChannel;
324
import java.nio.charset.Charset;
425
import java.nio.charset.CodingErrorAction;
526

627
import static org.msgpack.core.Preconditions.checkArgument;
728

829
/**
9-
* Includes MessagePack codes
30+
* This class has MessagePack prefix code definitions and packer/unpacker factory methods.
1031
*
1132
*/
1233
public class MessagePack {
@@ -91,8 +112,8 @@ public static class ConfigBuilder {
91112
private boolean readStringAsBinary = true;
92113
private boolean readBinaryAsString = true;
93114

94-
private CodingErrorAction onMalFormedInput = CodingErrorAction.REPORT;
95-
private CodingErrorAction onUnmappableCharacter = CodingErrorAction.REPORT;
115+
private CodingErrorAction onMalFormedInput = CodingErrorAction.REPLACE;
116+
private CodingErrorAction onUnmappableCharacter = CodingErrorAction.REPLACE;
96117

97118
private int maxUnpackStringSize = Integer.MAX_VALUE;
98119
private int stringEncoderBufferSize = 8192;
@@ -237,4 +258,137 @@ public static final boolean isFixedRaw(byte b) {
237258
public static final byte NEGFIXINT_PREFIX = (byte) 0xe0;
238259
}
239260

261+
// Packer/Unpacker factory methods
262+
263+
private final MessagePack.Config config;
264+
265+
public MessagePack() {
266+
this(MessagePack.DEFAULT_CONFIG);
267+
}
268+
269+
public MessagePack(MessagePack.Config config) {
270+
this.config = config;
271+
}
272+
273+
/**
274+
* Default MessagePack packer/unpacker factory
275+
*/
276+
public static final MessagePack DEFAULT = new MessagePack(MessagePack.DEFAULT_CONFIG);
277+
278+
279+
/**
280+
* Create a MessagePacker that outputs the packed data to the specified stream, using the default configuration
281+
* @param out
282+
* @return
283+
*/
284+
public static MessagePacker newDefaultPacker(OutputStream out) {
285+
return DEFAULT.newPacker(out);
286+
}
287+
288+
/**
289+
* Create a MessagePacker that outputs the packed data to the specified channel, using the default configuration
290+
* @param channel
291+
* @return
292+
*/
293+
public static MessagePacker newDefaultPacker(WritableByteChannel channel) {
294+
return DEFAULT.newPacker(channel);
295+
}
296+
297+
/**
298+
* Create a MessageUnpacker that reads data from then given InputStream, using the default configuration
299+
* @param in
300+
* @return
301+
*/
302+
public static MessageUnpacker newDefaultUnpacker(InputStream in) {
303+
return DEFAULT.newUnpacker(in);
304+
}
305+
306+
/**
307+
* Create a MessageUnpacker that reads data from the given channel, using the default configuration
308+
* @param channel
309+
* @return
310+
*/
311+
public static MessageUnpacker newDefaultUnpacker(ReadableByteChannel channel) {
312+
return DEFAULT.newUnpacker(channel);
313+
}
314+
315+
/**
316+
* Create a MessageUnpacker that reads data from the given byte array, using the default configuration
317+
* @param arr
318+
* @return
319+
*/
320+
public static MessageUnpacker newDefaultUnpacker(byte[] arr) {
321+
return DEFAULT.newUnpacker(arr);
322+
}
323+
324+
/**
325+
* Create a MessageUnpacker that reads data form the given byte array [offset, .. offset+length), using the default
326+
* configuration.
327+
* @param arr
328+
* @param offset
329+
* @param length
330+
* @return
331+
*/
332+
public static MessageUnpacker newDefaultUnpacker(byte[] arr, int offset, int length) {
333+
return DEFAULT.newUnpacker(arr, offset, length);
334+
}
335+
336+
337+
/**
338+
* Create a MessagePacker that outputs the packed data to the specified stream
339+
* @param out
340+
*/
341+
public MessagePacker newPacker(OutputStream out) {
342+
return new MessagePacker(new OutputStreamBufferOutput(out), config);
343+
}
344+
345+
/**
346+
* Create a MessagePacker that outputs the packed data to the specified channel
347+
* @param channel
348+
*/
349+
public MessagePacker newPacker(WritableByteChannel channel) {
350+
return new MessagePacker(new ChannelBufferOutput(channel), config);
351+
}
352+
353+
/**
354+
* Create a MessageUnpacker that reads data from the given InputStream.
355+
* For reading data efficiently from byte[], use {@link MessageUnpacker(byte[])} or {@link MessageUnpacker(byte[], int, int)} instead of this constructor.
356+
*
357+
* @param in
358+
*/
359+
public MessageUnpacker newUnpacker(InputStream in) {
360+
return new MessageUnpacker(InputStreamBufferInput.newBufferInput(in), config);
361+
}
362+
363+
/**
364+
* Create a MessageUnpacker that reads data from the given ReadableByteChannel.
365+
* @param in
366+
*/
367+
public MessageUnpacker newUnpacker(ReadableByteChannel in) {
368+
return new MessageUnpacker(new ChannelBufferInput(in), config);
369+
}
370+
371+
372+
/**
373+
* Create a MessageUnpacker that reads data from the given byte array.
374+
*
375+
* @param arr
376+
*/
377+
public MessageUnpacker newUnpacker(byte[] arr) {
378+
return new MessageUnpacker(new ArrayBufferInput(arr), config);
379+
}
380+
381+
/**
382+
* Create a MessageUnpacker that reads data from the given byte array [offset, offset+length)
383+
* @param arr
384+
* @param offset
385+
* @param length
386+
*/
387+
public MessageUnpacker newUnpacker(byte[] arr, int offset, int length) {
388+
return new MessageUnpacker(new ArrayBufferInput(arr, offset, length), config);
389+
}
390+
391+
392+
393+
240394
}

0 commit comments

Comments
 (0)