-
Notifications
You must be signed in to change notification settings - Fork 320
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
msgpack-value v07 API #109
Conversation
BIG_INTEGER | ||
} | ||
|
||
private Type tpe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a private field, which is not visible to the user, but using type
is OK.
package org.msgpack.core; | ||
|
||
/** | ||
* Created on 5/28/14. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we fix the comment to describe what this exception expresses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will add a description.
�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() : Value
ornextRef() : ValueRef
to 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.value
is now within the msgpack-core project becauseCursor
andValueHolder
need 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.value
package within msgpack-core project makes simple these interactions.Cursor.nextRef
is about 2.7 times faster than usingCursor.next
(returns immutable values):unpackValue(ValueHolder)
,unpackInteger(IntegerHolder)
,unpackFloat(FloatHolder)
Array/MapCursor
interfaces that can be obtained fromCursor
provide 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>
andValue
API 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 test
sbt publishSigned
, thensbt sonatypeRelease
.