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
653a4785
Commit
653a4785
authored
Jan 19, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c1eed395
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
8 deletions
+184
-8
t/neo/marshal.go
t/neo/marshal.go
+174
-0
t/neo/protogen.go
t/neo/protogen.go
+10
-8
No files found.
t/neo/marshal.go
View file @
653a4785
This diff is collapsed.
Click to expand it.
t/neo/protogen.go
View file @
653a4785
...
@@ -55,16 +55,18 @@ func main() {
...
@@ -55,16 +55,18 @@ func main() {
log
.
SetFlags
(
0
)
log
.
SetFlags
(
0
)
// go through proto.go and collect packets type definitions
// go through proto.go and collect packets type definitions
var
mode
parser
.
Mode
=
0
// parser.Trace
var
fv
[]
*
ast
.
File
var
fv
[]
*
ast
.
File
for
_
,
src
:=
range
[]
string
{
"proto.go"
,
"neo.go"
}
{
for
_
,
src
:=
range
[]
string
{
"proto.go"
,
"neo.go"
}
{
f
,
err
:=
parser
.
ParseFile
(
fset
,
src
,
nil
,
mode
)
f
,
err
:=
parser
.
ParseFile
(
fset
,
src
,
nil
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"parse: %v"
,
err
)
log
.
Fatalf
(
"parse: %v"
,
err
)
}
}
fv
=
append
(
fv
,
f
)
fv
=
append
(
fv
,
f
)
}
}
//ast.Print(fset, fv[0])
//return
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
neoPkg
,
err
:=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
neoPkg
,
err
:=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -73,11 +75,6 @@ func main() {
...
@@ -73,11 +75,6 @@ func main() {
neoQualifier
=
types
.
RelativeTo
(
neoPkg
)
neoQualifier
=
types
.
RelativeTo
(
neoPkg
)
//ncode := 0
//ast.Print(fset, f)
//return
// prologue
// prologue
f
:=
fv
[
0
]
// proto.go comes first
f
:=
fv
[
0
]
// proto.go comes first
buf
:=
bytes
.
Buffer
{}
buf
:=
bytes
.
Buffer
{}
...
@@ -90,6 +87,7 @@ import (
...
@@ -90,6 +87,7 @@ import (
`
)
`
)
// go over packet types declaration and generate marshal code for them
// go over packet types declaration and generate marshal code for them
pktCode
:=
0
for
_
,
decl
:=
range
f
.
Decls
{
for
_
,
decl
:=
range
f
.
Decls
{
// we look for types (which can be only under GenDecl)
// we look for types (which can be only under GenDecl)
gendecl
,
ok
:=
decl
.
(
*
ast
.
GenDecl
)
gendecl
,
ok
:=
decl
.
(
*
ast
.
GenDecl
)
...
@@ -99,7 +97,7 @@ import (
...
@@ -99,7 +97,7 @@ import (
for
_
,
spec
:=
range
gendecl
.
Specs
{
for
_
,
spec
:=
range
gendecl
.
Specs
{
typespec
:=
spec
.
(
*
ast
.
TypeSpec
)
// must be because tok = TYPE
typespec
:=
spec
.
(
*
ast
.
TypeSpec
)
// must be because tok = TYPE
//
typename := typespec.Name.Name
typename
:=
typespec
.
Name
.
Name
switch
typespec
.
Type
.
(
type
)
{
switch
typespec
.
Type
.
(
type
)
{
default
:
default
:
...
@@ -112,8 +110,12 @@ import (
...
@@ -112,8 +110,12 @@ import (
//fmt.Println(t)
//fmt.Println(t)
//ast.Print(fset, t)
//ast.Print(fset, t)
fmt
.
Fprintf
(
&
buf
,
"// %d. %s
\n\n
"
,
pktCode
,
typename
)
buf
.
WriteString
(
gendecode
(
typespec
))
buf
.
WriteString
(
gendecode
(
typespec
))
buf
.
WriteString
(
"
\n
"
)
buf
.
WriteString
(
"
\n
"
)
pktCode
++
}
}
}
}
...
...
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