Commit 05463172 authored by Kirill Smelkov's avatar Kirill Smelkov

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

In commit 5f13cc85 I changed enum encodings from int32 to int8, but did
not noticed that NEO/py commit 52db5607 ("protocol: a single byte is
more than enough to encode enums") despite specified intent and
ErrorCodes being marked with @Enum, changed encoding only for fields
that are marked as PEnum in structures. In NEO/py the Error.code field
is still marked as PNumber which encodes as 32-bit integer on the wire.
-> Fix it back.

With recent xtesting.DrvTestLoad update this error was manifesting itself as (on @t branch):

--- FAIL: TestLoad (2.08s)
    --- FAIL: TestLoad/py (2.07s)
        xtesting.go:306: load 0285cbac258bf265:0000000000000000: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac258bf265:0000000000000000: 127.0.0.1:42288 - 127.0.0.1:37109 .5: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac258bf265:0000000000000000: 0000000000000000: object was not yet created
        xtesting.go:306: load 0285cbac3d0369e5:0000000000000001: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac3d0369e5:0000000000000001: 127.0.0.1:42288 - 127.0.0.1:37109 .13: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac3d0369e5:0000000000000001: 0000000000000001: object was not yet created
        xtesting.go:306: load 0285cbac41b4e832:0000000000000002: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac41b4e832:0000000000000002: 127.0.0.1:42288 - 127.0.0.1:37109 .21: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac41b4e832:0000000000000002: 0000000000000002: object was not yet created
        xtesting.go:306: load 0285cbac4666667f:0000000000000003: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac4666667f:0000000000000003: 127.0.0.1:42288 - 127.0.0.1:37109 .29: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac4666667f:0000000000000003: 0000000000000003: object was not yet created
        xtesting.go:306: load 0285cbac4fc96318:0000000000000004: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac4fc96318:0000000000000004: 127.0.0.1:42288 - 127.0.0.1:37109 .41: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac4fc96318:0000000000000004: 0000000000000004: object was not yet created
        xtesting.go:306: load 0285cbac547ae165:0000000000000005: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac547ae165:0000000000000005: 127.0.0.1:42288 - 127.0.0.1:37109 .49: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac547ae165:0000000000000005: 0000000000000005: object was not yet created
        xtesting.go:306: load 0285cbac628f5c4b:0000000000000006: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbac628f5c4b:0000000000000006: 127.0.0.1:42288 - 127.0.0.1:37109 .65: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbac628f5c4b:0000000000000006: 0000000000000006: object was not yet created
        xtesting.go:306: load 0285cbaca444447f:0000000000000007: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbaca444447f:0000000000000007: 127.0.0.1:42288 - 127.0.0.1:37109 .125: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbaca444447f:0000000000000007: 0000000000000007: object was not yet created
        xtesting.go:306: load 0285cbacbbbbbbff:0000000000000008: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbacbbbbbbff:0000000000000008: 127.0.0.1:42288 - 127.0.0.1:37109 .149: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbacbbbbbbff:0000000000000008: 0000000000000008: object was not yet created
        xtesting.go:306: load 0285cbad80da7498:0000000000000009: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 0285cbad80da7498:0000000000000009: 127.0.0.1:42288 - 127.0.0.1:37109 .269: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 0285cbad80da7498:0000000000000009: 0000000000000009: object was not yet created
        xtesting.go:331: load 7fffffffffffffff:000000000000000a: returned err unexpected:
            have: neo://1@127.0.0.1:32731: load 7fffffffffffffff:000000000000000a: 127.0.0.1:42288 - 127.0.0.1:37109 .295: decode: decode: buffer overflow
            want: neo://1@127.0.0.1:32731: load 7fffffffffffffff:000000000000000a: 000000000000000a: no such object
parent f8696942
...@@ -134,7 +134,7 @@ var ErrDecodeOverflow = errors.New("decode: buffer overflow") ...@@ -134,7 +134,7 @@ var ErrDecodeOverflow = errors.New("decode: buffer overflow")
// ---- messages ---- // ---- messages ----
type ErrorCode int8 type ErrorCode uint32
const ( const (
ACK ErrorCode = iota ACK ErrorCode = iota
DENIED DENIED
......
...@@ -168,8 +168,8 @@ func TestMsgMarshal(t *testing.T) { ...@@ -168,8 +168,8 @@ func TestMsgMarshal(t *testing.T) {
// empty // empty
{&Ping{}, ""}, {&Ping{}, ""},
// uint8, string // uint32, string
{&Error{Code: 0x04, Message: "hello"}, "\x04\x00\x00\x00\x05hello"}, {&Error{Code: 0x01020304, Message: "hello"}, "\x01\x02\x03\x04\x00\x00\x00\x05hello"},
// Oid, Tid, bool, Checksum, []byte // Oid, Tid, bool, Checksum, []byte
{&StoreObject{ {&StoreObject{
......
...@@ -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 5 + len(p.Message) return 8 + len(p.Message)
} }
func (p *Error) NEOMsgEncode(data []byte) { func (p *Error) NEOMsgEncode(data []byte) {
(data[0:])[0] = uint8(int8(p.Code)) binary.BigEndian.PutUint32(data[0:], uint32(p.Code))
{ {
l := uint32(len(p.Message)) l := uint32(len(p.Message))
binary.BigEndian.PutUint32(data[1:], l) binary.BigEndian.PutUint32(data[4:], l)
data = data[5:] data = data[8:]
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) < 5 { if len(data) < 8 {
goto overflow goto overflow
} }
p.Code = ErrorCode(int8((data[0 : 0+1])[0])) p.Code = ErrorCode(binary.BigEndian.Uint32(data[0 : 0+4]))
{ {
l := binary.BigEndian.Uint32(data[1 : 1+4]) l := binary.BigEndian.Uint32(data[4 : 4+4])
data = data[5:] data = data[8:]
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 5 + int(nread), nil return 8 + int(nread), nil
overflow: overflow:
return 0, ErrDecodeOverflow return 0, ErrDecodeOverflow
......
...@@ -28,7 +28,7 @@ const _ErrorCode_name = "ACKDENIEDNOT_READYOID_NOT_FOUNDTID_NOT_FOUNDOID_DOES_NO ...@@ -28,7 +28,7 @@ const _ErrorCode_name = "ACKDENIEDNOT_READYOID_NOT_FOUNDTID_NOT_FOUNDOID_DOES_NO
var _ErrorCode_index = [...]uint8{0, 3, 9, 18, 31, 44, 62, 76, 93, 107, 130, 147, 163, 185} var _ErrorCode_index = [...]uint8{0, 3, 9, 18, 31, 44, 62, 76, 93, 107, 130, 147, 163, 185}
func (i ErrorCode) String() string { func (i ErrorCode) String() string {
if i < 0 || i >= ErrorCode(len(_ErrorCode_index)-1) { if 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