Commit 12a6a923 authored by Levin Zimmermann's avatar Levin Zimmermann Committed by Kirill Smelkov

go/neo/proto: Update 'Compression' to int to support different compression algorithms

With nexedi/neoppod@fd80cc30 NEO/py added support to encode the compression
algorithm with the 'Compression' parameter. Before this, compression could
only be true (= with compression) or false (= without compression). Now
the absence of compression is encoded with 0. Any other number than 0
encodes a compression algorithm. The mapping is currently:

	1 = zlib

In the future, 2 could mean zstd [1].

[1] https://github.com/facebook/zstd/issues/1134

/reviewed-by @kirr
/reviewed-on kirr/neo!6
parent dc844465
...@@ -332,6 +332,11 @@ func (a *Address) neoDecodeN(b []byte) (uint64, bool) { ...@@ -332,6 +332,11 @@ func (a *Address) neoDecodeN(b []byte) (uint64, bool) {
// Checksum is a SHA1 hash. // Checksum is a SHA1 hash.
type Checksum [20]byte type Checksum [20]byte
// Compression is an integer that tells the compression algorithm:
// 0 = no compression algorithm is used
// 1 = zlib is used
type Compression uint8
// PTid is Partition Table identifier. // PTid is Partition Table identifier.
// //
// Zero value means "invalid id" (<-> None in py.PPTID) // Zero value means "invalid id" (<-> None in py.PPTID)
...@@ -707,7 +712,7 @@ type AnswerRebaseObject struct { ...@@ -707,7 +712,7 @@ type AnswerRebaseObject struct {
Serial zodb.Tid Serial zodb.Tid
ConflictSerial zodb.Tid ConflictSerial zodb.Tid
// FIXME POption('data') // FIXME POption('data')
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf Data *mem.Buf
} }
...@@ -721,7 +726,7 @@ type AnswerRebaseObject struct { ...@@ -721,7 +726,7 @@ type AnswerRebaseObject struct {
type StoreObject struct { type StoreObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data []byte // TODO -> msg.Buf, separately (for writev) Data []byte // TODO -> msg.Buf, separately (for writev)
DataSerial zodb.Tid DataSerial zodb.Tid
...@@ -776,7 +781,7 @@ type AnswerObject struct { ...@@ -776,7 +781,7 @@ type AnswerObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
NextSerial zodb.Tid NextSerial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf // TODO encode -> separately (for writev) Data *mem.Buf // TODO encode -> separately (for writev)
DataSerial zodb.Tid DataSerial zodb.Tid
...@@ -1211,7 +1216,7 @@ type AddTransaction struct { ...@@ -1211,7 +1216,7 @@ type AddTransaction struct {
type AddObject struct { type AddObject struct {
Oid zodb.Oid Oid zodb.Oid
Serial zodb.Tid Serial zodb.Tid
Compression bool Compression Compression
Checksum Checksum Checksum Checksum
Data *mem.Buf Data *mem.Buf
DataSerial zodb.Tid DataSerial zodb.Tid
......
...@@ -182,7 +182,7 @@ func TestMsgMarshal(t *testing.T) { ...@@ -182,7 +182,7 @@ func TestMsgMarshal(t *testing.T) {
{&StoreObject{ {&StoreObject{
Oid: 0x0102030405060708, Oid: 0x0102030405060708,
Serial: 0x0a0b0c0d0e0f0102, Serial: 0x0a0b0c0d0e0f0102,
Compression: false, Compression: 0,
Checksum: Checksum{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, // XXX simpler? Checksum: Checksum{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, // XXX simpler?
Data: []byte("hello world"), Data: []byte("hello world"),
DataSerial: 0x0a0b0c0d0e0f0103, DataSerial: 0x0a0b0c0d0e0f0103,
...@@ -198,7 +198,7 @@ func TestMsgMarshal(t *testing.T) { ...@@ -198,7 +198,7 @@ func TestMsgMarshal(t *testing.T) {
hex("97") + hex("97") +
hex("c408") + hex("0102030405060708") + hex("c408") + hex("0102030405060708") +
hex("c408") + hex("0a0b0c0d0e0f0102") + hex("c408") + hex("0a0b0c0d0e0f0102") +
hex("c2") + hex("00") +
hex("c414") + hex("0102030405060708090a0b0c0d0e0f1011121314") + hex("c414") + hex("0102030405060708090a0b0c0d0e0f1011121314") +
hex("c40b") + "hello world" + hex("c40b") + "hello world" +
hex("c408") + hex("0a0b0c0d0e0f0103") + hex("c408") + hex("0a0b0c0d0e0f0103") +
......
...@@ -4064,7 +4064,7 @@ func (p *AnswerRebaseObject) neoMsgEncodedLenN() int { ...@@ -4064,7 +4064,7 @@ func (p *AnswerRebaseObject) neoMsgEncodedLenN() int {
func (p *AnswerRebaseObject) neoMsgEncodeN(data []byte) { func (p *AnswerRebaseObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[0:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[8:], uint64(p.ConflictSerial)) binary.BigEndian.PutUint64(data[8:], uint64(p.ConflictSerial))
(data[16:])[0] = bool2byte(p.Compression) (data[16:])[0] = uint8(p.Compression)
copy(data[17:], p.Checksum[:]) copy(data[17:], p.Checksum[:])
{ {
l := uint32(len(p.Data.XData())) l := uint32(len(p.Data.XData()))
...@@ -4082,7 +4082,7 @@ func (p *AnswerRebaseObject) neoMsgDecodeN(data []byte) (int, error) { ...@@ -4082,7 +4082,7 @@ func (p *AnswerRebaseObject) neoMsgDecodeN(data []byte) (int, error) {
} }
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.ConflictSerial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8])) p.ConflictSerial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = byte2bool((data[16 : 16+1])[0]) p.Compression = Compression((data[16 : 16+1])[0])
copy(p.Checksum[:], data[17:37]) copy(p.Checksum[:], data[17:37])
{ {
l := binary.BigEndian.Uint32(data[37 : 37+4]) l := binary.BigEndian.Uint32(data[37 : 37+4])
...@@ -4102,7 +4102,7 @@ overflow: ...@@ -4102,7 +4102,7 @@ overflow:
} }
func (p *AnswerRebaseObject) neoMsgEncodedLenM() int { func (p *AnswerRebaseObject) neoMsgEncodedLenM() int {
return 44 + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) return 43 + msgpack.Uint8Size(uint8(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData())
} }
func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) { func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) {
...@@ -4113,14 +4113,17 @@ func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) { ...@@ -4113,14 +4113,17 @@ func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) {
data[11] = byte(msgpack.Bin8) data[11] = byte(msgpack.Bin8)
data[12] = 8 data[12] = 8
binary.BigEndian.PutUint64(data[13:], uint64(p.ConflictSerial)) binary.BigEndian.PutUint64(data[13:], uint64(p.ConflictSerial))
data[21] = byte(msgpack.Bool(p.Compression)) {
data[22] = byte(msgpack.Bin8) n := msgpack.PutUint8(data[21:], uint8(p.Compression))
data[23] = 20 data = data[21+n:]
copy(data[24:], p.Checksum[:]) }
data[0] = byte(msgpack.Bin8)
data[1] = 20
copy(data[2:], p.Checksum[:])
{ {
l := len(p.Data.XData()) l := len(p.Data.XData())
n := msgpack.PutBinHead(data[44:], l) n := msgpack.PutBinHead(data[22:], l)
data = data[44+n:] data = data[22+n:]
copy(data, p.Data.XData()) copy(data, p.Data.XData())
data = data[l:] data = data[l:]
} }
...@@ -4128,7 +4131,7 @@ func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) { ...@@ -4128,7 +4131,7 @@ func (p *AnswerRebaseObject) neoMsgEncodeM(data []byte) {
func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) { func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 44 { if len(data) < 21 {
goto overflow goto overflow
} }
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|5; op != opOk { if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|5; op != opOk {
...@@ -4148,22 +4151,27 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -4148,22 +4151,27 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("AnswerRebaseObject.ConflictSerial", l, 8) return 0, mdecodeLen8Err("AnswerRebaseObject.ConflictSerial", l, 8)
} }
p.ConflictSerial = zodb.Tid(binary.BigEndian.Uint64(data[13:])) p.ConflictSerial = zodb.Tid(binary.BigEndian.Uint64(data[13:]))
switch op := msgpack.Op(data[21]); op { data = data[21:]
default: {
return 0, mdecodeOpErr("AnswerRebaseObject.Compression", op, msgpack.True, msgpack.False) v, tail, err := msgp.ReadUint8Bytes(data)
case msgpack.True: if err != nil {
p.Compression = true return 0, mdecodeErr("AnswerRebaseObject.Compression", err)
case msgpack.False:
p.Compression = false
} }
if op := msgpack.Op(data[22]); op != msgpack.Bin8 { p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
if len(data) < 22 {
goto overflow
}
if op := msgpack.Op(data[0]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AnswerRebaseObject.Checksum", op, msgpack.Bin8) return 0, mdecodeOpErr("AnswerRebaseObject.Checksum", op, msgpack.Bin8)
} }
if l := data[23]; l != 20 { if l := data[1]; l != 20 {
return 0, mdecodeLen8Err("AnswerRebaseObject.Checksum", l, 20) return 0, mdecodeLen8Err("AnswerRebaseObject.Checksum", l, 20)
} }
copy(p.Checksum[:], data[24:44]) copy(p.Checksum[:], data[2:22])
data = data[44:] data = data[22:]
{ {
b, tail, err := msgp.ReadBytesZC(data) b, tail, err := msgp.ReadBytesZC(data)
if err != nil { if err != nil {
...@@ -4174,7 +4182,7 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -4174,7 +4182,7 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
nread += uint64(len(data) - len(tail)) nread += uint64(len(data) - len(tail))
data = tail data = tail
} }
return 44 + int(nread), nil return 43 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -4193,7 +4201,7 @@ func (p *StoreObject) neoMsgEncodedLenN() int { ...@@ -4193,7 +4201,7 @@ func (p *StoreObject) neoMsgEncodedLenN() int {
func (p *StoreObject) neoMsgEncodeN(data []byte) { func (p *StoreObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid)) binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
(data[16:])[0] = bool2byte(p.Compression) (data[16:])[0] = uint8(p.Compression)
copy(data[17:], p.Checksum[:]) copy(data[17:], p.Checksum[:])
{ {
l := uint32(len(p.Data)) l := uint32(len(p.Data))
...@@ -4213,7 +4221,7 @@ func (p *StoreObject) neoMsgDecodeN(data []byte) (int, error) { ...@@ -4213,7 +4221,7 @@ func (p *StoreObject) neoMsgDecodeN(data []byte) (int, error) {
} }
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8])) p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = byte2bool((data[16 : 16+1])[0]) p.Compression = Compression((data[16 : 16+1])[0])
copy(p.Checksum[:], data[17:37]) copy(p.Checksum[:], data[17:37])
{ {
l := binary.BigEndian.Uint32(data[37 : 37+4]) l := binary.BigEndian.Uint32(data[37 : 37+4])
...@@ -4235,7 +4243,7 @@ overflow: ...@@ -4235,7 +4243,7 @@ overflow:
} }
func (p *StoreObject) neoMsgEncodedLenM() int { func (p *StoreObject) neoMsgEncodedLenM() int {
return 64 + msgpack.BinHeadSize(len(p.Data)) + len(p.Data) return 63 + msgpack.Uint8Size(uint8(p.Compression)) + msgpack.BinHeadSize(len(p.Data)) + len(p.Data)
} }
func (p *StoreObject) neoMsgEncodeM(data []byte) { func (p *StoreObject) neoMsgEncodeM(data []byte) {
...@@ -4246,14 +4254,17 @@ func (p *StoreObject) neoMsgEncodeM(data []byte) { ...@@ -4246,14 +4254,17 @@ func (p *StoreObject) neoMsgEncodeM(data []byte) {
data[11] = byte(msgpack.Bin8) data[11] = byte(msgpack.Bin8)
data[12] = 8 data[12] = 8
binary.BigEndian.PutUint64(data[13:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[13:], uint64(p.Serial))
data[21] = byte(msgpack.Bool(p.Compression)) {
data[22] = byte(msgpack.Bin8) n := msgpack.PutUint8(data[21:], uint8(p.Compression))
data[23] = 20 data = data[21+n:]
copy(data[24:], p.Checksum[:]) }
data[0] = byte(msgpack.Bin8)
data[1] = 20
copy(data[2:], p.Checksum[:])
{ {
l := len(p.Data) l := len(p.Data)
n := msgpack.PutBinHead(data[44:], l) n := msgpack.PutBinHead(data[22:], l)
data = data[44+n:] data = data[22+n:]
copy(data, p.Data) copy(data, p.Data)
data = data[l:] data = data[l:]
} }
...@@ -4267,7 +4278,7 @@ func (p *StoreObject) neoMsgEncodeM(data []byte) { ...@@ -4267,7 +4278,7 @@ func (p *StoreObject) neoMsgEncodeM(data []byte) {
func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) { func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 44 { if len(data) < 21 {
goto overflow goto overflow
} }
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|7; op != opOk { if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|7; op != opOk {
...@@ -4287,22 +4298,27 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -4287,22 +4298,27 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("StoreObject.Serial", l, 8) return 0, mdecodeLen8Err("StoreObject.Serial", l, 8)
} }
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[13:])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[13:]))
switch op := msgpack.Op(data[21]); op { data = data[21:]
default: {
return 0, mdecodeOpErr("StoreObject.Compression", op, msgpack.True, msgpack.False) v, tail, err := msgp.ReadUint8Bytes(data)
case msgpack.True: if err != nil {
p.Compression = true return 0, mdecodeErr("StoreObject.Compression", err)
case msgpack.False:
p.Compression = false
} }
if op := msgpack.Op(data[22]); op != msgpack.Bin8 { p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
if len(data) < 22 {
goto overflow
}
if op := msgpack.Op(data[0]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("StoreObject.Checksum", op, msgpack.Bin8) return 0, mdecodeOpErr("StoreObject.Checksum", op, msgpack.Bin8)
} }
if l := data[23]; l != 20 { if l := data[1]; l != 20 {
return 0, mdecodeLen8Err("StoreObject.Checksum", l, 20) return 0, mdecodeLen8Err("StoreObject.Checksum", l, 20)
} }
copy(p.Checksum[:], data[24:44]) copy(p.Checksum[:], data[2:22])
data = data[44:] data = data[22:]
{ {
b, tail, err := msgp.ReadBytesZC(data) b, tail, err := msgp.ReadBytesZC(data)
if err != nil { if err != nil {
...@@ -4330,7 +4346,7 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -4330,7 +4346,7 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("StoreObject.Tid", l, 8) return 0, mdecodeLen8Err("StoreObject.Tid", l, 8)
} }
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[12:])) p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[12:]))
return 64 + int(nread), nil return 63 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -4957,7 +4973,7 @@ func (p *AnswerObject) neoMsgEncodeN(data []byte) { ...@@ -4957,7 +4973,7 @@ func (p *AnswerObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid)) binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
binary.BigEndian.PutUint64(data[16:], uint64(p.NextSerial)) binary.BigEndian.PutUint64(data[16:], uint64(p.NextSerial))
(data[24:])[0] = bool2byte(p.Compression) (data[24:])[0] = uint8(p.Compression)
copy(data[25:], p.Checksum[:]) copy(data[25:], p.Checksum[:])
{ {
l := uint32(len(p.Data.XData())) l := uint32(len(p.Data.XData()))
...@@ -4977,7 +4993,7 @@ func (p *AnswerObject) neoMsgDecodeN(data []byte) (int, error) { ...@@ -4977,7 +4993,7 @@ func (p *AnswerObject) neoMsgDecodeN(data []byte) (int, error) {
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8])) p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.NextSerial = zodb.Tid(binary.BigEndian.Uint64(data[16 : 16+8])) p.NextSerial = zodb.Tid(binary.BigEndian.Uint64(data[16 : 16+8]))
p.Compression = byte2bool((data[24 : 24+1])[0]) p.Compression = Compression((data[24 : 24+1])[0])
copy(p.Checksum[:], data[25:45]) copy(p.Checksum[:], data[25:45])
{ {
l := binary.BigEndian.Uint32(data[45 : 45+4]) l := binary.BigEndian.Uint32(data[45 : 45+4])
...@@ -4998,7 +5014,7 @@ overflow: ...@@ -4998,7 +5014,7 @@ overflow:
} }
func (p *AnswerObject) neoMsgEncodedLenM() int { func (p *AnswerObject) neoMsgEncodedLenM() int {
return 64 + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) return 63 + msgpack.Uint8Size(uint8(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData())
} }
func (p *AnswerObject) neoMsgEncodeM(data []byte) { func (p *AnswerObject) neoMsgEncodeM(data []byte) {
...@@ -5012,14 +5028,17 @@ func (p *AnswerObject) neoMsgEncodeM(data []byte) { ...@@ -5012,14 +5028,17 @@ func (p *AnswerObject) neoMsgEncodeM(data []byte) {
data[21] = byte(msgpack.Bin8) data[21] = byte(msgpack.Bin8)
data[22] = 8 data[22] = 8
binary.BigEndian.PutUint64(data[23:], uint64(p.NextSerial)) binary.BigEndian.PutUint64(data[23:], uint64(p.NextSerial))
data[31] = byte(msgpack.Bool(p.Compression)) {
data[32] = byte(msgpack.Bin8) n := msgpack.PutUint8(data[31:], uint8(p.Compression))
data[33] = 20 data = data[31+n:]
copy(data[34:], p.Checksum[:]) }
data[0] = byte(msgpack.Bin8)
data[1] = 20
copy(data[2:], p.Checksum[:])
{ {
l := len(p.Data.XData()) l := len(p.Data.XData())
n := msgpack.PutBinHead(data[54:], l) n := msgpack.PutBinHead(data[22:], l)
data = data[54+n:] data = data[22+n:]
copy(data, p.Data.XData()) copy(data, p.Data.XData())
data = data[l:] data = data[l:]
} }
...@@ -5030,7 +5049,7 @@ func (p *AnswerObject) neoMsgEncodeM(data []byte) { ...@@ -5030,7 +5049,7 @@ func (p *AnswerObject) neoMsgEncodeM(data []byte) {
func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) { func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 54 { if len(data) < 31 {
goto overflow goto overflow
} }
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|7; op != opOk { if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|7; op != opOk {
...@@ -5057,22 +5076,27 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -5057,22 +5076,27 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("AnswerObject.NextSerial", l, 8) return 0, mdecodeLen8Err("AnswerObject.NextSerial", l, 8)
} }
p.NextSerial = zodb.Tid(binary.BigEndian.Uint64(data[23:])) p.NextSerial = zodb.Tid(binary.BigEndian.Uint64(data[23:]))
switch op := msgpack.Op(data[31]); op { data = data[31:]
default: {
return 0, mdecodeOpErr("AnswerObject.Compression", op, msgpack.True, msgpack.False) v, tail, err := msgp.ReadUint8Bytes(data)
case msgpack.True: if err != nil {
p.Compression = true return 0, mdecodeErr("AnswerObject.Compression", err)
case msgpack.False:
p.Compression = false
} }
if op := msgpack.Op(data[32]); op != msgpack.Bin8 { p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
if len(data) < 22 {
goto overflow
}
if op := msgpack.Op(data[0]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AnswerObject.Checksum", op, msgpack.Bin8) return 0, mdecodeOpErr("AnswerObject.Checksum", op, msgpack.Bin8)
} }
if l := data[33]; l != 20 { if l := data[1]; l != 20 {
return 0, mdecodeLen8Err("AnswerObject.Checksum", l, 20) return 0, mdecodeLen8Err("AnswerObject.Checksum", l, 20)
} }
copy(p.Checksum[:], data[34:54]) copy(p.Checksum[:], data[2:22])
data = data[54:] data = data[22:]
{ {
b, tail, err := msgp.ReadBytesZC(data) b, tail, err := msgp.ReadBytesZC(data)
if err != nil { if err != nil {
...@@ -5093,7 +5117,7 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -5093,7 +5117,7 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("AnswerObject.DataSerial", l, 8) return 0, mdecodeLen8Err("AnswerObject.DataSerial", l, 8)
} }
p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[2:])) p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[2:]))
return 64 + int(nread), nil return 63 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -10607,7 +10631,7 @@ func (p *AddObject) neoMsgEncodedLenN() int { ...@@ -10607,7 +10631,7 @@ func (p *AddObject) neoMsgEncodedLenN() int {
func (p *AddObject) neoMsgEncodeN(data []byte) { func (p *AddObject) neoMsgEncodeN(data []byte) {
binary.BigEndian.PutUint64(data[0:], uint64(p.Oid)) binary.BigEndian.PutUint64(data[0:], uint64(p.Oid))
binary.BigEndian.PutUint64(data[8:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[8:], uint64(p.Serial))
(data[16:])[0] = bool2byte(p.Compression) (data[16:])[0] = uint8(p.Compression)
copy(data[17:], p.Checksum[:]) copy(data[17:], p.Checksum[:])
{ {
l := uint32(len(p.Data.XData())) l := uint32(len(p.Data.XData()))
...@@ -10626,7 +10650,7 @@ func (p *AddObject) neoMsgDecodeN(data []byte) (int, error) { ...@@ -10626,7 +10650,7 @@ func (p *AddObject) neoMsgDecodeN(data []byte) (int, error) {
} }
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8])) p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0 : 0+8]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8 : 8+8]))
p.Compression = byte2bool((data[16 : 16+1])[0]) p.Compression = Compression((data[16 : 16+1])[0])
copy(p.Checksum[:], data[17:37]) copy(p.Checksum[:], data[17:37])
{ {
l := binary.BigEndian.Uint32(data[37 : 37+4]) l := binary.BigEndian.Uint32(data[37 : 37+4])
...@@ -10647,7 +10671,7 @@ overflow: ...@@ -10647,7 +10671,7 @@ overflow:
} }
func (p *AddObject) neoMsgEncodedLenM() int { func (p *AddObject) neoMsgEncodedLenM() int {
return 54 + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData()) return 53 + msgpack.Uint8Size(uint8(p.Compression)) + msgpack.BinHeadSize(len(p.Data.XData())) + len(p.Data.XData())
} }
func (p *AddObject) neoMsgEncodeM(data []byte) { func (p *AddObject) neoMsgEncodeM(data []byte) {
...@@ -10658,14 +10682,17 @@ func (p *AddObject) neoMsgEncodeM(data []byte) { ...@@ -10658,14 +10682,17 @@ func (p *AddObject) neoMsgEncodeM(data []byte) {
data[11] = byte(msgpack.Bin8) data[11] = byte(msgpack.Bin8)
data[12] = 8 data[12] = 8
binary.BigEndian.PutUint64(data[13:], uint64(p.Serial)) binary.BigEndian.PutUint64(data[13:], uint64(p.Serial))
data[21] = byte(msgpack.Bool(p.Compression)) {
data[22] = byte(msgpack.Bin8) n := msgpack.PutUint8(data[21:], uint8(p.Compression))
data[23] = 20 data = data[21+n:]
copy(data[24:], p.Checksum[:]) }
data[0] = byte(msgpack.Bin8)
data[1] = 20
copy(data[2:], p.Checksum[:])
{ {
l := len(p.Data.XData()) l := len(p.Data.XData())
n := msgpack.PutBinHead(data[44:], l) n := msgpack.PutBinHead(data[22:], l)
data = data[44+n:] data = data[22+n:]
copy(data, p.Data.XData()) copy(data, p.Data.XData())
data = data[l:] data = data[l:]
} }
...@@ -10676,7 +10703,7 @@ func (p *AddObject) neoMsgEncodeM(data []byte) { ...@@ -10676,7 +10703,7 @@ func (p *AddObject) neoMsgEncodeM(data []byte) {
func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) { func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 44 { if len(data) < 21 {
goto overflow goto overflow
} }
if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|6; op != opOk { if op, opOk := msgpack.Op(data[0]), msgpack.FixArray_4|6; op != opOk {
...@@ -10696,22 +10723,27 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -10696,22 +10723,27 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("AddObject.Serial", l, 8) return 0, mdecodeLen8Err("AddObject.Serial", l, 8)
} }
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[13:])) p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[13:]))
switch op := msgpack.Op(data[21]); op { data = data[21:]
default: {
return 0, mdecodeOpErr("AddObject.Compression", op, msgpack.True, msgpack.False) v, tail, err := msgp.ReadUint8Bytes(data)
case msgpack.True: if err != nil {
p.Compression = true return 0, mdecodeErr("AddObject.Compression", err)
case msgpack.False:
p.Compression = false
} }
if op := msgpack.Op(data[22]); op != msgpack.Bin8 { p.Compression = Compression(v)
nread += uint64(len(data) - len(tail))
data = tail
}
if len(data) < 22 {
goto overflow
}
if op := msgpack.Op(data[0]); op != msgpack.Bin8 {
return 0, mdecodeOpErr("AddObject.Checksum", op, msgpack.Bin8) return 0, mdecodeOpErr("AddObject.Checksum", op, msgpack.Bin8)
} }
if l := data[23]; l != 20 { if l := data[1]; l != 20 {
return 0, mdecodeLen8Err("AddObject.Checksum", l, 20) return 0, mdecodeLen8Err("AddObject.Checksum", l, 20)
} }
copy(p.Checksum[:], data[24:44]) copy(p.Checksum[:], data[2:22])
data = data[44:] data = data[22:]
{ {
b, tail, err := msgp.ReadBytesZC(data) b, tail, err := msgp.ReadBytesZC(data)
if err != nil { if err != nil {
...@@ -10732,7 +10764,7 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -10732,7 +10764,7 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
return 0, mdecodeLen8Err("AddObject.DataSerial", l, 8) return 0, mdecodeLen8Err("AddObject.DataSerial", l, 8)
} }
p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[2:])) p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[2:]))
return 54 + int(nread), nil return 53 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
......
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