Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
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
Hide 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:
...
@@ -400,13 +400,13 @@ overflow:
// 9. AcceptIdentification
// 9. AcceptIdentification
func
(
p
*
AcceptIdentification
)
NEOEncodedLen
()
int
{
func
(
p
*
AcceptIdentification
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
KnownMasterList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
KnownMasterList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
AcceptIdentification
)
NEOEncode
(
data
[]
byte
)
{
...
@@ -722,13 +722,13 @@ overflow:
...
@@ -722,13 +722,13 @@ overflow:
// 19. AnswerPartitionTable
// 19. AnswerPartitionTable
func
(
p
*
AnswerPartitionTable
)
NEOEncodedLen
()
int
{
func
(
p
*
AnswerPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
AnswerPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
@@ -812,13 +812,13 @@ overflow:
...
@@ -812,13 +812,13 @@ overflow:
// 20. NotifyPartitionTable
// 20. NotifyPartitionTable
func
(
p
*
NotifyPartitionTable
)
NEOEncodedLen
()
int
{
func
(
p
*
NotifyPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
NotifyPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
@@ -2596,13 +2596,13 @@ overflow:
...
@@ -2596,13 +2596,13 @@ overflow:
// 58. AnswerPartitionList
// 58. AnswerPartitionList
func
(
p
*
AnswerPartitionList
)
NEOEncodedLen
()
int
{
func
(
p
*
AnswerPartitionList
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
AnswerPartitionList
)
NEOEncode
(
data
[]
byte
)
{
...
@@ -2709,13 +2709,13 @@ overflow:
...
@@ -2709,13 +2709,13 @@ overflow:
// 60. AnswerNodeList
// 60. AnswerNodeList
func
(
p
*
AnswerNodeList
)
NEOEncodedLen
()
int
{
func
(
p
*
AnswerNodeList
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
AnswerNodeList
)
NEOEncode
(
data
[]
byte
)
{
...
@@ -2921,13 +2921,13 @@ overflow:
...
@@ -2921,13 +2921,13 @@ overflow:
// 64. NotifyNodeInformation
// 64. NotifyNodeInformation
func
(
p
*
NotifyNodeInformation
)
NEOEncodedLen
()
int
{
func
(
p
*
NotifyNodeInformation
)
NEOEncodedLen
()
int
{
var
size
int
var
size
0
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
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
)
{
func
(
p
*
NotifyNodeInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
t/neo/protogen.go
View file @
eaa81cd4
...
@@ -251,16 +251,25 @@ type sizer struct {
...
@@ -251,16 +251,25 @@ type sizer struct {
symLenv
[]
string
// symbolic part of size
symLenv
[]
string
// symbolic part of size
varN
int
// suffix to add to variables (size0, size1, ...) - for nested computations
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
coderForFunc
}
}
// get variable name for varname
// 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
)
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)
// create new sizer for subsize calculation (e.g. for loop)
func
(
s
*
sizer
)
subSizer
()
*
sizer
{
func
(
s
*
sizer
)
subSizer
()
*
sizer
{
return
&
sizer
{
varN
:
s
.
varN
+
1
}
return
&
sizer
{
varN
:
s
.
varN
+
1
}
...
@@ -289,8 +298,8 @@ func (s *sizer) resultExpr() string {
...
@@ -289,8 +298,8 @@ func (s *sizer) resultExpr() string {
if
len
(
s
.
symLenv
)
>
0
{
if
len
(
s
.
symLenv
)
>
0
{
size
+=
" + "
+
strings
.
Join
(
s
.
symLenv
,
" + "
)
size
+=
" + "
+
strings
.
Join
(
s
.
symLenv
,
" + "
)
}
}
if
s
.
var
SizeUsed
{
if
s
.
var
Used
[
"size"
]
{
size
+=
" +
size"
size
+=
" +
"
+
s
.
var__
(
"size"
)
}
}
return
size
return
size
}
}
...
@@ -301,8 +310,8 @@ func (s *sizer) generatedCode() string {
...
@@ -301,8 +310,8 @@ func (s *sizer) generatedCode() string {
if
s
.
recvName
!=
""
{
if
s
.
recvName
!=
""
{
code
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
code
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
}
}
if
s
.
var
SizeUsed
{
if
s
.
var
Used
[
"size"
]
{
code
.
emit
(
"var
size int"
)
code
.
emit
(
"var
%s int"
,
s
.
var__
(
"size"
)
)
}
}
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
...
@@ -440,7 +449,6 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
...
@@ -440,7 +449,6 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
return
return
}
}
s
.
varSizeUsed
=
true
s
.
n
+=
4
s
.
n
+=
4
s
.
emit
(
"for i := 0; i < len(%v); i++ {"
,
path
)
s
.
emit
(
"for i := 0; i < len(%v); i++ {"
,
path
)
s
.
emit
(
"a := &%s[i]"
,
path
)
s
.
emit
(
"a := &%s[i]"
,
path
)
...
@@ -449,7 +457,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
...
@@ -449,7 +457,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
sloop
)
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
sloop
)
// FIXME vvv if symLenv is ø; -> turn into "result" function
// FIXME vvv if symLenv is ø; -> turn into "result" function
s
.
emit
(
sloop
.
generatedCode
())
s
.
emit
(
sloop
.
generatedCode
())
s
.
emit
(
"
size += %v"
,
sloop
.
resultExpr
())
s
.
emit
(
"
%v += %v"
,
s
.
var_
(
"size"
)
,
sloop
.
resultExpr
())
s
.
emit
(
"}"
)
s
.
emit
(
"}"
)
}
}
...
@@ -505,13 +513,11 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
...
@@ -505,13 +513,11 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
}
}
panic
(
"UNTESTED"
)
panic
(
"UNTESTED"
)
s
.
varSizeUsed
=
true
s
.
n
+=
4
s
.
n
+=
4
s
.
emit
(
"size += %v"
,
s
.
n
)
s
.
emit
(
"for key := range %s {"
,
path
)
s
.
emit
(
"for key := range %s {"
,
path
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
s
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
s
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
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
(
"}"
)
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