good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
4f12f069
Commit
4f12f069
authored
10 years ago
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
rlp: move decoder type switch to decode.go
parent
195b2d2e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rlp/decode.go
+33
-0
33 additions, 0 deletions
rlp/decode.go
rlp/typecache.go
+3
-32
3 additions, 32 deletions
rlp/typecache.go
with
36 additions
and
32 deletions
rlp/decode.go
+
33
−
0
View file @
4f12f069
...
...
@@ -81,6 +81,39 @@ func (err decodeError) Error() string {
return
fmt
.
Sprintf
(
"rlp: %s for %v"
,
err
.
msg
,
err
.
typ
)
}
var
(
decoderInterface
=
reflect
.
TypeOf
(
new
(
Decoder
))
.
Elem
()
bigInt
=
reflect
.
TypeOf
(
big
.
Int
{})
)
func
makeDecoder
(
typ
reflect
.
Type
)
(
dec
decoder
,
err
error
)
{
kind
:=
typ
.
Kind
()
switch
{
case
typ
.
Implements
(
decoderInterface
)
:
return
decodeDecoder
,
nil
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
decoderInterface
)
:
return
decodeDecoderNoPtr
,
nil
case
typ
.
AssignableTo
(
reflect
.
PtrTo
(
bigInt
))
:
return
decodeBigInt
,
nil
case
typ
.
AssignableTo
(
bigInt
)
:
return
decodeBigIntNoPtr
,
nil
case
isInteger
(
kind
)
:
return
makeNumDecoder
(
typ
),
nil
case
kind
==
reflect
.
String
:
return
decodeString
,
nil
case
kind
==
reflect
.
Slice
||
kind
==
reflect
.
Array
:
return
makeListDecoder
(
typ
)
case
kind
==
reflect
.
Struct
:
return
makeStructDecoder
(
typ
)
case
kind
==
reflect
.
Ptr
:
return
makePtrDecoder
(
typ
)
case
kind
==
reflect
.
Interface
&&
typ
.
NumMethod
()
==
0
:
return
decodeInterface
,
nil
default
:
return
nil
,
fmt
.
Errorf
(
"rlp: type %v is not RLP-serializable"
,
typ
)
}
}
func
makeNumDecoder
(
typ
reflect
.
Type
)
decoder
{
kind
:=
typ
.
Kind
()
switch
{
...
...
This diff is collapsed.
Click to expand it.
rlp/typecache.go
+
3
−
32
View file @
4f12f069
package
rlp
import
(
"fmt"
"math/big"
"reflect"
"sync"
)
...
...
@@ -51,39 +49,12 @@ func cachedTypeInfo1(typ reflect.Type) (*typeinfo, error) {
return
typeCache
[
typ
],
err
}
var
(
decoderInterface
=
reflect
.
TypeOf
(
new
(
Decoder
))
.
Elem
()
bigInt
=
reflect
.
TypeOf
(
big
.
Int
{})
)
func
genTypeInfo
(
typ
reflect
.
Type
)
(
info
*
typeinfo
,
err
error
)
{
info
=
new
(
typeinfo
)
kind
:=
typ
.
Kind
()
switch
{
case
typ
.
Implements
(
decoderInterface
)
:
info
.
decoder
=
decodeDecoder
case
kind
!=
reflect
.
Ptr
&&
reflect
.
PtrTo
(
typ
)
.
Implements
(
decoderInterface
)
:
info
.
decoder
=
decodeDecoderNoPtr
case
typ
.
AssignableTo
(
reflect
.
PtrTo
(
bigInt
))
:
info
.
decoder
=
decodeBigInt
case
typ
.
AssignableTo
(
bigInt
)
:
info
.
decoder
=
decodeBigIntNoPtr
case
isInteger
(
kind
)
:
info
.
decoder
=
makeNumDecoder
(
typ
)
case
kind
==
reflect
.
String
:
info
.
decoder
=
decodeString
case
kind
==
reflect
.
Slice
||
kind
==
reflect
.
Array
:
info
.
decoder
,
err
=
makeListDecoder
(
typ
)
case
kind
==
reflect
.
Struct
:
info
.
decoder
,
err
=
makeStructDecoder
(
typ
)
case
kind
==
reflect
.
Ptr
:
info
.
decoder
,
err
=
makePtrDecoder
(
typ
)
case
kind
==
reflect
.
Interface
&&
typ
.
NumMethod
()
==
0
:
info
.
decoder
=
decodeInterface
default
:
err
=
fmt
.
Errorf
(
"rlp: type %v is not RLP-serializable"
,
typ
)
if
info
.
decoder
,
err
=
makeDecoder
(
typ
);
err
!=
nil
{
return
nil
,
err
}
return
info
,
err
return
info
,
nil
}
func
isInteger
(
k
reflect
.
Kind
)
bool
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment