Commit 6e705e4e authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: protogen: Factor-out handling of slice and map heads into common place

genSliceHead and genMapHead will be reused for MsgPack encoding.
Changes in generated code are mostly due to move of where things are
typecasted to e.g. uint32 without any change in semantic.
parent 1bb595cf
......@@ -479,6 +479,15 @@ type CodeGenerator interface {
generatedCode() string
}
// interface for codegenerators to inject themselves into {sizer/encoder/decoder}Common.
type CodeGenCustomize interface {
CodeGenerator
// generate code to process slice or map header
genSliceHead(path string, typ *types.Slice, obj types.Object)
genMapHead(path string, typ *types.Map, obj types.Object)
}
// X reports encoding=X
type N struct{}; func (_ *N) encoding() byte { return 'N' }
......@@ -981,11 +990,18 @@ func (d *decoderN) genBuf(assignto string) {
// emit code to size/encode/decode slice
// len u32
// [len]item
func (s *sizerN) genSlice(path string, typ *types.Slice, obj types.Object) {
func (s *sizerN) genSliceHead(path string, typ *types.Slice, obj types.Object) {
s.size.Add(4)
}
func (s *sizerN) genSlice(path string, typ *types.Slice, obj types.Object) {
s.genSliceCommon(s, path, typ, obj)
}
func (s *sizerCommon) genSliceCommon(xs CodeGenCustomize, path string, typ *types.Slice, obj types.Object) {
xs.genSliceHead(path, typ, obj)
// if size(item)==const - size update in one go
elemSize, ok := typeSizeFixed(s.encoding(), typ.Elem())
elemSize, ok := typeSizeFixed(xs.encoding(), typ.Elem())
if ok {
s.size.AddExpr("len(%v) * %v", path, elemSize)
return
......@@ -997,7 +1013,7 @@ func (s *sizerN) genSlice(path string, typ *types.Slice, obj types.Object) {
s.emit("for i := 0; i < len(%v); i++ {", path)
s.emit("a := &%s[i]", path)
codegenType("(*a)", typ.Elem(), obj, s)
codegenType("(*a)", typ.Elem(), obj, xs)
// merge-in size updates
s.emit("%v += %v", s.var_("size"), s.size.ExprString())
......@@ -1008,29 +1024,45 @@ func (s *sizerN) genSlice(path string, typ *types.Slice, obj types.Object) {
s.size = curSize
}
func (e *encoderN) 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)
func (e *encoderN) genSliceHead(path string, typ *types.Slice, obj types.Object) {
e.emit("l := len(%s)", path)
e.genBasic("l", types.Typ[types.Uint32], types.Typ[types.Int])
e.emit("data = data[%v:]", e.n)
e.n = 0
e.emit("for i := 0; uint32(i) <l; i++ {")
}
func (e *encoderN) genSlice(path string, typ *types.Slice, obj types.Object) {
e.genSliceCommon(e, path, typ, obj)
}
func (e *encoderCommon) genSliceCommon(xe CodeGenCustomize, path string, typ *types.Slice, obj types.Object) {
e.emit("{")
xe.genSliceHead(path, typ, obj)
e.emit("for i := 0; i <l; i++ {")
e.emit("a := &%s[i]", path)
codegenType("(*a)", typ.Elem(), obj, e)
codegenType("(*a)", typ.Elem(), obj, xe)
if e.n != 0 {
e.emit("data = data[%v:]", e.n)
e.n = 0
}
e.emit("}")
e.emit("}")
e.n = 0
}
func (d *decoderN) genSliceHead(assignto string, typ *types.Slice, obj types.Object) {
d.genBasic("l:", types.Typ[types.Uint32], nil)
}
func (d *decoderN) genSlice(assignto string, typ *types.Slice, obj types.Object) {
d.genSliceCommon(d, assignto, typ, obj)
}
func (d *decoderCommon) genSliceCommon(xd CodeGenCustomize, assignto string, typ *types.Slice, obj types.Object) {
d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil)
xd.genSliceHead(assignto, typ, obj)
d.resetPos()
// if size(item)==const - check overflow in one go
elemSize, elemFixed := typeSizeFixed(d.encoding(), typ.Elem())
elemSize, elemFixed := typeSizeFixed(xd.encoding(), typ.Elem())
if elemFixed {
d.overflowCheck()
d.overflow.AddExpr("uint64(l) * %v", elemSize)
......@@ -1043,7 +1075,7 @@ func (d *decoderN) genSlice(assignto string, typ *types.Slice, obj types.Object)
d.emit("a := &%s[i]", assignto)
d.overflowCheckLoopEntry()
codegenType("(*a)", typ.Elem(), obj, d)
codegenType("(*a)", typ.Elem(), obj, xd)
d.resetPos()
d.emit("}")
......@@ -1055,24 +1087,31 @@ func (d *decoderN) genSlice(assignto string, typ *types.Slice, obj types.Object)
// generate code to encode/decode map
// len u32
// [len](key, value)
func (s *sizerN) genMapHead(path string, typ *types.Map, obj types.Object) {
s.size.Add(4)
}
func (s *sizerN) genMap(path string, typ *types.Map, obj types.Object) {
keySize, keyFixed := typeSizeFixed(s.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(s.encoding(), typ.Elem())
s.genMapCommon(s, path, typ, obj)
}
func (s *sizerCommon) genMapCommon(xs CodeGenCustomize, path string, typ *types.Map, obj types.Object) {
xs.genMapHead(path, typ, obj)
keySize, keyFixed := typeSizeFixed(xs.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(xs.encoding(), typ.Elem())
if keyFixed && elemFixed {
s.size.Add(4)
s.size.AddExpr("len(%v) * %v", path, keySize+elemSize)
return
}
s.size.Add(4)
curSize := s.size
s.size.Reset()
// FIXME for map of map gives ...[key][key] => key -> different variables
s.emit("for key := range %s {", path)
codegenType("key", typ.Key(), obj, s)
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, s)
codegenType("key", typ.Key(), obj, xs)
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, xs)
// merge-in size updates
s.emit("%v += %v", s.var_("size"), s.size.ExprString())
......@@ -1083,12 +1122,19 @@ func (s *sizerN) genMap(path string, typ *types.Map, obj types.Object) {
s.size = curSize
}
func (e *encoderN) 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)
func (e *encoderN) genMapHead(path string, typ *types.Map, obj types.Object) {
e.emit("l := len(%s)", path)
e.genBasic("l", types.Typ[types.Uint32], types.Typ[types.Int])
e.emit("data = data[%v:]", e.n)
e.n = 0
}
func (e *encoderN) genMap(path string, typ *types.Map, obj types.Object) {
e.genMapCommon(e, path, typ, obj)
}
func (e *encoderCommon) genMapCommon(xe CodeGenCustomize, path string, typ *types.Map, obj types.Object) {
e.emit("{")
xe.genMapHead(path, typ, obj)
// output keys in sorted order on the wire
// (easier for debugging & deterministic for testing)
......@@ -1099,23 +1145,32 @@ func (e *encoderN) genMap(path string, typ *types.Map, obj types.Object) {
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)
codegenType("key", typ.Key(), obj, xe)
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, xe)
if e.n != 0 {
e.emit("data = data[%v:]", e.n) // XXX wrt map of map?
e.n = 0
}
e.emit("}")
e.emit("}")
e.n = 0
}
func (d *decoderN) genMapHead(assignto string, typ *types.Map, obj types.Object) {
d.genBasic("l:", types.Typ[types.Uint32], nil)
}
func (d *decoderN) genMap(assignto string, typ *types.Map, obj types.Object) {
d.genMapCommon(d, assignto, typ, obj)
}
func (d *decoderCommon) genMapCommon(xd CodeGenCustomize, assignto string, typ *types.Map, obj types.Object) {
d.emit("{")
d.genBasic("l:", types.Typ[types.Uint32], nil)
xd.genMapHead(assignto, typ, obj)
d.resetPos()
// if size(key,item)==const - check overflow in one go
keySize, keyFixed := typeSizeFixed(d.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(d.encoding(), typ.Elem())
keySize, keyFixed := typeSizeFixed(xd.encoding(), typ.Key())
elemSize, elemFixed := typeSizeFixed(xd.encoding(), typ.Elem())
if keyFixed && elemFixed {
d.overflowCheck()
d.overflow.AddExpr("uint64(l) * %v", keySize+elemSize)
......@@ -1128,18 +1183,19 @@ func (d *decoderN) genMap(assignto string, typ *types.Map, obj types.Object) {
d.emit("for i := 0; uint32(i) < l; i++ {")
d.overflowCheckLoopEntry()
codegenType("key:", typ.Key(), obj, d)
d.emit("var key %s", typeName(typ.Key()))
codegenType("key", typ.Key(), obj, xd)
switch typ.Elem().Underlying().(type) {
// basic types can be directly assigned to map entry
case *types.Basic:
codegenType("m[key]", typ.Elem(), obj, d)
codegenType("m[key]", typ.Elem(), obj, xd)
// otherwise assign via temporary
default:
d.emit("var v %v", typeName(typ.Elem()))
codegenType("v", typ.Elem(), obj, d)
d.emit("m[key] = v")
d.emit("var mv %v", typeName(typ.Elem()))
codegenType("mv", typ.Elem(), obj, xd)
d.emit("m[key] = mv")
}
d.resetPos()
......
......@@ -92,10 +92,10 @@ func (p *RequestIdentification) neoMsgEncodeN(data []byte) {
data = data[0+n:]
}
{
l := uint32(len(p.DevPath))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.DevPath)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.DevPath[i]
{
l := uint32(len((*a)))
......@@ -104,14 +104,13 @@ func (p *RequestIdentification) neoMsgEncodeN(data []byte) {
copy(data, (*a))
data = data[l:]
}
data = data[0:]
}
}
{
l := uint32(len(p.NewNID))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.NewNID)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NewNID[i]
binary.BigEndian.PutUint32(data[0:], (*a))
data = data[4:]
......@@ -344,16 +343,15 @@ func (p *NotPrimaryMaster) neoMsgEncodedLenN() int {
func (p *NotPrimaryMaster) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.Primary)))
{
l := uint32(len(p.KnownMasterList))
binary.BigEndian.PutUint32(data[4:], l)
l := len(p.KnownMasterList)
binary.BigEndian.PutUint32(data[4:], uint32(l))
data = data[8:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.KnownMasterList[i]
{
n := (*a).neoEncodeN(data[0:])
data = data[0+n:]
}
data = data[0:]
}
}
}
......@@ -407,10 +405,10 @@ func (p *NotifyNodeInformation) neoMsgEncodeN(data []byte) {
data = data[0+n:]
}
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
(data[0:])[0] = uint8(int8((*a).Type))
{
......@@ -423,7 +421,6 @@ func (p *NotifyNodeInformation) neoMsgEncodeN(data []byte) {
n := (*a).IdTime.neoEncodeN(data[5:])
data = data[5+n:]
}
data = data[0:]
}
}
}
......@@ -609,23 +606,22 @@ func (p *AnswerPartitionTable) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.PTid))
binary.BigEndian.PutUint32(data[8:], p.NumReplicas)
{
l := uint32(len(p.RowList))
binary.BigEndian.PutUint32(data[12:], l)
l := len(p.RowList)
binary.BigEndian.PutUint32(data[12:], uint32(l))
data = data[16:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.RowList[i]
{
l := uint32(len((*a).CellList))
binary.BigEndian.PutUint32(data[0:], l)
l := len((*a).CellList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
(data[4:])[0] = uint8(int8((*a).State))
data = data[5:]
}
}
data = data[0:]
}
}
}
......@@ -689,23 +685,22 @@ func (p *SendPartitionTable) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.PTid))
binary.BigEndian.PutUint32(data[8:], p.NumReplicas)
{
l := uint32(len(p.RowList))
binary.BigEndian.PutUint32(data[12:], l)
l := len(p.RowList)
binary.BigEndian.PutUint32(data[12:], uint32(l))
data = data[16:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.RowList[i]
{
l := uint32(len((*a).CellList))
binary.BigEndian.PutUint32(data[0:], l)
l := len((*a).CellList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
(data[4:])[0] = uint8(int8((*a).State))
data = data[5:]
}
}
data = data[0:]
}
}
}
......@@ -764,10 +759,10 @@ func (p *NotifyPartitionChanges) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.PTid))
binary.BigEndian.PutUint32(data[8:], p.NumReplicas)
{
l := uint32(len(p.CellList))
binary.BigEndian.PutUint32(data[12:], l)
l := len(p.CellList)
binary.BigEndian.PutUint32(data[12:], uint32(l))
data = data[16:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.CellList[i]
binary.BigEndian.PutUint32(data[0:], (*a).Offset)
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).CellInfo.UUID)))
......@@ -863,10 +858,10 @@ func (p *UnfinishedTransactions) neoMsgEncodedLenN() int {
func (p *UnfinishedTransactions) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.RowList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.RowList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.RowList[i]
binary.BigEndian.PutUint32(data[0:], (*a).Offset)
data = data[4:]
......@@ -912,10 +907,10 @@ func (p *AnswerUnfinishedTransactions) neoMsgEncodedLenN() int {
func (p *AnswerUnfinishedTransactions) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.MaxTID))
{
l := uint32(len(p.TidList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.TidList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.TidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a).UnfinishedTID))
data = data[8:]
......@@ -978,8 +973,8 @@ func (p *AnswerLockedTransactions) neoMsgEncodedLenN() int {
func (p *AnswerLockedTransactions) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.TidDict))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.TidDict)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
keyv := make([]zodb.Tid, 0, l)
for key := range p.TidDict {
......@@ -1009,7 +1004,8 @@ func (p *AnswerLockedTransactions) neoMsgDecodeN(data []byte) (int, error) {
p.TidDict = make(map[zodb.Tid]zodb.Tid, l)
m := p.TidDict
for i := 0; uint32(i) < l; i++ {
key := zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
var key zodb.Tid
key = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
m[key] = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
data = data[16:]
}
......@@ -1160,10 +1156,10 @@ func (p *FailedVote) neoMsgEncodedLenN() int {
func (p *FailedVote) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Tid))
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -1210,20 +1206,20 @@ func (p *FinishTransaction) neoMsgEncodedLenN() int {
func (p *FinishTransaction) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Tid))
{
l := uint32(len(p.OIDList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.OIDList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OIDList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
}
}
{
l := uint32(len(p.CheckedList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.CheckedList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.CheckedList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -1363,10 +1359,10 @@ func (p *InvalidateObjects) neoMsgEncodedLenN() int {
func (p *InvalidateObjects) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Tid))
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -1462,10 +1458,10 @@ func (p *AnswerNewOIDs) neoMsgEncodedLenN() int {
func (p *AnswerNewOIDs) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -1564,10 +1560,10 @@ func (p *AnswerRebaseTransaction) neoMsgEncodedLenN() int {
func (p *AnswerRebaseTransaction) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -1769,10 +1765,10 @@ func (p *AbortTransaction) neoMsgEncodedLenN() int {
func (p *AbortTransaction) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Tid))
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -1840,10 +1836,10 @@ func (p *StoreTransaction) neoMsgEncodeN(data []byte) {
data = data[l:]
}
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -2090,10 +2086,10 @@ func (p *AnswerTIDs) neoMsgEncodedLenN() int {
func (p *AnswerTIDs) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.TIDList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.TIDList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.TIDList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -2186,10 +2182,10 @@ func (p *AnswerTransactionInformation) neoMsgEncodeN(data []byte) {
}
(data[0:])[0] = bool2byte(p.Packed)
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[1:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[1:], uint32(l))
data = data[5:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -2296,10 +2292,10 @@ func (p *AnswerObjectHistory) neoMsgEncodedLenN() int {
func (p *AnswerObjectHistory) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
{
l := uint32(len(p.HistoryList))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.HistoryList)
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.HistoryList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a).Serial))
binary.BigEndian.PutUint32(data[8:], (*a).Size)
......@@ -2386,23 +2382,22 @@ func (p *AnswerPartitionList) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.PTid))
binary.BigEndian.PutUint32(data[8:], p.NumReplicas)
{
l := uint32(len(p.RowList))
binary.BigEndian.PutUint32(data[12:], l)
l := len(p.RowList)
binary.BigEndian.PutUint32(data[12:], uint32(l))
data = data[16:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.RowList[i]
{
l := uint32(len((*a).CellList))
binary.BigEndian.PutUint32(data[0:], l)
l := len((*a).CellList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
(data[4:])[0] = uint8(int8((*a).State))
data = data[5:]
}
}
data = data[0:]
}
}
}
......@@ -2489,10 +2484,10 @@ func (p *AnswerNodeList) neoMsgEncodedLenN() int {
func (p *AnswerNodeList) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
(data[0:])[0] = uint8(int8((*a).Type))
{
......@@ -2505,7 +2500,6 @@ func (p *AnswerNodeList) neoMsgEncodeN(data []byte) {
n := (*a).IdTime.neoEncodeN(data[5:])
data = data[5+n:]
}
data = data[0:]
}
}
}
......@@ -2596,10 +2590,10 @@ func (p *AddPendingNodes) neoMsgEncodedLenN() int {
func (p *AddPendingNodes) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -2645,10 +2639,10 @@ func (p *TweakPartitionTable) neoMsgEncodedLenN() int {
func (p *TweakPartitionTable) neoMsgEncodeN(data []byte) {
(data[0:])[0] = bool2byte(p.DryRun)
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[1:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[1:], uint32(l))
data = data[5:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -2700,23 +2694,22 @@ func (p *AnswerTweakPartitionTable) neoMsgEncodedLenN() int {
func (p *AnswerTweakPartitionTable) neoMsgEncodeN(data []byte) {
(data[0:])[0] = bool2byte(p.Changed)
{
l := uint32(len(p.RowList))
binary.BigEndian.PutUint32(data[1:], l)
l := len(p.RowList)
binary.BigEndian.PutUint32(data[1:], uint32(l))
data = data[5:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.RowList[i]
{
l := uint32(len((*a).CellList))
binary.BigEndian.PutUint32(data[0:], l)
l := len((*a).CellList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
(data[4:])[0] = uint8(int8((*a).State))
data = data[5:]
}
}
data = data[0:]
}
}
}
......@@ -2822,10 +2815,10 @@ func (p *Repair) neoMsgEncodedLenN() int {
func (p *Repair) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.NodeList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.NodeList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -2967,10 +2960,10 @@ func (p *ObjectUndoSerial) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[8:], uint64(p.LTID))
binary.BigEndian.PutUint64(data[16:], uint64(p.UndoneTID))
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[24:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[24:], uint32(l))
data = data[28:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -3018,8 +3011,8 @@ func (p *AnswerObjectUndoSerial) neoMsgEncodedLenN() int {
func (p *AnswerObjectUndoSerial) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.ObjectTIDDict))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.ObjectTIDDict)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
keyv := make([]zodb.Oid, 0, l)
for key := range p.ObjectTIDDict {
......@@ -3055,16 +3048,17 @@ func (p *AnswerObjectUndoSerial) neoMsgDecodeN(data []byte) (int, error) {
}, l)
m := p.ObjectTIDDict
for i := 0; uint32(i) < l; i++ {
key := zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
var v struct {
var key zodb.Oid
key = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
var mv struct {
CurrentSerial zodb.Tid
UndoSerial zodb.Tid
IsCurrent bool
}
v.CurrentSerial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
v.UndoSerial = zodb.Tid(binary.BigEndian.Uint64(data[16 : 16+8]))
v.IsCurrent = byte2bool((data[24 : 24+1])[0])
m[key] = v
mv.CurrentSerial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
mv.UndoSerial = zodb.Tid(binary.BigEndian.Uint64(data[16 : 16+8]))
mv.IsCurrent = byte2bool((data[24 : 24+1])[0])
m[key] = mv
data = data[25:]
}
}
......@@ -3117,10 +3111,10 @@ func (p *AnswerTIDsFrom) neoMsgEncodedLenN() int {
func (p *AnswerTIDsFrom) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.TidList))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.TidList)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.TidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -3215,8 +3209,8 @@ func (p *CheckReplicas) neoMsgEncodedLenN() int {
func (p *CheckReplicas) neoMsgEncodeN(data []byte) {
{
l := uint32(len(p.PartitionDict))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.PartitionDict)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
keyv := make([]uint32, 0, l)
for key := range p.PartitionDict {
......@@ -3248,7 +3242,8 @@ func (p *CheckReplicas) neoMsgDecodeN(data []byte) (int, error) {
p.PartitionDict = make(map[uint32]NodeUUID, l)
m := p.PartitionDict
for i := 0; uint32(i) < l; i++ {
key := binary.BigEndian.Uint32(data[0 : 0+4])
var key uint32
key = binary.BigEndian.Uint32(data[0 : 0+4])
m[key] = NodeUUID(int32(binary.BigEndian.Uint32(data[4 : 4+4])))
data = data[8:]
}
......@@ -3462,10 +3457,10 @@ func (p *PartitionCorrupted) neoMsgEncodedLenN() int {
func (p *PartitionCorrupted) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint32(data[0:], p.Partition)
{
l := uint32(len(p.CellList))
binary.BigEndian.PutUint32(data[4:], l)
l := len(p.CellList)
binary.BigEndian.PutUint32(data[4:], uint32(l))
data = data[8:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a))))
data = data[4:]
......@@ -3663,8 +3658,8 @@ func (p *Replicate) neoMsgEncodeN(data []byte) {
data = data[l:]
}
{
l := uint32(len(p.SourceDict))
binary.BigEndian.PutUint32(data[0:], l)
l := len(p.SourceDict)
binary.BigEndian.PutUint32(data[0:], uint32(l))
data = data[4:]
keyv := make([]uint32, 0, l)
for key := range p.SourceDict {
......@@ -3680,7 +3675,6 @@ func (p *Replicate) neoMsgEncodeN(data []byte) {
copy(data, p.SourceDict[key])
data = data[l:]
}
data = data[0:]
}
}
}
......@@ -3710,7 +3704,8 @@ func (p *Replicate) neoMsgDecodeN(data []byte) (int, error) {
if len(data) < 8 {
goto overflow
}
key := binary.BigEndian.Uint32(data[0 : 0+4])
var key uint32
key = binary.BigEndian.Uint32(data[0 : 0+4])
{
l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[8:]
......@@ -3773,10 +3768,10 @@ func (p *FetchTransactions) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[8:], uint64(p.MinTid))
binary.BigEndian.PutUint64(data[16:], uint64(p.MaxTid))
{
l := uint32(len(p.TxnKnownList))
binary.BigEndian.PutUint32(data[24:], l)
l := len(p.TxnKnownList)
binary.BigEndian.PutUint32(data[24:], uint32(l))
data = data[28:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.TxnKnownList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -3827,10 +3822,10 @@ func (p *AnswerFetchTransactions) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.PackTid))
binary.BigEndian.PutUint64(data[8:], uint64(p.NextTid))
{
l := uint32(len(p.TxnDeleteList))
binary.BigEndian.PutUint32(data[16:], l)
l := len(p.TxnDeleteList)
binary.BigEndian.PutUint32(data[16:], uint32(l))
data = data[20:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.TxnDeleteList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......@@ -3886,8 +3881,8 @@ func (p *FetchObjects) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[16:], uint64(p.MaxTid))
binary.BigEndian.PutUint64(data[24:], uint64(p.MinOid))
{
l := uint32(len(p.ObjKnownDict))
binary.BigEndian.PutUint32(data[32:], l)
l := len(p.ObjKnownDict)
binary.BigEndian.PutUint32(data[32:], uint32(l))
data = data[36:]
keyv := make([]zodb.Tid, 0, l)
for key := range p.ObjKnownDict {
......@@ -3897,16 +3892,15 @@ func (p *FetchObjects) neoMsgEncodeN(data []byte) {
for _, key := range keyv {
binary.BigEndian.PutUint64(data[0:], uint64(key))
{
l := uint32(len(p.ObjKnownDict[key]))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.ObjKnownDict[key])
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.ObjKnownDict[key][i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
}
}
data = data[0:]
}
}
}
......@@ -3930,8 +3924,9 @@ func (p *FetchObjects) neoMsgDecodeN(data []byte) (int, error) {
if len(data) < 12 {
goto overflow
}
key := zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
var v []zodb.Oid
var key zodb.Tid
key = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
var mv []zodb.Oid
{
l := binary.BigEndian.Uint32(data[8 : 8+4])
data = data[12:]
......@@ -3939,14 +3934,14 @@ func (p *FetchObjects) neoMsgDecodeN(data []byte) (int, error) {
goto overflow
}
nread += uint64(l) * 8
v = make([]zodb.Oid, l)
mv = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &v[i]
a := &mv[i]
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
data = data[8:]
}
}
m[key] = v
m[key] = mv
}
nread += uint64(l) * 12
}
......@@ -3975,8 +3970,8 @@ func (p *AnswerFetchObjects) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[8:], uint64(p.NextTid))
binary.BigEndian.PutUint64(data[16:], uint64(p.NextOid))
{
l := uint32(len(p.ObjDeleteDict))
binary.BigEndian.PutUint32(data[24:], l)
l := len(p.ObjDeleteDict)
binary.BigEndian.PutUint32(data[24:], uint32(l))
data = data[28:]
keyv := make([]zodb.Tid, 0, l)
for key := range p.ObjDeleteDict {
......@@ -3986,16 +3981,15 @@ func (p *AnswerFetchObjects) neoMsgEncodeN(data []byte) {
for _, key := range keyv {
binary.BigEndian.PutUint64(data[0:], uint64(key))
{
l := uint32(len(p.ObjDeleteDict[key]))
binary.BigEndian.PutUint32(data[8:], l)
l := len(p.ObjDeleteDict[key])
binary.BigEndian.PutUint32(data[8:], uint32(l))
data = data[12:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.ObjDeleteDict[key][i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
}
}
data = data[0:]
}
}
}
......@@ -4017,8 +4011,9 @@ func (p *AnswerFetchObjects) neoMsgDecodeN(data []byte) (int, error) {
if len(data) < 12 {
goto overflow
}
key := zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
var v []zodb.Oid
var key zodb.Tid
key = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
var mv []zodb.Oid
{
l := binary.BigEndian.Uint32(data[8 : 8+4])
data = data[12:]
......@@ -4026,14 +4021,14 @@ func (p *AnswerFetchObjects) neoMsgDecodeN(data []byte) (int, error) {
goto overflow
}
nread += uint64(l) * 8
v = make([]zodb.Oid, l)
mv = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &v[i]
a := &mv[i]
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
data = data[8:]
}
}
m[key] = v
m[key] = mv
}
nread += uint64(l) * 12
}
......@@ -4079,10 +4074,10 @@ func (p *AddTransaction) neoMsgEncodeN(data []byte) {
(data[0:])[0] = bool2byte(p.Packed)
binary.BigEndian.PutUint64(data[1:], uint64(p.TTid))
{
l := uint32(len(p.OidList))
binary.BigEndian.PutUint32(data[9:], l)
l := len(p.OidList)
binary.BigEndian.PutUint32(data[9:], uint32(l))
data = data[13:]
for i := 0; uint32(i) < l; i++ {
for i := 0; i < l; i++ {
a := &p.OidList[i]
binary.BigEndian.PutUint64(data[0:], uint64((*a)))
data = data[8:]
......
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