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
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() {
log
.
SetFlags
(
0
)
// go through proto.go and collect packets type definitions
var
mode
parser
.
Mode
=
0
// parser.Trace
var
fv
[]
*
ast
.
File
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
{
log
.
Fatalf
(
"parse: %v"
,
err
)
}
fv
=
append
(
fv
,
f
)
}
//ast.Print(fset, fv[0])
//return
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
neoPkg
,
err
:=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
if
err
!=
nil
{
...
...
@@ -73,11 +75,6 @@ func main() {
neoQualifier
=
types
.
RelativeTo
(
neoPkg
)
//ncode := 0
//ast.Print(fset, f)
//return
// prologue
f
:=
fv
[
0
]
// proto.go comes first
buf
:=
bytes
.
Buffer
{}
...
...
@@ -90,6 +87,7 @@ import (
`
)
// go over packet types declaration and generate marshal code for them
pktCode
:=
0
for
_
,
decl
:=
range
f
.
Decls
{
// we look for types (which can be only under GenDecl)
gendecl
,
ok
:=
decl
.
(
*
ast
.
GenDecl
)
...
...
@@ -99,7 +97,7 @@ import (
for
_
,
spec
:=
range
gendecl
.
Specs
{
typespec
:=
spec
.
(
*
ast
.
TypeSpec
)
// must be because tok = TYPE
//
typename := typespec.Name.Name
typename
:=
typespec
.
Name
.
Name
switch
typespec
.
Type
.
(
type
)
{
default
:
...
...
@@ -112,8 +110,12 @@ import (
//fmt.Println(t)
//ast.Print(fset, t)
fmt
.
Fprintf
(
&
buf
,
"// %d. %s
\n\n
"
,
pktCode
,
typename
)
buf
.
WriteString
(
gendecode
(
typespec
))
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