Skip to content

V07 value impl #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2242fe4
implemented Value API
frsyuki Jun 10, 2015
7685276
added org.msgpack.value.Variable
frsyuki Jun 10, 2015
3393110
implemented Variable.hashCode, equals, toString, and writeTo methods
frsyuki Jun 10, 2015
a40cbcb
fixed Value API
frsyuki Jun 10, 2015
2ff4f59
ImmutableMapValueImpl.equals should not assume order of elements is same
frsyuki Jun 10, 2015
e2fc4e6
Renmae ExtendedType -> ExtensionType
xerial Jun 13, 2015
bc7e503
ValueFactory.newXXXValue -> newXXX for brevity
xerial Jun 13, 2015
b123089
immutableValue() -> toImmutable()
xerial Jun 13, 2015
4bcfab5
Add visitor interface
xerial Jun 13, 2015
de6d1f5
Add augumented constructor for ExtensionTypeHeader
xerial Jun 13, 2015
04819a3
Fix test case
xerial Jun 13, 2015
d1807a5
Add ValueType bit mask to improve type check performance
xerial Jun 13, 2015
770f013
Preserve float and double differences
xerial Jun 13, 2015
775379d
Renamed xxxValue that returns primitive type value as toXXX
xerial Jun 13, 2015
301ae10
Remove public scope from interface
xerial Jun 13, 2015
9db3537
Fix compilation error of msgpack-jackson
xerial Jun 13, 2015
c782451
toImmutable -> immutableValue
xerial Jun 15, 2015
ed45331
Remove visitor, ExtensionTypeHeader constructor. Fix exception type o…
xerial Jun 15, 2015
787533c
Remove ValueFactory.newArrayOf
xerial Jun 15, 2015
53557e9
Removed ValueType.bitMask
xerial Jun 15, 2015
9e8c806
Fix test compile error
xerial Jun 15, 2015
33f9ccf
Changed the extension type interface to use byte
xerial Jun 15, 2015
3df8f36
FloatHolder test is no longer necesary
xerial Jun 15, 2015
5289289
Remove RawValue
xerial Jun 15, 2015
4cba605
Fix test case that checks nil value
xerial Jun 15, 2015
c14c87c
Fix test cases and range check of extension types
xerial Jun 15, 2015
f6f9e8f
Fixes test case to use getString to extract raw string value
xerial Jun 15, 2015
e1b8105
Removed obsolete classes
xerial Jun 15, 2015
1d1da11
Moved example codes to test folder
xerial Jun 15, 2015
005edf4
Map.Entry based builder. Add putAll methods
xerial Jun 16, 2015
bef3c55
nil() -> newNil() for method name consisitency
xerial Jun 16, 2015
ca2fb1e
Add comment to ExtensionTypeHeader
xerial Jun 16, 2015
5ba7366
Fix unit test errors
komamitsu Jun 18, 2015
080deb3
Merge pull request #1 from komamitsu/v07-value-impl-rev2-fix-jackson-…
xerial Jun 18, 2015
5ac35d1
Merge pull request #249 from xerial/v07-value-impl-rev2
xerial Jun 19, 2015
b7787d4
removed unnecessary empty lines
frsyuki Jun 23, 2015
27be4d9
removed unused ValueType.toTypeName()
frsyuki Jun 23, 2015
321d64b
added example javadoc on ExtensionTypeHeader constructor
frsyuki Jun 23, 2015
5c51b39
toXXX -> castAsXXX
xerial Jun 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ MessagePack for Java

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

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).
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 [extension format](https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext).

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

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

