-
Notifications
You must be signed in to change notification settings - Fork 58
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
conversion: behavioural changes in String
, MarshalText
and MarshalJSON
#144
Merged
Conversation
This file contains 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
cc @karalabe |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #144 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 1642 1643 +1
=========================================
+ Hits 1642 1643 +1 |
namiloh
reviewed
Nov 26, 2023
namiloh
reviewed
Nov 26, 2023
namiloh
reviewed
Nov 26, 2023
karalabe
reviewed
Nov 27, 2023
karalabe
reviewed
Nov 27, 2023
holiman
force-pushed
the
marshalling_compat
branch
from
November 27, 2023 09:04
25d5103
to
0016c17
Compare
…s, to maximise big.Int compatibility
holiman
force-pushed
the
marshalling_compat
branch
from
November 27, 2023 09:08
0016c17
to
6dee50a
Compare
karalabe
reviewed
Nov 27, 2023
holiman
commented
Nov 27, 2023
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 PR changes the way marshalling and unmarshalling behaves, in order to maximize compatibilty with
big.Int
: as in, maximize the chance that a 'drop in' replacement ofbig.Int
foruint256.Int
will work seamlessly.String()
- before this change,String()
would return the integer in hexadecimal format. This PR changes it to instead return the input in decimal format, likebig.Int
does.MarshalText()
now returns the integer in decimal format, previously hexadecimal.MarshalJSON()
now returns the integer in decimal format, previously hexadecimal.UnmarshalText
now accepts either hex,0x234
or234
. Previously it accepted only hex.UnmarshalJSON
now accepts either hex-string,"0x234"
, dec-string"234"
or naked numeric decimal234
. Previously it accepted only string-hex.JSON marshalling is, alas, not 100% compatible, since
big.Int
marshals to json numeric format:{ Foo: 5}
as opposed to string-format:{ Foo: "5" }
. The former is not ideal for large numbers, since platforms like javascript do not support arbitary large numbers, usually capped at53
bits or so.To clarify a bit more, re backwards compatibility.
Example 1
If you previously had a struct,
And you
json
-encoded that to disk. the format would be e.g{"Value":5}
. If you then replacebig
withuint256
Before this PR: The
json
-encoded old format could not be unmarshalled into the newuint256
-format, sinceuint256.UnmarshalJSON
only accepted hex-encoded strings.After this PR: The
json
-encoded old format can be unmarshalled into the newuint256
-format, sinceuint256.UnmarshalJSON
now accepts json numerics.