Commit 55b0c760 authored by Levin Zimmermann's avatar Levin Zimmermann

fixup! first attempt to fix case where IdTime == None

parent cc62ba6c
...@@ -313,6 +313,7 @@ package proto ...@@ -313,6 +313,7 @@ package proto
import ( import (
"encoding/binary" "encoding/binary"
"math"
"reflect" "reflect"
"sort" "sort"
...@@ -1131,7 +1132,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1131,7 +1132,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
} }
// mgetfloat emits mgetfloat<size> // mgetfloat emits mgetfloat<size>
mgetfloat := func(size int) { mgetfloat := func(size int, optionalValue string) {
// delving into msgp - flush/prepare next site for overflow check // delving into msgp - flush/prepare next site for overflow check
d.overflowCheck() d.overflowCheck()
d.resetPos() d.resetPos()
...@@ -1140,7 +1141,15 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1140,7 +1141,15 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.emit("{") d.emit("{")
d.emit("v, tail, err := msgp.ReadFloat%dBytes(data)", size) d.emit("v, tail, err := msgp.ReadFloat%dBytes(data)", size)
d.emit("if err != nil {") d.emit("if err != nil {")
d.emit(" return 0, mdecodeErr(%q, err)", d.pathName(assignto)) if optionalValue != "" {
d.emit(" tail, err = msgp.ReadNilBytes(data)")
d.emit(" if err != nil {")
d.emit(" return 0, mdecodeErr(%q, err)", d.pathName(assignto))
d.emit(" }")
d.emit("v = %v", optionalValue)
} else {
d.emit(" return 0, mdecodeErr(%q, err)", d.pathName(assignto))
}
d.emit("}") d.emit("}")
d.emit("%s= %s", assignto, v) d.emit("%s= %s", assignto, v)
d.emit("%v += uint64(len(data) - len(tail))", d.var_("nread")) d.emit("%v += uint64(len(data) - len(tail))", d.var_("nread"))
...@@ -1148,6 +1157,14 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1148,6 +1157,14 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.emit("}") d.emit("}")
} }
// 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
if typeName(userType) == "IdTime" {
mgetfloat(64, "math.Inf(-1)")
return
}
switch typ.Kind() { switch typ.Kind() {
case types.Bool: case types.Bool:
d.emit("switch op := msgpack.Op(data[%v]); op {", d.n) d.emit("switch op := msgpack.Op(data[%v]); op {", d.n)
...@@ -1169,7 +1186,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1169,7 +1186,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
case types.Uint32: mgetint("u", 32) case types.Uint32: mgetint("u", 32)
case types.Uint64: mgetint("u", 64) case types.Uint64: mgetint("u", 64)
case types.Float64: mgetfloat(64) case types.Float64: mgetfloat(64, "")
} }
} }
......
...@@ -428,7 +428,11 @@ func (p *RequestIdentification) neoMsgDecodeM(data []byte) (int, error) { ...@@ -428,7 +428,11 @@ func (p *RequestIdentification) neoMsgDecodeM(data []byte) (int, error) {
{ {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
return 0, mdecodeErr("RequestIdentification.IdTime", err) tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("RequestIdentification.IdTime", err)
}
v = math.Inf(-1)
} }
p.IdTime = IdTime(v) p.IdTime = IdTime(v)
nread += uint64(len(data) - len(tail)) nread += uint64(len(data) - len(tail))
...@@ -1183,7 +1187,11 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) { ...@@ -1183,7 +1187,11 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) {
{ {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
return 0, mdecodeErr("NotifyNodeInformation.IdTime", err) tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("NotifyNodeInformation.IdTime", err)
}
v = math.Inf(-1)
} }
p.IdTime = IdTime(v) p.IdTime = IdTime(v)
nread += uint64(len(data) - len(tail)) nread += uint64(len(data) - len(tail))
...@@ -1287,7 +1295,6 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) { ...@@ -1287,7 +1295,6 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) {
if err != nil { if err != nil {
return 0, mdecodeErr("NotifyNodeInformation.IdTime", err) return 0, mdecodeErr("NotifyNodeInformation.IdTime", err)
} }
// see https://lab.nexedi.com/levin.zimmermann/neoppod/-/blob/4d73d206/go/neo/proto/proto.go#L352-353
v = math.Inf(-1) v = math.Inf(-1)
} }
(*a).IdTime = IdTime(v) (*a).IdTime = IdTime(v)
...@@ -6996,7 +7003,11 @@ func (p *AnswerNodeList) neoMsgDecodeM(data []byte) (int, error) { ...@@ -6996,7 +7003,11 @@ func (p *AnswerNodeList) neoMsgDecodeM(data []byte) (int, error) {
{ {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
return 0, mdecodeErr("AnswerNodeList.IdTime", err) tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("AnswerNodeList.IdTime", err)
}
v = math.Inf(-1)
} }
(*a).IdTime = IdTime(v) (*a).IdTime = IdTime(v)
nread += uint64(len(data) - len(tail)) nread += uint64(len(data) - len(tail))
......
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