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
8b45c47e
Commit
8b45c47e
authored
Jan 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6ab00523
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
10 deletions
+128
-10
t/neo/marshal.go
t/neo/marshal.go
+94
-0
t/neo/protogen.go
t/neo/protogen.go
+34
-10
No files found.
t/neo/marshal.go
View file @
8b45c47e
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"sort"
"sort"
)
)
// packets marshalling
// 0. Address
// 0. Address
func
(
p
*
Address
)
NEOEncodedLen
()
int
{
func
(
p
*
Address
)
NEOEncodedLen
()
int
{
...
@@ -3063,3 +3065,95 @@ func (p *NotifyReady) NEOEncode(data []byte) {
...
@@ -3063,3 +3065,95 @@ func (p *NotifyReady) NEOEncode(data []byte) {
func
(
p
*
NotifyReady
)
NEODecode
(
data
[]
byte
)
(
int
,
error
)
{
func
(
p
*
NotifyReady
)
NEODecode
(
data
[]
byte
)
(
int
,
error
)
{
return
0
,
nil
return
0
,
nil
}
}
// registry of packet types
var
pktTypeRegistry
=
map
[
PktCode
]
reflect
.
Type
{
{
0
:
reflect
.
TypeOf
(
&
Address
{})},
{
1
:
reflect
.
TypeOf
(
&
NodeInfo
{})},
{
2
:
reflect
.
TypeOf
(
&
CellInfo
{})},
{
3
:
reflect
.
TypeOf
(
&
RowInfo
{})},
{
4
:
reflect
.
TypeOf
(
&
XXXTest
{})},
{
5
:
reflect
.
TypeOf
(
&
Notify
{})},
{
6
:
reflect
.
TypeOf
(
&
Error
{})},
{
7
:
reflect
.
TypeOf
(
&
Ping
{})},
{
8
:
reflect
.
TypeOf
(
&
CloseClient
{})},
{
9
:
reflect
.
TypeOf
(
&
RequestIdentification
{})},
{
10
:
reflect
.
TypeOf
(
&
AcceptIdentification
{})},
{
11
:
reflect
.
TypeOf
(
&
PrimaryMaster
{})},
{
12
:
reflect
.
TypeOf
(
&
AnswerPrimary
{})},
{
13
:
reflect
.
TypeOf
(
&
AnnouncePrimary
{})},
{
14
:
reflect
.
TypeOf
(
&
ReelectPrimary
{})},
{
15
:
reflect
.
TypeOf
(
&
Recovery
{})},
{
16
:
reflect
.
TypeOf
(
&
AnswerRecovery
{})},
{
17
:
reflect
.
TypeOf
(
&
LastIDs
{})},
{
18
:
reflect
.
TypeOf
(
&
AnswerLastIDs
{})},
{
19
:
reflect
.
TypeOf
(
&
PartitionTable
{})},
{
20
:
reflect
.
TypeOf
(
&
AnswerPartitionTable
{})},
{
21
:
reflect
.
TypeOf
(
&
NotifyPartitionTable
{})},
{
22
:
reflect
.
TypeOf
(
&
PartitionChanges
{})},
{
23
:
reflect
.
TypeOf
(
&
StartOperation
{})},
{
24
:
reflect
.
TypeOf
(
&
StopOperation
{})},
{
25
:
reflect
.
TypeOf
(
&
UnfinishedTransactions
{})},
{
26
:
reflect
.
TypeOf
(
&
AnswerUnfinishedTransactions
{})},
{
27
:
reflect
.
TypeOf
(
&
LockedTransactions
{})},
{
28
:
reflect
.
TypeOf
(
&
AnswerLockedTransactions
{})},
{
29
:
reflect
.
TypeOf
(
&
FinalTID
{})},
{
30
:
reflect
.
TypeOf
(
&
AnswerFinalTID
{})},
{
31
:
reflect
.
TypeOf
(
&
ValidateTransaction
{})},
{
32
:
reflect
.
TypeOf
(
&
BeginTransaction
{})},
{
33
:
reflect
.
TypeOf
(
&
AnswerBeginTransaction
{})},
{
34
:
reflect
.
TypeOf
(
&
FinishTransaction
{})},
{
35
:
reflect
.
TypeOf
(
&
AnswerFinishTransaction
{})},
{
36
:
reflect
.
TypeOf
(
&
NotifyTransactionFinished
{})},
{
37
:
reflect
.
TypeOf
(
&
LockInformation
{})},
{
38
:
reflect
.
TypeOf
(
&
AnswerLockInformation
{})},
{
39
:
reflect
.
TypeOf
(
&
InvalidateObjects
{})},
{
40
:
reflect
.
TypeOf
(
&
UnlockInformation
{})},
{
41
:
reflect
.
TypeOf
(
&
GenerateOIDs
{})},
{
42
:
reflect
.
TypeOf
(
&
AnswerGenerateOIDs
{})},
{
43
:
reflect
.
TypeOf
(
&
StoreObject
{})},
{
44
:
reflect
.
TypeOf
(
&
AnswerStoreObject
{})},
{
45
:
reflect
.
TypeOf
(
&
AbortTransaction
{})},
{
46
:
reflect
.
TypeOf
(
&
StoreTransaction
{})},
{
47
:
reflect
.
TypeOf
(
&
VoteTransaction
{})},
{
48
:
reflect
.
TypeOf
(
&
GetObject
{})},
{
49
:
reflect
.
TypeOf
(
&
AnswerGetObject
{})},
{
50
:
reflect
.
TypeOf
(
&
TIDList
{})},
{
51
:
reflect
.
TypeOf
(
&
AnswerTIDList
{})},
{
52
:
reflect
.
TypeOf
(
&
TIDListFrom
{})},
{
53
:
reflect
.
TypeOf
(
&
AnswerTIDListFrom
{})},
{
54
:
reflect
.
TypeOf
(
&
TransactionInformation
{})},
{
55
:
reflect
.
TypeOf
(
&
AnswerTransactionInformation
{})},
{
56
:
reflect
.
TypeOf
(
&
ObjectHistory
{})},
{
57
:
reflect
.
TypeOf
(
&
AnswerObjectHistory
{})},
{
58
:
reflect
.
TypeOf
(
&
PartitionList
{})},
{
59
:
reflect
.
TypeOf
(
&
AnswerPartitionList
{})},
{
60
:
reflect
.
TypeOf
(
&
X_NodeList
{})},
{
61
:
reflect
.
TypeOf
(
&
AnswerNodeList
{})},
{
62
:
reflect
.
TypeOf
(
&
SetNodeState
{})},
{
63
:
reflect
.
TypeOf
(
&
AddPendingNodes
{})},
{
64
:
reflect
.
TypeOf
(
&
TweakPartitionTable
{})},
{
65
:
reflect
.
TypeOf
(
&
NotifyNodeInformation
{})},
{
66
:
reflect
.
TypeOf
(
&
NodeInformation
{})},
{
67
:
reflect
.
TypeOf
(
&
SetClusterState
{})},
{
68
:
reflect
.
TypeOf
(
&
ClusterInformation
{})},
{
69
:
reflect
.
TypeOf
(
&
X_ClusterState
{})},
{
70
:
reflect
.
TypeOf
(
&
ObjectUndoSerial
{})},
{
71
:
reflect
.
TypeOf
(
&
AnswerObjectUndoSerial
{})},
{
72
:
reflect
.
TypeOf
(
&
HasLock
{})},
{
73
:
reflect
.
TypeOf
(
&
AnswerHasLock
{})},
{
74
:
reflect
.
TypeOf
(
&
CheckCurrentSerial
{})},
{
75
:
reflect
.
TypeOf
(
&
AnswerCheckCurrentSerial
{})},
{
76
:
reflect
.
TypeOf
(
&
Pack
{})},
{
77
:
reflect
.
TypeOf
(
&
AnswerPack
{})},
{
78
:
reflect
.
TypeOf
(
&
CheckReplicas
{})},
{
79
:
reflect
.
TypeOf
(
&
CheckPartition
{})},
{
80
:
reflect
.
TypeOf
(
&
CheckTIDRange
{})},
{
81
:
reflect
.
TypeOf
(
&
AnswerCheckTIDRange
{})},
{
82
:
reflect
.
TypeOf
(
&
CheckSerialRange
{})},
{
83
:
reflect
.
TypeOf
(
&
AnswerCheckSerialRange
{})},
{
84
:
reflect
.
TypeOf
(
&
PartitionCorrupted
{})},
{
85
:
reflect
.
TypeOf
(
&
LastTransaction
{})},
{
86
:
reflect
.
TypeOf
(
&
AnswerLastTransaction
{})},
{
87
:
reflect
.
TypeOf
(
&
NotifyReady
{})},
}
t/neo/protogen.go
View file @
8b45c47e
...
@@ -65,6 +65,7 @@ import (
...
@@ -65,6 +65,7 @@ import (
"go/types"
"go/types"
"log"
"log"
"os"
"os"
"sort"
"strings"
"strings"
)
)
...
@@ -86,6 +87,16 @@ func typeName(typ types.Type) string {
...
@@ -86,6 +87,16 @@ func typeName(typ types.Type) string {
return
types
.
TypeString
(
typ
,
neoQualifier
)
return
types
.
TypeString
(
typ
,
neoQualifier
)
}
}
// bytes.Buffer + bell & whistles
type
Buffer
struct
{
bytes
.
Buffer
}
func
(
b
*
Buffer
)
emit
(
format
string
,
a
...
interface
{})
{
fmt
.
Fprintf
(
b
,
format
+
"
\n
"
,
a
...
)
}
func
main
()
{
func
main
()
{
var
err
error
var
err
error
...
@@ -114,7 +125,8 @@ func main() {
...
@@ -114,7 +125,8 @@ func main() {
// prologue
// prologue
f
:=
fv
[
0
]
// proto.go comes first
f
:=
fv
[
0
]
// proto.go comes first
buf
:=
bytes
.
Buffer
{}
buf
:=
Buffer
{}
// XXX vvv -> emit
buf
.
WriteString
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
buf
.
WriteString
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
package neo
package neo
...
@@ -124,7 +136,10 @@ import (
...
@@ -124,7 +136,10 @@ import (
)
)
`
)
`
)
pktTypeRegistry
:=
map
[
int
]
string
{}
// pktCode -> typename
// go over packet types declaration and generate marshal code for them
// go over packet types declaration and generate marshal code for them
buf
.
emit
(
"// packets marshalling
\n
"
)
pktCode
:=
0
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)
...
@@ -153,11 +168,29 @@ import (
...
@@ -153,11 +168,29 @@ import (
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
encoder
{}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
encoder
{}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
decoder
{}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
decoder
{}))
pktTypeRegistry
[
pktCode
]
=
typename
pktCode
++
pktCode
++
}
}
}
}
}
}
// now packet types registry
buf
.
emit
(
"
\n
// registry of packet types"
)
buf
.
emit
(
"var pktTypeRegistry = map[PktCode]reflect.Type {"
)
// ordered by pktCode
pktCodeV
:=
[]
int
{}
for
pktCode
:=
range
pktTypeRegistry
{
pktCodeV
=
append
(
pktCodeV
,
pktCode
)
}
sort
.
Ints
(
pktCodeV
)
for
_
,
pktCode
:=
range
pktCodeV
{
buf
.
emit
(
"{%v: reflect.TypeOf(&%v{})},"
,
pktCode
,
pktTypeRegistry
[
pktCode
])
}
buf
.
emit
(
"}"
)
// format & emit generated code
// format & emit generated code
code
,
err
:=
format
.
Source
(
buf
.
Bytes
())
code
,
err
:=
format
.
Source
(
buf
.
Bytes
())
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -234,15 +267,6 @@ func typeSizeFixed1(typ types.Type) bool {
...
@@ -234,15 +267,6 @@ func typeSizeFixed1(typ types.Type) bool {
}
}
// bytes.Buffer + bell & whistles
type
Buffer
struct
{
bytes
.
Buffer
}
func
(
b
*
Buffer
)
emit
(
format
string
,
a
...
interface
{})
{
fmt
.
Fprintf
(
b
,
format
+
"
\n
"
,
a
...
)
}
// interface of a codegenerator (for sizer/coder/decoder)
// interface of a codegenerator (for sizer/coder/decoder)
type
CodeGenerator
interface
{
type
CodeGenerator
interface
{
// tell codegen it should generate code for which type & receiver name
// tell codegen it should generate code for which type & receiver name
...
...
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