Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
eaa81cd4
Commit
eaa81cd4
authored
Jan 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
487229da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
29 deletions
+35
-29
t/neo/marshal.go
t/neo/marshal.go
+18
-18
t/neo/protogen.go
t/neo/protogen.go
+17
-11
No files found.
t/neo/marshal.go
View file @
eaa81cd4
...
...
@@ -400,13 +400,13 @@ overflow:
// 9. AcceptIdentification
func
(
p
*
AcceptIdentification
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
KnownMasterList
);
i
++
{
a
:=
&
p
.
KnownMasterList
[
i
]
size
+=
10
+
len
((
*
a
)
.
Address
.
Host
)
size
0
+=
10
+
len
((
*
a
)
.
Address
.
Host
)
}
return
30
+
len
(
p
.
Primary
.
Host
)
+
size
return
30
+
len
(
p
.
Primary
.
Host
)
+
size
0
}
func
(
p
*
AcceptIdentification
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -722,13 +722,13 @@ overflow:
// 19. AnswerPartitionTable
func
(
p
*
AnswerPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
size
0
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
}
return
12
+
size
return
12
+
size
0
}
func
(
p
*
AnswerPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -812,13 +812,13 @@ overflow:
// 20. NotifyPartitionTable
func
(
p
*
NotifyPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
size
0
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
}
return
12
+
size
return
12
+
size
0
}
func
(
p
*
NotifyPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2596,13 +2596,13 @@ overflow:
// 58. AnswerPartitionList
func
(
p
*
AnswerPartitionList
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
size
0
+=
8
+
len
((
*
a
)
.
CellList
)
*
8
}
return
12
+
size
return
12
+
size
0
}
func
(
p
*
AnswerPartitionList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2709,13 +2709,13 @@ overflow:
// 60. AnswerNodeList
func
(
p
*
AnswerNodeList
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
size
+=
26
+
len
((
*
a
)
.
Address
.
Host
)
size
0
+=
26
+
len
((
*
a
)
.
Address
.
Host
)
}
return
4
+
size
return
4
+
size
0
}
func
(
p
*
AnswerNodeList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2921,13 +2921,13 @@ overflow:
// 64. NotifyNodeInformation
func
(
p
*
NotifyNodeInformation
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
size
+=
26
+
len
((
*
a
)
.
Address
.
Host
)
size
0
+=
26
+
len
((
*
a
)
.
Address
.
Host
)
}
return
4
+
size
return
4
+
size
0
}
func
(
p
*
NotifyNodeInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
t/neo/protogen.go
View file @
eaa81cd4
...
...
@@ -251,16 +251,25 @@ type sizer struct {
symLenv
[]
string
// symbolic part of size
varN
int
// suffix to add to variables (size0, size1, ...) - for nested computations
var
SizeUsed
bool
// whether var siz
e was used
var
Used
map
[
string
]
bool
// whether a variabl
e was used
coderForFunc
}
// get variable name for varname
func
(
s
*
sizer
)
var_
(
varname
string
)
string
{
func
(
s
*
sizer
)
var_
_
(
varname
string
)
string
{
return
fmt
.
Sprintf
(
"%s%d"
,
varname
,
s
.
varN
)
}
func
(
s
*
sizer
)
var_
(
varname
string
)
string
{
varnameX
:=
s
.
var__
(
varname
)
if
s
.
varUsed
==
nil
{
s
.
varUsed
=
make
(
map
[
string
]
bool
)
}
s
.
varUsed
[
varname
]
=
true
return
varnameX
}
// create new sizer for subsize calculation (e.g. for loop)
func
(
s
*
sizer
)
subSizer
()
*
sizer
{
return
&
sizer
{
varN
:
s
.
varN
+
1
}
...
...
@@ -289,8 +298,8 @@ func (s *sizer) resultExpr() string {
if
len
(
s
.
symLenv
)
>
0
{
size
+=
" + "
+
strings
.
Join
(
s
.
symLenv
,
" + "
)
}
if
s
.
var
SizeUsed
{
size
+=
" +
size"
if
s
.
var
Used
[
"size"
]
{
size
+=
" +
"
+
s
.
var__
(
"size"
)
}
return
size
}
...
...
@@ -301,8 +310,8 @@ func (s *sizer) generatedCode() string {
if
s
.
recvName
!=
""
{
code
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
}
if
s
.
var
SizeUsed
{
code
.
emit
(
"var
size int"
)
if
s
.
var
Used
[
"size"
]
{
code
.
emit
(
"var
%s int"
,
s
.
var__
(
"size"
)
)
}
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
...
...
@@ -440,7 +449,6 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
return
}
s
.
varSizeUsed
=
true
s
.
n
+=
4
s
.
emit
(
"for i := 0; i < len(%v); i++ {"
,
path
)
s
.
emit
(
"a := &%s[i]"
,
path
)
...
...
@@ -449,7 +457,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
sloop
)
// FIXME vvv if symLenv is ø; -> turn into "result" function
s
.
emit
(
sloop
.
generatedCode
())
s
.
emit
(
"
size += %v"
,
sloop
.
resultExpr
())
s
.
emit
(
"
%v += %v"
,
s
.
var_
(
"size"
)
,
sloop
.
resultExpr
())
s
.
emit
(
"}"
)
}
...
...
@@ -505,13 +513,11 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
}
panic
(
"UNTESTED"
)
s
.
varSizeUsed
=
true
s
.
n
+=
4
s
.
emit
(
"size += %v"
,
s
.
n
)
s
.
emit
(
"for key := range %s {"
,
path
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
s
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
obj
,
s
)
s
.
emit
(
"
size += %v"
,
s
.
n
)
s
.
emit
(
"
%v += %v"
,
s
.
var_
(
"size"
)
,
s
.
n
)
s
.
emit
(
"}"
)
}
...
...
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