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
fc0cf8de
Commit
fc0cf8de
authored
Jan 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
93447c73
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
t/neo/protogen.go
t/neo/protogen.go
+26
-22
No files found.
t/neo/protogen.go
View file @
fc0cf8de
...
...
@@ -48,7 +48,7 @@ can do a good job the work is delegated to it.
--------
TODO also types registry tables
XXX also types registry tables are generated - document
*/
...
...
@@ -173,7 +173,7 @@ import (
}
}
// now packet types registry
// now
generate
packet types registry
buf
.
emit
(
"
\n
// registry of packet types"
)
buf
.
emit
(
"var pktTypeRegistry = map[int]reflect.Type {"
)
// XXX key -> PktCode ?
...
...
@@ -190,7 +190,7 @@ import (
buf
.
emit
(
"}"
)
// format &
emi
t generated code
// format &
outpu
t generated code
code
,
err
:=
format
.
Source
(
buf
.
Bytes
())
if
err
!=
nil
{
panic
(
err
)
// should not happen
...
...
@@ -423,7 +423,7 @@ func (o *OverflowCheck) AddExpr(format string, a ...interface{}) {
// sizer generates code to compute encoded size of a packet
//
// when type is recursively walked, for every case symbolic size is added appropriately.
// in case when it was needed to generate loops runtime accumulator variable is additionally used.
// in case when it was needed to generate loops
,
runtime accumulator variable is additionally used.
// result is: symbolic size + (optionally) runtime accumulator.
type
sizer
struct
{
commonCodeGen
...
...
@@ -436,7 +436,7 @@ type sizer struct {
// no overflow checks are generated as by NEOEncoder interface provided data
// buffer should have at least NEOEncodedLen() length (the size computed by sizer).
//
// the code emitted
is of kind
:
// the code emitted
looks like
:
//
// encode<typ1>(data[n1:], path1)
// encode<typ2>(data[n2:], path2)
...
...
@@ -451,11 +451,11 @@ type encoder struct {
// when type is recursively walked, for every case code to decode next item from
// `data[n:]` is generated.
//
// overflow checks and
, when convenient, nread updates are grouped and emitted
//
so that they are performed in the beginning of greedy fixed-wire-size
//
blocks - check
ing as much as possible to do ahead in one go.
// overflow checks and
nread updates are grouped and emitted so that they are
//
performed in the beginning of greedy fixed-wire-size blocks - checking /
//
updat
ing as much as possible to do ahead in one go.
//
// the code emitted
is of kind
:
// the code emitted
looks like
:
//
// if len(data) < wireSize(typ1) + wireSize(typ2) + ... {
// goto overflow
...
...
@@ -519,8 +519,8 @@ func (e *encoder) generatedCode() string {
}
// XXX place? naming?
// data
<- data[pos
:]
//
pos <-
0
// data
= data[n
:]
//
n =
0
func
(
d
*
decoder
)
resetPos
()
{
if
d
.
n
!=
0
{
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
...
...
@@ -528,18 +528,20 @@ func (d *decoder) resetPos() {
}
}
// mark current place for
delayed
insertion of overflow check code
// mark current place for insertion of overflow check code
//
// delayed: because we go forward in decode path scanning ahead as far as we
// can - until first seeing variable-size encoded something, and then - knowing
// fixed size would be to read - insert checking condition for accumulated size
// to here-marked overflow checkpoint.
// The check will be acutally inserted later.
//
// later: because first we go forward in decode path scanning ahead as far as
// we can - until first seeing variable-size encoded something, and then -
// knowing fixed size would be to read - insert checking condition for
// accumulated size to here-marked overflow checkpoint.
//
// so overflowCheck does:
// 1. emit overflow checking code for previous overflow checkpoint
// 2. mark current place as next overflow checkpoint to eventually emit
//
// it
is
inserted
// it
has to be
inserted
// - before reading a variable sized item
// - in the beginning of a loop inside (via overflowCheckLoopEntry)
// - right after loop exit (via overflowCheckLoopExit)
...
...
@@ -559,8 +561,9 @@ func (d *decoder) overflowCheck() {
// otherwise accumulate into var(nread) at runtime.
// we do not break runtime accumulation into numeric & symbolic
// parts, because just above whole expression num + symbolic
// was just given to compiler so compiler should have it just computed.
// XXX recheck ^^^ actually good with the compiler
// was given to compiler as a whole so compiler should have it
// just computed fully.
// XXX recheck ^^^ is actually good with the compiler
if
d
.
overflow
.
checkSize
.
IsNumeric
()
{
d
.
nread
+=
d
.
overflow
.
checkSize
.
num
}
else
{
...
...
@@ -574,7 +577,7 @@ func (d *decoder) overflowCheck() {
d
.
buf
.
Reset
()
}
// overflowCheck variant that should be
call
ed at the beginning of a loop inside
// overflowCheck variant that should be
insert
ed at the beginning of a loop inside
func
(
d
*
decoder
)
overflowCheckLoopEntry
()
{
if
d
.
overflow
.
checked
{
return
...
...
@@ -582,13 +585,13 @@ func (d *decoder) overflowCheckLoopEntry() {
d
.
overflowCheck
()
// upon entering a loop organize new nread, because what w
as
statically
// upon entering a loop organize new nread, because what w
ill be
statically
// read inside loop should be multiplied by loop len in parent context.
d
.
nreadStk
=
append
(
d
.
nreadStk
,
d
.
nread
)
d
.
nread
=
0
}
// overflowCheck variant that should be
call
ed right after loop exit
// overflowCheck variant that should be
insert
ed right after loop exit
func
(
d
*
decoder
)
overflowCheckLoopExit
(
loopLenExpr
string
)
{
if
d
.
overflow
.
checked
{
return
...
...
@@ -628,6 +631,7 @@ func (d *decoder) generatedCode() string {
code
.
emit
(
"return %v, nil"
,
retexpr
)
// `goto overflow` is not used only for empty structs
// NOTE for >0 check actual X in StdSizes{X} does not particularly matter
if
(
&
types
.
StdSizes
{
8
,
8
})
.
Sizeof
(
d
.
typ
)
>
0
{
code
.
emit
(
"
\n
overflow:"
)
code
.
emit
(
"return 0, ErrDecodeOverflow"
)
...
...
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