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
205af02a
Commit
205af02a
authored
Nov 24, 2014
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: add NewListStream (for p2p)
parent
5a5560f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
decode.go
rlp/decode.go
+9
-0
decode_test.go
rlp/decode_test.go
+18
-0
No files found.
rlp/decode.go
View file @
205af02a
...
@@ -442,6 +442,15 @@ func NewStream(r io.Reader) *Stream {
...
@@ -442,6 +442,15 @@ func NewStream(r io.Reader) *Stream {
s
.
Reset
(
r
)
s
.
Reset
(
r
)
return
s
return
s
}
}
// NewListStream creates a new stream that pretends to be positioned
// at an encoded list of the given length.
func
NewListStream
(
r
io
.
Reader
,
len
uint64
)
*
Stream
{
s
:=
new
(
Stream
)
s
.
Reset
(
r
)
s
.
kind
=
List
s
.
size
=
len
return
s
}
}
// Bytes reads an RLP string and returns its contents as a byte slice.
// Bytes reads an RLP string and returns its contents as a byte slice.
...
...
rlp/decode_test.go
View file @
205af02a
...
@@ -54,6 +54,24 @@ func TestStreamKind(t *testing.T) {
...
@@ -54,6 +54,24 @@ func TestStreamKind(t *testing.T) {
}
}
}
}
func
TestNewListStream
(
t
*
testing
.
T
)
{
ls
:=
NewListStream
(
bytes
.
NewReader
(
unhex
(
"0101010101"
)),
3
)
if
k
,
size
,
err
:=
ls
.
Kind
();
k
!=
List
||
size
!=
3
||
err
!=
nil
{
t
.
Errorf
(
"Kind() returned (%v, %d, %v), expected (List, 3, nil)"
,
k
,
size
,
err
)
}
if
size
,
err
:=
ls
.
List
();
size
!=
3
||
err
!=
nil
{
t
.
Errorf
(
"List() returned (%d, %v), expected (3, nil)"
,
size
,
err
)
}
for
i
:=
0
;
i
<
3
;
i
++
{
if
val
,
err
:=
ls
.
Uint
();
val
!=
1
||
err
!=
nil
{
t
.
Errorf
(
"Uint() returned (%d, %v), expected (1, nil)"
,
val
,
err
)
}
}
if
err
:=
ls
.
ListEnd
();
err
!=
nil
{
t
.
Errorf
(
"ListEnd() returned %v, expected (3, nil)"
,
err
)
}
}
func
TestStreamErrors
(
t
*
testing
.
T
)
{
func
TestStreamErrors
(
t
*
testing
.
T
)
{
type
calls
[]
string
type
calls
[]
string
tests
:=
[]
struct
{
tests
:=
[]
struct
{
...
...
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