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
6fd2401c
Commit
6fd2401c
authored
Jul 29, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue with var int reading.
Reading uneven byte slices were broken.
parent
6e94c024
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
bytes.go
ethutil/bytes.go
+27
-3
value.go
ethutil/value.go
+0
-1
No files found.
ethutil/bytes.go
View file @
6fd2401c
...
...
@@ -45,15 +45,15 @@ func BytesToNumber(b []byte) uint64 {
//
// Read a variable length number in big endian byte order
func
ReadVarint
(
reader
*
bytes
.
Reader
)
(
ret
uint64
)
{
if
reader
.
Len
()
==
8
{
if
reader
.
Len
()
>
4
{
var
num
uint64
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
}
else
if
reader
.
Len
()
==
4
{
}
else
if
reader
.
Len
()
>
2
{
var
num
uint32
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
}
else
if
reader
.
Len
()
==
2
{
}
else
if
reader
.
Len
()
>
0
{
var
num
uint16
binary
.
Read
(
reader
,
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
...
...
@@ -66,6 +66,30 @@ func ReadVarint(reader *bytes.Reader) (ret uint64) {
return
ret
}
func
ReadVarInt
(
buff
[]
byte
)
(
ret
uint64
)
{
switch
l
:=
len
(
buff
);
{
case
l
>
4
:
d
:=
LeftPadBytes
(
buff
,
8
)
binary
.
Read
(
bytes
.
NewReader
(
d
),
binary
.
BigEndian
,
&
ret
)
case
l
>
2
:
var
num
uint32
d
:=
LeftPadBytes
(
buff
,
4
)
binary
.
Read
(
bytes
.
NewReader
(
d
),
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
case
l
>
1
:
var
num
uint16
d
:=
LeftPadBytes
(
buff
,
2
)
binary
.
Read
(
bytes
.
NewReader
(
d
),
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
default
:
var
num
uint8
binary
.
Read
(
bytes
.
NewReader
(
buff
),
binary
.
BigEndian
,
&
num
)
ret
=
uint64
(
num
)
}
return
}
// Binary length
//
// Returns the true binary length of the given number
...
...
ethutil/value.go
View file @
6fd2401c
...
...
@@ -67,7 +67,6 @@ func (val *Value) Uint() uint64 {
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
([]
byte
);
ok
{
return
new
(
big
.
Int
)
.
SetBytes
(
Val
)
.
Uint64
()
//return ReadVarint(bytes.NewReader(Val))
}
else
if
Val
,
ok
:=
val
.
Val
.
(
*
big
.
Int
);
ok
{
return
Val
.
Uint64
()
}
...
...
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