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
b111a1c8
Commit
b111a1c8
authored
Jan 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8b45c47e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
95 deletions
+109
-95
t/neo/marshal.go
t/neo/marshal.go
+90
-89
t/neo/proto_test.go
t/neo/proto_test.go
+16
-4
t/neo/protogen.go
t/neo/protogen.go
+3
-2
No files found.
t/neo/marshal.go
View file @
b111a1c8
...
...
@@ -4,6 +4,7 @@ package neo
import
(
"encoding/binary"
"reflect"
"sort"
)
...
...
@@ -3067,93 +3068,93 @@ func (p *NotifyReady) NEODecode(data []byte) (int, error) {
}
// 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
{})}
,
var
pktTypeRegistry
=
map
[
int
]
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/proto_test.go
View file @
b111a1c8
...
...
@@ -68,10 +68,6 @@ type NEOCodec interface {
NEODecoder
}
// TODO for _all_ packet types:
// zero-value -> encodedlen -> [encodedlen]byte -> decode (= ok) + check for overflow
// zero-value.encode([<encodedlen]byte) -> panic
// test marshalling for one packet type
func
testPktMarshal
(
t
*
testing
.
T
,
pkt
NEOCodec
,
encoded
string
)
{
typ
:=
reflect
.
TypeOf
(
pkt
)
.
Elem
()
// type of *pkt
...
...
@@ -258,3 +254,19 @@ func TestPktMarshal(t *testing.T) {
testPktMarshal
(
t
,
tt
.
pkt
,
tt
.
encoded
)
}
}
// XXX for _all_ packet types:
// zero-value -> encodedlen -> [encodedlen]byte -> decode (= ok) + check for overflow
// zero-value.encode([<encodedlen]byte) -> panic
//
// same as testPktMarshal but zero-values of _all_ packet types
// (additional light checks for encode / decode overflow behaviour on all types)
func
TestPktMarshalAllOverflowLightly
(
t
*
testing
.
T
)
{
for
_
,
typ
:=
range
pktTypeRegistry
{
// zero-value for a type
pkt
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
NEOCodec
)
l
:=
pkt
.
NEOEncodedLen
()
encoded
:=
strings
.
Repeat
(
"
\x00
"
,
l
)
testPktMarshal
(
t
,
pkt
,
encoded
)
}
}
t/neo/protogen.go
View file @
b111a1c8
...
...
@@ -132,6 +132,7 @@ func main() {
package neo
import (
"encoding/binary"
"reflect"
"sort"
)
`
)
...
...
@@ -176,7 +177,7 @@ import (
// now packet types registry
buf
.
emit
(
"
\n
// registry of packet types"
)
buf
.
emit
(
"var pktTypeRegistry = map[
PktCode]reflect.Type {"
)
buf
.
emit
(
"var pktTypeRegistry = map[
int]reflect.Type {"
)
// XXX key -> PktCode ?
// ordered by pktCode
pktCodeV
:=
[]
int
{}
...
...
@@ -186,7 +187,7 @@ import (
sort
.
Ints
(
pktCodeV
)
for
_
,
pktCode
:=
range
pktCodeV
{
buf
.
emit
(
"
{%v: reflect.TypeOf(&%v{})}
,"
,
pktCode
,
pktTypeRegistry
[
pktCode
])
buf
.
emit
(
"
%v: reflect.TypeOf(%v{})
,"
,
pktCode
,
pktTypeRegistry
[
pktCode
])
}
buf
.
emit
(
"}"
)
...
...
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