Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
8c3095fa
Commit
8c3095fa
authored
Jan 30, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: fix encoding of arrays with byte element type
parent
410b35e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
encode.go
rlp/encode.go
+21
-1
encode_test.go
rlp/encode_test.go
+6
-0
No files found.
rlp/encode.go
View file @
8c3095fa
...
...
@@ -301,8 +301,10 @@ func makeWriter(typ reflect.Type) (writer, error) {
return
writeUint
,
nil
case
kind
==
reflect
.
String
:
return
writeString
,
nil
case
kind
==
reflect
.
Slice
&&
typ
.
Elem
()
.
Kind
()
==
reflect
.
Uint8
&&
!
typ
.
Elem
()
.
Implements
(
encoderInterface
)
:
case
kind
==
reflect
.
Slice
&&
isByte
(
typ
.
Elem
()
)
:
return
writeBytes
,
nil
case
kind
==
reflect
.
Array
&&
isByte
(
typ
.
Elem
())
:
return
writeByteArray
,
nil
case
kind
==
reflect
.
Slice
||
kind
==
reflect
.
Array
:
return
makeSliceWriter
(
typ
)
case
kind
==
reflect
.
Struct
:
...
...
@@ -314,6 +316,10 @@ func makeWriter(typ reflect.Type) (writer, error) {
}
}
func
isByte
(
typ
reflect
.
Type
)
bool
{
return
typ
.
Kind
()
==
reflect
.
Uint8
&&
!
typ
.
Implements
(
encoderInterface
)
}
func
writeUint
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
i
:=
val
.
Uint
()
if
i
==
0
{
...
...
@@ -358,6 +364,20 @@ func writeBytes(val reflect.Value, w *encbuf) error {
return
nil
}
func
writeByteArray
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
if
!
val
.
CanAddr
()
{
// Slice requires the value to be addressable.
// Make it addressable by copying.
copy
:=
reflect
.
New
(
val
.
Type
())
.
Elem
()
copy
.
Set
(
val
)
val
=
copy
}
size
:=
val
.
Len
()
slice
:=
val
.
Slice
(
0
,
size
)
.
Bytes
()
w
.
encodeString
(
slice
)
return
nil
}
func
writeString
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
s
:=
val
.
String
()
w
.
encodeStringHeader
(
len
(
s
))
...
...
rlp/encode_test.go
View file @
8c3095fa
...
...
@@ -40,6 +40,8 @@ func (e *encodableReader) Read(b []byte) (int, error) {
panic
(
"called"
)
}
type
namedByteType
byte
var
(
_
=
Encoder
(
&
testEncoder
{})
_
=
Encoder
(
byteEncoder
(
0
))
...
...
@@ -102,6 +104,10 @@ var encTests = []encTest{
// byte slices, strings
{
val
:
[]
byte
{},
output
:
"80"
},
{
val
:
[]
byte
{
1
,
2
,
3
},
output
:
"83010203"
},
{
val
:
[]
namedByteType
{
1
,
2
,
3
},
output
:
"83010203"
},
{
val
:
[
...
]
namedByteType
{
1
,
2
,
3
},
output
:
"83010203"
},
{
val
:
""
,
output
:
"80"
},
{
val
:
"dog"
,
output
:
"83646F67"
},
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment