forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 5
feat(rlp/rlpgen): support alias types #154
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b25ad2
feat(rlp/rlpgen): support alias types
qdm12 51a44bd
Merge branch 'main' into qdm12/rlp/rlpgen/alias-support
ARR4N 96a991a
test(rlp/rlpgen): aliased types
ARR4N d155384
refactor(rlp/rlpgen): use `Unalias` instead of `Rhs`
ARR4N 623a80d
refactor(rlp/rlpgen): `Unalias` all instead of adding a `case`
ARR4N 4c6e2fd
test(rlp/rlpgen): demonstrate recursive unaliasing
ARR4N 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // -*- mode: go -*- | ||
|
|
||
| package test | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "github.com/holiman/uint256" | ||
| ) | ||
|
|
||
| // Alias types chosen because their originals have special handling that is easy | ||
| // to spot when inspecting generated output. | ||
| type ( | ||
| Big = big.Int | ||
| // Demonstrate recursive unaliasing | ||
| intermediate = uint256.Int | ||
| Uint256 = intermediate | ||
| ) | ||
|
|
||
| type Test struct { | ||
| BigAlias Big | ||
| Uint256Alias Uint256 | ||
| } | ||
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,43 @@ | ||
| package test | ||
|
|
||
| import "github.com/ava-labs/libevm/rlp" | ||
| import "github.com/holiman/uint256" | ||
| import "io" | ||
|
|
||
| func (obj *Test) EncodeRLP(_w io.Writer) error { | ||
| w := rlp.NewEncoderBuffer(_w) | ||
| _tmp0 := w.List() | ||
| if obj.BigAlias.Sign() == -1 { | ||
| return rlp.ErrNegativeBigInt | ||
| } | ||
| w.WriteBigInt(&obj.BigAlias) | ||
| w.WriteUint256(&obj.Uint256Alias) | ||
| w.ListEnd(_tmp0) | ||
| return w.Flush() | ||
| } | ||
|
|
||
| func (obj *Test) DecodeRLP(dec *rlp.Stream) error { | ||
| var _tmp0 Test | ||
| { | ||
| if _, err := dec.List(); err != nil { | ||
| return err | ||
| } | ||
| // BigAlias: | ||
| _tmp1, err := dec.BigInt() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _tmp0.BigAlias = (*_tmp1) | ||
| // Uint256Alias: | ||
| var _tmp2 uint256.Int | ||
| if err := dec.ReadUint256(&_tmp2); err != nil { | ||
| return err | ||
| } | ||
| _tmp0.Uint256Alias = _tmp2 | ||
| if err := dec.ListEnd(); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| *obj = _tmp0 | ||
| return nil | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.