Skip to content

Commit 5ac35d1

Browse files
committed
Merge pull request msgpack#249 from xerial/v07-value-impl-rev2
V07 value impl revision 2
2 parents 2ff4f59 + 080deb3 commit 5ac35d1

51 files changed

Lines changed: 534 additions & 986 deletions

Some content is hidden

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

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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
* @param type extension type (byte). You can check the valid byte range with {@link #checkedCastToByte(int)} method.
15+
* @param length extension type data length
16+
*/
17+
public ExtensionTypeHeader(byte type, int length) {
18+
checkArgument(length >= 0, "length must be >= 0");
19+
this.type = type;
20+
this.length = length;
21+
}
22+
23+
public static byte checkedCastToByte(int code) {
24+
checkArgument(Byte.MIN_VALUE <= code && code <= Byte.MAX_VALUE, "Extension type code must be within the range of byte");
25+
return (byte) code;
26+
}
27+
28+
public byte getType() {
29+
return type;
30+
}
31+
32+
public int getLength() {
33+
return length;
34+
}
35+
36+
@Override
37+
public int hashCode() {
38+
return (type + 31) * 31 + length;
39+
}
40+
41+
@Override
42+
public boolean equals(Object obj) {
43+
if(obj instanceof ExtensionTypeHeader) {
44+
ExtensionTypeHeader other = (ExtensionTypeHeader) obj;
45+
return this.type == other.type && this.length == other.length;
46+
}
47+
return false;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return String.format("ExtensionTypeHeader(type:%d, length:%,d)", type, length);
53+
}
54+
55+
}

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: 8 additions & 8 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),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +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 {
26+
public class MessageIntegerOverflowException extends MessageTypeException {
2727
private final BigInteger bigInteger;
2828

2929
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
}

0 commit comments

Comments
 (0)