msgpack-java supports serialization and deserialization of Java objects through [jackson-databind](https://github.com/FasterXML/jackson-databind).
For details, see [msgpack-jackson/README.md](msgpack-jackson/README.md). The template-based serialization mechanism used in v06 is deprecated.
Expand Down
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Fix [#217] when reading from SockectInputStream

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

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.msgpack.core;

import static org.msgpack.core.Preconditions.*;

/**
* Header of the Extension types
*/
public class ExtensionTypeHeader {
private final byte type;
private final int length;

/**
* Create an extension type header
* Example:
* <pre>
* {@code
* import org.msgpack.core.ExtensionTypeHeader;
* import static org.msgpack.core.ExtensionTypeHeader.checkedCastToByte;
* ...
* ExtensionTypeHeader header = new ExtensionTypeHeader(checkedCastToByte(0x01), 32);
* ...
* }
* </pre>
* @param type extension type (byte). You can check the valid byte range with {@link #checkedCastToByte(int)} method.
* @param length extension type data length
*/
public ExtensionTypeHeader(byte type, int length) {
checkArgument(length >= 0, "length must be >= 0");
this.type = type;
this.length = length;
}

public static byte checkedCastToByte(int code) {
checkArgument(Byte.MIN_VALUE <= code && code <= Byte.MAX_VALUE, "Extension type code must be within the range of byte");
return (byte) code;
}

public byte getType() {
return type;
}

public int getLength() {
return length;
}

@Override
public int hashCode() {
return (type + 31) * 31 + length;
}

@Override
public boolean equals(Object obj) {
if(obj instanceof ExtensionTypeHeader) {
ExtensionTypeHeader other = (ExtensionTypeHeader) obj;
return this.type == other.type && this.length == other.length;
}
return false;
}

@Override
public String toString() {
return String.format("ExtensionTypeHeader(type:%d, length:%,d)", type, length);
}

}

This file was deleted.

18 changes: 9 additions & 9 deletions msgpack-core/src/main/java/org/msgpack/core/MessageFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public enum MessageFormat {
BIN8(ValueType.BINARY),
BIN16(ValueType.BINARY),
BIN32(ValueType.BINARY),
EXT8(ValueType.EXTENDED),
EXT16(ValueType.EXTENDED),
EXT32(ValueType.EXTENDED),
EXT8(ValueType.EXTENSION),
EXT16(ValueType.EXTENSION),
EXT32(ValueType.EXTENSION),
FLOAT32(ValueType.FLOAT),
FLOAT64(ValueType.FLOAT),
UINT8(ValueType.INTEGER),
Expand All @@ -38,11 +38,11 @@ public enum MessageFormat {
INT16(ValueType.INTEGER),
INT32(ValueType.INTEGER),
INT64(ValueType.INTEGER),
FIXEXT1(ValueType.EXTENDED),
FIXEXT2(ValueType.EXTENDED),
FIXEXT4(ValueType.EXTENDED),
FIXEXT8(ValueType.EXTENDED),
FIXEXT16(ValueType.EXTENDED),
FIXEXT1(ValueType.EXTENSION),
FIXEXT2(ValueType.EXTENSION),
FIXEXT4(ValueType.EXTENSION),
FIXEXT8(ValueType.EXTENSION),
FIXEXT16(ValueType.EXTENSION),
STR8(ValueType.STRING),
STR16(ValueType.STRING),
STR32(ValueType.STRING),
Expand Down Expand Up @@ -95,7 +95,7 @@ public static MessageFormat valueOf(final byte b) {
* @return
*/
@VisibleForTesting
public static MessageFormat toMessageFormat(final byte b) {
static MessageFormat toMessageFormat(final byte b) {
if (Code.isPosFixInt(b)) {
return POSFIXINT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* using a smaller types. For example, calling MessageUnpacker.unpackInt() for an integer value
* that is larger than Integer.MAX_VALUE will cause this exception.
*/
public class MessageIntegerOverflowException extends MessageOverflowException {

public class MessageIntegerOverflowException extends MessageTypeException {
private final BigInteger bigInteger;

public MessageIntegerOverflowException(BigInteger bigInteger) {
Expand Down

This file was deleted.

26 changes: 13 additions & 13 deletions msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public MessagePacker packString(String s) throws IOException {
flush();

prepareBuffer();
boolean isExtended = false;
boolean isExtension = false;
ByteBuffer encodeBuffer = buffer.toByteBuffer(position, buffer.size() - position);
encoder.reset();
while(in.hasRemaining()) {
Expand All @@ -400,7 +400,7 @@ public MessagePacker packString(String s) throws IOException {
// Coy the current encodeBuffer contents to the new buffer
newBuffer.put(encodeBuffer);
encodeBuffer = newBuffer;
isExtended = true;
isExtension = true;
encoder.reset();
continue;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ public MessagePacker packString(String s) throws IOException {
flush(); // We need to dump the data here to MessageBufferOutput so that we can switch back to the original buffer

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

public MessagePacker packExtendedTypeHeader(int extType, int payloadLen) throws IOException {
public MessagePacker packExtensionTypeHeader(byte extType, int payloadLen) throws IOException {
if(payloadLen < (1 << 8)) {
if(payloadLen > 0 && (payloadLen & (payloadLen - 1)) == 0) { // check whether dataLen == 2^x
if(payloadLen == 1) {
writeByteAndByte(FIXEXT1, (byte) extType);
writeByteAndByte(FIXEXT1, extType);
}
else if(payloadLen == 2) {
writeByteAndByte(FIXEXT2, (byte) extType);
writeByteAndByte(FIXEXT2, extType);
}
else if(payloadLen == 4) {
writeByteAndByte(FIXEXT4, (byte) extType);
writeByteAndByte(FIXEXT4, extType);
}
else if(payloadLen == 8) {
writeByteAndByte(FIXEXT8, (byte) extType);
writeByteAndByte(FIXEXT8, extType);
}
else if(payloadLen == 16) {
writeByteAndByte(FIXEXT16, (byte) extType);
writeByteAndByte(FIXEXT16, extType);
}
else {
writeByteAndByte(EXT8, (byte) payloadLen);
writeByte((byte) extType);
writeByte(extType);
}
}
else {
writeByteAndByte(EXT8, (byte) payloadLen);
writeByte((byte) extType);
writeByte(extType);
}
}
else if(payloadLen < (1 << 16)) {
writeByteAndShort(EXT16, (short) payloadLen);
writeByte((byte) extType);
writeByte(extType);
}
else {
writeByteAndInt(EXT32, payloadLen);
writeByte((byte) extType);
writeByte(extType);

// TODO support dataLen > 2^31 - 1
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// MessagePack for Java
//
// 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.core;

public class MessageTypeCastException extends MessageTypeException {
public MessageTypeCastException() {
super();
}

public MessageTypeCastException(String message) {
super(message);
}

public MessageTypeCastException(String message, Throwable cause) {
super(message, cause);
}

public MessageTypeCastException(Throwable cause) {
super(cause);
}
}
Loading