Commit 732db7ce authored by Kirill Smelkov's avatar Kirill Smelkov

X separate-out sizer

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