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