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
499704c0
Commit
499704c0
authored
Dec 27, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
67cc55ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
39 deletions
+44
-39
t/neo/marshal.go
t/neo/marshal.go
+30
-0
t/neo/proto.go
t/neo/proto.go
+4
-2
t/neo/protogen.go
t/neo/protogen.go
+10
-37
No files found.
t/neo/marshal.go
0 → 100644
View file @
499704c0
func
(
p
*
Address
)
NEODecode
(
data
[]
byte
)
(
int
,
error
)
{
{
l
:=
BigEndian
.
Uint32
(
data
[
0
:
])
data
=
data
[
4
:
]
if
len
(
data
)
<
l
{
return
0
,
ErrDecodeOverflow
}
p
.
Host
=
string
(
data
[
:
l
])
data
=
data
[
l
:
]
}
p
.
Port
=
BigEndian
.
Uint16
(
data
[
0
:
])
return
2
/* + TODO variable part */
,
nil
}
func
(
p
*
NodeInfo
)
NEODecode
(
data
[]
byte
)
(
int
,
error
)
{
p
.
NodeType
=
int32
(
BigEndian
.
Uint32
(
data
[
0
:
]))
{
l
:=
BigEndian
.
Uint32
(
data
[
4
:
])
data
=
data
[
8
:
]
if
len
(
data
)
<
l
{
return
0
,
ErrDecodeOverflow
}
p
.
Address
.
Host
=
string
(
data
[
:
l
])
data
=
data
[
l
:
]
}
p
.
Address
.
Port
=
BigEndian
.
Uint16
(
data
[
0
:
])
p
.
UUID
=
int32
(
BigEndian
.
Uint32
(
data
[
2
:
]))
p
.
NodeState
=
int32
(
BigEndian
.
Uint32
(
data
[
6
:
]))
p
.
IdTimestamp
=
float64_NEODecode
(
data
[
10
:
])
return
18
/* + TODO variable part */
,
nil
}
t/neo/proto.go
View file @
499704c0
// NEO. Protocol description
// NEO. Protocol description
//go:generate sh -c "go run protogen.go >marshal.go"
package
neo
package
neo
// XXX move imports out of here
// XXX move imports out of here
...
@@ -54,7 +56,7 @@ const (
...
@@ -54,7 +56,7 @@ const (
ADMIN
ADMIN
)
)
type
NodeState
int
type
NodeState
int
32
const
(
const
(
RUNNING
NodeState
=
iota
//short: R // XXX tag prefix name ?
RUNNING
NodeState
=
iota
//short: R // XXX tag prefix name ?
TEMPORARILY_DOWN
//short: T
TEMPORARILY_DOWN
//short: T
...
@@ -152,7 +154,6 @@ func float64_NEODecode(b []byte) float64 {
...
@@ -152,7 +154,6 @@ func float64_NEODecode(b []byte) float64 {
return
math
.
Float64frombits
(
fu
)
return
math
.
Float64frombits
(
fu
)
}
}
/*
// NOTE original NodeList = []NodeInfo
// NOTE original NodeList = []NodeInfo
type
NodeInfo
struct
{
type
NodeInfo
struct
{
NodeType
NodeType
...
@@ -162,6 +163,7 @@ type NodeInfo struct {
...
@@ -162,6 +163,7 @@ type NodeInfo struct {
IdTimestamp
float64
IdTimestamp
float64
}
}
/*
//type CellList []struct {
//type CellList []struct {
type CellInfo struct {
type CellInfo struct {
UUID
UUID
...
...
t/neo/protogen.go
View file @
499704c0
...
@@ -49,11 +49,13 @@ func pos(x interface { Pos() token.Pos }) token.Position {
...
@@ -49,11 +49,13 @@ func pos(x interface { Pos() token.Pos }) token.Position {
}
}
func
main
()
{
func
main
()
{
var
err
error
log
.
SetFlags
(
0
)
log
.
SetFlags
(
0
)
//typeMap := map[string]*PacketType{} // XXX needed ?
//typeMap := map[string]*PacketType{} // XXX needed ?
// 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
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"
}
{
...
@@ -65,7 +67,7 @@ func main() {
...
@@ -65,7 +67,7 @@ func main() {
}
}
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
_
,
err
:
=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
_
,
err
=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"typecheck: %v"
,
err
)
log
.
Fatalf
(
"typecheck: %v"
,
err
)
}
}
...
@@ -77,7 +79,7 @@ func main() {
...
@@ -77,7 +79,7 @@ func main() {
//return
//return
f
:=
fv
[
0
]
// proto.go comes first
f
:=
fv
[
0
]
// proto.go comes first
out
:=
Buffer
{}
buf
:=
Buffer
{}
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)
...
@@ -101,35 +103,7 @@ func main() {
...
@@ -101,35 +103,7 @@ func main() {
//fmt.Println(t)
//fmt.Println(t)
//ast.Print(fset, t)
//ast.Print(fset, t)
out
.
WriteString
(
gendecode
(
typespec
))
buf
.
WriteString
(
gendecode
(
typespec
))
/*
PacketType{name: typename, msgCode: ncode}
// if ncode != 0 {
// fmt.Println()
// }
for _, fieldv := range t.Fields.List {
// we only support simple types like uint16
ftype, ok := fieldv.Type.(*ast.Ident)
if !ok {
// TODO log
// TODO proper error message
panic(fmt.Sprintf("%#v not supported", fieldv.Type))
}
if len(fieldv.Names) != 0 {
for _, field := range fieldv.Names {
fmt.Printf("%s(%d).%s\t%s\n", typename, ncode, field.Name, ftype)
}
} else {
// no names means embedding
fmt.Printf("%s(%d).<%s>\n", typename, ncode, ftype)
}
}
ncode++
*/
}
}
}
}
...
@@ -137,14 +111,13 @@ func main() {
...
@@ -137,14 +111,13 @@ func main() {
//ast.Print(fset, gdecl)
//ast.Print(fset, gdecl)
}
}
// format & emit
out
// format & emit
bufferred code
outf
,
err
:=
format
.
Source
(
out
.
Bytes
())
code
,
err
:=
format
.
Source
(
buf
.
Bytes
())
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
// should not happen
panic
(
err
)
// should not happen
}
}
_
,
err
=
os
.
Stdout
.
Write
(
outf
)
_
,
err
=
os
.
Stdout
.
Write
(
code
)
//_, err = os.Stdout.Write(out.Bytes())
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
...
@@ -208,7 +181,7 @@ func (d *decoder) emit(format string, a ...interface{}) {
...
@@ -208,7 +181,7 @@ func (d *decoder) emit(format string, a ...interface{}) {
func
(
d
*
decoder
)
decodedBasic
(
obj
types
.
Object
,
typ
*
types
.
Basic
)
string
{
func
(
d
*
decoder
)
decodedBasic
(
obj
types
.
Object
,
typ
*
types
.
Basic
)
string
{
bdec
,
ok
:=
basicDecode
[
typ
.
Kind
()]
bdec
,
ok
:=
basicDecode
[
typ
.
Kind
()]
if
!
ok
{
if
!
ok
{
log
.
Fatalf
(
"%v:
basic type %v not supported"
,
pos
(
obj
),
typ
)
log
.
Fatalf
(
"%v:
%v: basic type %v not supported"
,
pos
(
obj
),
obj
.
Name
(
),
typ
)
}
}
dataptr
:=
fmt
.
Sprintf
(
"data[%v:]"
,
d
.
n
)
dataptr
:=
fmt
.
Sprintf
(
"data[%v:]"
,
d
.
n
)
decoded
:=
fmt
.
Sprintf
(
bdec
.
decode
,
dataptr
)
decoded
:=
fmt
.
Sprintf
(
bdec
.
decode
,
dataptr
)
...
...
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