Skip to content
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

rlp: support for uint256 #26898

Merged
merged 17 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rlp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,7 @@ func (s *Stream) decodeUint256(dst *uint256.Int) error {
// Avoid zero-length read.
s.kind = -1
case size <= uint64(len(s.uintbuf)):
// For integers smaller than s.uintbuf, allocating a buffer
// can be avoided.
// All possible uint256 values fit into s.uintbuf.
buffer = s.uintbuf[:size]
if err := s.readFull(buffer); err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions rlp/encbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ func (w *encBuffer) writeBigInt(i *big.Int) {
}
}

// writeU256Int writes i as a uint256.Int.
func (w *encBuffer) writeU256Int(z *uint256.Int) {
// writeUint256 writes z as an integer.
func (w *encBuffer) writeUint256(z *uint256.Int) {
bitlen := z.BitLen()
if bitlen <= 64 {
w.writeUint64(z.Uint64())
Expand Down Expand Up @@ -396,6 +396,11 @@ func (w EncoderBuffer) WriteBigInt(i *big.Int) {
w.buf.writeBigInt(i)
}

// WriteUint256 encodes uint256.Int as an RLP string.
func (w EncoderBuffer) WriteUint256(i *big.Int) {
holiman marked this conversation as resolved.
Show resolved Hide resolved
w.buf.writeUint256(i)
}

// WriteBytes encodes b as an RLP string.
func (w EncoderBuffer) WriteBytes(b []byte) {
w.buf.writeBytes(b)
Expand Down
4 changes: 2 additions & 2 deletions rlp/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ func writeU256IntPtr(val reflect.Value, w *encBuffer) error {
w.str = append(w.str, 0x80)
return nil
}
w.writeU256Int(ptr)
w.writeUint256(ptr)
return nil
}

func writeU256IntNoPtr(val reflect.Value, w *encBuffer) error {
i := val.Interface().(uint256.Int)
w.writeU256Int(&i)
w.writeUint256(&i)
return nil
}

Expand Down