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"),
}, },
......
This diff is collapsed.
...@@ -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