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
79eaa6f2
Commit
79eaa6f2
authored
Jan 01, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed old serialization
parent
34d62c38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
83 deletions
+0
-83
serialization.go
serialization.go
+0
-63
serialization_test.go
serialization_test.go
+0
-20
No files found.
serialization.go
deleted
100644 → 0
View file @
34d62c38
package
main
import
(
"math"
"bytes"
)
func
ToBinary
(
x
int
,
bytes
int
)
string
{
if
bytes
==
0
{
return
""
}
else
{
return
ToBinary
(
int
(
x
/
256
),
bytes
-
1
)
+
string
(
x
%
256
)
}
}
func
NumToVarInt
(
x
int
)
string
{
if
x
<
253
{
return
string
(
x
)
}
else
if
x
<
int
(
math
.
Pow
(
2
,
16
))
{
return
string
(
253
)
+
ToBinary
(
x
,
2
)
}
else
if
x
<
int
(
math
.
Pow
(
2
,
32
))
{
return
string
(
253
)
+
ToBinary
(
x
,
4
)
}
else
{
return
string
(
253
)
+
ToBinary
(
x
,
8
)
}
}
func
RlpEncode
(
object
interface
{})
string
{
if
str
,
ok
:=
object
.
(
string
);
ok
{
return
"
\x00
"
+
NumToVarInt
(
len
(
str
))
+
str
}
else
if
num
,
ok
:=
object
.
(
uint32
);
ok
{
return
RlpEncode
(
Uitoa
(
num
))
}
else
if
byt
,
ok
:=
object
.
([]
byte
);
ok
{
return
RlpEncode
(
string
(
byt
))
}
else
if
slice
,
ok
:=
object
.
([]
interface
{});
ok
{
var
buffer
bytes
.
Buffer
for
_
,
val
:=
range
slice
{
if
v
,
ok
:=
val
.
(
string
);
ok
{
buffer
.
WriteString
(
RlpEncode
(
v
))
}
else
{
buffer
.
WriteString
(
RlpEncode
(
val
))
}
}
return
"
\x01
"
+
RlpEncode
(
len
(
buffer
.
String
()))
+
buffer
.
String
()
}
else
if
slice
,
ok
:=
object
.
([]
string
);
ok
{
// FIXME this isn't dry. Fix this
var
buffer
bytes
.
Buffer
for
_
,
val
:=
range
slice
{
buffer
.
WriteString
(
RlpEncode
(
val
))
}
return
"
\x01
"
+
RlpEncode
(
len
(
buffer
.
String
()))
+
buffer
.
String
()
}
return
""
}
type
RlpSerializer
interface
{
MarshalRlp
()
[]
byte
UnmarshalRlp
([]
byte
)
}
serialization_test.go
deleted
100644 → 0
View file @
34d62c38
package
main
import
(
"testing"
"fmt"
)
func
TestRlpEncode
(
t
*
testing
.
T
)
{
strRes
:=
"
\x00\x03
dog"
str
:=
RlpEncode
(
"dog"
)
if
str
!=
strRes
{
t
.
Error
(
fmt
.
Sprintf
(
"Expected %q, got %q"
,
strRes
,
str
))
}
sliceRes
:=
"
\x01\x00\x03
dog
\x00\x03
god
\x00\x03
cat"
slice
:=
RlpEncode
([]
string
{
"dog"
,
"god"
,
"cat"
})
if
slice
!=
sliceRes
{
t
.
Error
(
fmt
.
Sprintf
(
"Expected %q, got %q"
,
sliceRes
,
slice
))
}
}
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