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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
732db7ce
Commit
732db7ce
authored
Jan 23, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X separate-out sizer
parent
2cd55b6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
342 additions
and
506 deletions
+342
-506
t/neo/marshal.go
t/neo/marshal.go
+239
-416
t/neo/protogen.go
t/neo/protogen.go
+103
-90
No files found.
t/neo/marshal.go
View file @
732db7ce
...
...
@@ -10,12 +10,9 @@ import (
// 0. Address
func
(
p
*
Address
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Host
))
size
+=
4
+
l
}
return
int
(
size
)
+
2
var
size
int
size
+=
4
+
len
(
p
.
Host
)
return
size
+
2
}
func
(
p
*
Address
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -58,12 +55,9 @@ overflow:
// 1. NodeInfo
func
(
p
*
NodeInfo
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Address
.
Host
))
size
+=
8
+
l
}
return
int
(
size
)
+
18
var
size
int
size
+=
8
+
len
(
p
.
Address
.
Host
)
return
size
+
18
}
func
(
p
*
NodeInfo
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -126,8 +120,8 @@ overflow:
// 2. CellInfo
func
(
p
*
CellInfo
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
CellInfo
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -155,13 +149,9 @@ overflow:
// 3. RowInfo
func
(
p
*
RowInfo
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
CellList
))
size
+=
8
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
CellList
)
*
8
return
size
+
4
}
func
(
p
*
RowInfo
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -217,12 +207,9 @@ overflow:
// 4. Notify
func
(
p
*
Notify
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Message
))
size
+=
4
+
l
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
Message
)
return
size
+
0
}
func
(
p
*
Notify
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -260,12 +247,9 @@ overflow:
// 5. Error
func
(
p
*
Error
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Message
))
size
+=
8
+
l
}
return
int
(
size
)
+
0
var
size
int
size
+=
8
+
len
(
p
.
Message
)
return
size
+
0
}
func
(
p
*
Error
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -308,8 +292,8 @@ overflow:
// 6. Ping
func
(
p
*
Ping
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
Ping
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -327,8 +311,8 @@ overflow:
// 7. CloseClient
func
(
p
*
CloseClient
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
CloseClient
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -346,16 +330,10 @@ overflow:
// 8. RequestIdentification
func
(
p
*
RequestIdentification
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Address
.
Host
))
size
+=
16
+
l
}
{
l
:=
uint32
(
len
(
p
.
Name
))
size
+=
6
+
l
}
return
int
(
size
)
+
8
var
size
int
size
+=
16
+
len
(
p
.
Address
.
Host
)
size
+=
6
+
len
(
p
.
Name
)
return
size
+
8
}
func
(
p
*
RequestIdentification
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -438,25 +416,15 @@ overflow:
// 9. AcceptIdentification
func
(
p
*
AcceptIdentification
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Primary
.
Host
))
size
+=
24
+
l
}
{
l
:=
uint32
(
len
(
p
.
KnownMasterList
))
var
size
int
size
+=
24
+
len
(
p
.
Primary
.
Host
)
size
+=
2
+
4
for
i
:=
0
;
i
<
len
(
p
.
KnownMasterList
);
i
++
{
a
:=
&
p
.
KnownMasterList
[
i
]
size
+=
4
+
len
((
*
a
)
.
Address
.
Host
)
size
+=
6
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
KnownMasterList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
Address
.
Host
))
size
+=
4
+
l
}
_
=
a
size
+=
6
}
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
AcceptIdentification
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -580,8 +548,8 @@ overflow:
// 10. PrimaryMaster
func
(
p
*
PrimaryMaster
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
PrimaryMaster
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -599,8 +567,8 @@ overflow:
// 11. AnswerPrimary
func
(
p
*
AnswerPrimary
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
AnswerPrimary
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -623,8 +591,8 @@ overflow:
// 12. AnnouncePrimary
func
(
p
*
AnnouncePrimary
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
AnnouncePrimary
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -642,8 +610,8 @@ overflow:
// 13. ReelectPrimary
func
(
p
*
ReelectPrimary
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
ReelectPrimary
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -661,8 +629,8 @@ overflow:
// 14. Recovery
func
(
p
*
Recovery
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
Recovery
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -680,8 +648,8 @@ overflow:
// 15. AnswerRecovery
func
(
p
*
AnswerRecovery
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
AnswerRecovery
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -714,8 +682,8 @@ overflow:
// 16. LastIDs
func
(
p
*
LastIDs
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
LastIDs
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -733,8 +701,8 @@ overflow:
// 17. AnswerLastIDs
func
(
p
*
AnswerLastIDs
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
AnswerLastIDs
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -762,8 +730,8 @@ overflow:
// 18. PartitionTable
func
(
p
*
PartitionTable
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
PartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -781,22 +749,14 @@ overflow:
// 19. AnswerPartitionTable
func
(
p
*
AnswerPartitionTable
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
RowList
))
size
+=
12
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
RowList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
CellList
))
size
+=
8
size
+=
l
*
8
}
_
=
a
size
+=
0
}
var
size
int
size
+=
8
+
4
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
4
+
len
((
*
a
)
.
CellList
)
*
8
size
+=
4
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
AnswerPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -880,22 +840,14 @@ overflow:
// 20. NotifyPartitionTable
func
(
p
*
NotifyPartitionTable
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
RowList
))
size
+=
12
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
RowList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
CellList
))
size
+=
8
size
+=
l
*
8
}
_
=
a
size
+=
0
}
var
size
int
size
+=
8
+
4
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
4
+
len
((
*
a
)
.
CellList
)
*
8
size
+=
4
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
NotifyPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -979,13 +931,9 @@ overflow:
// 21. PartitionChanges
func
(
p
*
PartitionChanges
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
CellList
))
size
+=
12
size
+=
l
*
12
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
CellList
)
*
12
return
size
+
8
}
func
(
p
*
PartitionChanges
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1050,8 +998,8 @@ overflow:
// 22. StartOperation
func
(
p
*
StartOperation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
1
var
size
int
return
size
+
1
}
func
(
p
*
StartOperation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1074,8 +1022,8 @@ overflow:
// 23. StopOperation
func
(
p
*
StopOperation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
StopOperation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1093,8 +1041,8 @@ overflow:
// 24. UnfinishedTransactions
func
(
p
*
UnfinishedTransactions
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
UnfinishedTransactions
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1112,13 +1060,9 @@ overflow:
// 25. AnswerUnfinishedTransactions
func
(
p
*
AnswerUnfinishedTransactions
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
TidList
))
size
+=
12
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
TidList
)
*
8
return
size
+
8
}
func
(
p
*
AnswerUnfinishedTransactions
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1169,8 +1113,8 @@ overflow:
// 26. LockedTransactions
func
(
p
*
LockedTransactions
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
LockedTransactions
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1188,14 +1132,9 @@ overflow:
// 27. AnswerLockedTransactions
func
(
p
*
AnswerLockedTransactions
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
TidDict
))
_
=
l
size
+=
4
size
+=
l
*
16
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
TidDict
)
*
16
return
size
+
0
}
func
(
p
*
AnswerLockedTransactions
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1250,8 +1189,8 @@ overflow:
// 28. FinalTID
func
(
p
*
FinalTID
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
FinalTID
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1274,8 +1213,8 @@ overflow:
// 29. AnswerFinalTID
func
(
p
*
AnswerFinalTID
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
AnswerFinalTID
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1298,8 +1237,8 @@ overflow:
// 30. ValidateTransaction
func
(
p
*
ValidateTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
ValidateTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1327,8 +1266,8 @@ overflow:
// 31. BeginTransaction
func
(
p
*
BeginTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
BeginTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1351,8 +1290,8 @@ overflow:
// 32. AnswerBeginTransaction
func
(
p
*
AnswerBeginTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
AnswerBeginTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1375,18 +1314,10 @@ overflow:
// 33. FinishTransaction
func
(
p
*
FinishTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
OIDList
))
size
+=
12
size
+=
l
*
8
}
{
l
:=
uint32
(
len
(
p
.
CheckedList
))
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
OIDList
)
*
8
size
+=
4
+
len
(
p
.
CheckedList
)
*
8
return
size
+
8
}
func
(
p
*
FinishTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1465,8 +1396,8 @@ overflow:
// 34. AnswerFinishTransaction
func
(
p
*
AnswerFinishTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
AnswerFinishTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1494,8 +1425,8 @@ overflow:
// 35. NotifyTransactionFinished
func
(
p
*
NotifyTransactionFinished
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
NotifyTransactionFinished
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1523,8 +1454,8 @@ overflow:
// 36. LockInformation
func
(
p
*
LockInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
LockInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1552,8 +1483,8 @@ overflow:
// 37. AnswerLockInformation
func
(
p
*
AnswerLockInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
AnswerLockInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1576,13 +1507,9 @@ overflow:
// 38. InvalidateObjects
func
(
p
*
InvalidateObjects
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
OidList
))
size
+=
12
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
OidList
)
*
8
return
size
+
8
}
func
(
p
*
InvalidateObjects
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1633,8 +1560,8 @@ overflow:
// 39. UnlockInformation
func
(
p
*
UnlockInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
UnlockInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1657,8 +1584,8 @@ overflow:
// 40. GenerateOIDs
func
(
p
*
GenerateOIDs
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
GenerateOIDs
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1681,13 +1608,9 @@ overflow:
// 41. AnswerGenerateOIDs
func
(
p
*
AnswerGenerateOIDs
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
OidList
))
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
OidList
)
*
8
return
size
+
0
}
func
(
p
*
AnswerGenerateOIDs
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1733,13 +1656,9 @@ overflow:
// 42. StoreObject
func
(
p
*
StoreObject
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Data
))
size
+=
41
size
+=
l
*
1
}
return
int
(
size
)
+
17
var
size
int
size
+=
4
+
len
(
p
.
Data
)
*
1
return
size
+
54
}
func
(
p
*
StoreObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1915,8 +1834,8 @@ overflow:
// 43. AnswerStoreObject
func
(
p
*
AnswerStoreObject
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
17
var
size
int
return
size
+
17
}
func
(
p
*
AnswerStoreObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1949,8 +1868,8 @@ overflow:
// 44. AbortTransaction
func
(
p
*
AbortTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
AbortTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -1973,25 +1892,12 @@ overflow:
// 45. StoreTransaction
func
(
p
*
StoreTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
User
))
size
+=
12
+
l
}
{
l
:=
uint32
(
len
(
p
.
Description
))
size
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
Extension
))
size
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
OidList
))
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
12
+
len
(
p
.
User
)
size
+=
4
+
len
(
p
.
Description
)
size
+=
4
+
len
(
p
.
Extension
)
size
+=
4
+
len
(
p
.
OidList
)
*
8
return
size
+
0
}
func
(
p
*
StoreTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2102,8 +2008,8 @@ overflow:
// 46. VoteTransaction
func
(
p
*
VoteTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
VoteTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2126,8 +2032,8 @@ overflow:
// 47. GetObject
func
(
p
*
GetObject
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
GetObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2160,13 +2066,9 @@ overflow:
// 48. AnswerGetObject
func
(
p
*
AnswerGetObject
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Data
))
size
+=
49
size
+=
l
*
1
}
return
int
(
size
)
+
8
var
size
int
size
+=
4
+
len
(
p
.
Data
)
*
1
return
size
+
53
}
func
(
p
*
AnswerGetObject
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2337,8 +2239,8 @@ overflow:
// 49. TIDList
func
(
p
*
TIDList
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
20
var
size
int
return
size
+
20
}
func
(
p
*
TIDList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2371,13 +2273,9 @@ overflow:
// 50. AnswerTIDList
func
(
p
*
AnswerTIDList
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
TIDList
))
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
TIDList
)
*
8
return
size
+
0
}
func
(
p
*
AnswerTIDList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2423,8 +2321,8 @@ overflow:
// 51. TIDListFrom
func
(
p
*
TIDListFrom
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
TIDListFrom
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2462,13 +2360,9 @@ overflow:
// 52. AnswerTIDListFrom
func
(
p
*
AnswerTIDListFrom
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
TidList
))
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
TidList
)
*
8
return
size
+
0
}
func
(
p
*
AnswerTIDListFrom
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2514,8 +2408,8 @@ overflow:
// 53. TransactionInformation
func
(
p
*
TransactionInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
TransactionInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2538,25 +2432,12 @@ overflow:
// 54. AnswerTransactionInformation
func
(
p
*
AnswerTransactionInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
User
))
size
+=
12
+
l
}
{
l
:=
uint32
(
len
(
p
.
Description
))
size
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
Extension
))
size
+=
4
+
l
}
{
l
:=
uint32
(
len
(
p
.
OidList
))
size
+=
5
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
12
+
len
(
p
.
User
)
size
+=
4
+
len
(
p
.
Description
)
size
+=
4
+
len
(
p
.
Extension
)
size
+=
4
+
len
(
p
.
OidList
)
*
8
return
size
+
1
}
func
(
p
*
AnswerTransactionInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2672,8 +2553,8 @@ overflow:
// 55. ObjectHistory
func
(
p
*
ObjectHistory
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
ObjectHistory
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2706,13 +2587,9 @@ overflow:
// 56. AnswerObjectHistory
func
(
p
*
AnswerObjectHistory
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
HistoryList
))
size
+=
12
size
+=
l
*
12
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
HistoryList
)
*
12
return
size
+
8
}
func
(
p
*
AnswerObjectHistory
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2771,8 +2648,8 @@ overflow:
// 57. PartitionList
func
(
p
*
PartitionList
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
12
var
size
int
return
size
+
12
}
func
(
p
*
PartitionList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2805,22 +2682,14 @@ overflow:
// 58. AnswerPartitionList
func
(
p
*
AnswerPartitionList
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
RowList
))
size
+=
12
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
RowList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
CellList
))
size
+=
8
size
+=
l
*
8
}
_
=
a
size
+=
0
}
var
size
int
size
+=
8
+
4
for
i
:=
0
;
i
<
len
(
p
.
RowList
);
i
++
{
a
:=
&
p
.
RowList
[
i
]
size
+=
4
+
len
((
*
a
)
.
CellList
)
*
8
size
+=
4
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
AnswerPartitionList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2904,8 +2773,8 @@ overflow:
// 59. X_NodeList
func
(
p
*
X_NodeList
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
X_NodeList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -2928,21 +2797,14 @@ overflow:
// 60. AnswerNodeList
func
(
p
*
AnswerNodeList
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
NodeList
))
size
+=
4
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
NodeList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
Address
.
Host
))
size
+=
8
+
l
}
_
=
a
size
+=
18
}
var
size
int
size
+=
0
+
4
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
size
+=
8
+
len
((
*
a
)
.
Address
.
Host
)
size
+=
18
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
AnswerNodeList
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3028,8 +2890,8 @@ overflow:
// 61. SetNodeState
func
(
p
*
SetNodeState
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
SetNodeState
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3057,13 +2919,9 @@ overflow:
// 62. AddPendingNodes
func
(
p
*
AddPendingNodes
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
UUIDList
))
size
+=
4
size
+=
l
*
4
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
UUIDList
)
*
4
return
size
+
0
}
func
(
p
*
AddPendingNodes
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3109,13 +2967,9 @@ overflow:
// 63. TweakPartitionTable
func
(
p
*
TweakPartitionTable
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
UUIDList
))
size
+=
4
size
+=
l
*
4
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
UUIDList
)
*
4
return
size
+
0
}
func
(
p
*
TweakPartitionTable
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3161,21 +3015,14 @@ overflow:
// 64. NotifyNodeInformation
func
(
p
*
NotifyNodeInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
NodeList
))
size
+=
4
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
NodeList
[
i
]
{
l
:=
uint32
(
len
((
*
a
)
.
Address
.
Host
))
size
+=
8
+
l
}
_
=
a
size
+=
18
}
var
size
int
size
+=
0
+
4
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
size
+=
8
+
len
((
*
a
)
.
Address
.
Host
)
size
+=
18
}
return
int
(
size
)
+
0
return
size
+
0
}
func
(
p
*
NotifyNodeInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3261,8 +3108,8 @@ overflow:
// 65. NodeInformation
func
(
p
*
NodeInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
NodeInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3280,8 +3127,8 @@ overflow:
// 66. SetClusterState
func
(
p
*
SetClusterState
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
SetClusterState
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3304,8 +3151,8 @@ overflow:
// 67. ClusterInformation
func
(
p
*
ClusterInformation
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
ClusterInformation
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3328,8 +3175,8 @@ overflow:
// 68. X_ClusterState
func
(
p
*
X_ClusterState
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
4
var
size
int
return
size
+
4
}
func
(
p
*
X_ClusterState
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3352,13 +3199,9 @@ overflow:
// 69. ObjectUndoSerial
func
(
p
*
ObjectUndoSerial
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
OidList
))
size
+=
28
size
+=
l
*
8
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
OidList
)
*
8
return
size
+
24
}
func
(
p
*
ObjectUndoSerial
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3419,14 +3262,9 @@ overflow:
// 70. AnswerObjectUndoSerial
func
(
p
*
AnswerObjectUndoSerial
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
ObjectTIDDict
))
_
=
l
size
+=
4
size
+=
l
*
25
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
ObjectTIDDict
)
*
25
return
size
+
0
}
func
(
p
*
AnswerObjectUndoSerial
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3501,8 +3339,8 @@ overflow:
// 71. HasLock
func
(
p
*
HasLock
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
16
var
size
int
return
size
+
16
}
func
(
p
*
HasLock
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3530,8 +3368,8 @@ overflow:
// 72. AnswerHasLock
func
(
p
*
AnswerHasLock
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
12
var
size
int
return
size
+
12
}
func
(
p
*
AnswerHasLock
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3559,8 +3397,8 @@ overflow:
// 73. CheckCurrentSerial
func
(
p
*
CheckCurrentSerial
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
CheckCurrentSerial
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3593,8 +3431,8 @@ overflow:
// 74. AnswerCheckCurrentSerial
func
(
p
*
AnswerCheckCurrentSerial
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
17
var
size
int
return
size
+
17
}
func
(
p
*
AnswerCheckCurrentSerial
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3627,8 +3465,8 @@ overflow:
// 75. Pack
func
(
p
*
Pack
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
Pack
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3651,8 +3489,8 @@ overflow:
// 76. AnswerPack
func
(
p
*
AnswerPack
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
1
var
size
int
return
size
+
1
}
func
(
p
*
AnswerPack
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3675,14 +3513,9 @@ overflow:
// 77. CheckReplicas
func
(
p
*
CheckReplicas
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
PartitionDict
))
_
=
l
size
+=
4
size
+=
l
*
8
}
return
int
(
size
)
+
16
var
size
int
size
+=
4
+
len
(
p
.
PartitionDict
)
*
8
return
size
+
16
}
func
(
p
*
CheckReplicas
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3747,16 +3580,10 @@ overflow:
// 78. CheckPartition
func
(
p
*
CheckPartition
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
Source
.
UpstreamName
))
size
+=
8
+
l
}
{
l
:=
uint32
(
len
(
p
.
Source
.
Address
.
Host
))
size
+=
4
+
l
}
return
int
(
size
)
+
18
var
size
int
size
+=
8
+
len
(
p
.
Source
.
UpstreamName
)
size
+=
4
+
len
(
p
.
Source
.
Address
.
Host
)
return
size
+
18
}
func
(
p
*
CheckPartition
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3834,8 +3661,8 @@ overflow:
// 79. CheckTIDRange
func
(
p
*
CheckTIDRange
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
24
var
size
int
return
size
+
24
}
func
(
p
*
CheckTIDRange
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -3873,8 +3700,8 @@ overflow:
// 80. AnswerCheckTIDRange
func
(
p
*
AnswerCheckTIDRange
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
32
var
size
int
return
size
+
32
}
func
(
p
*
AnswerCheckTIDRange
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4002,8 +3829,8 @@ overflow:
// 81. CheckSerialRange
func
(
p
*
CheckSerialRange
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
32
var
size
int
return
size
+
32
}
func
(
p
*
CheckSerialRange
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4046,8 +3873,8 @@ overflow:
// 82. AnswerCheckSerialRange
func
(
p
*
AnswerCheckSerialRange
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
60
var
size
int
return
size
+
60
}
func
(
p
*
AnswerCheckSerialRange
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4280,13 +4107,9 @@ overflow:
// 83. PartitionCorrupted
func
(
p
*
PartitionCorrupted
)
NEOEncodedLen
()
int
{
var
size
uint32
{
l
:=
uint32
(
len
(
p
.
CellList
))
size
+=
8
size
+=
l
*
4
}
return
int
(
size
)
+
0
var
size
int
size
+=
4
+
len
(
p
.
CellList
)
*
4
return
size
+
4
}
func
(
p
*
PartitionCorrupted
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4337,8 +4160,8 @@ overflow:
// 84. LastTransaction
func
(
p
*
LastTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
LastTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4356,8 +4179,8 @@ overflow:
// 85. AnswerLastTransaction
func
(
p
*
AnswerLastTransaction
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
8
var
size
int
return
size
+
8
}
func
(
p
*
AnswerLastTransaction
)
NEOEncode
(
data
[]
byte
)
{
...
...
@@ -4380,8 +4203,8 @@ overflow:
// 86. NotifyReady
func
(
p
*
NotifyReady
)
NEOEncodedLen
()
int
{
var
size
uint32
return
int
(
size
)
+
0
var
size
int
return
size
+
0
}
func
(
p
*
NotifyReady
)
NEOEncode
(
data
[]
byte
)
{
...
...
t/neo/protogen.go
View file @
732db7ce
...
...
@@ -120,7 +120,7 @@ import (
fmt
.
Fprintf
(
&
buf
,
"// %d. %s
\n\n
"
,
pktCode
,
typename
)
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
encoder
{
SizeOnly
:
true
}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
sizer
{
}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
encoder
{}))
buf
.
WriteString
(
generateCodecCode
(
typespec
,
&
decoder
{}))
...
...
@@ -215,7 +215,7 @@ type CodecCodeGen interface {
// emit code to process basic fixed types (not string)
// userType is type actually used in source (for which typ is underlying), or nil
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
,
obj
types
.
Object
)
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
genMap
(
path
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
...
...
@@ -227,10 +227,14 @@ type CodecCodeGen interface {
}
// encode/decode codegen
type
sizer
struct
{
Buffer
// XXX
n
int
}
type
encoder
struct
{
Buffer
// XXX
n
int
SizeOnly
bool
// generate code only to compute encoded size
}
type
decoder
struct
{
...
...
@@ -241,6 +245,10 @@ type decoder struct {
var
_
CodecCodeGen
=
(
*
encoder
)(
nil
)
var
_
CodecCodeGen
=
(
*
decoder
)(
nil
)
func
(
s
*
sizer
)
generatedCode
()
string
{
return
s
.
String
()
// XXX -> d.buf.String() ?
}
func
(
e
*
encoder
)
generatedCode
()
string
{
return
e
.
String
()
// XXX -> d.buf.String() ?
}
...
...
@@ -249,13 +257,13 @@ func (d *decoder) generatedCode() string {
return
d
.
String
()
// XXX -> d.buf.String() ?
}
func
(
s
*
sizer
)
genPrologue
(
recvName
,
typeName
string
)
{
s
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
recvName
,
typeName
)
s
.
emit
(
"var size int"
)
}
func
(
e
*
encoder
)
genPrologue
(
recvName
,
typeName
string
)
{
if
e
.
SizeOnly
{
e
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
recvName
,
typeName
)
e
.
emit
(
"var size uint32"
)
}
else
{
e
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
recvName
,
typeName
)
}
e
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
recvName
,
typeName
)
}
func
(
d
*
decoder
)
genPrologue
(
recvName
,
typeName
string
)
{
...
...
@@ -263,10 +271,12 @@ func (d *decoder) genPrologue(recvName, typeName string) {
d
.
emit
(
"var nread uint32"
)
}
func
(
e
*
sizer
)
genEpilogue
()
{
e
.
emit
(
"return size + %v"
,
e
.
n
)
e
.
emit
(
"}
\n
"
)
}
func
(
e
*
encoder
)
genEpilogue
()
{
if
e
.
SizeOnly
{
e
.
emit
(
"return int(size) + %v"
,
e
.
n
)
}
e
.
emit
(
"}
\n
"
)
}
...
...
@@ -274,11 +284,16 @@ func (d *decoder) genEpilogue() {
d
.
emit
(
"return int(nread) + %v, nil"
,
d
.
n
)
d
.
emit
(
"
\n
overflow:"
)
d
.
emit
(
"return 0, ErrDecodeOverflow"
)
d
.
emit
(
"goto overflow"
)
// TODO remove
d
.
emit
(
"goto overflow"
)
// TODO
check if overflow used at all and
remove
d
.
emit
(
"}
\n
"
)
}
func
(
e
*
encoder
)
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
,
obj
types
.
Object
)
{
func
(
s
*
sizer
)
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
{
basic
:=
basicTypes
[
typ
.
Kind
()]
s
.
n
+=
basic
.
wireSize
}
func
(
e
*
encoder
)
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
{
basic
:=
basicTypes
[
typ
.
Kind
()]
dataptr
:=
fmt
.
Sprintf
(
"data[%v:]"
,
e
.
n
)
if
userType
!=
nil
&&
userType
!=
typ
{
...
...
@@ -288,14 +303,10 @@ func (e *encoder) genBasic(path string, typ *types.Basic, userType types.Type, o
path
=
fmt
.
Sprintf
(
"%v(%v)"
,
typeName
(
typ
),
path
)
}
e
.
n
+=
basic
.
wireSize
if
!
e
.
SizeOnly
{
// NOTE no space before "=" - to be able to merge with ":"
// prefix and become defining assignment
e
.
emit
(
basic
.
encode
,
dataptr
,
path
)
}
e
.
emit
(
basic
.
encode
,
dataptr
,
path
)
}
func
(
d
*
decoder
)
genBasic
(
assignto
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
,
obj
types
.
Object
)
{
func
(
d
*
decoder
)
genBasic
(
assignto
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
{
basic
:=
basicTypes
[
typ
.
Kind
()]
d
.
emit
(
"if len(data) < %v { goto overflow }"
,
d
.
n
+
basic
.
wireSize
)
dataptr
:=
fmt
.
Sprintf
(
"data[%v:]"
,
d
.
n
)
...
...
@@ -316,24 +327,26 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
// len u32
// [len]byte
// TODO []byte support
func
(
s
*
sizer
)
genStrBytes
(
path
string
)
{
s
.
n
+=
4
s
.
emit
(
"size += %v + len(%s)"
,
s
.
n
,
path
)
s
.
n
=
0
}
func
(
e
*
encoder
)
genStrBytes
(
path
string
)
{
e
.
emit
(
"{"
)
e
.
emit
(
"l := uint32(len(%s))"
,
path
)
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
if
!
e
.
SizeOnly
{
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
e
.
emit
(
"copy(data, %v)"
,
path
)
e
.
emit
(
"data = data[l:]"
)
}
else
{
e
.
emit
(
"size += %v + l"
,
e
.
n
)
}
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
e
.
emit
(
"copy(data, %v)"
,
path
)
e
.
emit
(
"data = data[l:]"
)
e
.
emit
(
"}"
)
e
.
n
=
0
}
func
(
d
*
decoder
)
genStrBytes
(
assignto
string
)
{
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"if uint32(len(data)) < l { goto overflow }"
)
d
.
emit
(
"%v= string(data[:l])"
,
assignto
)
...
...
@@ -347,32 +360,35 @@ func (d *decoder) genStrBytes(assignto string) {
// len u32
// [len]item
// TODO optimize for []byte
func
(
s
*
sizer
)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
// if size(item)==const - size update in one go
elemSize
,
ok
:=
typeSizeFixed
(
typ
.
Elem
())
if
ok
{
s
.
emit
(
"size += 4 + len(%v) * %v"
,
path
,
elemSize
)
return
}
s
.
emit
(
"size += %v + 4"
,
s
.
n
)
s
.
n
=
0
s
.
emit
(
"for i := 0; i < len(%v); i++ {"
,
path
)
s
.
emit
(
"a := &%s[i]"
,
path
)
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
s
)
s
.
emit
(
"size += %v"
,
s
.
n
)
s
.
emit
(
"}"
)
s
.
n
=
0
}
func
(
e
*
encoder
)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
e
.
emit
(
"{"
)
e
.
emit
(
"l := uint32(len(%s))"
,
path
)
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
if
!
e
.
SizeOnly
{
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
}
else
{
e
.
emit
(
"size += %v"
,
e
.
n
)
}
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
e
.
n
=
0
// TODO if size(item)==const - size update in one go
elemSize
,
ok
:=
typeSizeFixed
(
typ
.
Elem
())
if
e
.
SizeOnly
&&
ok
{
e
.
emit
(
"size += l * %v"
,
elemSize
)
}
else
{
e
.
emit
(
"for i := 0; uint32(i) <l; i++ {"
)
e
.
emit
(
"a := &%s[i]"
,
path
)
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
e
)
if
!
e
.
SizeOnly
{
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// FIXME wrt slice of slice ?
}
else
{
e
.
emit
(
"_ = a"
)
// FIXME try to remove
e
.
emit
(
"size += %v"
,
e
.
n
)
}
e
.
emit
(
"}"
)
}
e
.
emit
(
"for i := 0; uint32(i) <l; i++ {"
)
e
.
emit
(
"a := &%s[i]"
,
path
)
codegenType
(
"(*a)"
,
typ
.
Elem
(),
obj
,
e
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// FIXME wrt slice of slice ?
e
.
emit
(
"}"
)
// see vvv
e
.
emit
(
"}"
)
e
.
n
=
0
...
...
@@ -380,7 +396,7 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) {
func
(
d
*
decoder
)
genSlice
(
assignto
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
{
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
n
=
0
...
...
@@ -403,46 +419,43 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
// generate code to encode/decode map
// len u32
// [len](key, value)
func
(
s
*
sizer
)
genMap
(
path
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
{
keySize
,
keyFixed
:=
typeSizeFixed
(
typ
.
Key
())
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
if
keyFixed
&&
elemFixed
{
s
.
emit
(
"size += 4 + len(%v) * %v"
,
path
,
keySize
+
elemSize
)
return
}
s
.
emit
(
"size += %v + 4"
,
s
.
n
)
s
.
n
=
0
s
.
emit
(
"for key := range %s {"
,
path
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
s
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
obj
,
s
)
s
.
emit
(
"size += %v"
,
s
.
n
)
s
.
emit
(
"}"
)
s
.
n
=
0
}
func
(
e
*
encoder
)
genMap
(
path
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
{
e
.
emit
(
"{"
)
e
.
emit
(
"l := uint32(len(%s))"
,
path
)
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
if
!
e
.
SizeOnly
{
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
}
else
{
e
.
emit
(
"_ = l"
)
// FIXME remove
e
.
emit
(
"size += %v"
,
e
.
n
)
}
e
.
genBasic
(
"l"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
e
.
n
=
0
keySize
,
keyFixed
:=
typeSizeFixed
(
typ
.
Key
())
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
if
!
e
.
SizeOnly
{
// output keys in sorted order on the wire
// (easier for debugging & deterministic for testing)
e
.
emit
(
"keyv := make([]%s, 0, l)"
,
typeName
(
typ
.
Key
()))
e
.
emit
(
"for key := range %s {"
,
path
)
e
.
emit
(
" keyv = append(keyv, key)"
)
e
.
emit
(
"}"
)
e
.
emit
(
"sort.Slice(keyv, func (i, j int) bool { return keyv[i] < keyv[j] })"
)
e
.
emit
(
"for _, key := range keyv {"
)
}
else
{
if
keyFixed
&&
elemFixed
{
e
.
emit
(
"size += l * %v"
,
keySize
+
elemSize
)
}
else
{
e
.
emit
(
"for key := range %s {"
,
path
)
}
}
if
!
(
e
.
SizeOnly
&&
keyFixed
&&
elemFixed
)
{
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
e
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
obj
,
e
)
if
!
e
.
SizeOnly
{
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// XXX wrt map of map?
}
else
{
e
.
emit
(
"_ = key"
)
// FIXME remove
e
.
emit
(
"size += %v"
,
e
.
n
)
}
e
.
emit
(
"}"
)
}
// output keys in sorted order on the wire
// (easier for debugging & deterministic for testing)
e
.
emit
(
"keyv := make([]%s, 0, l)"
,
typeName
(
typ
.
Key
()))
e
.
emit
(
"for key := range %s {"
,
path
)
e
.
emit
(
" keyv = append(keyv, key)"
)
e
.
emit
(
"}"
)
e
.
emit
(
"sort.Slice(keyv, func (i, j int) bool { return keyv[i] < keyv[j] })"
)
e
.
emit
(
"for _, key := range keyv {"
)
codegenType
(
"key"
,
typ
.
Key
(),
obj
,
e
)
codegenType
(
fmt
.
Sprintf
(
"%s[key]"
,
path
),
typ
.
Elem
(),
obj
,
e
)
e
.
emit
(
"data = data[%v:]"
,
e
.
n
)
// XXX wrt map of map?
e
.
emit
(
"}"
)
// XXX vvv ?
e
.
emit
(
"}"
)
e
.
n
=
0
...
...
@@ -450,7 +463,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
func
(
d
*
decoder
)
genMap
(
assignto
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
{
d
.
emit
(
"{"
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
,
nil
)
d
.
genBasic
(
"l:"
,
types
.
Typ
[
types
.
Uint32
],
nil
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
)
d
.
emit
(
"nread += %v"
,
d
.
n
)
d
.
n
=
0
...
...
@@ -503,7 +516,7 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodecCod
if
!
ok
{
log
.
Fatalf
(
"%v: %v: basic type %v not supported"
,
pos
(
obj
),
obj
.
Name
(),
u
)
}
codegen
.
genBasic
(
path
,
u
,
typ
,
obj
)
codegen
.
genBasic
(
path
,
u
,
typ
)
case
*
types
.
Struct
:
for
i
:=
0
;
i
<
u
.
NumFields
();
i
++
{
...
...
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