Skip to content

Commit 21816fb

Browse files
committed
Merge pull request msgpack#246 from msgpack/v07-value-impl
V07 value impl
2 parents c221990 + 5c51b39 commit 21816fb

File tree

95 files changed

+3971
-4352
lines changed

Some content is hidden

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

95 files changed

+3971
-4352
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ MessagePack for Java
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).
8+
MessagePack v7 (0.7.x) is a faster implementation of the previous version [v06](https://github.com/msgpack/msgpack-java/tree/v06), and
9+
supports all of the message pack types, including [extension format](https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext).
910

1011
## Limitation
1112
- Value API is in a designing phase: https://github.com/msgpack/msgpack-java/pull/109
@@ -26,7 +27,7 @@ For sbt users:
2627
libraryDependencies += "org.msgpack" % "msgpack-core" % "0.7.0-p9"
2728
```
2829

29-
- [Usage examples](msgpack-core/src/main/java/org/msgpack/core/example/MessagePackExample.java)
30+
- [Usage examples](msgpack-core/src/test/java/org/msgpack/core/example/MessagePackExample.java)
3031

3132
msgpack-java supports serialization and deserialization of Java objects through [jackson-databind](https://github.com/FasterXML/jackson-databind).
3233
For details, see [msgpack-jackson/README.md](msgpack-jackson/README.md). The template-based serialization mechanism used in v06 is deprecated.

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fix [#217] when reading from SockectInputStream
55

66
* 2015-04-09 0.7.0-p8
7-
* Support Extended type (defined in MessagePack) in msgpack-jackson
7+
* Support Extension type (defined in MessagePack) in msgpack-jackson
88
* Support BigDecimal type (defined in Jackson) in msgpack-jackson
99
* Fix MessageUnpacker#unpackString [#215](https://github.com/msgpack/msgpack-java/pull/215), [#216](https://github.com/msgpack/msgpack-java/pull/216)
1010

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

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.msgpack.core;
2+
3+
import static org.msgpack.core.Preconditions.*;
4+
5+
/**
6+
* Header of the Extension types
7+
*/
8+
public class ExtensionTypeHeader {
9+
private final byte type;
10+
private final int length;
11+
12+
/**
13+
* Create an extension type header
14+
* Example:
15+
* <pre>
16+
* {@code
17+
* import org.msgpack.core.ExtensionTypeHeader;
18+
* import static org.msgpack.core.ExtensionTypeHeader.checkedCastToByte;
19+
* ...
20+
* ExtensionTypeHeader header = new ExtensionTypeHeader(checkedCastToByte(0x01), 32);
21+
* ...
22+
* }
23+
* </pre>
24+
* @param type extension type (byte). You can check the valid byte range with {@link #checkedCastToByte(int)} method.
25+
* @param length extension type data length
26+
*/
27+
public ExtensionTypeHeader(byte type, int length) {
28+
checkArgument(length >= 0, "length must be >= 0");
29+
this.type = type;
30+
this.length = length;
31+
}
32+
33+
public static byte checkedCastToByte(int code) {
34+
checkArgument(Byte.MIN_VALUE <= code && code <= Byte.MAX_VALUE, "Extension type code must be within the range of byte");
35+
return (byte) code;
36+
}
37+
38+
public byte getType() {
39+
return type;
40+
}
41+
42+
public int getLength() {
43+
return length;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return (type + 31) * 31 + length;
49+
}
50+
51+
@Override
52+
public boolean equals(Object obj) {
53+
if(obj instanceof ExtensionTypeHeader) {
54+
ExtensionTypeHeader other = (ExtensionTypeHeader) obj;
55+
return this.type == other.type && this.length == other.length;
56+
}
57+
return false;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return String.format("ExtensionTypeHeader(type:%d, length:%,d)", type, length);
63+
}
64+
65+
}

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

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

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public enum MessageFormat {
2424
BIN8(ValueType.BINARY),
2525
BIN16(ValueType.BINARY),
2626
BIN32(ValueType.BINARY),
27-
EXT8(ValueType.EXTENDED),
28-
EXT16(ValueType.EXTENDED),
29-
EXT32(ValueType.EXTENDED),
27+
EXT8(ValueType.EXTENSION),
28+
EXT16(ValueType.EXTENSION),
29+
EXT32(ValueType.EXTENSION),
3030
FLOAT32(ValueType.FLOAT),
3131
FLOAT64(ValueType.FLOAT),
3232
UINT8(ValueType.INTEGER),
@@ -38,11 +38,11 @@ public enum MessageFormat {
3838
INT16(ValueType.INTEGER),
3939
INT32(ValueType.INTEGER),
4040
INT64(ValueType.INTEGER),
41-
FIXEXT1(ValueType.EXTENDED),
42-
FIXEXT2(ValueType.EXTENDED),
43-
FIXEXT4(ValueType.EXTENDED),
44-
FIXEXT8(ValueType.EXTENDED),
45-
FIXEXT16(ValueType.EXTENDED),
41+
FIXEXT1(ValueType.EXTENSION),
42+
FIXEXT2(ValueType.EXTENSION),
43+
FIXEXT4(ValueType.EXTENSION),
44+
FIXEXT8(ValueType.EXTENSION),
45+
FIXEXT16(ValueType.EXTENSION),
4646
STR8(ValueType.STRING),
4747
STR16(ValueType.STRING),
4848
STR32(ValueType.STRING),
@@ -95,7 +95,7 @@ public static MessageFormat valueOf(final byte b) {
9595
* @return
9696
*/
9797
@VisibleForTesting
98-
public static MessageFormat toMessageFormat(final byte b) {
98+
static MessageFormat toMessageFormat(final byte b) {
9999
if (Code.isPosFixInt(b)) {
100100
return POSFIXINT;
101101
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* using a smaller types. For example, calling MessageUnpacker.unpackInt() for an integer value
2424
* that is larger than Integer.MAX_VALUE will cause this exception.
2525
*/
26-
public class MessageIntegerOverflowException extends MessageOverflowException {
27-
26+
public class MessageIntegerOverflowException extends MessageTypeException {
2827
private final BigInteger bigInteger;
2928

3029
public MessageIntegerOverflowException(BigInteger bigInteger) {

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

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

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public MessagePacker packString(String s) throws IOException {
379379
flush();
380380

381381
prepareBuffer();
382-
boolean isExtended = false;
382+
boolean isExtension = false;
383383
ByteBuffer encodeBuffer = buffer.toByteBuffer(position, buffer.size() - position);
384384
encoder.reset();
385385
while(in.hasRemaining()) {
@@ -400,7 +400,7 @@ public MessagePacker packString(String s) throws IOException {
400400
// Coy the current encodeBuffer contents to the new buffer
401401
newBuffer.put(encodeBuffer);
402402
encodeBuffer = newBuffer;
403-
isExtended = true;
403+
isExtension = true;
404404
encoder.reset();
405405
continue;
406406
}
@@ -434,7 +434,7 @@ public MessagePacker packString(String s) throws IOException {
434434
flush(); // We need to dump the data here to MessageBufferOutput so that we can switch back to the original buffer
435435

436436
// Reset to the original buffer (or encodeBuffer if new buffer is allocated)
437-
buffer = isExtended ? MessageBuffer.wrap(encodeBuffer) : tmpBuf;
437+
buffer = isExtension ? MessageBuffer.wrap(encodeBuffer) : tmpBuf;
438438
// No need exists to write payload since the encoded string (payload) is already written to the buffer
439439
position = strLen;
440440
return this;
@@ -477,41 +477,41 @@ public MessagePacker packValue(Value v) throws IOException {
477477
return this;
478478
}
479479

480-
public MessagePacker packExtendedTypeHeader(int extType, int payloadLen) throws IOException {
480+
public MessagePacker packExtensionTypeHeader(byte extType, int payloadLen) throws IOException {
481481
if(payloadLen < (1 << 8)) {
482482
if(payloadLen > 0 && (payloadLen & (payloadLen - 1)) == 0) { // check whether dataLen == 2^x
483483
if(payloadLen == 1) {
484-
writeByteAndByte(FIXEXT1, (byte) extType);
484+
writeByteAndByte(FIXEXT1, extType);
485485
}
486486
else if(payloadLen == 2) {
487-
writeByteAndByte(FIXEXT2, (byte) extType);
487+
writeByteAndByte(FIXEXT2, extType);
488488
}
489489
else if(payloadLen == 4) {
490-
writeByteAndByte(FIXEXT4, (byte) extType);
490+
writeByteAndByte(FIXEXT4, extType);
491491
}
492492
else if(payloadLen == 8) {
493-
writeByteAndByte(FIXEXT8, (byte) extType);
493+
writeByteAndByte(FIXEXT8, extType);
494494
}
495495
else if(payloadLen == 16) {
496-
writeByteAndByte(FIXEXT16, (byte) extType);
496+
writeByteAndByte(FIXEXT16, extType);
497497
}
498498
else {
499499
writeByteAndByte(EXT8, (byte) payloadLen);
500-
writeByte((byte) extType);
500+
writeByte(extType);
501501
}
502502
}
503503
else {
504504
writeByteAndByte(EXT8, (byte) payloadLen);
505-
writeByte((byte) extType);
505+
writeByte(extType);
506506
}
507507
}
508508
else if(payloadLen < (1 << 16)) {
509509
writeByteAndShort(EXT16, (short) payloadLen);
510-
writeByte((byte) extType);
510+
writeByte(extType);
511511
}
512512
else {
513513
writeByteAndInt(EXT32, payloadLen);
514-
writeByte((byte) extType);
514+
writeByte(extType);
515515

516516
// TODO support dataLen > 2^31 - 1
517517
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
//
16+
package org.msgpack.core;
17+
18+
public class MessageTypeCastException extends MessageTypeException {
19+
public MessageTypeCastException() {
20+
super();
21+
}
22+
23+
public MessageTypeCastException(String message) {
24+
super(message);
25+
}
26+
27+
public MessageTypeCastException(String message, Throwable cause) {
28+
super(message, cause);
29+
}
30+
31+
public MessageTypeCastException(Throwable cause) {
32+
super(cause);
33+
}
34+
}

0 commit comments

Comments
 (0)