Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
msgpack-value v07 API #109
Conversation
| BIG_INTEGER | ||
| } | ||
|
|
||
| private Type tpe; |
komamitsu
Jun 22, 2014
Member
type is better?
type is better?
xerial
Jun 22, 2014
Author
Member
It's a private field, which is not visible to the user, but using type is OK.
It's a private field, which is not visible to the user, but using type is OK.
| return isBigInteger() ? biValue.byteValue() : (byte) longValue; | ||
| } | ||
|
|
||
| public short toShort() { |
komamitsu
Jun 22, 2014
Member
Can you add a comment to explain the difference of toXxxx() and asXxxx? It seems that the difference is whether it allows a cast that causes overflow, though.
Can you add a comment to explain the difference of toXxxx() and asXxxx? It seems that the difference is whether it allows a cast that causes overflow, though.
xerial
Jun 22, 2014
Author
Member
NumberValue, a base class of IntegerValue and IntegerHolder, has detailed descriptions of these methods. https://github.com/msgpack/msgpack-java/blob/v07-value/msgpack-core/src/main/java/org/msgpack/value/NumberValue.java
Please look at these docs.
NumberValue, a base class of IntegerValue and IntegerHolder, has detailed descriptions of these methods. https://github.com/msgpack/msgpack-java/blob/v07-value/msgpack-core/src/main/java/org/msgpack/value/NumberValue.java
Please look at these docs.
xerial
Jun 22, 2014
Author
Member
@Override annotation should be here.
@Override annotation should be here.
komamitsu
Jun 22, 2014
Member
Please look at these docs.
Thanks :)
Please look at these docs.
Thanks :)
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return isBigInteger() ? biValue.hashCode() : (int) longValue; |
komamitsu
Jun 22, 2014
Member
Integer.MAX_VALUE + 1 and Integer.MIN_VALUE return the same hash?
Integer.MAX_VALUE + 1 and Integer.MIN_VALUE return the same hash?
xerial
Jun 22, 2014
Author
Member
It could be. A better hash function should produce the same pos/negative flag to the original value. Here is the hash function of BigInteger:
public int hashCode() {
int hashCode = 0;
for (int i=0; i<mag.length; i++)
hashCode = (int)(31*hashCode + (mag[i] & LONG_MASK));
return hashCode * signum;
}
We should use a similar hash computation here.
It could be. A better hash function should produce the same pos/negative flag to the original value. Here is the hash function of BigInteger:
public int hashCode() {
int hashCode = 0;
for (int i=0; i<mag.length; i++)
hashCode = (int)(31*hashCode + (mag[i] & LONG_MASK));
return hashCode * signum;
}
We should use a similar hash computation here.
| @Override | ||
| public ByteBuffer toByteBuffer() { | ||
| switch(tpe) { | ||
| case STRING: |
komamitsu
Jun 22, 2014
Member
What about BINARY?
What about BINARY?
xerial
Jun 22, 2014
Author
Member
It is missing. I will add a statement for BINARY.
It is missing. I will add a statement for BINARY.
| public class RawHolder extends RawHolderImpl { | ||
|
|
||
| private static class StringValueWrap extends RawHolderImpl implements StringValue { | ||
| public StringValue toValue() { |
komamitsu
Jun 22, 2014
Member
Can you add Override annotation here?
Can you add Override annotation here?
xerial
Jun 22, 2014
Author
Member
ok.
ok.
| } | ||
| } | ||
|
|
||
| private StringValueWrap stringWrap = new StringValueWrap(); |
komamitsu
Jun 22, 2014
Member
final keyword.
final keyword.
xerial
Jun 22, 2014
Author
Member
These wraps should be final. Thanks.
These wraps should be final. Thanks.
| package org.msgpack.core; | ||
|
|
||
| /** | ||
| * Created on 5/28/14. |
oza
Jun 29, 2014
Member
Should we fix the comment to describe what this exception expresses?
Should we fix the comment to describe what this exception expresses?
xerial
Jun 30, 2014
Author
Member
OK. I will add a description.
OK. I will add a description.
| case Code.UINT32: // unsigned int 32 | ||
| int u32 = readInt(); | ||
| if(u32 < 0) { | ||
| holder.setLong((long) (u32 & 0x7fffffff) + 0x80000000L); |
oza
Jun 29, 2014
Member
Can we calculate this result by using only bit operation instead of the combination of bit operation and add operation?
(long) (u32 & 0xffffffffL)
Can we calculate this result by using only bit operation instead of the combination of bit operation and add operation?
(long) (u32 & 0xffffffffL)
xerial
Jun 30, 2014
Author
Member
👍
|
�Simplified the interface by removing Cursor and ValueRef. Instead the Value interface now has |
|
why not adding ImmutableXxxValue interfaces? |
|
@frsyuki Do you mean |
|
@oza that's right. ImmutableXxxValue are an interfaces extending XxxValue. As an user, I want to know whether "this value" could be changed by other modules. With ImmutableValue and ImmutableXxxValue, I can use compiler's help to make sure this value is guaranteed to be immutable without writing unlimited amount of tests. |
|
I'm assuming Cursor, MapCursor and ArrayCursor will be removed. Am I correct? |
|
Hmm, latest patch still has Cursor, MapCursor and ArrayCursor. @xerial could you clarify this point? |
|
@frsyuki OK. I'm now working on adding ImmutableValue interfaces. |
|
@xerial Thank you for the explication. Overall, I agree with you.
My draft code implemented this idea: https://github.com/msgpack/msgpack-java/blob/v07-value-sf/msgpack-value/src/main/java/org/msgpack/value/ValueBuffer.java A difficulty is reusing nested values to store nested elements of a array and map Value. A known solution is to use an object pool (ValueBufferPool). Another difficulty here is the timing to reuse nested elements. A solution is to add ValueBuffer.release(). These ideas need following complex interfaces:
You may have another idea. |
|
How can I pack a JavaBean?I found there is no method to pack JAVABean |
|
This work in progress at #246 |
I implemented msgpack-value API for v07. Here is an overview of the API:

msgpack-value has the following components:
hasNext(), thennext() : ValueornextRef() : ValueRefto retrieve values.cursor.next()/nextRef()is called. To make it immutable, callValueRef.toValue() : Value, which creates a copy of the referenced value.ValueRef, a sort of union (in C language) that can hold any type of a value. This is useful to reduce the cost of Value instance creation. MessageUnpacker directly feeds a value into the holder viaunpackValue(ValueHolder)method.Miscellaneous notes:
org.msgpack.valueis now within the msgpack-core project becauseCursorandValueHolderneed to interact with MessageUnpacker, and it makes difficult to separate msgpack-core and msgpack-value projects. For example, to switch the holder to use (e.g., long? or BigInteger?), addingunpackValue(ValueHolder)to the unpacker, then let it choose the target holder is the most straightforward way. And also ValueHolder can be used as an implementation of ValueRef. Movingorg.msgpack.valuepackage within msgpack-core project makes simple these interactions.Cursor.nextRefis about 2.7 times faster than usingCursor.next(returns immutable values):unpackValue(ValueHolder),unpackInteger(IntegerHolder),unpackFloat(FloatHolder)Array/MapCursorinterfaces that can be obtained fromCursorprovide the methods for traversing arrays and maps without constructing the whole array/map values.List<Value>andMap<Value, Value>interfaces, but this design makes complicate the implementation since Java does not allow mixin of theList<Value>andValueAPI implementations (e.g., AbstractValue). Because of this, we needed to copy many codes to implement Array/MapCursor. Instead, I chose to provide onlyhasNext()andnext()methods to traverse map/array values.sbt testsbt publishSigned, thensbt sonatypeRelease.