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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
5a2d62e4
Commit
5a2d62e4
authored
Jul 30, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Added better data parser
parent
42d47ecf
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ethutil/bytes.go
+20
-0
20 additions, 0 deletions
ethutil/bytes.go
ethutil/bytes_test.go
+14
-0
14 additions, 0 deletions
ethutil/bytes_test.go
with
34 additions
and
0 deletions
ethutil/bytes.go
+
20
−
0
View file @
5a2d62e4
...
@@ -131,6 +131,26 @@ func FormatData(data string) []byte {
...
@@ -131,6 +131,26 @@ func FormatData(data string) []byte {
return
BigToBytes
(
d
,
256
)
return
BigToBytes
(
d
,
256
)
}
}
func
ParseData
(
data
...
interface
{})
(
ret
[]
byte
)
{
for
_
,
item
:=
range
data
{
switch
t
:=
item
.
(
type
)
{
case
string
:
var
str
[]
byte
if
IsHex
(
t
)
{
str
=
Hex2Bytes
(
t
[
2
:
])
}
else
{
str
=
[]
byte
(
t
)
}
ret
=
append
(
ret
,
RightPadBytes
(
str
,
32
)
...
)
case
[]
byte
:
ret
=
append
(
ret
,
LeftPadBytes
(
t
,
32
)
...
)
}
}
return
}
func
RightPadBytes
(
slice
[]
byte
,
l
int
)
[]
byte
{
func
RightPadBytes
(
slice
[]
byte
,
l
int
)
[]
byte
{
if
l
<
len
(
slice
)
{
if
l
<
len
(
slice
)
{
return
slice
return
slice
...
...
This diff is collapsed.
Click to expand it.
ethutil/bytes_test.go
0 → 100644
+
14
−
0
View file @
5a2d62e4
package
ethutil
import
(
"bytes"
"testing"
)
func
TestParseData
(
t
*
testing
.
T
)
{
data
:=
ParseData
(
"hello"
,
"world"
,
"0x0106"
)
exp
:=
"68656c6c6f000000000000000000000000000000000000000000000000000000776f726c640000000000000000000000000000000000000000000000000000000106000000000000000000000000000000000000000000000000000000000000"
if
bytes
.
Compare
(
data
,
Hex2Bytes
(
exp
))
!=
0
{
t
.
Error
(
"Error parsing data"
)
}
}
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