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 !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") +
......
This diff is collapsed.
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