Commit d4317253 authored by Levin Zimmermann's avatar Levin Zimmermann

proto: Fix case where Compression = None

'Compression' is py type 'Optional[int]'. Before this patch only 'int' was
supported. Now NEO/go also understands 'Compression' with value 'Nil'.
parent 34c4d915
......@@ -1130,8 +1130,21 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
v = fmt.Sprintf("%s(v)", typeName(userType))
}
// optional emits optional value of int/float
optional := func(optionalValue string) {
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))
}
}
// mgetint emits assignto = mget<kind>int<size>()
mgetint := func(kind string, size int) {
mgetint := func(kind string, size int, optionalValue string) {
// we are going to go into msgp - flush previously queued
// overflow checks; put place for next overflow check after
// msgp is done.
......@@ -1146,7 +1159,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.emit("{")
d.emit("v, tail, err := msgp.Read%snt%dBytes(data)", KI, size)
d.emit("if err != nil {")
d.emit(" return 0, mdecodeErr(%q, err)", d.pathName(assignto))
optional(optionalValue)
d.emit("}")
d.emit("%s= %s", assignto, v)
d.emit("%v += uint64(len(data) - len(tail))", d.var_("nread"))
......@@ -1164,15 +1177,7 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.emit("{")
d.emit("v, tail, err := msgp.ReadFloat%dBytes(data)", size)
d.emit("if err != nil {")
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))
}
optional(optionalValue)
d.emit("}")
d.emit("%s= %s", assignto, v)
d.emit("%v += uint64(len(data) - len(tail))", d.var_("nread"))
......@@ -1188,6 +1193,13 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
return
}
// Compression can be nil ('None'), this means the same as
// no compression ('py/NoneType.__bool__' is 'False').
if typeName(userType) == "Compression" {
mgetint("u", 64, "0")
return
}
switch typ.Kind() {
case types.Bool:
d.emit("switch op := msgpack.Op(data[%v]); op {", d.n)
......@@ -1199,15 +1211,15 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.n++
d.overflow.Add(1)
case types.Int8: mgetint("", 8)
case types.Int16: mgetint("", 16)
case types.Int32: mgetint("", 32)
case types.Int64: mgetint("", 64)
case types.Int8: mgetint("", 8, "")
case types.Int16: mgetint("", 16, "")
case types.Int32: mgetint("", 32, "")
case types.Int64: mgetint("", 64, "")
case types.Uint8: mgetint("u", 8)
case types.Uint16: mgetint("u", 16)
case types.Uint32: mgetint("u", 32)
case types.Uint64: mgetint("u", 64)
case types.Uint8: mgetint("u", 8, "")
case types.Uint16: mgetint("u", 16, "")
case types.Uint32: mgetint("u", 32, "")
case types.Uint64: mgetint("u", 64, "")
case types.Float64: mgetfloat(64, "")
}
......
......@@ -4986,7 +4986,7 @@ func (p *AnswerRebaseObject) neoMsgEncodedLenN() int {
func (p *AnswerRebaseObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[8:], uint64(p.ConflictSerial))
binary.BigEndian.PutUint64(data[16:], p.Compression)
binary.BigEndian.PutUint64(data[16:], uint64(p.Compression))
copy(data[24:], p.Checksum[:])
{
l := uint32(len(p.Data.XData()))
......@@ -5004,7 +5004,7 @@ func (p *AnswerRebaseObject) neoMsgDecodeN(data []byte) (int, error) {
}
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.ConflictSerial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = binary.BigEndian.Uint64(data[16 : 16+8])
p.Compression = Compression(binary.BigEndian.Uint64(data[16 : 16+8]))
copy(p.Checksum[:], data[24:44])
{
l := binary.BigEndian.Uint32(data[44 : 44+4])
......@@ -5035,7 +5035,7 @@ func (p *AnswerRebaseObject) neoMsgEncodedLenM() int {
} else {
size += 1 + 1 + 8 // mbin8 + 8 + [8]data
}
return 23 + msgpack.Uint64Size(p.Compression) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
return 23 + msgpack.Uint64Size(uint64(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
}
func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) {
......@@ -5059,7 +5059,7 @@ func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) {
data = data[10:]
}
{
n := msgpack.PutUint64(data[0:], p.Compression)
n := msgpack.PutUint64(data[0:], uint64(p.Compression))
data = data[0+n:]
}
data[0] = byte(msgpack.Bin8)
......@@ -5118,9 +5118,13 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
{
v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil {
return 0, mdecodeErr("AnswerRebaseObject.Compression", err)
tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("AnswerRebaseObject.Compression", err)
}
v = 0
}
p.Compression = v
p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
......@@ -5164,7 +5168,7 @@ func (p *StoreObject) neoMsgEncodedLenN() int {
func (p *StoreObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[16:], p.Compression)
binary.BigEndian.PutUint64(data[16:], uint64(p.Compression))
copy(data[24:], p.Checksum[:])
{
l := uint32(len(p.Data))
......@@ -5184,7 +5188,7 @@ func (p *StoreObject) neoMsgDecodeN(data []byte) (int, error) {
}
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = binary.BigEndian.Uint64(data[16 : 16+8])
p.Compression = Compression(binary.BigEndian.Uint64(data[16 : 16+8]))
copy(p.Checksum[:], data[24:44])
{
l := binary.BigEndian.Uint32(data[44 : 44+4])
......@@ -5227,7 +5231,7 @@ func (p *StoreObject) neoMsgEncodedLenM() int {
} else {
size += 1 + 1 + 8 // mbin8 + 8 + [8]data
}
return 23 + msgpack.Uint64Size(p.Compression) + msgpack.BinHeadSize(len(p.Data)) + len(p.Data) + size
return 23 + msgpack.Uint64Size(uint64(p.Compression)) + msgpack.BinHeadSize(len(p.Data)) + len(p.Data) + size
}
func (p *StoreObject) neoMsgEncodeM(data []byte) {
......@@ -5251,7 +5255,7 @@ func (p *StoreObject) neoMsgEncodeM(data []byte) {
data = data[10:]
}
{
n := msgpack.PutUint64(data[0:], p.Compression)
n := msgpack.PutUint64(data[0:], uint64(p.Compression))
data = data[0+n:]
}
data[0] = byte(msgpack.Bin8)
......@@ -5328,9 +5332,13 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
{
v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil {
return 0, mdecodeErr("StoreObject.Compression", err)
tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("StoreObject.Compression", err)
}
v = 0
}
p.Compression = v
p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
......@@ -6191,7 +6199,7 @@ func (p *AnswerObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[16:], uint64(p.NextSerial))
binary.BigEndian.PutUint64(data[24:], p.Compression)
binary.BigEndian.PutUint64(data[24:], uint64(p.Compression))
copy(data[32:], p.Checksum[:])
{
l := uint32(len(p.Data.XData()))
......@@ -6211,7 +6219,7 @@ func (p *AnswerObject) neoMsgDecodeN(data []byte) (int, error) {
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.NextSerial = zodb.Tid(binary.BigEndian.Uint64(data[16 : 16+8]))
p.Compression = binary.BigEndian.Uint64(data[24 : 24+8])
p.Compression = Compression(binary.BigEndian.Uint64(data[24 : 24+8]))
copy(p.Checksum[:], data[32:52])
{
l := binary.BigEndian.Uint32(data[52 : 52+4])
......@@ -6253,7 +6261,7 @@ func (p *AnswerObject) neoMsgEncodedLenM() int {
} else {
size += 1 + 1 + 8 // mbin8 + 8 + [8]data
}
return 23 + msgpack.Uint64Size(p.Compression) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
return 23 + msgpack.Uint64Size(uint64(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
}
func (p *AnswerObject) neoMsgEncodeM(data []byte) {
......@@ -6286,7 +6294,7 @@ func (p *AnswerObject) neoMsgEncodeM(data []byte) {
data = data[10:]
}
{
n := msgpack.PutUint64(data[0:], p.Compression)
n := msgpack.PutUint64(data[0:], uint64(p.Compression))
data = data[0+n:]
}
data[0] = byte(msgpack.Bin8)
......@@ -6367,9 +6375,13 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
{
v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil {
return 0, mdecodeErr("AnswerObject.Compression", err)
tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("AnswerObject.Compression", err)
}
v = 0
}
p.Compression = v
p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
......@@ -13237,7 +13249,7 @@ func (p *AddObject) neoMsgEncodedLenN() int {
func (p *AddObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[16:], p.Compression)
binary.BigEndian.PutUint64(data[16:], uint64(p.Compression))
copy(data[24:], p.Checksum[:])
{
l := uint32(len(p.Data.XData()))
......@@ -13256,7 +13268,7 @@ func (p *AddObject) neoMsgDecodeN(data []byte) (int, error) {
}
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = binary.BigEndian.Uint64(data[16 : 16+8])
p.Compression = Compression(binary.BigEndian.Uint64(data[16 : 16+8]))
copy(p.Checksum[:], data[24:44])
{
l := binary.BigEndian.Uint32(data[44 : 44+4])
......@@ -13293,7 +13305,7 @@ func (p *AddObject) neoMsgEncodedLenM() int {
} else {
size += 1 + 1 + 8 // mbin8 + 8 + [8]data
}
return 23 + msgpack.Uint64Size(p.Compression) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
return 23 + msgpack.Uint64Size(uint64(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) + size
}
func (p *AddObject) neoMsgEncodeM(data []byte) {
......@@ -13317,7 +13329,7 @@ func (p *AddObject) neoMsgEncodeM(data []byte) {
data = data[10:]
}
{
n := msgpack.PutUint64(data[0:], p.Compression)
n := msgpack.PutUint64(data[0:], uint64(p.Compression))
data = data[0+n:]
}
data[0] = byte(msgpack.Bin8)
......@@ -13385,9 +13397,13 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
{
v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil {
return 0, mdecodeErr("AddObject.Compression", err)
tail, err = msgp.ReadNilBytes(data)
if err != nil {
return 0, mdecodeErr("AddObject.Compression", err)
}
v = 0
}
p.Compression = v
p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = 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