Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Renmae ExtendedType -> ExtensionType
  • Loading branch information
xerial committed Jun 13, 2015
commit e2fc4e68171348bc83755ed80c6d048d776c9f4d
3 changes: 2 additions & 1 deletion 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 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import static org.msgpack.core.Preconditions.*;

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

ExtendedTypeHeader(byte type, int length) {
ExtensionTypeHeader(byte type, int length) {
checkArgument(length >= 0, String.format("length must be >= 0: %,d", length));
this.length = length;
this.type = type;
Expand All @@ -30,16 +30,16 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if(obj instanceof ExtendedTypeHeader) {
ExtendedTypeHeader other = (ExtendedTypeHeader) 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("ExtendedTypeHeader(type:%d, length:%,d)", type, length);
return String.format("ExtensionTypeHeader(type:%d, length:%,d)", type, length);
}

}
16 changes: 8 additions & 8 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
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,7 +477,7 @@ public MessagePacker packValue(Value v) throws IOException {
return this;
}

public MessagePacker packExtendedTypeHeader(int extType, int payloadLen) throws IOException {
public MessagePacker packExtensionTypeHeader(int extType, int payloadLen) throws IOException {
if(payloadLen < (1 << 8)) {
if(payloadLen > 0 && (payloadLen & (payloadLen - 1)) == 0) { // check whether dataLen == 2^x
if(payloadLen == 1) {
Expand Down
31 changes: 15 additions & 16 deletions msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.msgpack.value.Value;
import org.msgpack.value.ImmutableValue;
import org.msgpack.value.Variable;
import org.msgpack.value.ValueType;
import org.msgpack.value.ValueFactory;

import static org.msgpack.core.Preconditions.*;
Expand Down Expand Up @@ -580,9 +579,9 @@ public ImmutableValue unpackValue() throws IOException {
}
return ValueFactory.newMapValue(kvs);
}
case EXTENDED: {
ExtendedTypeHeader extHeader = unpackExtendedTypeHeader();
return ValueFactory.newExtendedValue(extHeader.getType(), readPayload(extHeader.getLength()));
case EXTENSION: {
ExtensionTypeHeader extHeader = unpackExtensionTypeHeader();
return ValueFactory.newExtensionValue(extHeader.getType(), readPayload(extHeader.getLength()));
}
default:
throw new MessageFormatException("Unknown value type");
Expand Down Expand Up @@ -648,9 +647,9 @@ public Variable unpackValue(Variable var) throws IOException {
var.setMapValue(map);
return var;
}
case EXTENDED: {
ExtendedTypeHeader extHeader = unpackExtendedTypeHeader();
var.setExtendedValue(extHeader.getType(), readPayload(extHeader.getLength()));
case EXTENSION: {
ExtensionTypeHeader extHeader = unpackExtensionTypeHeader();
var.setExtensionValue(extHeader.getType(), readPayload(extHeader.getLength()));
return var;
}
default:
Expand Down Expand Up @@ -1042,33 +1041,33 @@ public int unpackMapHeader() throws IOException {
throw unexpected("Map", b);
}

public ExtendedTypeHeader unpackExtendedTypeHeader() throws IOException {
public ExtensionTypeHeader unpackExtensionTypeHeader() throws IOException {
byte b = consume();
switch(b) {
case Code.FIXEXT1:
return new ExtendedTypeHeader(readByte(), 1);
return new ExtensionTypeHeader(readByte(), 1);
case Code.FIXEXT2:
return new ExtendedTypeHeader(readByte(), 2);
return new ExtensionTypeHeader(readByte(), 2);
case Code.FIXEXT4:
return new ExtendedTypeHeader(readByte(), 4);
return new ExtensionTypeHeader(readByte(), 4);
case Code.FIXEXT8:
return new ExtendedTypeHeader(readByte(), 8);
return new ExtensionTypeHeader(readByte(), 8);
case Code.FIXEXT16:
return new ExtendedTypeHeader(readByte(), 16);
return new ExtensionTypeHeader(readByte(), 16);
case Code.EXT8: {
int length = readNextLength8();
byte type = readByte();
return new ExtendedTypeHeader(type, length);
return new ExtensionTypeHeader(type, length);
}
case Code.EXT16: {
int length = readNextLength16();
byte type = readByte();
return new ExtendedTypeHeader(type, length);
return new ExtensionTypeHeader(type, length);
}
case Code.EXT32: {
int length = readNextLength32();
byte type = readByte();
return new ExtendedTypeHeader(type, length);
return new ExtensionTypeHeader(type, length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.msgpack.core.example;

import org.msgpack.core.*;
import org.msgpack.core.buffer.MessageBuffer;
import org.msgpack.value.*;

import java.math.BigInteger;
Expand Down Expand Up @@ -126,7 +125,7 @@ public static void packer() throws IOException {

// Write ext type data: https://github.com/msgpack/msgpack/blob/master/spec.md#ext-format-family
byte[] extData = "custom data type".getBytes(MessagePack.UTF8);
packer.packExtendedTypeHeader(1, 10); // type number [0, 127], data byte length
packer.packExtensionTypeHeader(1, 10); // type number [0, 127], data byte length
packer.writePayload(extData);

// Succinct syntax for packing
Expand Down Expand Up @@ -217,8 +216,8 @@ else if (iv.isInLongRange()) {
System.out.println("read array element: " + e);
}
break;
case EXTENDED:
ExtendedValue ev = v.asExtendedValue();
case EXTENSION:
ExtensionValue ev = v.asExtensionValue();
byte extType = ev.getType();
byte[] extValue = ev.getData();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
package org.msgpack.value;

/**
* The interface {@code ExtendedValue} represents MessagePack's Extended type.
* The interface {@code ExtensionValue} represents MessagePack's Extension type.
*
* MessagePack's Extended type can represent represents a tuple of type information and a byte array where type information is an integer whose meaning is defined by applications.
* MessagePack's Extension type can represent represents a tuple of type information and a byte array where type information is an
* integer whose meaning is defined by applications.
*
* As the type information, applications can use 0 to 127 as the application-specific types. -1 to -128 is reserved for MessagePack's future extension.
*/
public interface ExtendedValue extends Value {
public interface ExtensionValue extends Value {
@Override
public ImmutableExtendedValue immutableValue();
public ImmutableExtensionValue immutableValue();

public byte getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//
package org.msgpack.value;

public interface ImmutableExtendedValue extends ExtendedValue, ImmutableValue {
public interface ImmutableExtensionValue extends ExtensionValue, ImmutableValue {
}
19 changes: 11 additions & 8 deletions msgpack-core/src/main/java/org/msgpack/value/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.msgpack.value;

import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageTypeCastException;

import java.io.IOException;

Expand Down Expand Up @@ -119,12 +120,13 @@ public interface Value {
public boolean isMapValue();

/**
* Returns true if type of this an Extended.
* Returns true if type of this an Extension.
*
* If this method returns true, {@code asExtendedValue} never throws exceptions.
* Note that you can't use <code>instanceof</code> or cast <code>((ExtendedValue) thisValue)</code> to check type of a value because type of a mutable value is variable.
* If this method returns true, {@code asExtensionValue} never throws exceptions.
* Note that you can't use <code>instanceof</code> or cast <code>((ExtensionValue) thisValue)</code> to check type of a value because
* type of a mutable value is variable.
*/
public boolean isExtendedValue();
public boolean isExtensionValue();

/**
* Returns the value as {@code NilValue}. Otherwise throws {@code MessageTypeCastException}.
Expand Down Expand Up @@ -227,14 +229,15 @@ public interface Value {
public MapValue asMapValue();

/**
* Returns the value as {@code ExtendedValue}. Otherwise throws {@code MessageTypeCastException}.
* Returns the value as {@code ExtensionValue}. Otherwise throws {@code MessageTypeCastException}.
*
* Note that you can't use <code>instanceof</code> or cast <code>((ExtendedValue) thisValue)</code> to check type of a value because type of a mutable value is variable.
* Note that you can't use <code>instanceof</code> or cast <code>((ExtensionValue) thisValue)</code> to check type of a value
* because type of a mutable value is variable.
*
* @throws MessageTypeCastException
* If type of this value is not Extended.
* If type of this value is not an Extension.
*/
public ExtendedValue asExtendedValue();
public ExtensionValue asExtensionValue();

/**
* Serializes the value using the specified {@code MessagePacker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
import org.msgpack.value.impl.ImmutableStringValueImpl;
import org.msgpack.value.impl.ImmutableArrayValueImpl;
import org.msgpack.value.impl.ImmutableMapValueImpl;
import org.msgpack.value.impl.ImmutableExtendedValueImpl;
import org.msgpack.value.impl.ImmutableExtensionValueImpl;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
import java.math.BigInteger;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public final class ValueFactory {
private ValueFactory() { }
Expand Down Expand Up @@ -134,7 +132,7 @@ public static ImmutableMapValue newMapValue(Value[] kvs) {
return new ImmutableMapValueImpl(Arrays.copyOf(kvs, kvs.length));
}

public static ImmutableExtendedValue newExtendedValue(byte type, byte[] data) {
return new ImmutableExtendedValueImpl(type, data);
public static ImmutableExtensionValue newExtensionValue(byte type, byte[] data) {
return new ImmutableExtensionValueImpl(type, data);
}
}
8 changes: 3 additions & 5 deletions msgpack-core/src/main/java/org/msgpack/value/ValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
//
package org.msgpack.value;

import org.msgpack.core.MessageFormat;

/**
* MessageTypeFamily is a group of {@link org.msgpack.core.MessageFormat}s
*/
Expand All @@ -30,7 +28,7 @@ public enum ValueType {
BINARY(false, true),
ARRAY(false, false),
MAP(false, false),
EXTENDED(false, true);
EXTENSION(false, true);

private final boolean numberType;
private final boolean rawType;
Expand Down Expand Up @@ -80,7 +78,7 @@ public boolean isMapType() {
return this == MAP;
}

public boolean isExtendedType() {
return this == EXTENDED;
public boolean isExtensionType() {
return this == EXTENSION;
}
}
Loading