Commit 7429c8ba authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e1f92e97
......@@ -400,6 +400,7 @@ overflow:
// 9. AcceptIdentification
func (p *AcceptIdentification) NEOEncodedLen() int {
var size int
size += 30
for i := 0; i < len(p.KnownMasterList); i++ {
a := &p.KnownMasterList[i]
......@@ -721,6 +722,7 @@ overflow:
// 19. AnswerPartitionTable
func (p *AnswerPartitionTable) NEOEncodedLen() int {
var size int
size += 12
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
......@@ -810,6 +812,7 @@ overflow:
// 20. NotifyPartitionTable
func (p *NotifyPartitionTable) NEOEncodedLen() int {
var size int
size += 12
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
......@@ -1092,8 +1095,7 @@ overflow:
// 27. AnswerLockedTransactions
func (p *AnswerLockedTransactions) NEOEncodedLen() int {
size += 4 + len(p.TidDict)*16
return 0
return 4 + len(p.TidDict)*16
}
func (p *AnswerLockedTransactions) NEOEncode(data []byte) {
......@@ -2594,6 +2596,7 @@ overflow:
// 58. AnswerPartitionList
func (p *AnswerPartitionList) NEOEncodedLen() int {
var size int
size += 12
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
......@@ -2706,6 +2709,7 @@ overflow:
// 60. AnswerNodeList
func (p *AnswerNodeList) NEOEncodedLen() int {
var size int
size += 4
for i := 0; i < len(p.NodeList); i++ {
a := &p.NodeList[i]
......@@ -2917,6 +2921,7 @@ overflow:
// 64. NotifyNodeInformation
func (p *NotifyNodeInformation) NEOEncodedLen() int {
var size int
size += 4
for i := 0; i < len(p.NodeList); i++ {
a := &p.NodeList[i]
......@@ -3156,8 +3161,7 @@ overflow:
// 70. AnswerObjectUndoSerial
func (p *AnswerObjectUndoSerial) NEOEncodedLen() int {
size += 4 + len(p.ObjectTIDDict)*25
return 0
return 4 + len(p.ObjectTIDDict)*25
}
func (p *AnswerObjectUndoSerial) NEOEncode(data []byte) {
......@@ -3400,8 +3404,7 @@ overflow:
// 77. CheckReplicas
func (p *CheckReplicas) NEOEncodedLen() int {
size += 4 + len(p.PartitionDict)*8
return 16
return 20 + len(p.PartitionDict)*8
}
func (p *CheckReplicas) NEOEncode(data []byte) {
......
......@@ -232,6 +232,9 @@ type sizer struct {
n int
symLenv []string // symbolic lengths to add to size
varSizeUsed bool // whether var size was used
recvName string // receiver/type for top-level func
typeName string // or empty
}
type encoder struct {
......@@ -249,7 +252,26 @@ var _ CodecCodeGen = (*encoder)(nil)
var _ CodecCodeGen = (*decoder)(nil)
func (s *sizer) generatedCode() string {
return s.String() // XXX -> d.buf.String() ?
prologue := Buffer{}
if s.recvName != "" {
prologue.emit("func (%s *%s) NEOEncodedLen() int {", s.recvName, s.typeName)
}
if s.varSizeUsed {
prologue.emit("var size int")
}
epilogue := Buffer{}
size := fmt.Sprintf("%v", s.n)
if len(s.symLenv) > 0 {
size += " + " + strings.Join(s.symLenv, " + ")
}
if s.varSizeUsed {
size += " + size"
}
epilogue.emit("return %v", size)
epilogue.emit("}\n")
return prologue.String() + s.String() + epilogue.String() // XXX -> d.buf.String() ?
}
func (e *encoder) generatedCode() string {
......@@ -261,10 +283,9 @@ func (d *decoder) generatedCode() string {
}
func (s *sizer) genPrologue(recvName, typeName string) {
s.emit("func (%s *%s) NEOEncodedLen() int {", recvName, typeName)
if s.varSizeUsed {
s.emit("var size int")
}
s.recvName = recvName
s.typeName = typeName
//s.emit("func (%s *%s) NEOEncodedLen() int {", recvName, typeName)
}
func (e *encoder) genPrologue(recvName, typeName string) {
......@@ -277,6 +298,7 @@ func (d *decoder) genPrologue(recvName, typeName string) {
}
func (s *sizer) genEpilogue() {
/*
size := fmt.Sprintf("%v", s.n)
if len(s.symLenv) > 0 {
size += " + " + strings.Join(s.symLenv, " + ")
......@@ -286,6 +308,7 @@ func (s *sizer) genEpilogue() {
}
s.emit("return %v", size)
s.emit("}\n")
*/
}
func (e *encoder) genEpilogue() {
......@@ -442,10 +465,12 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
elemSize, elemFixed := typeSizeFixed(typ.Elem())
if keyFixed && elemFixed {
s.emit("size += 4 + len(%v) * %v", path, keySize + elemSize)
s.n += 4
s.symLenv = append(s.symLenv, fmt.Sprintf("len(%v) * %v", path, keySize + elemSize))
return
}
s.varSizeUsed = true
s.emit("size += %v + 4", s.n)
s.n = 0
s.emit("for key := range %s {", path)
......
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