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
eee96a5b
Commit
eee96a5b
authored
Mar 07, 2017
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: add support for "-" struct tag
parent
667cd518
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
7 deletions
+31
-7
decode.go
rlp/decode.go
+10
-6
decode_test.go
rlp/decode_test.go
+13
-0
encode_test.go
rlp/encode_test.go
+1
-0
typecache.go
rlp/typecache.go
+7
-1
No files found.
rlp/decode.go
View file @
eee96a5b
...
...
@@ -63,12 +63,16 @@ type Decoder interface {
// must contain an element for each decoded field. Decode returns an
// error if there are too few or too many elements.
//
// The decoding of struct fields honours two struct tags, "tail" and
// "nil". For an explanation of "tail", see the example.
// The "nil" tag applies to pointer-typed fields and changes the
// decoding rules for the field such that input values of size zero
// decode as a nil pointer. This tag can be useful when decoding
// recursive types.
// The decoding of struct fields honours certain struct tags, "tail",
// "nil" and "-".
//
// The "-" tag ignores fields.
//
// For an explanation of "tail", see the example.
//
// The "nil" tag applies to pointer-typed fields and changes the decoding
// rules for the field such that input values of size zero decode as a nil
// pointer. This tag can be useful when decoding recursive types.
//
// type StructWithEmptyOK struct {
// Foo *[20]byte `rlp:"nil"`
...
...
rlp/decode_test.go
View file @
eee96a5b
...
...
@@ -339,6 +339,12 @@ var (
)
)
type
hasIgnoredField
struct
{
A
uint
B
uint
`rlp:"-"`
C
uint
}
var
decodeTests
=
[]
decodeTest
{
// booleans
{
input
:
"01"
,
ptr
:
new
(
bool
),
value
:
true
},
...
...
@@ -490,6 +496,13 @@ var decodeTests = []decodeTest{
value
:
tailRaw
{
A
:
1
,
Tail
:
[]
RawValue
{}},
},
// struct tag "-"
{
input
:
"C20102"
,
ptr
:
new
(
hasIgnoredField
),
value
:
hasIgnoredField
{
A
:
1
,
C
:
2
},
},
// RawValue
{
input
:
"01"
,
ptr
:
new
(
RawValue
),
value
:
RawValue
(
unhex
(
"01"
))},
{
input
:
"82FFFF"
,
ptr
:
new
(
RawValue
),
value
:
RawValue
(
unhex
(
"82FFFF"
))},
...
...
rlp/encode_test.go
View file @
eee96a5b
...
...
@@ -218,6 +218,7 @@ var encTests = []encTest{
{
val
:
&
tailRaw
{
A
:
1
,
Tail
:
[]
RawValue
{
unhex
(
"02"
)}},
output
:
"C20102"
},
{
val
:
&
tailRaw
{
A
:
1
,
Tail
:
[]
RawValue
{}},
output
:
"C101"
},
{
val
:
&
tailRaw
{
A
:
1
,
Tail
:
nil
},
output
:
"C101"
},
{
val
:
&
hasIgnoredField
{
A
:
1
,
B
:
2
,
C
:
3
},
output
:
"C20103"
},
// nil
{
val
:
(
*
uint
)(
nil
),
output
:
"80"
},
...
...
rlp/typecache.go
View file @
eee96a5b
...
...
@@ -37,11 +37,12 @@ type typeinfo struct {
type
tags
struct
{
// rlp:"nil" controls whether empty input results in a nil pointer.
nilOK
bool
// rlp:"tail" controls whether this field swallows additional list
// elements. It can only be set for the last field, which must be
// of slice type.
tail
bool
// rlp:"-" ignores fields.
ignored
bool
}
type
typekey
struct
{
...
...
@@ -101,6 +102,9 @@ func structFields(typ reflect.Type) (fields []field, err error) {
if
err
!=
nil
{
return
nil
,
err
}
if
tags
.
ignored
{
continue
}
info
,
err
:=
cachedTypeInfo1
(
f
.
Type
,
tags
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -117,6 +121,8 @@ func parseStructTag(typ reflect.Type, fi int) (tags, error) {
for
_
,
t
:=
range
strings
.
Split
(
f
.
Tag
.
Get
(
"rlp"
),
","
)
{
switch
t
=
strings
.
TrimSpace
(
t
);
t
{
case
""
:
case
"-"
:
ts
.
ignored
=
true
case
"nil"
:
ts
.
nilOK
=
true
case
"tail"
:
...
...
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