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
7429c8ba
Commit
7429c8ba
authored
Jan 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e1f92e97
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
12 deletions
+40
-12
t/neo/marshal.go
t/neo/marshal.go
+9
-6
t/neo/protogen.go
t/neo/protogen.go
+31
-6
No files found.
t/neo/marshal.go
View file @
7429c8ba
...
...
@@ -400,6 +400,7 @@ overflow:
// 9. AcceptIdentification
func
(
p
*
AcceptIdentification
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
30
for
i
:=
0
;
i
<
len
(
p
.
KnownMasterList
);
i
++
{
a
:=
&
p
.
KnownMasterList
[
i
]
...
...
@@ -721,6 +722,7 @@ overflow:
// 19. AnswerPartitionTable
func
(
p
*
AnswerPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
12
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
...
...
@@ -810,6 +812,7 @@ overflow:
// 20. NotifyPartitionTable
func
(
p
*
NotifyPartitionTable
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
12
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
...
...
@@ -1092,8 +1095,7 @@ overflow:
// 27. AnswerLockedTransactions
func
(
p
*
AnswerLockedTransactions
)
NEOEncodedLen
()
int
{
size
+=
4
+
len
(
p
.
TidDict
)
*
16
return
0
return
4
+
len
(
p
.
TidDict
)
*
16
}
func
(
p
*
AnswerLockedTransactions
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2594,6 +2596,7 @@ overflow:
// 58. AnswerPartitionList
func
(
p
*
AnswerPartitionList
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
12
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
...
...
@@ -2706,6 +2709,7 @@ overflow:
// 60. AnswerNodeList
func
(
p
*
AnswerNodeList
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
4
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
...
...
@@ -2917,6 +2921,7 @@ overflow:
// 64. NotifyNodeInformation
func
(
p
*
NotifyNodeInformation
)
NEOEncodedLen
()
int
{
var
size
int
size
+=
4
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
...
...
@@ -3156,8 +3161,7 @@ overflow:
// 70. AnswerObjectUndoSerial
func
(
p
*
AnswerObjectUndoSerial
)
NEOEncodedLen
()
int
{
size
+=
4
+
len
(
p
.
ObjectTIDDict
)
*
25
return
0
return
4
+
len
(
p
.
ObjectTIDDict
)
*
25
}
func
(
p
*
AnswerObjectUndoSerial
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3400,8 +3404,7 @@ overflow:
// 77. CheckReplicas
func
(
p
*
CheckReplicas
)
NEOEncodedLen
()
int
{
size
+=
4
+
len
(
p
.
PartitionDict
)
*
8
return
16
return
20
+
len
(
p
.
PartitionDict
)
*
8
}
func
(
p
*
CheckReplicas
)
NEOEncode
(
data
[]
byte
)
{
...
...
t/neo/protogen.go
View file @
7429c8ba
...
...
@@ -232,6 +232,9 @@ type sizer struct {
n
int
symLenv
[]
string
// symbolic lengths to add to size
varSizeUsed
bool
// whether var size was used
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
}
type
encoder
struct
{
...
...
@@ -249,7 +252,26 @@ var _ CodecCodeGen = (*encoder)(nil)
var
_
CodecCodeGen
=
(
*
decoder
)(
nil
)
func
(
s
*
sizer
)
generatedCode
()
string
{
return
s
.
String
()
// XXX -> d.buf.String() ?
prologue
:=
Buffer
{}
if
s
.
recvName
!=
""
{
prologue
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
}
if
s
.
varSizeUsed
{
prologue
.
emit
(
"var size int"
)
}
epilogue
:=
Buffer
{}
size
:=
fmt
.
Sprintf
(
"%v"
,
s
.
n
)
if
len
(
s
.
symLenv
)
>
0
{
size
+=
" + "
+
strings
.
Join
(
s
.
symLenv
,
" + "
)
}
if
s
.
varSizeUsed
{
size
+=
" + size"
}
epilogue
.
emit
(
"return %v"
,
size
)
epilogue
.
emit
(
"}
\n
"
)
return
prologue
.
String
()
+
s
.
String
()
+
epilogue
.
String
()
// XXX -> d.buf.String() ?
}
func
(
e
*
encoder
)
generatedCode
()
string
{
...
...
@@ -261,10 +283,9 @@ func (d *decoder) generatedCode() string {
}
func
(
s
*
sizer
)
genPrologue
(
recvName
,
typeName
string
)
{
s
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
recvName
,
typeName
)
if
s
.
varSizeUsed
{
s
.
emit
(
"var size int"
)
}
s
.
recvName
=
recvName
s
.
typeName
=
typeName
//s.emit("func (%s *%s) NEOEncodedLen() int {", recvName, typeName)
}
func
(
e
*
encoder
)
genPrologue
(
recvName
,
typeName
string
)
{
...
...
@@ -277,6 +298,7 @@ func (d *decoder) genPrologue(recvName, typeName string) {
}
func
(
s
*
sizer
)
genEpilogue
()
{
/*
size := fmt.Sprintf("%v", s.n)
if len(s.symLenv) > 0 {
size += " + " + strings.Join(s.symLenv, " + ")
...
...
@@ -286,6 +308,7 @@ func (s *sizer) genEpilogue() {
}
s.emit("return %v", size)
s.emit("}\n")
*/
}
func
(
e
*
encoder
)
genEpilogue
()
{
...
...
@@ -442,10 +465,12 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
if
keyFixed
&&
elemFixed
{
s
.
emit
(
"size += 4 + len(%v) * %v"
,
path
,
keySize
+
elemSize
)
s
.
n
+=
4
s
.
symLenv
=
append
(
s
.
symLenv
,
fmt
.
Sprintf
(
"len(%v) * %v"
,
path
,
keySize
+
elemSize
))
return
}
s
.
varSizeUsed
=
true
s
.
emit
(
"size += %v + 4"
,
s
.
n
)
s
.
n
=
0
s
.
emit
(
"for key := range %s {"
,
path
)
...
...
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