Commit d779695c authored by Levin Zimmermann's avatar Levin Zimmermann

proto/msgpack: Allow nil=false simplification

NEO/py sometimes sends 'None' for boolean values (being equal to 'False'
due to pythons 'bool(None) == False' logic). Let's accept python based
False values (= Nil) as equally acceptable.

Without this patch we can see errors as:

xtesting.go:330: load 0285cbad6e147b66:0000000000000005: returned err unexpected:
        have: neo://127.0.0.1:30002/1: load 0285cbad6e147b66:0000000000000005: 127.0.0.1:48928 - 127.0.0.1:33051 .251: decode: decode: M: AnswerObject.Compression/op: got opcode 00;  expected any from c3c2
parent 9e4dd249
......@@ -1175,6 +1175,21 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.emit("}")
}
// mgetbool emits bool
mgetbool := func(optional bool) {
d.emit("switch op := msgpack.Op(data[%v]); op {", d.n)
d.emit("default: return 0, mdecodeOpErr(%q, op, msgpack.True, msgpack.False)", d.pathName(assignto))
d.emit("case msgpack.True: %s = true", assignto)
d.emit("case msgpack.False: %s = false", assignto)
if optional {
d.emit("case msgpack.Nil : %s = false", assignto)
}
d.emit("}")
d.n++
d.overflow.Add(1)
}
// IdTime can be nil ('None' in py), in this case we use
// infinite -1, see
// https://lab.nexedi.com/kirr/neo/-/blob/1ad088c8/go/neo/proto/proto.go#L352-357
......@@ -1184,15 +1199,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
}
switch typ.Kind() {
case types.Bool:
d.emit("switch op := msgpack.Op(data[%v]); op {", d.n)
d.emit("default: return 0, mdecodeOpErr(%q, op, msgpack.True, msgpack.False)", d.pathName(assignto))
d.emit("case msgpack.True: %s = true", assignto)
d.emit("case msgpack.False: %s = false", assignto)
d.emit("}")
d.n++
d.overflow.Add(1)
case types.Bool: mgetbool(true)
case types.Int8: mgetint("", 8)
case types.Int16: mgetint("", 16)
......
......@@ -2422,6 +2422,8 @@ func (p *StartOperation) neoMsgDecodeM(data []byte) (int, error) {
p.Backup = true
case msgpack.False:
p.Backup = false
case msgpack.Nil:
p.Backup = false
}
return 2, nil
......@@ -4914,6 +4916,8 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
p.Compression = true
case msgpack.False:
p.Compression = false
case msgpack.Nil:
p.Compression = false
}
if op := msgpack.Op(data[21]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AnswerRebaseObject.Checksum", op, msgpack.Bin8)
......@@ -5105,6 +5109,8 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
p.Compression = true
case msgpack.False:
p.Compression = false
case msgpack.Nil:
p.Compression = false
}
if op := msgpack.Op(data[21]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("StoreObject.Checksum", op, msgpack.Bin8)
......@@ -6062,6 +6068,8 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
p.Compression = true
case msgpack.False:
p.Compression = false
case msgpack.Nil:
p.Compression = false
}
if op := msgpack.Op(data[31]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AnswerObject.Checksum", op, msgpack.Bin8)
......@@ -6612,6 +6620,8 @@ func (p *AnswerTransactionInformation) neoMsgDecodeM(data []byte) (int, error) {
p.Packed = true
case msgpack.False:
p.Packed = false
case msgpack.Nil:
p.Packed = false
}
{
data = data[1:]
......@@ -7916,6 +7926,8 @@ func (p *TweakPartitionTable) neoMsgDecodeM(data []byte) (int, error) {
p.DryRun = true
case msgpack.False:
p.DryRun = false
case msgpack.Nil:
p.DryRun = false
}
{
data = data[1:]
......@@ -8091,6 +8103,8 @@ func (p *AnswerTweakPartitionTable) neoMsgDecodeM(data []byte) (int, error) {
p.Changed = true
case msgpack.False:
p.Changed = false
case msgpack.Nil:
p.Changed = false
}
{
data = data[1:]
......@@ -8442,6 +8456,8 @@ func (p *Repair) neoMsgDecodeM(data []byte) (int, error) {
p.repairFlags.DryRun = true
case msgpack.False:
p.repairFlags.DryRun = false
case msgpack.Nil:
p.repairFlags.DryRun = false
}
return 3 + int(nread), nil
......@@ -8515,6 +8531,8 @@ func (p *RepairOne) neoMsgDecodeM(data []byte) (int, error) {
p.repairFlags.DryRun = true
case msgpack.False:
p.repairFlags.DryRun = false
case msgpack.Nil:
p.repairFlags.DryRun = false
}
return 3, nil
......@@ -9097,6 +9115,8 @@ func (p *AnswerObjectUndoSerial) neoMsgDecodeM(data []byte) (int, error) {
mv.IsCurrent = true
case msgpack.False:
mv.IsCurrent = false
case msgpack.Nil:
mv.IsCurrent = false
}
m[key] = mv
data = data[21:]
......@@ -9486,6 +9506,8 @@ func (p *AnswerPack) neoMsgDecodeM(data []byte) (int, error) {
p.Status = true
case msgpack.False:
p.Status = false
case msgpack.Nil:
p.Status = false
}
return 2, nil
......@@ -12543,6 +12565,8 @@ func (p *AddTransaction) neoMsgDecodeM(data []byte) (int, error) {
p.Packed = true
case msgpack.False:
p.Packed = false
case msgpack.Nil:
p.Packed = false
}
if op := msgpack.Op(data[1]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AddTransaction.TTid", op, msgpack.Bin8)
......@@ -12732,6 +12756,8 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
p.Compression = true
case msgpack.False:
p.Compression = false
case msgpack.Nil:
p.Compression = false
}
if op := msgpack.Op(data[21]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AddObject.Checksum", op, msgpack.Bin8)
......
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