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
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
Stefane Fermigier
neo
Commits
ff786dd0
Commit
ff786dd0
authored
Sep 03, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
368f5366
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
332 additions
and
416 deletions
+332
-416
go/neo/proto.go
go/neo/proto.go
+8
-4
go/neo/protogen.go
go/neo/protogen.go
+60
-15
go/neo/zproto-marshal.go
go/neo/zproto-marshal.go
+264
-397
No files found.
go/neo/proto.go
View file @
ff786dd0
...
...
@@ -23,7 +23,11 @@ package neo
// This file defines everything that relates to messages on the wire.
// In particular every type that is included in a message is defined here as well.
// XXX neo:proto justtype
//
// By default a structure defined in this file becomes a separate network message.
// If a structure is defined only to represent basic type that is included in
// several messages and does not itself denote a separate message, its
// definition is prefixed with `//neo:proto typeonly` comment.
// XXX neo:proto answerto x? (btw just needs "answer" flag)
// TODO regroup messages definitions to stay more close to 1 communication topic
...
...
@@ -256,7 +260,7 @@ func float64_NEODecode(b []byte) float64 {
}
// NodeInfo is information about a node
//
FIXME not pkt
//
neo:proto typeonly
type
NodeInfo
struct
{
Type
NodeType
Addr
Address
// serving address
...
...
@@ -265,13 +269,13 @@ type NodeInfo struct {
IdTimestamp
float64
// FIXME clarify semantic where it is used
}
//
FIXME not pkt
//
neo:proto typeonly
type
CellInfo
struct
{
UUID
NodeUUID
State
CellState
}
//
FIXME not pkt
//
neo:proto typeonly
type
RowInfo
struct
{
Offset
uint32
// PNumber XXX -> Pid
CellList
[]
CellInfo
...
...
go/neo/protogen.go
View file @
ff786dd0
...
...
@@ -144,7 +144,7 @@ func loadPkg(pkgPath string, sources ...string) *types.Package {
// parse
for
_
,
src
:=
range
sources
{
f
,
err
:=
parser
.
ParseFile
(
fset
,
src
,
nil
,
0
)
f
,
err
:=
parser
.
ParseFile
(
fset
,
src
,
nil
,
parser
.
ParseComments
)
if
err
!=
nil
{
log
.
Fatalf
(
"parse: %v"
,
err
)
}
...
...
@@ -165,6 +165,39 @@ func loadPkg(pkgPath string, sources ...string) *types.Package {
return
pkg
}
// `//neo:proto ...` annotations
type
Annotation
struct
{
typeonly
bool
}
// parse checks doc for specific comment annotations and, if present, loads them.
func
(
a
*
Annotation
)
parse
(
doc
*
ast
.
CommentGroup
)
{
if
doc
==
nil
{
return
// for many types .Doc = nil if there is no comments
}
for
_
,
comment
:=
range
doc
.
List
{
cpos
:=
pos
(
comment
)
if
!
(
cpos
.
Column
==
1
&&
strings
.
HasPrefix
(
comment
.
Text
,
"//neo:proto "
))
{
continue
}
__
:=
strings
.
SplitN
(
comment
.
Text
,
" "
,
2
)
arg
:=
__
[
1
]
switch
arg
{
case
"typeonly"
:
if
a
.
typeonly
{
log
.
Fatalf
(
"%v: duplicate typeonly"
,
cpos
)
}
a
.
typeonly
=
true
default
:
log
.
Fatalf
(
"%v: unknown neo:proto directive %q"
,
cpos
,
arg
)
}
}
}
func
main
()
{
var
err
error
...
...
@@ -206,16 +239,29 @@ import (
//ast.Print(fset, gendecl)
//continue
// `//neo:proto ...` annotations for whole decl
// (e.g. <here> type ( t1 struct{...}; t2 struct{...} )
declAnnotation
:=
Annotation
{}
declAnnotation
.
parse
(
gendecl
.
Doc
)
for
_
,
spec
:=
range
gendecl
.
Specs
{
typespec
:=
spec
.
(
*
ast
.
TypeSpec
)
// must be because tok = TYPE
typename
:=
typespec
.
Name
.
Name
switch
typespec
.
Type
.
(
type
)
{
default
:
// we are only interested in struct types
if
_
,
ok
:=
typespec
.
Type
.
(
*
ast
.
StructType
);
!
ok
{
continue
}
// `//neo:proto ...` annotation for this particular type
specAnnotation
:=
declAnnotation
// inheriting from decl
specAnnotation
.
parse
(
typespec
.
Doc
)
// type only -> don't generate message interface for it
if
specAnnotation
.
typeonly
{
continue
}
case
*
ast
.
StructType
:
fmt
.
Fprintf
(
&
buf
,
"// %d. %s
\n\n
"
,
msgCode
,
typename
)
buf
.
emit
(
"func (*%s) neoMsgCode() uint16 {"
,
typename
)
...
...
@@ -230,7 +276,6 @@ import (
msgCode
++
}
}
}
// now generate message types registry
buf
.
emit
(
"
\n
// registry of message types"
)
...
...
go/neo/zproto-marshal.go
View file @
ff786dd0
This diff is collapsed.
Click to expand it.
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