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
24bb68e7
Commit
24bb68e7
authored
Sep 09, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: add RawValue
parent
bc17dba8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
1 deletion
+39
-1
decode.go
rlp/decode.go
+11
-0
decode_test.go
rlp/decode_test.go
+5
-0
encode.go
rlp/encode.go
+7
-0
encode_test.go
rlp/encode_test.go
+5
-0
raw.go
rlp/raw.go
+11
-1
No files found.
rlp/decode.go
View file @
24bb68e7
...
@@ -173,6 +173,8 @@ var (
...
@@ -173,6 +173,8 @@ var (
func
makeDecoder
(
typ
reflect
.
Type
,
tags
tags
)
(
dec
decoder
,
err
error
)
{
func
makeDecoder
(
typ
reflect
.
Type
,
tags
tags
)
(
dec
decoder
,
err
error
)
{
kind
:=
typ
.
Kind
()
kind
:=
typ
.
Kind
()
switch
{
switch
{
case
typ
==
rawValueType
:
return
decodeRawValue
,
nil
case
typ
.
Implements
(
decoderInterface
)
:
case
typ
.
Implements
(
decoderInterface
)
:
return
decodeDecoder
,
nil
return
decodeDecoder
,
nil
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
decoderInterface
)
:
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
decoderInterface
)
:
...
@@ -203,6 +205,15 @@ func makeDecoder(typ reflect.Type, tags tags) (dec decoder, err error) {
...
@@ -203,6 +205,15 @@ func makeDecoder(typ reflect.Type, tags tags) (dec decoder, err error) {
}
}
}
}
func
decodeRawValue
(
s
*
Stream
,
val
reflect
.
Value
)
error
{
r
,
err
:=
s
.
Raw
()
if
err
!=
nil
{
return
err
}
val
.
SetBytes
(
r
)
return
nil
}
func
decodeUint
(
s
*
Stream
,
val
reflect
.
Value
)
error
{
func
decodeUint
(
s
*
Stream
,
val
reflect
.
Value
)
error
{
typ
:=
val
.
Type
()
typ
:=
val
.
Type
()
num
,
err
:=
s
.
uint
(
typ
.
Bits
())
num
,
err
:=
s
.
uint
(
typ
.
Bits
())
...
...
rlp/decode_test.go
View file @
24bb68e7
...
@@ -438,6 +438,11 @@ var decodeTests = []decodeTest{
...
@@ -438,6 +438,11 @@ var decodeTests = []decodeTest{
error
:
"rlp: expected input string or byte for uint, decoding into (rlp.recstruct).Child.I"
,
error
:
"rlp: expected input string or byte for uint, decoding into (rlp.recstruct).Child.I"
,
},
},
// RawValue
{
input
:
"01"
,
ptr
:
new
(
RawValue
),
value
:
RawValue
(
unhex
(
"01"
))},
{
input
:
"82FFFF"
,
ptr
:
new
(
RawValue
),
value
:
RawValue
(
unhex
(
"82FFFF"
))},
{
input
:
"C20102"
,
ptr
:
new
([]
RawValue
),
value
:
[]
RawValue
{
unhex
(
"01"
),
unhex
(
"02"
)}},
// pointers
// pointers
{
input
:
"00"
,
ptr
:
new
(
*
[]
byte
),
value
:
&
[]
byte
{
0
}},
{
input
:
"00"
,
ptr
:
new
(
*
[]
byte
),
value
:
&
[]
byte
{
0
}},
{
input
:
"80"
,
ptr
:
new
(
*
uint
),
value
:
uintp
(
0
)},
{
input
:
"80"
,
ptr
:
new
(
*
uint
),
value
:
uintp
(
0
)},
...
...
rlp/encode.go
View file @
24bb68e7
...
@@ -354,6 +354,8 @@ var (
...
@@ -354,6 +354,8 @@ var (
func
makeWriter
(
typ
reflect
.
Type
)
(
writer
,
error
)
{
func
makeWriter
(
typ
reflect
.
Type
)
(
writer
,
error
)
{
kind
:=
typ
.
Kind
()
kind
:=
typ
.
Kind
()
switch
{
switch
{
case
typ
==
rawValueType
:
return
writeRawValue
,
nil
case
typ
.
Implements
(
encoderInterface
)
:
case
typ
.
Implements
(
encoderInterface
)
:
return
writeEncoder
,
nil
return
writeEncoder
,
nil
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
encoderInterface
)
:
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
encoderInterface
)
:
...
@@ -389,6 +391,11 @@ func isByte(typ reflect.Type) bool {
...
@@ -389,6 +391,11 @@ func isByte(typ reflect.Type) bool {
return
typ
.
Kind
()
==
reflect
.
Uint8
&&
!
typ
.
Implements
(
encoderInterface
)
return
typ
.
Kind
()
==
reflect
.
Uint8
&&
!
typ
.
Implements
(
encoderInterface
)
}
}
func
writeRawValue
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
w
.
str
=
append
(
w
.
str
,
val
.
Bytes
()
...
)
return
nil
}
func
writeUint
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
func
writeUint
(
val
reflect
.
Value
,
w
*
encbuf
)
error
{
i
:=
val
.
Uint
()
i
:=
val
.
Uint
()
if
i
==
0
{
if
i
==
0
{
...
...
rlp/encode_test.go
View file @
24bb68e7
...
@@ -204,6 +204,11 @@ var encTests = []encTest{
...
@@ -204,6 +204,11 @@ var encTests = []encTest{
output
:
"F90200CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376"
,
output
:
"F90200CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376CF84617364668471776572847A786376"
,
},
},
// RawValue
{
val
:
RawValue
(
unhex
(
"01"
)),
output
:
"01"
},
{
val
:
RawValue
(
unhex
(
"82FFFF"
)),
output
:
"82FFFF"
},
{
val
:
[]
RawValue
{
unhex
(
"01"
),
unhex
(
"02"
)},
output
:
"C20102"
},
// structs
// structs
{
val
:
simplestruct
{},
output
:
"C28080"
},
{
val
:
simplestruct
{},
output
:
"C28080"
},
{
val
:
simplestruct
{
A
:
3
,
B
:
"foo"
},
output
:
"C50383666F6F"
},
{
val
:
simplestruct
{
A
:
3
,
B
:
"foo"
},
output
:
"C50383666F6F"
},
...
...
rlp/raw.go
View file @
24bb68e7
...
@@ -16,7 +16,17 @@
...
@@ -16,7 +16,17 @@
package
rlp
package
rlp
import
"io"
import
(
"io"
"reflect"
)
// RawValue represents an encoded RLP value and can be used to delay
// RLP decoding or precompute an encoding. Note that the decoder does
// not verify whether the content of RawValues is valid RLP.
type
RawValue
[]
byte
var
rawValueType
=
reflect
.
TypeOf
(
RawValue
{})
// Split returns the content of first RLP value and any
// Split returns the content of first RLP value and any
// bytes after the value as subslices of b.
// bytes after the value as subslices of b.
...
...
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