-
Notifications
You must be signed in to change notification settings - Fork 325
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
V07 value impl #246
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
2242fe4
implemented Value API
frsyuki 7685276
added org.msgpack.value.Variable
frsyuki 3393110
implemented Variable.hashCode, equals, toString, and writeTo methods
frsyuki a40cbcb
fixed Value API
frsyuki 2ff4f59
ImmutableMapValueImpl.equals should not assume order of elements is same
frsyuki e2fc4e6
Renmae ExtendedType -> ExtensionType
xerial bc7e503
ValueFactory.newXXXValue -> newXXX for brevity
xerial b123089
immutableValue() -> toImmutable()
xerial 4bcfab5
Add visitor interface
xerial de6d1f5
Add augumented constructor for ExtensionTypeHeader
xerial 04819a3
Fix test case
xerial d1807a5
Add ValueType bit mask to improve type check performance
xerial 770f013
Preserve float and double differences
xerial 775379d
Renamed xxxValue that returns primitive type value as toXXX
xerial 301ae10
Remove public scope from interface
xerial 9db3537
Fix compilation error of msgpack-jackson
xerial c782451
toImmutable -> immutableValue
xerial ed45331
Remove visitor, ExtensionTypeHeader constructor. Fix exception type o…
xerial 787533c
Remove ValueFactory.newArrayOf
xerial 53557e9
Removed ValueType.bitMask
xerial 9e8c806
Fix test compile error
xerial 33f9ccf
Changed the extension type interface to use byte
xerial 3df8f36
FloatHolder test is no longer necesary
xerial 5289289
Remove RawValue
xerial 4cba605
Fix test case that checks nil value
xerial c14c87c
Fix test cases and range check of extension types
xerial f6f9e8f
Fixes test case to use getString to extract raw string value
xerial e1b8105
Removed obsolete classes
xerial 1d1da11
Moved example codes to test folder
xerial 005edf4
Map.Entry based builder. Add putAll methods
xerial bef3c55
nil() -> newNil() for method name consisitency
xerial ca2fb1e
Add comment to ExtensionTypeHeader
xerial 5ba7366
Fix unit test errors
komamitsu 080deb3
Merge pull request #1 from komamitsu/v07-value-impl-rev2-fix-jackson-…
xerial 5ac35d1
Merge pull request #249 from xerial/v07-value-impl-rev2
xerial b7787d4
removed unnecessary empty lines
frsyuki 27be4d9
removed unused ValueType.toTypeName()
frsyuki 321d64b
added example javadoc on ExtensionTypeHeader constructor
frsyuki 5c51b39
toXXX -> castAsXXX
xerial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
implemented Value API
- Loading branch information
commit 2242fe497b88c6add197b67ffd46a71e926ff593
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
msgpack-core/src/main/java/org/msgpack/core/MessageTypeCastException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I remembered why FloatHolder was necessary. When reading a float value as double, it will add some fractions. For example:
If user wants to print this float value as String,
0.13410000503063202will be shown. This is unexpected behavior for the user.Another example:
0.1fbecomes0.10000000149011612string if we use double as0.1fs internal representation.I'll fix this in another pull request.
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.
I think it is OK to say say that it's a limitation because of internal representation of a Value because anyways it is impossible to preserve all information of floating point numbers using decimal string format.
A reason is this trade-off: First of all,
Float.intBitsToFloat(0x3e09374c)is equal toDouble.longBitsToDouble(0x3fc126e980000000)in MessagePack because MessagePack does not distinguish single-precision from double-precision in terms of type system. So,FloatValue#equalsmethod 1) should always usedouble, or 2) should always cast to single-precision float if precision of the actual value fits in single-precision float like IntgerValue implementation. Same forFloatValue#hashCode(). If we take 1), whenfloatValue.equals(other)returns true,floatValue.toString().equals(other.toString())may return false. If we take 2), deserialization of msgpack'sfloat 64format becomes slow.If implement, options are:
a) create ImmutableFloatValueImpl as you mention
b) add
boolean floatIsSinglePrecisionfield. If this is true,toString()andwriteTo(Packer)uses single-precision.I think b) is better for Variable. Otherwise
Variable#equalsmethod becomes more complicated. For ImmutableValue, a) or b).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.
Discussed this topic with @frsyuki. MessagePack type system will not preserve the error range of float values since some msgpack implementation cannot have float values. So application developers needs to be careful so as not to write a code that depends on float precision. Even if the data is written in FLOAT32, Value interface will represent it in double precision.
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.
Going this route means that if a single precision number is in the data stream and read into a value.
Value.writeTowill write a double to the MessagePacker. ShouldwriteToreproduce the original msgpacked data or just something close to it?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.
This discussion has started in MessagePack specification side:
msgpack/msgpack#200
If we can preserve original message-packed data in an efficient way, lossless
writeToimplementation would be useful, but the message type system does not require it.