GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — V07 value impl by frsyuki · Pull Request #246 · msgpack/msgpack-java

Conversation

@frsyuki

@frsyuki frsyuki commented Jun 10, 2015

Copy link
Copy Markdown
Member

This pull request implements Value API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
frsyuki added 3 commits June 10, 2015 10:05
@frsyuki
implemented Value API
2242fe4
@frsyuki
added org.msgpack.value.Variable
7685276
@frsyuki
implemented Variable.hashCode, equals, toString, and writeTo methods
3393110
fdinoff
fdinoff reviewed Jun 10, 2015
View reviewed changes
Comment thread msgpack-core/src/main/java/org/msgpack/value/impl/ImmutableArrayValueImpl.java Outdated

@fdinoff fdinoff Jun 10, 2015

Copy link
Copy Markdown
Contributor

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 condition seems to be backwards. I think it should be index < array.length

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frsyuki frsyuki Jun 10, 2015

Copy link
Copy Markdown
Member Author

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.

ouch. fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
frsyuki added 2 commits June 10, 2015 14:41
@frsyuki
fixed Value API
a40cbcb
@frsyuki
ImmutableMapValueImpl.equals should not assume order of elements is same
2ff4f59
@xerial xerial self-assigned this Jun 10, 2015
@xerial xerial added this to the 0.7.0-M6 milestone Jun 10, 2015
@fdinoff fdinoff mentioned this pull request Jun 10, 2015
What needs to be done? fdinoff/neovim-java-client#1
Open
xerial added 10 commits June 13, 2015 22:14
@xerial
Renmae ExtendedType -> ExtensionType
e2fc4e6
@xerial
ValueFactory.newXXXValue -> newXXX for brevity
bc7e503
@xerial
immutableValue() -> toImmutable()
b123089
@xerial
Add visitor interface
4bcfab5
@xerial
Add augumented constructor for ExtensionTypeHeader
de6d1f5
@xerial
Fix test case
04819a3
@xerial
Add ValueType bit mask to improve type check performance
d1807a5
@xerial
Preserve float and double differences
770f013
@xerial
Renamed xxxValue that returns primitive type value as toXXX
775379d
@xerial
Remove public scope from interface
301ae10
xerial
xerial reviewed Jun 13, 2015
View reviewed changes
Comment thread msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java Outdated

@xerial xerial Jun 13, 2015

Copy link
Copy Markdown
Member

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:

scala> 0.1341f.toDouble
res5: Double = 0.13410000503063202

If user wants to print this float value as String, 0.13410000503063202 will be shown. This is unexpected behavior for the user.

Another example: 0.1f becomes 0.10000000149011612 string if we use double as 0.1fs internal representation.

I'll fix this in another pull request.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frsyuki frsyuki Jun 14, 2015

Copy link
Copy Markdown
Member Author

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 to Double.longBitsToDouble(0x3fc126e980000000) in MessagePack because MessagePack does not distinguish single-precision from double-precision in terms of type system. So, FloatValue#equals method 1) should always use double, or 2) should always cast to single-precision float if precision of the actual value fits in single-precision float like IntgerValue implementation. Same for FloatValue#hashCode(). If we take 1), when floatValue.equals(other) returns true, floatValue.toString().equals(other.toString()) may return false. If we take 2), deserialization of msgpack's float 64 format becomes slow.

If implement, options are:

a) create ImmutableFloatValueImpl as you mention
b) add boolean floatIsSinglePrecision field. If this is true, toString() and writeTo(Packer) uses single-precision.

I think b) is better for Variable. Otherwise Variable#equals method becomes more complicated. For ImmutableValue, a) or b).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xerial xerial Jun 19, 2015

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fdinoff fdinoff Jun 19, 2015

Copy link
Copy Markdown
Contributor

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.writeTo will write a double to the MessagePacker. Should writeTo reproduce the original msgpacked data or just something close to it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@xerial xerial Jun 19, 2015

Copy link
Copy Markdown
Member

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 writeTo implementation would be useful, but the message type system does not require it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
xerial added 10 commits June 14, 2015 00:30
@xerial
Fix compilation error of msgpack-jackson
9db3537
@xerial
toImmutable -> immutableValue
c782451
@xerial
Remove visitor, ExtensionTypeHeader constructor. Fix exception type o…
ed45331
…f integer overflow
@xerial
Remove ValueFactory.newArrayOf
787533c
@xerial
Removed ValueType.bitMask
53557e9
@xerial
Fix test compile error
9e8c806
@xerial
Changed the extension type interface to use byte
33f9ccf
@xerial
FloatHolder test is no longer necesary
3df8f36
@xerial
Remove RawValue
5289289
@xerial
Fix test case that checks nil value
4cba605
xerial and others added 8 commits June 15, 2015 17:23
@xerial
Removed obsolete classes
e1b8105
@xerial
Moved example codes to test folder
1d1da11
@xerial
Map.Entry based builder. Add putAll methods
005edf4
@xerial
nil() -> newNil() for method name consisitency
bef3c55
@xerial
Add comment to ExtensionTypeHeader
ca2fb1e
@komamitsu
Fix unit test errors
5ba7366
@xerial
Merge pull request #1 from komamitsu/v07-value-impl-rev2-fix-jackson-…
080deb3
…test

Fix unit test errors
@xerial
Merge pull request #249 from xerial/v07-value-impl-rev2
5ac35d1
V07 value impl revision 2
@xerial xerial mentioned this pull request Jun 19, 2015
msgpack-value v07 API #109
Closed
frsyuki added 3 commits June 22, 2015 18:44
@frsyuki
removed unnecessary empty lines
b7787d4
@frsyuki
removed unused ValueType.toTypeName()
27be4d9
@frsyuki
added example javadoc on ExtensionTypeHeader constructor
321d64b
@xerial

