Conversation
Bersaelor
approved these changes
Feb 22, 2018
Bersaelor
left a comment
There was a problem hiding this comment.
I like this PR, definitely would help with the use-cases I had in mind for MessagePack.
Also kudos for going the extra mile with the Unit Tests
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request has arisen from my work on what is now an alternative implementation to pull request #61. I realized the need for more precision in the decoding process of integers (signed and unsigned) and floating point numbers. This patch does not modify the packing or unpacking process. It only provides a more robust and specific set of convenience properties for each width of integer, float, or double, requiring the value be exactly representable by the target type if the packed value is not already of the correct type.
I believe this approach might result in less decoding errors. For example, previously, if you have a Double precision float point number, and accidentally invoke
MessagePackValue.floatValueyou would get back a nicely truncated float. This loss of precision could easily go unnoticed. Instead,MessagePackValue.floatValuewill only return non-nil if the underlyingDoublecan truly be represented by a float (in many cases, it cannot). While this might seem somewhat inconvenient initially, it offers a nice forcing function to ensure the correct data type is being decoded earlier in the development process. If one is okay with loss of precision, a simple truncating is no more difficult (but entirely more clear to the reader) than:I think this stricter typing in the convenience property API is more in line with the strict typing promoted by swift itself.