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
1e542169
Commit
1e542169
authored
Jan 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
eaa81cd4
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
234 additions
and
282 deletions
+234
-282
t/neo/marshal.go
t/neo/marshal.go
+197
-252
t/neo/protogen.go
t/neo/protogen.go
+37
-30
No files found.
t/neo/marshal.go
View file @
1e542169
This diff is collapsed.
Click to expand it.
t/neo/protogen.go
View file @
1e542169
...
...
@@ -234,59 +234,59 @@ type CodecCodeGen interface {
}
// sizer/encode/decode codegen
type
co
derForFunc
struct
{
type
co
mmonCoder
struct
{
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
varN
int
// suffix to add to variables (size0, size1, ...) - for nested computations
varUsed
map
[
string
]
bool
// whether a variable was used
}
func
(
c
*
co
derForFunc
)
setFunc
(
recvName
,
typeName
string
)
{
func
(
c
*
co
mmonCoder
)
setFunc
(
recvName
,
typeName
string
)
{
c
.
recvName
=
recvName
c
.
typeName
=
typeName
}
// get variable name for varname
func
(
c
*
commonCoder
)
var__
(
varname
string
)
string
{
return
fmt
.
Sprintf
(
"%s%d"
,
varname
,
c
.
varN
)
}
func
(
c
*
commonCoder
)
var_
(
varname
string
)
string
{
varnameX
:=
c
.
var__
(
varname
)
if
c
.
varUsed
==
nil
{
c
.
varUsed
=
make
(
map
[
string
]
bool
)
}
c
.
varUsed
[
varname
]
=
true
return
varnameX
}
type
sizer
struct
{
Buffer
// buffer for code
n
int
// fixed part of size
symLenv
[]
string
// symbolic part of size
varN
int
// suffix to add to variables (size0, size1, ...) - for nested computations
varUsed
map
[
string
]
bool
// whether a variable was used
coderForFunc
}
// get variable name for varname
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
commonCoder
}
// create new sizer for subsize calculation (e.g. for loop)
func
(
s
*
sizer
)
subSizer
()
*
sizer
{
return
&
sizer
{
varN
:
s
.
varN
+
1
}
return
&
sizer
{
commonCoder
:
commonCoder
{
varN
:
s
.
varN
+
1
}
}
}
type
encoder
struct
{
Buffer
// XXX
n
int
co
derForFunc
co
mmonCoder
}
type
decoder
struct
{
Buffer
// buffer for generated code
n
int
// current decode position in data
co
derForFunc
co
mmonCoder
}
var
_
CodecCodeGen
=
(
*
sizer
)(
nil
)
...
...
@@ -354,12 +354,19 @@ func (d *decoder) generatedCode() string {
if
d
.
recvName
!=
""
{
code
.
emit
(
"func (%s *%s) NEODecode(data []byte) (int, error) {"
,
d
.
recvName
,
d
.
typeName
)
}
code
.
emit
(
"var nread uint32"
)
if
d
.
varUsed
[
"nread"
]
{
code
.
emit
(
"var %v uint32"
,
d
.
var__
(
"nread"
))
}
code
.
Write
(
d
.
Bytes
())
// XXX -> d.buf.Bytes() ?
// epilogue
code
.
emit
(
"return int(nread) + %v, nil"
,
d
.
n
)
retexpr
:=
fmt
.
Sprintf
(
"%v"
,
d
.
n
)
if
d
.
varUsed
[
"nread"
]
{
retexpr
+=
fmt
.
Sprintf
(
" + int(%v)"
,
d
.
var__
(
"nread"
))
}
code
.
emit
(
"return %v, nil"
,
retexpr
)
code
.
emit
(
"
\n
overflow:"
)
code
.
emit
(
"return 0, ErrDecodeOverflow"
)
code
.
emit
(
"goto overflow"
)
// TODO check if overflow used at all and remove
...
...
@@ -431,7 +438,7 @@ func (d *decoder) genStrBytes(assignto string) {
d
.
emit
(
"if uint32(len(data)) < l { goto overflow }"
)
d
.
emit
(
"%v= string(data[:l])"
,
assignto
)
d
.
emit
(
"data = data[l:]"
)
d
.
emit
(
"
nread += %v + l"
,
d
.
n
)
d
.
emit
(
"
%v += %v + l"
,
d
.
var_
(
"nread"
)
,
d
.
n
)
d
.
emit
(
"}"
)
d
.
n
=
0
}
...
...
@@ -481,7 +488,7 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"
nread += %v"
,
d
.
n
)
d
.
emit
(
"
%v += %v"
,
d
.
var_
(
"nread"
)
,
d
.
n
)
d
.
n
=
0
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
// TODO size check
...
...
@@ -492,7 +499,7 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
// XXX try to avoid (*) in a
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
d
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt slice of slice ?
d
.
emit
(
"
nread += %v"
,
d
.
n
)
d
.
emit
(
"
%v += %v"
,
d
.
var_
(
"nread"
)
,
d
.
n
)
d
.
emit
(
"}"
)
//d.emit("%v= string(data[:l])", assignto)
d
.
emit
(
"}"
)
...
...
@@ -548,7 +555,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"
nread += %v"
,
d
.
n
)
d
.
emit
(
"
%v += %v"
,
d
.
var_
(
"nread"
)
,
d
.
n
)
d
.
n
=
0
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
// TODO size check
...
...
@@ -572,7 +579,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
}
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
// FIXME wrt map of map ?
d
.
emit
(
"
nread += %v"
,
d
.
n
)
d
.
emit
(
"
%v += %v"
,
d
.
var_
(
"nread"
)
,
d
.
n
)
d
.
emit
(
"}"
)
//d.emit("%v= string(data[:l])", assignto)
d
.
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