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
0413e93b
Commit
0413e93b
authored
Jan 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6745433a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
t/neo/protogen.go
t/neo/protogen.go
+20
-20
No files found.
t/neo/protogen.go
View file @
0413e93b
...
...
@@ -124,7 +124,7 @@ func main() {
// prologue
f
:=
fv
[
0
]
// proto.go comes first
f
:=
fv
[
0
]
// proto.go comes first
buf
:=
Buffer
{}
buf
.
emit
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
...
...
@@ -135,7 +135,7 @@ import (
"sort"
)`
)
pktTypeRegistry
:=
map
[
int
]
string
{}
// pktCode -> typename
pktTypeRegistry
:=
map
[
int
]
string
{}
// pktCode -> typename
// go over packet types declaration and generate marshal code for them
buf
.
emit
(
"// packets marshalling
\n
"
)
...
...
@@ -175,7 +175,7 @@ import (
// now generate packet types registry
buf
.
emit
(
"
\n
// registry of packet types"
)
buf
.
emit
(
"var pktTypeRegistry = map[int]reflect.Type {"
)
// XXX key -> PktCode ?
buf
.
emit
(
"var pktTypeRegistry = map[int]reflect.Type {"
)
// XXX key -> PktCode ?
// ordered by pktCode
pktCodeV
:=
[]
int
{}
...
...
@@ -193,7 +193,7 @@ import (
// format & output generated code
code
,
err
:=
format
.
Source
(
buf
.
Bytes
())
if
err
!=
nil
{
panic
(
err
)
// should not happen
panic
(
err
)
// should not happen
}
_
,
err
=
os
.
Stdout
.
Write
(
code
)
...
...
@@ -295,13 +295,13 @@ type CodeGenerator interface {
// common part of codegenerators
type
commonCodeGen
struct
{
buf
Buffer
// code is emitted here
buf
Buffer
// code is emitted here
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
typ
types
.
Type
varUsed
map
[
string
]
bool
// whether a variable was used
varUsed
map
[
string
]
bool
// whether a variable was used
}
func
(
c
*
commonCodeGen
)
emit
(
format
string
,
a
...
interface
{})
{
...
...
@@ -327,8 +327,8 @@ func (c *commonCodeGen) var_(varname string) string {
// consists of numeric & symbolic expression parts
// size is num + expr1 + expr2 + ...
type
SymSize
struct
{
num
int
// numeric part of size
exprv
[]
string
// symbolic part of size
num
int
// numeric part of size
exprv
[]
string
// symbolic part of size
}
func
(
s
*
SymSize
)
Add
(
n
int
)
{
...
...
@@ -425,7 +425,7 @@ func (o *OverflowCheck) AddExpr(format string, a ...interface{}) {
// result is: symbolic size + (optionally) runtime accumulator.
type
sizer
struct
{
commonCodeGen
size
SymSize
// currently accumulated packet size
size
SymSize
// currently accumulated packet size
}
// encoder generates code to encode a packet
...
...
@@ -441,7 +441,7 @@ type sizer struct {
// ...
type
encoder
struct
{
commonCodeGen
n
int
// current write position in data
n
int
// current write position in data
}
// decoder generates code to decode a packet
...
...
@@ -468,9 +468,9 @@ type decoder struct {
// current delayed overflow check will be inserted in between bufDone & buf
bufDone
Buffer
n
int
// current read position in data.
nread
int
// numeric part of total nread return
nreadStk
[]
int
// stack to push/pop nread on loops
n
int
// current read position in data.
nread
int
// numeric part of total nread return
nreadStk
[]
int
// stack to push/pop nread on loops
// overflow check state and size that will be checked for overflow at
// current overflow check point
...
...
@@ -686,7 +686,7 @@ func (e *encoder) genArray1(path string, typ *types.Array) {
func
(
d
*
decoder
)
genArray1
(
assignto
string
,
typ
*
types
.
Array
)
{
typLen
:=
int
(
typ
.
Len
())
d
.
emit
(
"copy(%v[:], data[%v:%v])"
,
assignto
,
d
.
n
,
d
.
n
+
typLen
)
d
.
emit
(
"copy(%v[:], data[%v:%v])"
,
assignto
,
d
.
n
,
d
.
n
+
typLen
)
d
.
n
+=
typLen
d
.
overflow
.
Add
(
typLen
)
}
...
...
@@ -823,7 +823,7 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
if
keyFixed
&&
elemFixed
{
s
.
size
.
Add
(
4
)
s
.
size
.
AddExpr
(
"len(%v) * %v"
,
path
,
keySize
+
elemSize
)
s
.
size
.
AddExpr
(
"len(%v) * %v"
,
path
,
keySize
+
elemSize
)
return
}
...
...
@@ -863,7 +863,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
e
.
emit
(
"for _, key := range keyv {"
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
e
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
obj
,
e
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// XXX wrt map of map?
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// XXX wrt map of map?
e
.
emit
(
"}"
)
e
.
emit
(
"}"
)
e
.
n
=
0
...
...
@@ -880,7 +880,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
if
keyFixed
&&
elemFixed
{
d
.
overflowCheck
()
d
.
overflow
.
AddExpr
(
"l * %v"
,
keySize
+
elemSize
)
d
.
overflow
.
AddExpr
(
"l * %v"
,
keySize
+
elemSize
)
d
.
overflow
.
PushChecked
(
true
)
defer
d
.
overflow
.
PopChecked
()
}
...
...
@@ -933,7 +933,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
case
*
types
.
Struct
:
for
i
:=
0
;
i
<
u
.
NumFields
();
i
++
{
v
:=
u
.
Field
(
i
)
codegenType
(
path
+
"."
+
v
.
Name
(),
v
.
Type
(),
v
,
codegen
)
codegenType
(
path
+
"."
+
v
.
Name
(),
v
.
Type
(),
v
,
codegen
)
}
case
*
types
.
Array
:
...
...
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