xerial commented Jun 23, 2015

Copy link
Copy Markdown
Member

@muga
I also feel getXXX and toXXX are confusing. And also toString produces JSON string that produces double quoted strings even if user need to get a string value. There are lot of confusing points.

How about renaming these methods as follows?:

  • (round)toXXX (with truncation or rounding)
  • (cast)asXXX throws Exception (checked cast)
  • toJSON (produces json string. The same with the current implementation of toString)

Then remove getXXX methods.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frsyuki

frsyuki commented Jun 23, 2015

Copy link
Copy Markdown
Member Author

How about this simply?

  • rename NumberValue#toXxx() methods to NumberValue#roundToXxx()

I think it's a possible idea to separate toJson from toString. However, because some values are not compatible with JSON (non-string keys of a map, ExtensionValue, floating point values, etc.), we would need another class like ValueToJsonPacker that converts Value to JSON so that the conversion behavior can be configurable using the constructor of the packer class.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 23, 2015

Copy link
Copy Markdown
Member

@frsyuki
If we recommend to use Value.getXXX to extract values, simply renaming toXXX -> roundToXXX is better.

My concern on StringValue.toString is it always returns double quoted value in generating string messages with StringValue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 23, 2015

Copy link
Copy Markdown
Member

Using double quoted string looks good for distinguishing StringValue "1" and FloatValue 1 when debugging.

OK. I'll go with roundToXXX, getXXX and toString. toJSON should be implemented in another class as @frsyuki said.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 23, 2015

Copy link
Copy Markdown
Member

A problem is getting float value has no good name like roundToXXX.

How about using asXXX for truncation and rounding (e.g., asInt, asFloat, etc., rather than roundToInt, roundToFloat?).

If we use asXXX, we can simply say representing this value as XXX type.

mmm. But asXXXValue is already used for converting Value types. So castAsXXX might be better.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial
toXXX -> castAsXXX
5c51b39
xerial added a commit that referenced this pull request Jun 23, 2015
@xerial
Merge pull request #246 from msgpack/v07-value-impl
21816fb
V07 value impl
@xerial
xerial merged commit 21816fb into v07-develop Jun 23, 2015
@xerial

xerial commented Jun 23, 2015

Copy link
Copy Markdown
Member

Merged. Will add test codes and further internal improvement in another PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frsyuki

frsyuki commented Jun 25, 2015

Copy link
Copy Markdown
Member Author

Why don't you use roundToXxx? I think that castAsXxx assumes that users understand the actual implementation the methods. If we assume that users don't have to know the actual implementation, I think castToXxx is confusing because I don't know whether it throws exceptions or not. For example, Double v = 1.1; Integer iv = (Integer) v; throws an exception in Java. So, "cast" doesn't always implies rounding.

In my opinion, roundToFloat / roundToDouble is correct name because it actually can rounding.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frsyuki

frsyuki commented Jun 25, 2015

Copy link
Copy Markdown
Member Author

@xerial How about this radical idea?:

  • Concept:
    • toXxx and asXxx are the type casting methods.
    • toXxx methods may lose some information but never throws exceptions.
    • asXxx methods don't lose information but might throw exceptions. Perhaps it's good idea to make them checked-exception so that difference of toXxx and asXxx becomes very clear.
  • Implementation:
    • a) change IntegerValue#getXxx() to asXxx()
    • b) change NumberValue#castAsXxx() to toXxx() including toFloat() and toDouble()
    • c) change RawValue#getString() to asString(), RawValue#getByteBuffer() to asByteBuffer(), RawValue#getByteArray() to asByteArray()
    • d) change ListValue#list() to asList(), MapValue#map() to asMap()
    • e) change BooleanValue#getBoolean() to asBoolean()
    • f) remove StringValue#stringValue()
    • g) change StringValue#toString() so that it doesn't add double quotes
    • h) add String Value#toJson(). This implementation is same with current #toString(). So, it's easy to implement.
    • i) add void Value#toJson(JsonPacker) in the future so that we can customize behavior and improve performance if necessary. For example, "how to convert BinaryValue to JSON?", "how to convert ExntesionValue to JSON?", "how to convert FloatValue to JSON?", "how to handle non-string keys in a MapValue?"

With this idea, you can achieve short names and consistent concept at the same time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 25, 2015

Copy link
Copy Markdown
Member

@frsyuki
If we do h) (toString -> toJson), I agree with your idea:

  • toXXX (may lose information with casting, but throws no exception)
  • asXXX (may throw exception)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 25, 2015

Copy link
Copy Markdown
Member

@frsyuki
But NumberValue.asXXX is already used for Value.asXXXValue. That was why I choose castAsXXX to distinguish methods that produce native values and msgpack Values.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frsyuki

frsyuki commented Jun 25, 2015

Copy link
Copy Markdown
Member Author

@xerial I think that Value.asAbcValue methods are also a kind of asXxx methods because it doesn't lose information, may throw exception, and Xxx is the returning class name.
(I edited above comment. toJson is not f but h. please check on github)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial

xerial commented Jun 26, 2015

Copy link
Copy Markdown
Member

If having asInt and asIntegerValue is OK, there would be no problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xerial xerial mentioned this pull request Jun 27, 2015
Rename data access methods #259
Closed
@komamitsu komamitsu mentioned this pull request Jun 28, 2015
Jackson: Serializing and Deserializing Extended Types #238
Closed
@xerial
xerial deleted the v07-value-impl branch July 19, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@xerial xerial

Labels

None yet

Projects

None yet

Milestone

0.7.0-M6

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@frsyuki @xerial @muga @fdinoff @komamitsu
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.