Commit 144dafa0 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: Switch enum encoding from int32 to int8

This corresponds to NEO/py commit 52db5607 ("protocol: a single byte is
more than enough to encode enums").
parent 7cfe181b
...@@ -135,7 +135,7 @@ var ErrDecodeOverflow = errors.New("decode: buffer overflow") ...@@ -135,7 +135,7 @@ var ErrDecodeOverflow = errors.New("decode: buffer overflow")
// ---- messages ---- // ---- messages ----
type ErrorCode uint32 type ErrorCode int8
const ( const (
ACK ErrorCode = iota ACK ErrorCode = iota
NOT_READY NOT_READY
...@@ -154,7 +154,7 @@ const ( ...@@ -154,7 +154,7 @@ const (
// XXX move this to neo.clusterState wrapping proto.ClusterState? // XXX move this to neo.clusterState wrapping proto.ClusterState?
//trace:event traceClusterStateChanged(cs *ClusterState) //trace:event traceClusterStateChanged(cs *ClusterState)
type ClusterState int32 type ClusterState int8
const ( const (
// The cluster is initially in the RECOVERING state, and it goes back to // The cluster is initially in the RECOVERING state, and it goes back to
// this state whenever the partition table becomes non-operational again. // this state whenever the partition table becomes non-operational again.
...@@ -187,7 +187,7 @@ const ( ...@@ -187,7 +187,7 @@ const (
STOPPING_BACKUP STOPPING_BACKUP
) )
type NodeType int32 type NodeType int8
const ( const (
MASTER NodeType = iota MASTER NodeType = iota
STORAGE STORAGE
...@@ -195,7 +195,7 @@ const ( ...@@ -195,7 +195,7 @@ const (
ADMIN ADMIN
) )
type NodeState int32 type NodeState int8
const ( const (
UNKNOWN NodeState = iota //short: U // XXX tag prefix name ? UNKNOWN NodeState = iota //short: U // XXX tag prefix name ?
DOWN //short: D DOWN //short: D
...@@ -203,7 +203,7 @@ const ( ...@@ -203,7 +203,7 @@ const (
PENDING //short: P PENDING //short: P
) )
type CellState int32 type CellState int8
const ( const (
// Write-only cell. Last transactions are missing because storage is/was down // Write-only cell. Last transactions are missing because storage is/was down
// for a while, or because it is new for the partition. It usually becomes // for a while, or because it is new for the partition. It usually becomes
......
...@@ -42,6 +42,11 @@ func hex(s string) string { ...@@ -42,6 +42,11 @@ func hex(s string) string {
return string(b) return string(b)
} }
// uint8 -> string as encoded on the wire
func u8(v uint8) string {
return string(v)
}
// uint16 -> string as encoded on the wire // uint16 -> string as encoded on the wire
func u16(v uint16) string { func u16(v uint16) string {
var b [2]byte var b [2]byte
...@@ -163,8 +168,8 @@ func TestMsgMarshal(t *testing.T) { ...@@ -163,8 +168,8 @@ func TestMsgMarshal(t *testing.T) {
// empty // empty
{&Ping{}, ""}, {&Ping{}, ""},
// uint32, string // uint8, string
{&Error{Code: 0x01020304, Message: "hello"}, "\x01\x02\x03\x04\x00\x00\x00\x05hello"}, {&Error{Code: 0x04, Message: "hello"}, "\x04\x00\x00\x00\x05hello"},
// Oid, Tid, bool, Checksum, []byte // Oid, Tid, bool, Checksum, []byte
{&StoreObject{ {&StoreObject{
...@@ -194,9 +199,9 @@ func TestMsgMarshal(t *testing.T) { ...@@ -194,9 +199,9 @@ func TestMsgMarshal(t *testing.T) {
hex("0102030405060708") + hex("0102030405060708") +
hex("00000003") + hex("00000003") +
hex("00000001000000020000000b000000010000001100000000") + hex("00000001000000020000000b010000001100") +
hex("00000002000000010000000b00000002") + hex("00000002000000010000000b02") +
hex("00000007000000030000000b000000030000000f000000040000001700000001"), hex("00000007000000030000000b030000000f040000001701"),
}, },
// map[Oid]struct {Tid,Tid,bool} // map[Oid]struct {Tid,Tid,bool}
...@@ -247,7 +252,7 @@ func TestMsgMarshal(t *testing.T) { ...@@ -247,7 +252,7 @@ func TestMsgMarshal(t *testing.T) {
// uint32, Address, string, IdTime // uint32, Address, string, IdTime
{&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678}, {&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678},
u32(2) + u32(17) + u32(9) + u8(2) + u32(17) + u32(9) +
"localhost" + u16(7777) + "localhost" + u16(7777) +
u32(6) + "myname" + u32(6) + "myname" +
hex("3fbf9add1091c895"), hex("3fbf9add1091c895"),
...@@ -258,7 +263,7 @@ func TestMsgMarshal(t *testing.T) { ...@@ -258,7 +263,7 @@ func TestMsgMarshal(t *testing.T) {
{CLIENT, Address{}, UUID(CLIENT, 1), RUNNING, 1504466245.925599}}}, {CLIENT, Address{}, UUID(CLIENT, 1), RUNNING, 1504466245.925599}}},
hex("41d66b15517b469d") + u32(1) + hex("41d66b15517b469d") + u32(1) +
u32(2) + u32(0) /* <- ø Address */ + hex("e0000001") + u32(2) + u8(2) + u32(0) /* <- ø Address */ + hex("e0000001") + u8(2) +
hex("41d66b15517b3d04"), hex("41d66b15517b3d04"),
}, },
......
...@@ -22,15 +22,15 @@ func (*Error) NEOMsgCode() uint16 { ...@@ -22,15 +22,15 @@ func (*Error) NEOMsgCode() uint16 {
} }
func (p *Error) NEOMsgEncodedLen() int { func (p *Error) NEOMsgEncodedLen() int {
return 8 + len(p.Message) return 5 + len(p.Message)
} }
func (p *Error) NEOMsgEncode(data []byte) { func (p *Error) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(p.Code)) (data[0:])[0] = uint8(int8(p.Code))
{ {
l := uint32(len(p.Message)) l := uint32(len(p.Message))
binary.BigEndian.PutUint32(data[4:], l) binary.BigEndian.PutUint32(data[1:], l)
data = data[8:] data = data[5:]
copy(data, p.Message) copy(data, p.Message)
data = data[l:] data = data[l:]
} }
...@@ -38,13 +38,13 @@ func (p *Error) NEOMsgEncode(data []byte) { ...@@ -38,13 +38,13 @@ func (p *Error) NEOMsgEncode(data []byte) {
func (p *Error) NEOMsgDecode(data []byte) (int, error) { func (p *Error) NEOMsgDecode(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 8 { if len(data) < 5 {
goto overflow goto overflow
} }
p.Code = ErrorCode(binary.BigEndian.Uint32(data[0 : 0+4])) p.Code = ErrorCode(int8((data[0 : 0+1])[0]))
{ {
l := binary.BigEndian.Uint32(data[4 : 4+4]) l := binary.BigEndian.Uint32(data[1 : 1+4])
data = data[8:] data = data[5:]
if uint64(len(data)) < uint64(l) { if uint64(len(data)) < uint64(l) {
goto overflow goto overflow
} }
...@@ -52,7 +52,7 @@ func (p *Error) NEOMsgDecode(data []byte) (int, error) { ...@@ -52,7 +52,7 @@ func (p *Error) NEOMsgDecode(data []byte) (int, error) {
p.Message = string(data[:l]) p.Message = string(data[:l])
data = data[l:] data = data[l:]
} }
return 8 + int(nread), nil return 5 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -65,15 +65,15 @@ func (*RequestIdentification) NEOMsgCode() uint16 { ...@@ -65,15 +65,15 @@ func (*RequestIdentification) NEOMsgCode() uint16 {
} }
func (p *RequestIdentification) NEOMsgEncodedLen() int { func (p *RequestIdentification) NEOMsgEncodedLen() int {
return 12 + p.Address.neoEncodedLen() + len(p.ClusterName) + p.IdTime.neoEncodedLen() return 9 + p.Address.neoEncodedLen() + len(p.ClusterName) + p.IdTime.neoEncodedLen()
} }
func (p *RequestIdentification) NEOMsgEncode(data []byte) { func (p *RequestIdentification) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.NodeType))) (data[0:])[0] = uint8(int8(p.NodeType))
binary.BigEndian.PutUint32(data[4:], uint32(int32(p.UUID))) binary.BigEndian.PutUint32(data[1:], uint32(int32(p.UUID)))
{ {
n := p.Address.neoEncode(data[8:]) n := p.Address.neoEncode(data[5:])
data = data[8+n:] data = data[5+n:]
} }
{ {
l := uint32(len(p.ClusterName)) l := uint32(len(p.ClusterName))
...@@ -90,12 +90,12 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) { ...@@ -90,12 +90,12 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) { func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
var nread uint64 var nread uint64
if len(data) < 8 { if len(data) < 5 {
goto overflow goto overflow
} }
p.NodeType = NodeType(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.NodeType = NodeType(int8((data[0 : 0+1])[0]))
p.UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) p.UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[1 : 1+4])))
data = data[8:] data = data[5:]
{ {
n, ok := p.Address.neoDecode(data) n, ok := p.Address.neoDecode(data)
if !ok { if !ok {
...@@ -125,7 +125,7 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) { ...@@ -125,7 +125,7 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
data = data[n:] data = data[n:]
nread += n nread += n
} }
return 12 + int(nread), nil return 9 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -138,27 +138,27 @@ func (*AcceptIdentification) NEOMsgCode() uint16 { ...@@ -138,27 +138,27 @@ func (*AcceptIdentification) NEOMsgCode() uint16 {
} }
func (p *AcceptIdentification) NEOMsgEncodedLen() int { func (p *AcceptIdentification) NEOMsgEncodedLen() int {
return 20 return 17
} }
func (p *AcceptIdentification) NEOMsgEncode(data []byte) { func (p *AcceptIdentification) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.NodeType))) (data[0:])[0] = uint8(int8(p.NodeType))
binary.BigEndian.PutUint32(data[4:], uint32(int32(p.MyUUID))) binary.BigEndian.PutUint32(data[1:], uint32(int32(p.MyUUID)))
binary.BigEndian.PutUint32(data[8:], p.NumPartitions) binary.BigEndian.PutUint32(data[5:], p.NumPartitions)
binary.BigEndian.PutUint32(data[12:], p.NumReplicas) binary.BigEndian.PutUint32(data[9:], p.NumReplicas)
binary.BigEndian.PutUint32(data[16:], uint32(int32(p.YourUUID))) binary.BigEndian.PutUint32(data[13:], uint32(int32(p.YourUUID)))
} }
func (p *AcceptIdentification) NEOMsgDecode(data []byte) (int, error) { func (p *AcceptIdentification) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 20 { if len(data) < 17 {
goto overflow goto overflow
} }
p.NodeType = NodeType(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.NodeType = NodeType(int8((data[0 : 0+1])[0]))
p.MyUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) p.MyUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[1 : 1+4])))
p.NumPartitions = binary.BigEndian.Uint32(data[8 : 8+4]) p.NumPartitions = binary.BigEndian.Uint32(data[5 : 5+4])
p.NumReplicas = binary.BigEndian.Uint32(data[12 : 12+4]) p.NumReplicas = binary.BigEndian.Uint32(data[9 : 9+4])
p.YourUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[16 : 16+4]))) p.YourUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[13 : 13+4])))
return 20, nil return 17, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -329,7 +329,7 @@ func (p *NotifyNodeInformation) NEOMsgEncodedLen() int { ...@@ -329,7 +329,7 @@ func (p *NotifyNodeInformation) NEOMsgEncodedLen() int {
a := &p.NodeList[i] a := &p.NodeList[i]
size += (*a).Addr.neoEncodedLen() + (*a).IdTime.neoEncodedLen() size += (*a).Addr.neoEncodedLen() + (*a).IdTime.neoEncodedLen()
} }
return 4 + p.IdTime.neoEncodedLen() + len(p.NodeList)*12 + size return 4 + p.IdTime.neoEncodedLen() + len(p.NodeList)*6 + size
} }
func (p *NotifyNodeInformation) NEOMsgEncode(data []byte) { func (p *NotifyNodeInformation) NEOMsgEncode(data []byte) {
...@@ -343,16 +343,16 @@ func (p *NotifyNodeInformation) NEOMsgEncode(data []byte) { ...@@ -343,16 +343,16 @@ func (p *NotifyNodeInformation) NEOMsgEncode(data []byte) {
data = data[4:] data = data[4:]
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).Type))) (data[0:])[0] = uint8(int8((*a).Type))
{ {
n := (*a).Addr.neoEncode(data[4:]) n := (*a).Addr.neoEncode(data[1:])
data = data[4+n:] data = data[1+n:]
} }
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).State))) (data[4:])[0] = uint8(int8((*a).State))
{ {
n := (*a).IdTime.neoEncode(data[8:]) n := (*a).IdTime.neoEncode(data[5:])
data = data[8+n:] data = data[5+n:]
} }
data = data[0:] data = data[0:]
} }
...@@ -378,11 +378,11 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) { ...@@ -378,11 +378,11 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) {
p.NodeList = make([]NodeInfo, l) p.NodeList = make([]NodeInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
(*a).Type = NodeType(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).Type = NodeType(int8((data[0 : 0+1])[0]))
data = data[4:] data = data[1:]
{ {
n, ok := (*a).Addr.neoDecode(data) n, ok := (*a).Addr.neoDecode(data)
if !ok { if !ok {
...@@ -391,12 +391,12 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) { ...@@ -391,12 +391,12 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) {
data = data[n:] data = data[n:]
nread += n nread += n
} }
if len(data) < 8 { if len(data) < 5 {
goto overflow goto overflow
} }
(*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
(*a).State = NodeState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).State = NodeState(int8((data[4 : 4+1])[0]))
data = data[8:] data = data[5:]
{ {
n, ok := (*a).IdTime.neoDecode(data) n, ok := (*a).IdTime.neoDecode(data)
if !ok { if !ok {
...@@ -406,7 +406,7 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) { ...@@ -406,7 +406,7 @@ func (p *NotifyNodeInformation) NEOMsgDecode(data []byte) (int, error) {
nread += n nread += n
} }
} }
nread += uint64(l) * 12 nread += uint64(l) * 6
} }
return 4 + int(nread), nil return 4 + int(nread), nil
...@@ -531,7 +531,7 @@ func (p *AnswerPartitionTable) NEOMsgEncodedLen() int { ...@@ -531,7 +531,7 @@ func (p *AnswerPartitionTable) NEOMsgEncodedLen() int {
var size int var size int
for i := 0; i < len(p.RowList); i++ { for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i] a := &p.RowList[i]
size += len((*a).CellList) * 8 size += len((*a).CellList) * 5
} }
return 12 + len(p.RowList)*8 + size return 12 + len(p.RowList)*8 + size
} }
...@@ -552,8 +552,8 @@ func (p *AnswerPartitionTable) NEOMsgEncode(data []byte) { ...@@ -552,8 +552,8 @@ func (p *AnswerPartitionTable) NEOMsgEncode(data []byte) {
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).State))) (data[4:])[0] = uint8(int8((*a).State))
data = data[8:] data = data[5:]
} }
} }
data = data[0:] data = data[0:]
...@@ -580,16 +580,16 @@ func (p *AnswerPartitionTable) NEOMsgDecode(data []byte) (int, error) { ...@@ -580,16 +580,16 @@ func (p *AnswerPartitionTable) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[4 : 4+4]) l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[8:] data = data[8:]
if uint64(len(data)) < uint64(l)*8 { if uint64(len(data)) < uint64(l)*5 {
goto overflow goto overflow
} }
nread += uint64(l) * 8 nread += uint64(l) * 5
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
(*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
(*a).State = CellState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).State = CellState(int8((data[4 : 4+1])[0]))
data = data[8:] data = data[5:]
} }
} }
} }
...@@ -611,7 +611,7 @@ func (p *SendPartitionTable) NEOMsgEncodedLen() int { ...@@ -611,7 +611,7 @@ func (p *SendPartitionTable) NEOMsgEncodedLen() int {
var size int var size int
for i := 0; i < len(p.RowList); i++ { for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i] a := &p.RowList[i]
size += len((*a).CellList) * 8 size += len((*a).CellList) * 5
} }
return 12 + len(p.RowList)*8 + size return 12 + len(p.RowList)*8 + size
} }
...@@ -632,8 +632,8 @@ func (p *SendPartitionTable) NEOMsgEncode(data []byte) { ...@@ -632,8 +632,8 @@ func (p *SendPartitionTable) NEOMsgEncode(data []byte) {
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).State))) (data[4:])[0] = uint8(int8((*a).State))
data = data[8:] data = data[5:]
} }
} }
data = data[0:] data = data[0:]
...@@ -660,16 +660,16 @@ func (p *SendPartitionTable) NEOMsgDecode(data []byte) (int, error) { ...@@ -660,16 +660,16 @@ func (p *SendPartitionTable) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[4 : 4+4]) l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[8:] data = data[8:]
if uint64(len(data)) < uint64(l)*8 { if uint64(len(data)) < uint64(l)*5 {
goto overflow goto overflow
} }
nread += uint64(l) * 8 nread += uint64(l) * 5
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
(*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
(*a).State = CellState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).State = CellState(int8((data[4 : 4+1])[0]))
data = data[8:] data = data[5:]
} }
} }
} }
...@@ -688,7 +688,7 @@ func (*NotifyPartitionChanges) NEOMsgCode() uint16 { ...@@ -688,7 +688,7 @@ func (*NotifyPartitionChanges) NEOMsgCode() uint16 {
} }
func (p *NotifyPartitionChanges) NEOMsgEncodedLen() int { func (p *NotifyPartitionChanges) NEOMsgEncodedLen() int {
return 12 + len(p.CellList)*12 return 12 + len(p.CellList)*9
} }
func (p *NotifyPartitionChanges) NEOMsgEncode(data []byte) { func (p *NotifyPartitionChanges) NEOMsgEncode(data []byte) {
...@@ -701,8 +701,8 @@ func (p *NotifyPartitionChanges) NEOMsgEncode(data []byte) { ...@@ -701,8 +701,8 @@ func (p *NotifyPartitionChanges) NEOMsgEncode(data []byte) {
a := &p.CellList[i] a := &p.CellList[i]
binary.BigEndian.PutUint32(data[0:], (*a).Offset) binary.BigEndian.PutUint32(data[0:], (*a).Offset)
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).CellInfo.UUID))) binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).CellInfo.UUID)))
binary.BigEndian.PutUint32(data[8:], uint32(int32((*a).CellInfo.State))) (data[8:])[0] = uint8(int8((*a).CellInfo.State))
data = data[12:] data = data[9:]
} }
} }
} }
...@@ -716,10 +716,10 @@ func (p *NotifyPartitionChanges) NEOMsgDecode(data []byte) (int, error) { ...@@ -716,10 +716,10 @@ func (p *NotifyPartitionChanges) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[8 : 8+4]) l := binary.BigEndian.Uint32(data[8 : 8+4])
data = data[12:] data = data[12:]
if uint64(len(data)) < uint64(l)*12 { if uint64(len(data)) < uint64(l)*9 {
goto overflow goto overflow
} }
nread += uint64(l) * 12 nread += uint64(l) * 9
p.CellList = make([]struct { p.CellList = make([]struct {
Offset uint32 Offset uint32
CellInfo CellInfo CellInfo CellInfo
...@@ -728,8 +728,8 @@ func (p *NotifyPartitionChanges) NEOMsgDecode(data []byte) (int, error) { ...@@ -728,8 +728,8 @@ func (p *NotifyPartitionChanges) NEOMsgDecode(data []byte) (int, error) {
a := &p.CellList[i] a := &p.CellList[i]
(*a).Offset = binary.BigEndian.Uint32(data[0 : 0+4]) (*a).Offset = binary.BigEndian.Uint32(data[0 : 0+4])
(*a).CellInfo.UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).CellInfo.UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[4 : 4+4])))
(*a).CellInfo.State = CellState(int32(binary.BigEndian.Uint32(data[8 : 8+4]))) (*a).CellInfo.State = CellState(int8((data[8 : 8+1])[0]))
data = data[12:] data = data[9:]
} }
} }
return 12 + int(nread), nil return 12 + int(nread), nil
...@@ -2306,7 +2306,7 @@ func (p *AnswerPartitionList) NEOMsgEncodedLen() int { ...@@ -2306,7 +2306,7 @@ func (p *AnswerPartitionList) NEOMsgEncodedLen() int {
var size int var size int
for i := 0; i < len(p.RowList); i++ { for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i] a := &p.RowList[i]
size += len((*a).CellList) * 8 size += len((*a).CellList) * 5
} }
return 12 + len(p.RowList)*8 + size return 12 + len(p.RowList)*8 + size
} }
...@@ -2327,8 +2327,8 @@ func (p *AnswerPartitionList) NEOMsgEncode(data []byte) { ...@@ -2327,8 +2327,8 @@ func (p *AnswerPartitionList) NEOMsgEncode(data []byte) {
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).State))) (data[4:])[0] = uint8(int8((*a).State))
data = data[8:] data = data[5:]
} }
} }
data = data[0:] data = data[0:]
...@@ -2355,16 +2355,16 @@ func (p *AnswerPartitionList) NEOMsgDecode(data []byte) (int, error) { ...@@ -2355,16 +2355,16 @@ func (p *AnswerPartitionList) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[4 : 4+4]) l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[8:] data = data[8:]
if uint64(len(data)) < uint64(l)*8 { if uint64(len(data)) < uint64(l)*5 {
goto overflow goto overflow
} }
nread += uint64(l) * 8 nread += uint64(l) * 5
(*a).CellList = make([]CellInfo, l) (*a).CellList = make([]CellInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &(*a).CellList[i] a := &(*a).CellList[i]
(*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
(*a).State = CellState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).State = CellState(int8((data[4 : 4+1])[0]))
data = data[8:] data = data[5:]
} }
} }
} }
...@@ -2383,19 +2383,19 @@ func (*NodeList) NEOMsgCode() uint16 { ...@@ -2383,19 +2383,19 @@ func (*NodeList) NEOMsgCode() uint16 {
} }
func (p *NodeList) NEOMsgEncodedLen() int { func (p *NodeList) NEOMsgEncodedLen() int {
return 4 return 1
} }
func (p *NodeList) NEOMsgEncode(data []byte) { func (p *NodeList) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.NodeType))) (data[0:])[0] = uint8(int8(p.NodeType))
} }
func (p *NodeList) NEOMsgDecode(data []byte) (int, error) { func (p *NodeList) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
p.NodeType = NodeType(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.NodeType = NodeType(int8((data[0 : 0+1])[0]))
return 4, nil return 1, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -2413,7 +2413,7 @@ func (p *AnswerNodeList) NEOMsgEncodedLen() int { ...@@ -2413,7 +2413,7 @@ func (p *AnswerNodeList) NEOMsgEncodedLen() int {
a := &p.NodeList[i] a := &p.NodeList[i]
size += (*a).Addr.neoEncodedLen() + (*a).IdTime.neoEncodedLen() size += (*a).Addr.neoEncodedLen() + (*a).IdTime.neoEncodedLen()
} }
return 4 + len(p.NodeList)*12 + size return 4 + len(p.NodeList)*6 + size
} }
func (p *AnswerNodeList) NEOMsgEncode(data []byte) { func (p *AnswerNodeList) NEOMsgEncode(data []byte) {
...@@ -2423,16 +2423,16 @@ func (p *AnswerNodeList) NEOMsgEncode(data []byte) { ...@@ -2423,16 +2423,16 @@ func (p *AnswerNodeList) NEOMsgEncode(data []byte) {
data = data[4:] data = data[4:]
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).Type))) (data[0:])[0] = uint8(int8((*a).Type))
{ {
n := (*a).Addr.neoEncode(data[4:]) n := (*a).Addr.neoEncode(data[1:])
data = data[4+n:] data = data[1+n:]
} }
binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32((*a).UUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32((*a).State))) (data[4:])[0] = uint8(int8((*a).State))
{ {
n := (*a).IdTime.neoEncode(data[8:]) n := (*a).IdTime.neoEncode(data[5:])
data = data[8+n:] data = data[5+n:]
} }
data = data[0:] data = data[0:]
} }
...@@ -2450,11 +2450,11 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) { ...@@ -2450,11 +2450,11 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) {
p.NodeList = make([]NodeInfo, l) p.NodeList = make([]NodeInfo, l)
for i := 0; uint32(i) < l; i++ { for i := 0; uint32(i) < l; i++ {
a := &p.NodeList[i] a := &p.NodeList[i]
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
(*a).Type = NodeType(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).Type = NodeType(int8((data[0 : 0+1])[0]))
data = data[4:] data = data[1:]
{ {
n, ok := (*a).Addr.neoDecode(data) n, ok := (*a).Addr.neoDecode(data)
if !ok { if !ok {
...@@ -2463,12 +2463,12 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) { ...@@ -2463,12 +2463,12 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) {
data = data[n:] data = data[n:]
nread += n nread += n
} }
if len(data) < 8 { if len(data) < 5 {
goto overflow goto overflow
} }
(*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) (*a).UUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
(*a).State = NodeState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) (*a).State = NodeState(int8((data[4 : 4+1])[0]))
data = data[8:] data = data[5:]
{ {
n, ok := (*a).IdTime.neoDecode(data) n, ok := (*a).IdTime.neoDecode(data)
if !ok { if !ok {
...@@ -2478,7 +2478,7 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) { ...@@ -2478,7 +2478,7 @@ func (p *AnswerNodeList) NEOMsgDecode(data []byte) (int, error) {
nread += n nread += n
} }
} }
nread += uint64(l) * 12 nread += uint64(l) * 6
} }
return 4 + int(nread), nil return 4 + int(nread), nil
...@@ -2493,21 +2493,21 @@ func (*SetNodeState) NEOMsgCode() uint16 { ...@@ -2493,21 +2493,21 @@ func (*SetNodeState) NEOMsgCode() uint16 {
} }
func (p *SetNodeState) NEOMsgEncodedLen() int { func (p *SetNodeState) NEOMsgEncodedLen() int {
return 8 return 5
} }
func (p *SetNodeState) NEOMsgEncode(data []byte) { func (p *SetNodeState) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.NodeUUID))) binary.BigEndian.PutUint32(data[0:], uint32(int32(p.NodeUUID)))
binary.BigEndian.PutUint32(data[4:], uint32(int32(p.NodeState))) (data[4:])[0] = uint8(int8(p.NodeState))
} }
func (p *SetNodeState) NEOMsgDecode(data []byte) (int, error) { func (p *SetNodeState) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 8 { if len(data) < 5 {
goto overflow goto overflow
} }
p.NodeUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.NodeUUID = NodeUUID(int32(binary.BigEndian.Uint32(data[0 : 0+4])))
p.NodeState = NodeState(int32(binary.BigEndian.Uint32(data[4 : 4+4]))) p.NodeState = NodeState(int8((data[4 : 4+1])[0]))
return 8, nil return 5, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -2616,19 +2616,19 @@ func (*SetClusterState) NEOMsgCode() uint16 { ...@@ -2616,19 +2616,19 @@ func (*SetClusterState) NEOMsgCode() uint16 {
} }
func (p *SetClusterState) NEOMsgEncodedLen() int { func (p *SetClusterState) NEOMsgEncodedLen() int {
return 4 return 1
} }
func (p *SetClusterState) NEOMsgEncode(data []byte) { func (p *SetClusterState) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.State))) (data[0:])[0] = uint8(int8(p.State))
} }
func (p *SetClusterState) NEOMsgDecode(data []byte) (int, error) { func (p *SetClusterState) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
p.State = ClusterState(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.State = ClusterState(int8((data[0 : 0+1])[0]))
return 4, nil return 1, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -2716,19 +2716,19 @@ func (*NotifyClusterState) NEOMsgCode() uint16 { ...@@ -2716,19 +2716,19 @@ func (*NotifyClusterState) NEOMsgCode() uint16 {
} }
func (p *NotifyClusterState) NEOMsgEncodedLen() int { func (p *NotifyClusterState) NEOMsgEncodedLen() int {
return 4 return 1
} }
func (p *NotifyClusterState) NEOMsgEncode(data []byte) { func (p *NotifyClusterState) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.State))) (data[0:])[0] = uint8(int8(p.State))
} }
func (p *NotifyClusterState) NEOMsgDecode(data []byte) (int, error) { func (p *NotifyClusterState) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
p.State = ClusterState(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.State = ClusterState(int8((data[0 : 0+1])[0]))
return 4, nil return 1, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
...@@ -2758,19 +2758,19 @@ func (*AnswerClusterState) NEOMsgCode() uint16 { ...@@ -2758,19 +2758,19 @@ func (*AnswerClusterState) NEOMsgCode() uint16 {
} }
func (p *AnswerClusterState) NEOMsgEncodedLen() int { func (p *AnswerClusterState) NEOMsgEncodedLen() int {
return 4 return 1
} }
func (p *AnswerClusterState) NEOMsgEncode(data []byte) { func (p *AnswerClusterState) NEOMsgEncode(data []byte) {
binary.BigEndian.PutUint32(data[0:], uint32(int32(p.State))) (data[0:])[0] = uint8(int8(p.State))
} }
func (p *AnswerClusterState) NEOMsgDecode(data []byte) (int, error) { func (p *AnswerClusterState) NEOMsgDecode(data []byte) (int, error) {
if len(data) < 4 { if len(data) < 1 {
goto overflow goto overflow
} }
p.State = ClusterState(int32(binary.BigEndian.Uint32(data[0 : 0+4]))) p.State = ClusterState(int8((data[0 : 0+1])[0]))
return 4, nil return 1, nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
......
...@@ -27,7 +27,7 @@ const _ErrorCode_name = "ACKNOT_READYOID_NOT_FOUNDTID_NOT_FOUNDOID_DOES_NOT_EXIS ...@@ -27,7 +27,7 @@ const _ErrorCode_name = "ACKNOT_READYOID_NOT_FOUNDTID_NOT_FOUNDOID_DOES_NOT_EXIS
var _ErrorCode_index = [...]uint8{0, 3, 12, 25, 38, 56, 70, 87, 101, 124, 141, 157, 179} var _ErrorCode_index = [...]uint8{0, 3, 12, 25, 38, 56, 70, 87, 101, 124, 141, 157, 179}
func (i ErrorCode) String() string { func (i ErrorCode) String() string {
if i >= ErrorCode(len(_ErrorCode_index)-1) { if i < 0 || i >= ErrorCode(len(_ErrorCode_index)-1) {
return "ErrorCode(" + strconv.FormatInt(int64(i), 10) + ")" return "ErrorCode(" + strconv.FormatInt(int64(i), 10) + ")"
} }
return _ErrorCode_name[_ErrorCode_index[i]:_ErrorCode_index[i+1]] return _ErrorCode_name[_ErrorCode_index[i]:_ErrorCode_index[i+1]]
......
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